disgroove 2.2.7 → 3.0.0-dev.513aea4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/lib/Client.d.ts +252 -251
  2. package/dist/lib/Client.js +472 -471
  3. package/dist/lib/gateway/Shard.d.ts +7 -4
  4. package/dist/lib/gateway/Shard.js +261 -191
  5. package/dist/lib/index.d.ts +4 -0
  6. package/dist/lib/index.js +4 -0
  7. package/dist/lib/rest/Endpoints.d.ts +94 -94
  8. package/dist/lib/rest/Endpoints.js +104 -104
  9. package/dist/lib/transformers/ApplicationCommands.js +4 -4
  10. package/dist/lib/transformers/Applications.d.ts +2 -0
  11. package/dist/lib/transformers/Applications.js +110 -4
  12. package/dist/lib/transformers/AuditLogs.js +10 -10
  13. package/dist/lib/transformers/AutoModeration.js +6 -6
  14. package/dist/lib/transformers/Channels.js +16 -16
  15. package/dist/lib/transformers/Components.js +16 -16
  16. package/dist/lib/transformers/Entitlements.d.ts +2 -2
  17. package/dist/lib/transformers/Entitlements.js +16 -16
  18. package/dist/lib/transformers/GuildScheduledEvents.js +8 -8
  19. package/dist/lib/transformers/GuildTemplates.js +4 -4
  20. package/dist/lib/transformers/Guilds.js +28 -28
  21. package/dist/lib/transformers/Interactions.js +44 -44
  22. package/dist/lib/transformers/Lobbies.js +2 -2
  23. package/dist/lib/transformers/Messages.js +18 -18
  24. package/dist/lib/transformers/Polls.js +2 -2
  25. package/dist/lib/transformers/Presences.js +6 -6
  26. package/dist/lib/transformers/Roles.js +6 -6
  27. package/dist/lib/transformers/SKUs.js +2 -2
  28. package/dist/lib/transformers/Soundboards.js +6 -6
  29. package/dist/lib/transformers/StageInstances.js +6 -6
  30. package/dist/lib/transformers/Stickers.js +3 -3
  31. package/dist/lib/transformers/Subscriptions.js +8 -8
  32. package/dist/lib/transformers/Teams.js +4 -4
  33. package/dist/lib/transformers/Users.js +6 -6
  34. package/dist/lib/transformers/Voice.js +8 -8
  35. package/dist/lib/transformers/Webhooks.js +6 -6
  36. package/dist/lib/types/application-command.d.ts +9 -4
  37. package/dist/lib/types/application-role-connection-metadata.d.ts +1 -0
  38. package/dist/lib/types/application.d.ts +12 -7
  39. package/dist/lib/types/audit-log.d.ts +9 -5
  40. package/dist/lib/types/auto-moderation.d.ts +7 -3
  41. package/dist/lib/types/channel.d.ts +17 -23
  42. package/dist/lib/types/common.d.ts +2 -0
  43. package/dist/lib/types/components.d.ts +43 -15
  44. package/dist/lib/types/emoji.d.ts +1 -0
  45. package/dist/lib/types/entitlements.d.ts +5 -4
  46. package/dist/lib/types/gateway-events.d.ts +181 -130
  47. package/dist/lib/types/guild-scheduled-event.d.ts +10 -5
  48. package/dist/lib/types/guild-template.d.ts +3 -2
  49. package/dist/lib/types/guild.d.ts +33 -17
  50. package/dist/lib/types/interaction.d.ts +23 -10
  51. package/dist/lib/types/invite.d.ts +3 -0
  52. package/dist/lib/types/lobby.d.ts +3 -1
  53. package/dist/lib/types/message.d.ts +29 -15
  54. package/dist/lib/types/poll.d.ts +7 -1
  55. package/dist/lib/types/role.d.ts +6 -3
  56. package/dist/lib/types/sku.d.ts +2 -1
  57. package/dist/lib/types/soundboard.d.ts +4 -3
  58. package/dist/lib/types/stage-instance.d.ts +4 -3
  59. package/dist/lib/types/sticker.d.ts +8 -5
  60. package/dist/lib/types/subscription.d.ts +6 -5
  61. package/dist/lib/types/team.d.ts +4 -2
  62. package/dist/lib/types/user.d.ts +10 -3
  63. package/dist/lib/types/voice.d.ts +6 -4
  64. package/dist/lib/types/webhook.d.ts +4 -3
  65. package/dist/lib/utils/CDN.d.ts +22 -22
  66. package/dist/lib/utils/CDN.js +22 -22
  67. package/dist/lib/utils/formatters.d.ts +6 -6
  68. package/dist/lib/utils/formatters.js +18 -18
  69. package/dist/package.json +1 -1
  70. package/package.json +1 -1
