-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
466 lines (462 loc) · 23.3 KB
/
index.js
File metadata and controls
466 lines (462 loc) · 23.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
import * as c from "./constants.js"
import * as accounts from "./server/accounts.js"
import * as comments from "./server/comments.js"
import * as levels from "./server/levels.js"
import * as lists from "./server/lists.js"
import * as likes from "./server/like.js"
import * as users from "./server/users.js"
import * as songs from "./server/songs.js"
import * as socials from "./server/socials.js"
import * as u from "./utils.js"
import * as rewards from "./server/rewards.js"
import * as scores from "./server/leaderboards.js"
export const constants = c
export class GDAccount {
constructor(playerID, accountID, password, username, udid) {
let digits = "1234567890".split("")
this.playerID = playerID || 0
this.accountID = accountID || 0
this.password = password || ""
this.udid = udid || `S15${utils.rs(25, digits)}1000`
this.uuid = playerID || utils.generateRandomUUID()
this.username = username || "Player"
}
}
export class GDClient {
constructor(account, server, endpoints, versions, headers, accountServer, contentServer) {
this.server = server ? server.replace(/\/$/, "") : c.DEFAULT_SERVER
this.accountServer = accountServer ? accountServer.replace(/\/$/, "") : this.server
this.contentServer = contentServer ? contentServer.replace(/\/$/, "") : this.server
if (this.accountServer == c.DEFAULT_SERVER) this.accountServer = c.DEFAULT_ACCOUNT_URL
if (this.contentServer == c.DEFAULT_SERVER) this.contentServer = c.DEFAULT_CONTENT_URL
this.endpoints = endpoints || c.DEFAULT_ENDPOINTS
this.headers = headers || c.DEFAULT_HEADERS_22
this.versions = versions || c.VERSIONS
this.account = account || new GDAccount()
}
likeItem(itemID, special, type, like, callback, params, options, secret) {
likes.likeItem(itemID, special, type, like, this, params, callback, options, secret)
}
likeLevel(levelID, like, callback, params, options, secret) {
likes.likeItem(levelID, 0, 1, like ? 1 : 0, this, params, callback, options, secret)
}
likeComment(commentID, levelID, like, callback, params, options, secret) {
likes.likeItem(commentID, levelID, 2, like ? 1 : 0, this, params, callback, options, secret)
}
likeAccountPost(postID, accountID, like, callback, params, options, secret) {
likes.likeItem(postID, accountID, 3, like ? 1 : 0, this, params, callback, options, secret)
}
likeList(listID, like, callback, params, options, secret) {
likes.likeItem(listID, 0, 4, like ? 1 : 0, this, params, callback, options, secret)
}
rateLevel(levelID, stars, callback, params, options, secret) {
levels.rateLevel(levelID, stars, this, params, callback, options, secret)
}
rateDemon(levelID, rating, callback, params, options, secret) {
levels.rateDemon(levelID, rating, this, params, callback, options, secret)
}
getLevelComments(levelID, count, mode, page, callback, params, options, secret) {
comments.getLevelComments(levelID, count, mode, page, this, params, callback, options, secret)
}
getCommentHistory(playerID, count, mode, callback, params, options, secret) {
comments.getCommentHistory(playerID, count, mode, this, params, callback, options, secret)
}
uploadComment(levelID, content, percentage, callback, params, options, secret) {
comments.uploadComment(levelID, content, percentage, this, params, callback, options, secret)
}
deleteComment(levelID, commentID, callback, params, options, secret) {
comments.deleteComment(levelID, commentID, this, params, callback, options, secret)
}
getProfilePosts(accountID, page, total, callback, params, options, secret) {
comments.getProfilePosts(accountID, page, total, this, params, callback, options, secret)
}
uploadProfilePost(content, callback, params, options, secret) {
comments.uploadProfilePost(content, this, params, callback, options, secret)
}
deleteProfilePost(id, accountID, callback, params, options, secret) {
comments.deleteProfilePost(id, accountID, this, params, callback, options, secret)
}
getLevels(opts, callback, params, options, secret) {
levels.getLevels(opts, this, params, callback, options, secret)
}
getLevelLists(opts, callback, params, options, secret) {
lists.getLevelLists(opts, this, params, callback, options, secret)
}
getMostDownloadedLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 1, ...opts}, this, params, callback, options, secret)
}
getMostDownloadedLevelLists(opts, callback, params, options, secret) {
lists.getLevelLists({type: 1, ...opts}, this, params, callback, options, secret)
}
getMostLikedLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 2, ...opts}, this, params, callback, options, secret)
}
getMostLikedLevelLists(opts, callback, params, options, secret) {
lists.getLevelLists({type: 2, ...opts}, this, params, callback, options, secret)
}
getTrendingLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 3, ...opts}, this, params, callback, options, secret)
}
getTrendingLevelLists(opts, callback, params, options, secret) {
lists.getLevelLists({type: 3, ...opts}, this, params, callback, options, secret)
}
getRecentLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 4, ...opts}, this, params, callback, options, secret)
}
getRecentLevelLists(opts, callback, params, options, secret) {
lists.getLevelLists({type: 4, ...opts}, this, params, callback, options, secret)
}
getFeaturedLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 6, ...opts}, this, params, callback, options, secret)
}
getTopLevelLists(opts, callback, params, options, secret) {
lists.getLevelLists({type: 6, ...opts}, this, params, callback, options, secret)
}
getMagicLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 7, ...opts}, this, params, callback, options, secret)
}
getMagicLevelLists(opts, callback, params, options, secret) {
lists.getLevelLists({type: 7, ...opts}, this, params, callback, options, secret)
}
getSentLevelsOld(opts, callback, params, options, secret) {
levels.getLevels({type: 8, ...opts}, this, params, callback, options, secret)
}
getAwardedLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 11, ...opts}, this, params, callback, options, secret)
}
getAwardedLevelLists(callback, params, options, secret) {
lists.getLevelLists({type: 11, ...opts}, this, params, callback, options, secret)
}
getFriendLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 13, ...opts}, this, params, callback, options, secret)
}
getFriendLevelLists(opts, callback, params, options, secret) {
lists.getLevelLists({type: 13, ...opts}, this, params, callback, options, secret)
}
getMostLikedWorldLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 15, ...opts}, this, params, callback, options, secret)
}
getHallOfFameLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 16, ...opts}, this, params, callback, options, secret)
}
getFeaturedWorldLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 17, ...opts}, this, params, callback, options, secret)
}
getOldDailyLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 21, ...opts}, this, params, callback, options, secret)
}
getOldWeeklyLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 22, ...opts}, this, params, callback, options, secret)
}
getOldEventLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 23, ...opts}, this, params, callback, options, secret)
}
getLevelsFromList(listID, opts, callback, params, options, secret) {
levels.getLevels({type: 25, listID, ...opts}, this, params, callback, options, secret)
}
getSentLevels(opts, callback, params, options, secret) {
levels.getLevels({type: 27, ...opts}, this, params, callback, options, secret)
}
getSentLevelLists(callback, params, options, secret) {
lists.getLevelLists({type: 27, ...opts}, this, params, callback, options, secret)
}
getDailyLevel(callback, params, options, secret) {
levels.getDailyLevel(this, params, callback, options, secret)
}
getWeeklyLevel(callback, params, options, secret) {
levels.getDailyLevel(this, {type: 1, ...params}, callback, options, secret)
}
getEventLevel(callback, params, options, secret) {
levels.getDailyLevel(this, {type: 2, ...params}, callback, options, secret)
}
reportLevel(levelID, callback, params, options, secret) {
levels.reportLevel(levelID, this, params, callback, options, secret)
}
searchLevels(query, opts, callback, params, options, secret) {
levels.getLevels({
type: 0,
query,
...opts
}, this, params, callback, options, secret)
}
searchLevelLists(query, opts, callback, params, options, secret) {
lists.getLevelLists({type: 0, query, ...opts}, this, params, callback, options, secret)
}
getRatedLevelsByID(levelIDs, opts, callback, params, options, secret) {
levels.getLevels({
type: 10,
levelIDs,
...opts
}, this, params, callback, options, secret)
}
getLevelsByAccountIDs(accountIDs, opts, callback, params, options, secret) {
levels.getLevels({
type: 12,
accountIDs,
...opts
}, this, params, callback, options, secret)
}
getLevelListsByAccountIDs(accountIDs, opts, callback, params, options, secret) {
lists.getLevelLists({type: 12, accountIDs, ...opts}, this, params, callback, options, secret)
}
getLevelsByPlayerID(playerID, opts, callback, params, options, secret) {
levels.getLevels({
type: 5,
playerID,
...opts
}, this, params, callback, options, secret)
}
getLevelListsByAccountID(accountID, opts, callback, params, options, secret) {
lists.getLevelLists({type: 5, accountID, ...opts}, this, params, callback, options, secret)
}
getLevelsByID(levelIDs, opts, callback, params, options, secret) {
levels.getLevels({
type: 19,
levelIDs,
...opts
}, this, params, callback, options, secret)
}
getMapPacks(page, callback, params, options, secret) {
levels.getMapPacks(this, {page, ...params}, callback, options, secret)
}
getGauntlets(callback, params, options, secret) {
levels.getGauntlets(this, {...params}, callback, options, secret)
}
downloadLevel(id, callback, params, options, secret) {
levels.downloadLevel(id, this, {...params}, callback, options, secret)
}
downloadDailyLevel(callback, params, options, secret) {
levels.downloadLevel(-1, this, {...params}, callback, options, secret)
}
downloadWeeklyLevel(callback, params, options, secret) {
levels.downloadLevel(-2, this, {...params}, callback, options, secret)
}
downloadEventLevel(callback, params, options, secret) {
levels.downloadLevel(-3, this, {...params}, callback, options, secret)
}
deleteLevel(levelID, callback, params, options, secret) {
levels.deleteLevel(levelID, this, {...params}, callback, options, secret)
}
getSongInfo(songID, callback, params, options, secret) {
songs.getSongInfo(songID, this, params, callback, options, secret)
}
getTopArtists(page, callback, params, options, secret) {
songs.getTopArtists(page, this, params, callback, options, secret)
}
searchUsers(query, callback, params, options, secret) {
users.searchUsers(query, this, params, callback, options, secret)
}
getUserByAccountID(accountID, logout, callback, params, options, secret) {
users.getUserByAccountID(accountID, logout, this, params, callback, options, secret)
}
registerAccount(username, email, password, callback, params, options, secret) {
accounts.registerAccount(username, email, password, this, params, callback, options, secret)
}
loginAccount(username, password, callback, params, options, secret) {
accounts.loginAccount(username, password, this, params, callback, options, secret)
}
getGlobalStarLeaderboards(callback, params, options, secret) {
scores.getLeaderboards(constants.SCORES.TOP, this, params, callback, options, secret)
}
getRelativeLeaderboards(accountID, callback, params, options, secret) {
scores.getLeaderboards(constants.SCORES.RELATIVE, this, {
accountID,
...params
}, callback, options, secret)
}
getFriendLeaderboards(callback, params, options, secret) {
scores.getLeaderboards(constants.SCORES.FRIENDS, this, params, callback, options, secret)
}
getGlobalCreatorLeaderboards(callback, params, options, secret) {
scores.getLeaderboards(constants.SCORES.CREATORS, this, params, callback, options, secret)
}
/**
* Updates your account stats.
*
* @param {object} opt The options
* @param {number} opt.stars Your star count
* @param {number} opt.moons Your moon count
* @param {number} opt.demons Your demon count. If left out, defaults to the length of the completedDemons array
* @param {number} opt.diamonds Your diamond count
* @param {number} opt.secretCoins Your secret coin count
* @param {number} opt.userCoins Your user coin count
* @param {number} opt.iconType Your selected icon type
* @param {number} opt.cubeID Your cube's ID
* @param {number} opt.shipID Your ship's ID
* @param {number} opt.ballID Your ball's ID
* @param {number} opt.ufoID Your UFO's ID
* @param {number} opt.waveID Your wave's ID
* @param {number} opt.robotID Your robot's ID
* @param {number} opt.spiderID Your spider's ID
* @param {number} opt.swingID Your swing's ID
* @param {number} opt.jetpackID Your jetpack's ID
* @param {number} opt.deathEffectID Your death effect ID
* @param {number} opt.color1 Your primary color
* @param {number} opt.color2 Your secondary color
* @param {number} opt.glowColor Your glow color. Will default to secondary if left out
* @param {boolean} opt.glow Whether glow is enabled
* @param {Array[number]} opt.completedDemons Array of all the IDs of your completed demons
* @param {object} opt.classic Amounts of completed classic levels
* @param {number} opt.classic.auto Amount of completed classic auto levels
* @param {number} opt.classic.easy Amount of completed classic easy levels
* @param {number} opt.classic.normal Amount of completed classic normal levels
* @param {number} opt.classic.hard Amount of completed classic hard levels
* @param {number} opt.classic.harder Amount of completed classic harder levels
* @param {number} opt.classic.insane Amount of completed classic insane levels
* @param {object} opt.platformer Amounts of completed platformer levels
* @param {number} opt.platformer.auto Amount of completed platformer auto levels
* @param {number} opt.platformer.easy Amount of completed platformer easy levels
* @param {number} opt.platformer.normal Amount of completed platformer normal levels
* @param {number} opt.platformer.hard Amount of completed platformer hard levels
* @param {number} opt.platformer.harder Amount of completed platformer harder levels
* @param {number} opt.platformer.insane Amount of completed platformer insane levels
* @param {number} opt.completedGauntletDemons Amount of completed gauntlet demons
* @param {number} opt.completedGauntletNonDemons Amount of completed gauntlet non-demons
* @param {number} opt.completedDailies Amount of completed dailies
* @param {number} opt.completedWeeklies Amount of completed weeklies
* @param {function} callback Function callback
* @param {object} params Extra parameters
* @param {object} options Axios options
* @param {string} secret The `secret` parameter (uses the correct one for the GD servers by default)
* @returns {number}
*/
updateUserScore(opt, callback, params, options, secret) {
users.updateUserScore(opt, this, params, callback, options, secret)
}
getDailyChests(callback, params, options, secret) {
rewards.getRewards(0, this, params, callback, options, secret)
}
getQuests(callback, params, options, secret) {
rewards.getChallenges(this, params, callback, options, secret)
}
requestModAccess(callback, params, options, secret) {
accounts.requestModAccess(this, params, callback, options, secret)
}
updateDescription(levelID, desc, callback, params, options, secret) {
levels.updateDescription(levelID, desc, this, params, callback, options, secret)
}
uploadLevel(opts, callback, params, options, secret) {
levels.uploadLevel(opts, this, params, callback, options, secret)
}
deleteLevel(levelID, callback, params, options, secret) {
levels.deleteLevel(levelID, this, params, callback, options, secret)
}
getUserList(type, callback, params, options, secret) {
socials.getUserList(type, this, params, callback, options, secret)
}
getFriendsList(callback, params, options, secret) {
socials.getUserList(0, this, params, callback, options, secret)
}
getBlockList(callback, params, options, secret) {
socials.getUserList(1, this, params, callback, options, secret)
}
loadSaveData(callback, params, options, secret) {
accounts.loadSaveData(this, params, callback, options, secret)
}
backupSaveData(gameManager, localLevels, callback, params, options, secret) {
accounts.backupSaveData(gameManager, localLevels, this, params, callback, options, secret)
}
updateAccountSettings(messagePermissions, friendPermissions, commentHistoryPermissions, youtube, twitter, twitch, callback, params, options, secret) {
users.updateAccountSettings(messagePermissions, friendPermissions, commentHistoryPermissions, youtube, twitter, twitch, this, params, callback, options, secret)
}
getMessages(page, type, callback, params, options, secret) {
socials.getMessages(page, type, this, params, callback, options, secret)
}
getIncomingMessages(page, callback, params, options, secret) {
socials.getMessages(page, 0, this, params, callback, options, secret)
}
getOutgoingMessages(page, callback, params, options, secret) {
socials.getMessages(page, 1, this, params, callback, options, secret)
}
readMessage(id, isSender, callback, params, options, secret) {
socials.readMessage(id, isSender, this, params, callback, options, secret)
}
sendMessage(accountID, subject, body, callback, params, options, secret) {
socials.sendMessage(accountID, subject, body, this, params, callback, options, secret)
}
deleteMessage(id, isSender, callback, params, options, secret) {
socials.deleteMessage(id, isSender, this, params, callback, options, secret)
}
blockUser(accountID, callback, params, options, secret) {
socials.blockUser(accountID, this, params, callback, options, secret)
}
unblockUser(accountID, callback, params, options, secret) {
socials.unblockUser(accountID, this, params, callback, options, secret)
}
getFriendRequests(page, type, callback, params, options, secret) {
socials.getFriendRequests(page, type, this, params, callback, options, secret)
}
getIncomingFriendRequests(page, callback, params, options, secret) {
socials.getFriendRequests(page, 0, this, params, callback, options, secret)
}
getOutgoingFriendRequests(page, callback, params, options, secret) {
socials.getFriendRequests(page, 1, this, params, callback, options, secret)
}
deleteFriendRequests(accountIDs, isSender, callback, params, options, secret) {
socials.deleteFriendRequests(accountIDs, isSender, this, params, callback, options, secret)
}
sendFriendRequest(accountID, comment, callback, params, options, secret) {
socials.sendFriendRequest(accountID, comment, this, params, callback, options, secret)
}
readFriendRequest(requestID, callback, params, options, secret) {
socials.readFriendRequest(requestID, this, params, callback, options, secret)
}
acceptFriendRequest(targetAccountID, requestID, callback, params, options, secret) {
socials.acceptFriendRequest(requestID, targetAccountID, this, params, callback, options, secret)
}
removeFriend(targetAccountID, callback, params, options, secret) {
socials.removeFriend(targetAccountID, this, params, callback, options, secret)
}
uploadLevelList(opts, callback, params, options, secret) {
lists.uploadLevelList(opts, this, params, callback, options, secret)
}
deleteLevelList(id, callback, params, options, secret) {
lists.deleteLevelList(id, this, params, callback, options, secret)
}
getAccountURL(type, callback, params, options, secret) {
accounts.getAccountURL(type, this, params, callback, options, secret)
}
getBackupAccountURL(callback, params, options, secret) {
accounts.getAccountURL(1, this, params, callback, options, secret)
}
getSyncAccountURL(callback, params, options, secret) {
accounts.getAccountURL(2, this, params, callback, options, secret)
}
getLevelScores(levelID, type, opts, callback, params, options, secret) {
scores.getLevelScores(levelID, type, opts, this, params, callback, options, secret)
}
getPlatformerLevelScores(levelID, type, mode, opts, callback, params, options, secret) {
scores.getPlatformerLevelScores(levelID, type, mode, opts, this, params, callback, options, secret)
}
getContentURL(callback, params, options, secret) {
songs.getContentURL(this, params, callback, options, secret)
}
getMusicLibraryVersion(callback, params, options) {
songs.getMusicLibraryVersion(this, params, callback, options)
}
getOldMusicLibraryVersion(callback, params, options) {
songs.getOldMusicLibraryVersion(this, params, callback, options)
}
getSFXLibraryVersion(callback, params, options) {
songs.getSFXLibraryVersion(this, params, callback, options)
}
getMusicLibrary(callback, params, options) {
songs.getMusicLibrary(this, params, callback, options)
}
getOldMusicLibrary(callback, params, options) {
songs.getOldMusicLibrary(this, params, callback, options)
}
downloadLibrarySong(id, callback, params, options) {
songs.downloadLibrarySong(id, this, params, callback, options)
}
downloadSoundEffect(id, callback, params, options) {
songs.downloadSoundEffect(id, this, params, callback, options)
}
getSFXLibrary(callback, params, options) {
songs.getSFXLibrary(this, params, callback, options)
}
getWraithCode(code, callback, params, options, secret) {
rewards.getWraithCode(this, code, params, callback, options, secret)
}
}
export let utils = u