@@ -37,63 +37,79 @@ class Shard {
37
37
  heartbeatInterval;
38
38
  client;
39
39
  ws;
40
- sessionID;
40
+ sessionId;
41
41
  resumeGatewayURL;
42
+ sequence;
42
43
  constructor(id, client) {
43
44
  this.id = id;
44
45
  this.heartbeatInterval = null;
45
46
  this.client = client;
46
- this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json", client.ws);
47
- this.sessionID = null;
47
+ this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json", this.client.ws);
48
+ this.sessionId = null;
48
49
  this.resumeGatewayURL = null;
50
+ this.sequence = null;
49
51
  }
50
52
  /** https://discord.com/developers/docs/topics/gateway#connections */
51
- connect() {
52
- this.ws.on("open", () => this.onWebSocketOpen());
53
- this.ws.on("message", (data) => this.onWebSocketMessage(data));
54
- this.ws.on("error", (err) => this.onWebSocketError(err));
55
- this.ws.on("close", (code, reason) => this.onWebSocketClose(code, reason));
53
+ connect(reconnect) {
54
+ if (this.ws) {
55
+ this.ws.on("open", () => this.onWebSocketOpen(reconnect));
56
+ this.ws.on("message", (data) => this.onWebSocketMessage(data));
57
+ this.ws.on("error", (err) => this.onWebSocketError(err));
58
+ this.ws.on("close", (code, reason) => this.onWebSocketClose(code, reason));
59
+ }
56
60
  }
57
- /** https://discord.com/developers/docs/topics/gateway#connections */
61
+ /** https://discord.com/developers/docs/events/gateway#initiating-a-disconnect */
58
62
  disconnect() {
59
- if (this.heartbeatInterval) {
60
- clearInterval(this.heartbeatInterval);
61
- this.heartbeatInterval = null;
63
+ if (this.ws) {
64
+ if (this.heartbeatInterval) {
65
+ clearInterval(this.heartbeatInterval);
66
+ this.heartbeatInterval = null;
67
+ }
68
+ if (this.ws.readyState !== ws_1.default.CLOSED) {
69
+ this.ws.removeAllListeners();
70
+ this.ws.close(1000, "Session Invalidated - Disconnect");
71
+ this.ws = null;
72
+ }
62
73
  }
63
74
  }
64
75
  /** https://discord.com/developers/docs/topics/gateway-events#heartbeat */
65
76
  heartbeat(lastSequence) {
66
- this.ws.send(JSON.stringify({
67
- op: constants_1.GatewayOPCodes.Heartbeat,
68
- d: lastSequence,
69
- }));
77
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
78
+ this.ws.send(JSON.stringify({
79
+ op: constants_1.GatewayOPCodes.Heartbeat,
80
+ d: lastSequence,
81
+ }));
82
+ }
70
83
  }
71
84
  /** https://discord.com/developers/docs/topics/gateway-events#identify */
72
85
  identify(options) {
73
- this.ws.send(JSON.stringify({
74
- op: constants_1.GatewayOPCodes.Identify,
75
- d: {
76
- token: options.token,
77
- properties: {
78
- os: options.properties.os,
79
- browser: options.properties.browser,
80
- device: options.properties.device,
86
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
87
+ this.ws.send(JSON.stringify({
88
+ op: constants_1.GatewayOPCodes.Identify,
89
+ d: {
90
+ token: options.token,
91
+ properties: {
92
+ os: options.properties.os,
93
+ browser: options.properties.browser,
94
+ device: options.properties.device,
95
+ },
96
+ compress: options.compress,
97
+ large_threshold: options.largeThreshold,
98
+ shard: options.shard,
99
+ presence: options.presence,
100
+ intents: options.intents,
81
101
  },
82
- compress: options.compress,
83
- large_threshold: options.largeThreshold,
84
- shard: options.shard,
85
- presence: options.presence,
86
- intents: options.intents,
87
- },
88
- }));
102
+ }));
103
+ }
89
104
  }
90
105
  onDispatch(packet) {
106
+ this.sequence = packet.s;
91
107
  this.client.emit("dispatch", packet, this.id);
92
108
  switch (packet.t) {
93
109
  case constants_1.GatewayEvents.Ready:
94
110
  {
95
- this.sessionID = packet.d.session_id;
96
- this.resumeGatewayURL = packet.d.resume_gateway_url;
111
+ this.sessionId = packet.d.session_id;
112
+ this.resumeGatewayURL = `${packet.d.resume_gateway_url}?v=10&encoding=json`;
97
113
  this.client.user = transformers_1.Users.userFromRaw(packet.d.user);
98
114
  this.client.application = packet.d.application;
99
115
  this.client.emit("ready");
@@ -109,7 +125,7 @@ class Shard {
109
125
  opcode: constants_1.GatewayOPCodes.RequestGuildMembers,
110
126
  retryAfter: packet.d.retry_after,
111
127
  meta: {
112
- guildID: packet.d.meta.guild_id,
128
+ guildId: packet.d.meta.guild_id,
113
129
  nonce: packet.d.nonce,
114
130
  },
115
131
  });
@@ -130,21 +146,21 @@ class Shard {
130
146
  break;
131
147
  case constants_1.GatewayEvents.AutoModerationActionExecution:
132
148
  this.client.emit("autoModerationActionExecution", {
133
- guildID: packet.d.guild_id,
149
+ guildId: packet.d.guild_id,
134
150
  action: {
135
151
  type: packet.d.action.type,
136
152
  metadata: {
137
- channelID: packet.d.action.metadata.channel_id,
153
+ channelId: packet.d.action.metadata.channel_id,
138
154
  durationSeconds: packet.d.action.metadata.duration_seconds,
139
155
  customMessage: packet.d.action.metadata.custom_message,
140
156
  },
141
157
  },
142
- ruleID: packet.d.rule_id,
158
+ ruleId: packet.d.rule_id,
143
159
  ruleTriggerType: packet.d.rule_trigger_type,
144
- userID: packet.d.user_id,
145
- channelID: packet.d.channel_id,
146
- messageID: packet.d.message_id,
147
- alertSystemMessageID: packet.d.alert_system_message_id,
160
+ userId: packet.d.user_id,
161
+ channelId: packet.d.channel_id,
162
+ messageId: packet.d.message_id,
163
+ alertSystemMessageId: packet.d.alert_system_message_id,
148
164
  content: packet.d.content,
149
165
  matchedKeyword: packet.d.matched_keyword,
150
166
  matchedContent: packet.d.matched_content,
@@ -161,8 +177,8 @@ class Shard {
161
177
  break;
162
178
  case constants_1.GatewayEvents.ChannelPinsUpdate:
163
179
  this.client.emit("channelPinsUpdate", {
164
- guildID: packet.d.guild_id,
165
- channelID: packet.d.channel_id,
180
+ guildId: packet.d.guild_id,
181
+ channelId: packet.d.channel_id,
166
182
  lastPinTimestamp: packet.d.last_pin_timestamp,
167
183
  });
168
184
  break;
@@ -177,8 +193,8 @@ class Shard {
177
193
  break;
178
194
  case constants_1.GatewayEvents.ThreadListSync:
179
195
  this.client.emit("threadListSync", {
180
- guildID: packet.d.guild_id,
181
- channelIDs: packet.d.channel_ids,
196
+ guildId: packet.d.guild_id,
197
+ channelIds: packet.d.channel_ids,
182
198
  threads: packet.d.threads.map((thread) => transformers_1.Channels.channelFromRaw(thread)),
183
199
  members: packet.d.members.map((threadMember) => transformers_1.Channels.threadMemberFromRaw(threadMember)),
184
200
  });
@@ -186,22 +202,22 @@ class Shard {
186
202
  case constants_1.GatewayEvents.ThreadMemberUpdate:
187
203
  this.client.emit("threadMemberUpdate", {
188
204
  id: packet.d.id,
189
- userID: packet.d.user_id,
205
+ userId: packet.d.user_id,
190
206
  joinTimestamp: packet.d.join_timestamp,
191
207
  flags: packet.d.flags,
192
208
  member: packet.d.member !== undefined
193
209
  ? transformers_1.Guilds.guildMemberFromRaw(packet.d.member)
194
210
  : undefined,
195
- guildID: packet.d.guild_id,
211
+ guildId: packet.d.guild_id,
196
212
  });
197
213
  break;
198
214
  case constants_1.GatewayEvents.ThreadMembersUpdate:
199
215
  this.client.emit("threadMembersUpdate", {
200
216
  id: packet.d.id,
201
- guildID: packet.d.guild_id,
217
+ guildId: packet.d.guild_id,
202
218
  memberCount: packet.d.member_count,
203
219
  addedMembers: packet.d.members.map((threadMember) => transformers_1.Channels.threadMemberFromRaw(threadMember)),
204
- removedMemberIDs: packet.d.removed_member_ids,
220
+ removedMemberIds: packet.d.removed_member_ids,
205
221
  });
206
222
  break;
207
223
  case constants_1.GatewayEvents.EntitlementCreate:
@@ -239,18 +255,18 @@ class Shard {
239
255
  case constants_1.GatewayEvents.GuildAuditLogEntryCreate:
240
256
  this.client.emit("guildAuditLogEntryCreate", {
241
257
  ...transformers_1.AuditLogs.auditLogEntryFromRaw(packet.d),
242
- guildID: packet.d.guild_id,
258
+ guildId: packet.d.guild_id,
243
259
  });
244
260
  break;
245
261
  case constants_1.GatewayEvents.GuildBanAdd:
246
262
  this.client.emit("guildBanAdd", {
247
- guildID: packet.d.guild_id,
263
+ guildId: packet.d.guild_id,
248
264
  user: transformers_1.Users.userFromRaw(packet.d.user),
249
265
  });
250
266
  break;
251
267
  case constants_1.GatewayEvents.GuildBanRemove:
252
268
  this.client.emit("guildBanRemove", {
253
- guildID: packet.d.guild_id,
269
+ guildId: packet.d.guild_id,
254
270
  user: transformers_1.Users.userFromRaw(packet.d.user),
255
271
  });
256
272
  break;
@@ -266,18 +282,18 @@ class Shard {
266
282
  case constants_1.GatewayEvents.GuildMemberAdd:
267
283
  this.client.emit("guildMemberAdd", {
268
284
  ...transformers_1.Guilds.guildMemberFromRaw(packet.d),
269
- guildID: packet.d.guild_id,
285
+ guildId: packet.d.guild_id,
270
286
  });
271
287
  break;
272
288
  case constants_1.GatewayEvents.GuildMemberRemove:
273
289
  this.client.emit("guildMemberRemove", {
274
- guildID: packet.d.guild_id,
290
+ guildId: packet.d.guild_id,
275
291
  user: transformers_1.Users.userFromRaw(packet.d.user),
276
292
  });
277
293
  break;
278
294
  case constants_1.GatewayEvents.GuildMemberUpdate:
279
295
  this.client.emit("guildMemberUpdate", {
280
- guildID: packet.d.guild_id,
296
+ guildId: packet.d.guild_id,
281
297
  roles: packet.d.roles,
282
298
  user: transformers_1.Users.userFromRaw(packet.d.user),
283
299
  nick: packet.d.nick,
@@ -293,14 +309,14 @@ class Shard {
293
309
  avatarDecorationData: packet.d.avatar_decoration_data !== undefined
294
310
  ? {
295
311
  asset: packet.d.asset,
296
- skuID: packet.d.sku_id,
312
+ skuId: packet.d.sku_id,
297
313
  }
298
314
  : undefined,
299
315
  });
300
316
  break;
301
317
  case constants_1.GatewayEvents.GuildMembersChunk:
302
318
  this.client.emit("guildMembersChunk", {
303
- guildID: packet.d.guild_id,
319
+ guildId: packet.d.guild_id,
304
320
  members: packet.d.members.map((guildMember) => transformers_1.Guilds.guildMemberFromRaw(guildMember)),
305
321
  chunkIndex: packet.d.chunk_index,
306
322
  chunkCount: packet.d.chunk_count,
@@ -341,8 +357,8 @@ class Shard {
341
357
  break;
342
358
  case constants_1.GatewayEvents.GuildSoundboardSoundDelete:
343
359
  this.client.emit("guildSoundboardSoundDelete", {
344
- soundID: packet.d.sound_id,
345
- guildID: packet.d.guild_id,
360
+ soundId: packet.d.sound_id,
361
+ guildId: packet.d.guild_id,
346
362
  });
347
363
  break;
348
364
  case constants_1.GatewayEvents.GuildSoundboardSoundsUpdate:
@@ -354,20 +370,20 @@ class Shard {
354
370
  case constants_1.GatewayEvents.IntegrationCreate:
355
371
  this.client.emit("integrationCreate", {
356
372
  ...transformers_1.Guilds.integrationFromRaw(packet.d),
357
- guildID: packet.d.guild_id,
373
+ guildId: packet.d.guild_id,
358
374
  });
359
375
  break;
360
376
  case constants_1.GatewayEvents.IntegrationUpdate:
361
377
  this.client.emit("integrationUpdate", {
362
378
  ...transformers_1.Guilds.integrationFromRaw(packet.d),
363
- guildID: packet.d.guild_id,
379
+ guildId: packet.d.guild_id,
364
380
  });
365
381
  break;
366
382
  case constants_1.GatewayEvents.IntegrationDelete:
367
383
  this.client.emit("integrationDelete", {
368
384
  id: packet.d.id,
369
- guildID: packet.d.guild_id,
370
- applicationID: packet.d.application_id,
385
+ guildId: packet.d.guild_id,
386
+ applicationId: packet.d.application_id,
371
387
  });
372
388
  break;
373
389
  case constants_1.GatewayEvents.InteractionCreate:
@@ -375,10 +391,10 @@ class Shard {
375
391
  break;
376
392
  case constants_1.GatewayEvents.InviteCreate:
377
393
  this.client.emit("inviteCreate", {
378
- channelID: packet.d.channel_id,
394
+ channelId: packet.d.channel_id,
379
395
  code: packet.d.code,
380
396
  createdAt: packet.d.created_at,
381
- guildID: packet.d.guild_id,
397
+ guildId: packet.d.guild_id,
382
398
  inviter: packet.d.inviter !== undefined
383
399
  ? transformers_1.Users.userFromRaw(packet.d.inviter)
384
400
  : undefined,
@@ -398,15 +414,15 @@ class Shard {
398
414
  break;
399
415
  case constants_1.GatewayEvents.InviteDelete:
400
416
  this.client.emit("inviteDelete", {
401
- channelID: packet.d.channel_id,
402
- guildID: packet.d.guild_id,
417
+ channelId: packet.d.channel_id,
418
+ guildId: packet.d.guild_id,
403
419
  code: packet.d.code,
404
420
  });
405
421
  break;
406
422
  case constants_1.GatewayEvents.MessageCreate:
407
423
  this.client.emit("messageCreate", {
408
424
  ...transformers_1.Messages.messageFromRaw(packet.d),
409
- guildID: packet.d.guild_id,
425
+ guildId: packet.d.guild_id,
410
426
  member: packet.d.member !== undefined
411
427
  ? transformers_1.Guilds.guildMemberFromRaw(packet.d.member)
412
428
  : undefined,
@@ -419,28 +435,28 @@ class Shard {
419
435
  case constants_1.GatewayEvents.MessageDelete:
420
436
  this.client.emit("messageDelete", {
421
437
  id: packet.d.id,
422
- channelID: packet.d.channel_id,
423
- guildID: packet.d.guild_id,
438
+ channelId: packet.d.channel_id,
439
+ guildId: packet.d.guild_id,
424
440
  });
425
441
  break;
426
442
  case constants_1.GatewayEvents.MessageDeleteBulk:
427
443
  this.client.emit("messageDeleteBulk", {
428
444
  ids: packet.d.ids,
429
- channelID: packet.d.channel_id,
430
- guildID: packet.d.guild_id,
445
+ channelId: packet.d.channel_id,
446
+ guildId: packet.d.guild_id,
431
447
  });
432
448
  break;
433
449
  case constants_1.GatewayEvents.MessageReactionAdd:
434
450
  this.client.emit("messageReactionAdd", {
435
- userID: packet.d.user_id,
436
- channelID: packet.d.user_id,
437
- messageID: packet.d.user_id,
438
- guildID: packet.d.user_id,
451
+ userId: packet.d.user_id,
452
+ channelId: packet.d.user_id,
453
+ messageId: packet.d.user_id,
454
+ guildId: packet.d.user_id,
439
455
  member: packet.d.member !== undefined
440
456
  ? transformers_1.Guilds.guildMemberFromRaw(packet.d.member)
441
457
  : undefined,
442
458
  emoji: transformers_1.Emojis.emojiFromRaw(packet.d.emoji),
443
- messageAuthorID: packet.d.message_author_id,
459
+ messageAuthorId: packet.d.message_author_id,
444
460
  burst: packet.d.burst,
445
461
  burstColors: packet.d.burst_colors,
446
462
  type: packet.d.type,
@@ -448,10 +464,10 @@ class Shard {
448
464
  break;
449
465
  case constants_1.GatewayEvents.MessageReactionRemove:
450
466
  this.client.emit("messageReactionRemove", {
451
- userID: packet.d.user_id,
452
- channelID: packet.d.user_id,
453
- messageID: packet.d.user_id,
454
- guildID: packet.d.user_id,
467
+ userId: packet.d.user_id,
468
+ channelId: packet.d.user_id,
469
+ messageId: packet.d.user_id,
470
+ guildId: packet.d.user_id,
455
471
  emoji: transformers_1.Emojis.emojiFromRaw(packet.d.emoji),
456
472
  burst: packet.d.burst,
457
473
  type: packet.d.type,
@@ -459,16 +475,16 @@ class Shard {
459
475
  break;
460
476
  case constants_1.GatewayEvents.MessageReactionRemoveAll:
461
477
  this.client.emit("messageReactionRemoveAll", {
462
- channelID: packet.d.channel_id,
463
- messageID: packet.d.message_id,
464
- guildID: packet.d.guild_id,
478
+ channelId: packet.d.channel_id,
479
+ messageId: packet.d.message_id,
480
+ guildId: packet.d.guild_id,
465
481
  });
466
482
  break;
467
483
  case constants_1.GatewayEvents.MessageReactionRemoveEmoji:
468
484
  this.client.emit("messageReactionRemoveEmoji", {
469
- channelID: packet.d.channel_id,
470
- guildID: packet.d.guild_id,
471
- messageID: packet.d.message_id,
485
+ channelId: packet.d.channel_id,
486
+ guildId: packet.d.guild_id,
487
+ messageId: packet.d.message_id,
472
488
  emoji: transformers_1.Emojis.emojiFromRaw(packet.d.emoji),
473
489
  });
474
490
  break;
@@ -486,9 +502,9 @@ class Shard {
486
502
  break;
487
503
  case constants_1.GatewayEvents.TypingStart:
488
504
  this.client.emit("typingStart", {
489
- channelID: packet.d.channel_id,
490
- guildID: packet.d.guild_id,
491
- userID: packet.d.user_id,
505
+ channelId: packet.d.channel_id,
506
+ guildId: packet.d.guild_id,
507
+ userId: packet.d.user_id,
492
508
  timestamp: packet.d.timestamp,
493
509
  member: packet.d.member !== undefined
494
510
  ? transformers_1.Guilds.guildMemberFromRaw(packet.d.member)
@@ -500,15 +516,15 @@ class Shard {
500
516
  break;
501
517
  case constants_1.GatewayEvents.VoiceChannelEffectSend:
502
518
  this.client.emit("voiceChannelEffectSend", {
503
- channelID: packet.d.channel_id,
504
- guildID: packet.d.guild_id,
505
- userID: packet.d.user_id,
519
+ channelId: packet.d.channel_id,
520
+ guildId: packet.d.guild_id,
521
+ userId: packet.d.user_id,
506
522
  emoji: packet.d.emoji !== null
507
523
  ? transformers_1.Emojis.emojiFromRaw(packet.d.emoji)
508
524
  : null,
509
525
  animationType: packet.d.animation_type,
510
- animationID: packet.d.animation_id,
511
- soundID: packet.d.sound_id,
526
+ animationId: packet.d.animation_id,
527
+ soundId: packet.d.sound_id,
512
528
  soundVolume: packet.d.sound_volume,
513
529
  });
514
530
  break;
@@ -519,7 +535,7 @@ class Shard {
519
535
  {
520
536
  this.client.emit("voiceServerUpdate", {
521
537
  token: packet.d.token,
522
- guildID: packet.d.guild_id,
538
+ guildId: packet.d.guild_id,
523
539
  endpoint: packet.d.endpoint,
524
540
  });
525
541
  }
@@ -538,54 +554,63 @@ class Shard {
538
554
  break;
539
555
  case constants_1.GatewayEvents.MessagePollVoteAdd:
540
556
  this.client.emit("messagePollVoteAdd", {
541
- userID: packet.d.user_id,
542
- channelID: packet.d.channel_id,
543
- messageID: packet.d.message_id,
544
- guildID: packet.d.guild_id,
545
- answerID: packet.d.answer_id,
557
+ userId: packet.d.user_id,
558
+ channelId: packet.d.channel_id,
559
+ messageId: packet.d.message_id,
560
+ guildId: packet.d.guild_id,
561
+ answerId: packet.d.answer_id,
546
562
  });
547
563
  break;
548
564
  case constants_1.GatewayEvents.MessagePollVoteRemove:
549
565
  this.client.emit("messagePollVoteRemove", {
550
- userID: packet.d.user_id,
551
- channelID: packet.d.channel_id,
552
- messageID: packet.d.message_id,
553
- guildID: packet.d.guild_id,
554
- answerID: packet.d.answer_id,
566
+ userId: packet.d.user_id,
567
+ channelId: packet.d.channel_id,
568
+ messageId: packet.d.message_id,
569
+ guildId: packet.d.guild_id,
570
+ answerId: packet.d.answer_id,
555
571
  });
556
572
  break;
557
573
  }
558
574
  }
559
- onWebSocketOpen() {
560
- this.identify({
561
- token: this.client.token,
562
- properties: {
563
- os: this.client.properties?.os ?? process.platform,
564
- browser: this.client.properties?.browser ?? pkg.name,
565
- device: this.client.properties?.device ?? pkg.name,
566
- },
567
- compress: this.client.compress,
568
- largeThreshold: this.client.largeThreshold,
569
- shard: [this.id, this.client.shardsCount],
570
- presence: this.client.presence !== undefined
571
- ? {
572
- since: this.client.presence.status === constants_1.StatusTypes.Idle
573
- ? Date.now()
574
- : null,
575
- activities: this.client.presence.activities?.map((activity) => ({
576
- name: activity.type === constants_1.ActivityType.Custom
577
- ? "Custom Status"
578
- : activity.name,
579
- type: activity.type,
580
- url: activity.url,
581
- state: activity.state,
582
- })),
583
- status: this.client.presence.status ?? constants_1.StatusTypes.Online,
584
- afk: !!this.client.presence.afk,
585
- }
586
- : undefined,
587
- intents: this.client.intents,
588
- });
575
+ onWebSocketOpen(reconnect) {
576
+ if (reconnect) {
577
+ this.resume({
578
+ token: this.client.token,
579
+ sessionId: this.sessionId,
580
+ seq: this.sequence,
581
+ });
582
+ }
583
+ else {
584
+ this.identify({
585
+ token: this.client.token,
586
+ properties: {
587
+ os: this.client.properties?.os ?? process.platform,
588
+ browser: this.client.properties?.browser ?? pkg.name,
589
+ device: this.client.properties?.device ?? pkg.name,
590
+ },
591
+ compress: this.client.compress,
592
+ largeThreshold: this.client.largeThreshold,
593
+ shard: [this.id, this.client.shardsCount],
594
+ presence: this.client.presence !== undefined
595
+ ? {
596
+ since: this.client.presence.status === constants_1.StatusTypes.Idle
597
+ ? Date.now()
598
+ : null,
599
+ activities: this.client.presence.activities?.map((activity) => ({
600
+ name: activity.type === constants_1.ActivityType.Custom
601
+ ? "Custom Status"
602
+ : activity.name,
603
+ type: activity.type,
604
+ url: activity.url,
605
+ state: activity.state,
606
+ })),
607
+ status: this.client.presence.status ?? constants_1.StatusTypes.Online,
608
+ afk: !!this.client.presence.afk,
609
+ }
610
+ : undefined,
611
+ intents: this.client.intents,
612
+ });
613
+ }
589
614
  }
590
615
  onWebSocketMessage(data) {
591
616
  const packet = JSON.parse(data.toString());
@@ -594,10 +619,23 @@ class Shard {
594
619
  this.onDispatch(packet);
595
620
  break;
596
621
  case constants_1.GatewayOPCodes.Reconnect:
597
- this.client.emit("reconnect");
622
+ {
623
+ this.client.emit("reconnect");
624
+ this.reconnect();
625
+ }
598
626
  break;
599
627
  case constants_1.GatewayOPCodes.InvalidSession:
600
- this.client.emit("invalidSession");
628
+ {
629
+ this.client.emit("invalidSession");
630
+ if (packet.d) {
631
+ this.reconnect();
632
+ }
633
+ else if (this.ws) {
634
+ this.ws.close(1000, "Invalid Session - Identify required");
635
+ this.ws = new ws_1.default("wss://gateway.discord.gg/?v=10&encoding=json", this.client.ws);
636
+ this.connect(false);
637
+ }
638
+ }
601
639
  break;
602
640
  case constants_1.GatewayOPCodes.Hello:
603
641
  {
@@ -614,74 +652,106 @@ class Shard {
614
652
  throw err;
615
653
  }
616
654
  onWebSocketClose(code, reason) {
617
- if (code === 1000)
618
- return;
619
- throw new utils_1.GatewayError(code, reason.toString());
655
+ switch (code) {
656
+ case 1000:
657
+ break;
658
+ case constants_1.GatewayCloseEventCodes.UnknownError:
659
+ case constants_1.GatewayCloseEventCodes.UnknownOPCode:
660
+ case constants_1.GatewayCloseEventCodes.DecodeError:
661
+ case constants_1.GatewayCloseEventCodes.NotAuthenticated:
662
+ case constants_1.GatewayCloseEventCodes.AlreadyAuthenticated:
663
+ case constants_1.GatewayCloseEventCodes.InvalidSequence:
664
+ case constants_1.GatewayCloseEventCodes.RateLimited:
665
+ case constants_1.GatewayCloseEventCodes.SessionTimedOut:
666
+ this.reconnect();
667
+ break;
668
+ default:
669
+ this.disconnect();
670
+ throw new utils_1.GatewayError(code, reason.toString());
671
+ }
672
+ }
673
+ /** https://discord.com/developers/docs/events/gateway#resuming */
674
+ reconnect() {
675
+ if (this.ws && this.resumeGatewayURL && this.sessionId && this.sequence) {
676
+ this.ws.close(1000, "Resume Attempt - Reconnect");
677
+ this.ws = new ws_1.default(this.resumeGatewayURL, this.client.ws);
678
+ this.connect(true);
679
+ }
620
680
  }
621
681
  /** https://discord.com/developers/docs/topics/gateway-events#request-guild-members */
622
682
  requestGuildMembers(options) {
623
- this.ws.send(JSON.stringify({
624
- op: constants_1.GatewayOPCodes.RequestGuildMembers,
625
- d: {
626
- guild_id: options.guildID,
627
- query: options.query,
628
- limit: options.limit,
629
- presences: options.presences,
630
- user_ids: options.userIDs,
631
- nonce: options.nonce,
632
- },
633
- }));
683
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
684
+ this.ws.send(JSON.stringify({
685
+ op: constants_1.GatewayOPCodes.RequestGuildMembers,
686
+ d: {
687
+ guild_id: options.guildId,
688
+ query: options.query,
689
+ limit: options.limit,
690
+ presences: options.presences,
691
+ user_ids: options.userIds,
692
+ nonce: options.nonce,
693
+ },
694
+ }));
695
+ }
634
696
  }
635
697
  /** https://discord.com/developers/docs/topics/gateway-events#request-soundboard-sounds */
636
698
  requestSoundboardSounds(options) {
637
- this.ws.send(JSON.stringify({
638
- op: constants_1.GatewayOPCodes.RequestSoundboardSounds,
639
- d: {
640
- guild_ids: options.guildIDs,
641
- },
642
- }));
699
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
700
+ this.ws.send(JSON.stringify({
701
+ op: constants_1.GatewayOPCodes.RequestSoundboardSounds,
702
+ d: {
703
+ guild_ids: options.guildIds,
704
+ },
705
+ }));
706
+ }
643
707
  }
644
708
  /** https://discord.com/developers/docs/topics/gateway-events#resume */
645
709
  resume(options) {
646
- this.ws.send(JSON.stringify({
647
- op: constants_1.GatewayOPCodes.Resume,
648
- d: {
649
- token: options.token,
650
- session_id: options.sessionID,
651
- seq: options.seq,
652
- },
653
- }));
710
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
711
+ this.ws.send(JSON.stringify({
712
+ op: constants_1.GatewayOPCodes.Resume,
713
+ d: {
714
+ token: options.token,
715
+ session_id: options.sessionId,
716
+ seq: options.seq,
717
+ },
718
+ }));
719
+ }
654
720
  }
655
721
  /** https://discord.com/developers/docs/topics/gateway-events#update-presence */
656
722
  updatePresence(options) {
657
- this.ws.send(JSON.stringify({
658
- op: constants_1.GatewayOPCodes.PresenceUpdate,
659
- d: {
660
- since: options.status === constants_1.StatusTypes.Idle ? Date.now() : null,
661
- activities: options.activities?.map((activity) => ({
662
- name: activity.type === constants_1.ActivityType.Custom
663
- ? "Custom Status"
664
- : activity.name,
665
- type: activity.type,
666
- url: activity.url,
667
- state: activity.state,
668
- })),
669
- status: options.status ?? constants_1.StatusTypes.Online,
670
- afk: !!options.afk,
671
- },
672
- }));
723
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
724
+ this.ws.send(JSON.stringify({
725
+ op: constants_1.GatewayOPCodes.PresenceUpdate,
726
+ d: {
727
+ since: options.status === constants_1.StatusTypes.Idle ? Date.now() : null,
728
+ activities: options.activities?.map((activity) => ({
729
+ name: activity.type === constants_1.ActivityType.Custom
730
+ ? "Custom Status"
731
+ : activity.name,
732
+ type: activity.type,
733
+ url: activity.url,
734
+ state: activity.state,
735
+ })),
736
+ status: options.status ?? constants_1.StatusTypes.Online,
737
+ afk: !!options.afk,
738
+ },
739
+ }));
740
+ }
673
741
  }
674
742
  /** https://discord.com/developers/docs/topics/gateway-events#update-voice-state */
675
743
  updateVoiceState(options) {
676
- this.ws.send(JSON.stringify({
677
- op: constants_1.GatewayOPCodes.VoiceStateUpdate,
678
- d: {
679
- guild_id: options.guildID,
680
- channel_id: options.channelID,
681
- self_mute: options.selfMute,
682
- self_deaf: options.selfDeaf,
683
- },
684
- }));
744
+ if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
745
+ this.ws.send(JSON.stringify({
746
+ op: constants_1.GatewayOPCodes.VoiceStateUpdate,
747
+ d: {
748
+ guild_id: options.guildId,
749
+ channel_id: options.channelId,
750
+ self_mute: options.selfMute,
751
+ self_deaf: options.selfDeaf,
752
+ },
753
+ }));
754
+ }
685
755
  }
686
756
  }
687
757
  exports.Shard = Shard;