@velliajs/discord 1.0.2 → 1.0.4
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.
- package/README.md +4 -11
- package/package.json +3 -3
- package/src/client/BaseClient.js +7 -28
- package/src/client/Client.js +116 -283
- package/src/client/WebhookClient.js +17 -59
- package/src/client/actions/Action.js +0 -10
- package/src/client/actions/ActionsManager.js +3 -3
- package/src/client/actions/ApplicationCommandPermissionsUpdate.js +2 -15
- package/src/client/actions/AutoModerationActionExecution.js +1 -6
- package/src/client/actions/AutoModerationRuleCreate.js +1 -6
- package/src/client/actions/AutoModerationRuleDelete.js +1 -6
- package/src/client/actions/AutoModerationRuleUpdate.js +1 -7
- package/src/client/actions/ChannelCreate.js +1 -5
- package/src/client/actions/ChannelDelete.js +1 -5
- package/src/client/actions/GuildAuditLogEntryCreate.js +1 -6
- package/src/client/actions/GuildBanAdd.js +1 -5
- package/src/client/actions/GuildBanRemove.js +1 -5
- package/src/client/actions/GuildDelete.js +6 -14
- package/src/client/actions/GuildEmojiCreate.js +1 -5
- package/src/client/actions/GuildEmojiDelete.js +1 -5
- package/src/client/actions/GuildEmojiUpdate.js +1 -6
- package/src/client/actions/GuildEmojisUpdate.js +4 -4
- package/src/client/actions/GuildIntegrationsUpdate.js +1 -5
- package/src/client/actions/GuildMemberRemove.js +1 -5
- package/src/client/actions/GuildMemberUpdate.js +2 -11
- package/src/client/actions/GuildRoleCreate.js +1 -5
- package/src/client/actions/GuildRoleDelete.js +1 -5
- package/src/client/actions/GuildRoleUpdate.js +1 -6
- package/src/client/actions/GuildScheduledEventCreate.js +1 -5
- package/src/client/actions/GuildScheduledEventDelete.js +1 -5
- package/src/client/actions/GuildScheduledEventUpdate.js +1 -6
- package/src/client/actions/GuildScheduledEventUserAdd.js +1 -6
- package/src/client/actions/GuildScheduledEventUserRemove.js +1 -6
- package/src/client/actions/GuildStickerCreate.js +1 -5
- package/src/client/actions/GuildStickerDelete.js +1 -5
- package/src/client/actions/GuildStickerUpdate.js +1 -6
- package/src/client/actions/GuildStickersUpdate.js +4 -4
- package/src/client/actions/GuildUpdate.js +1 -6
- package/src/client/actions/InteractionCreate.js +3 -7
- package/src/client/actions/InviteCreate.js +1 -7
- package/src/client/actions/InviteDelete.js +1 -7
- package/src/client/actions/MessageCreate.js +1 -5
- package/src/client/actions/MessageDelete.js +1 -5
- package/src/client/actions/MessageDeleteBulk.js +1 -6
- package/src/client/actions/MessageReactionAdd.js +5 -18
- package/src/client/actions/MessageReactionRemove.js +5 -16
- package/src/client/actions/MessageReactionRemoveAll.js +4 -9
- package/src/client/actions/MessageReactionRemoveEmoji.js +1 -5
- package/src/client/actions/PresenceUpdate.js +1 -6
- package/src/client/actions/StageInstanceCreate.js +1 -5
- package/src/client/actions/StageInstanceDelete.js +1 -5
- package/src/client/actions/StageInstanceUpdate.js +1 -6
- package/src/client/actions/ThreadCreate.js +1 -6
- package/src/client/actions/ThreadDelete.js +1 -5
- package/src/client/actions/ThreadListSync.js +2 -7
- package/src/client/actions/ThreadMemberUpdate.js +2 -7
- package/src/client/actions/ThreadMembersUpdate.js +2 -9
- package/src/client/actions/TypingStart.js +1 -5
- package/src/client/actions/UserUpdate.js +1 -8
- package/src/client/actions/VoiceStateUpdate.js +4 -9
- package/src/client/actions/WebhooksUpdate.js +1 -6
- package/src/client/voice/ClientVoiceManager.js +3 -13
- package/src/client/websocket/WebSocketManager.js +25 -117
- package/src/client/websocket/WebSocketShard.js +29 -116
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +2 -8
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -6
- package/src/client/websocket/handlers/GUILD_CREATE.js +3 -7
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +2 -16
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +1 -5
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -6
- package/src/client/websocket/handlers/RESUMED.js +1 -6
- package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -6
- package/src/errors/DJSError.js +3 -14
- package/src/errors/ErrorCodes.js +2 -164
- package/src/index.js +6 -6
- package/src/managers/ApplicationCommandManager.js +14 -130
- package/src/managers/ApplicationCommandPermissionsManager.js +31 -202
- package/src/managers/AutoModerationRuleManager.js +17 -145
- package/src/managers/BaseGuildEmojiManager.js +7 -38
- package/src/managers/BaseManager.js +2 -10
- package/src/managers/CachedManager.js +3 -17
- package/src/managers/CategoryChannelChildManager.js +6 -48
- package/src/managers/ChannelManager.js +11 -52
- package/src/managers/DataManager.js +5 -27
- package/src/managers/GuildApplicationCommandManager.js +3 -12
- package/src/managers/GuildBanManager.js +16 -105
- package/src/managers/GuildChannelManager.js +31 -226
- package/src/managers/GuildEmojiManager.js +9 -65
- package/src/managers/GuildEmojiRoleManager.js +8 -47
- package/src/managers/GuildForumThreadManager.js +5 -39
- package/src/managers/GuildInviteManager.js +18 -117
- package/src/managers/GuildManager.js +14 -115
- package/src/managers/GuildMemberManager.js +38 -256
- package/src/managers/GuildMemberRoleManager.js +13 -76
- package/src/managers/GuildScheduledEventManager.js +25 -128
- package/src/managers/GuildStickerManager.js +16 -96
- package/src/managers/GuildTextThreadManager.js +4 -47
- package/src/managers/MessageManager.js +23 -137
- package/src/managers/PermissionOverwriteManager.js +10 -78
- package/src/managers/PresenceManager.js +6 -27
- package/src/managers/ReactionManager.js +7 -40
- package/src/managers/ReactionUserManager.js +6 -29
- package/src/managers/RoleManager.js +29 -177
- package/src/managers/StageInstanceManager.js +14 -77
- package/src/managers/ThreadManager.js +23 -113
- package/src/managers/ThreadMemberManager.js +20 -89
- package/src/managers/UserManager.js +13 -65
- package/src/managers/VoiceStateManager.js +3 -13
- package/src/sharding/Shard.js +42 -158
- package/src/sharding/ShardClientUtil.js +17 -101
- package/src/sharding/ShardingManager.js +34 -151
- package/src/structures/ActionRow.js +4 -21
- package/src/structures/ActionRowBuilder.js +3 -13
- package/src/structures/AnonymousGuild.js +10 -43
- package/src/structures/ApplicationCommand.js +54 -308
- package/src/structures/ApplicationRoleConnectionMetadata.js +7 -27
- package/src/structures/Attachment.js +16 -65
- package/src/structures/AttachmentBuilder.js +13 -58
- package/src/structures/AutoModerationActionExecution.js +16 -69
- package/src/structures/AutoModerationRule.js +32 -164
- package/src/structures/AutocompleteInteraction.js +10 -52
- package/src/structures/Base.js +2 -10
- package/src/structures/BaseChannel.js +16 -80
- package/src/structures/BaseGuild.js +13 -59
- package/src/structures/BaseGuildEmoji.js +5 -21
- package/src/structures/BaseGuildTextChannel.js +19 -100
- package/src/structures/BaseGuildVoiceChannel.js +21 -110
- package/src/structures/BaseInteraction.js +40 -196
- package/src/structures/BaseSelectMenuComponent.js +6 -29
- package/src/structures/ButtonBuilder.js +4 -18
- package/src/structures/ButtonComponent.js +7 -34
- package/src/structures/ButtonInteraction.js +1 -4
- package/src/structures/CategoryChannel.js +5 -30
- package/src/structures/ChannelSelectMenuBuilder.js +3 -13
- package/src/structures/ChannelSelectMenuComponent.js +2 -9
- package/src/structures/ChannelSelectMenuInteraction.js +3 -12
- package/src/structures/ChatInputCommandInteraction.js +3 -13
- package/src/structures/ClientApplication.js +20 -83
- package/src/structures/ClientPresence.js +5 -20
- package/src/structures/ClientUser.js +21 -118
- package/src/structures/CommandInteraction.js +21 -96
- package/src/structures/CommandInteractionOptionResolver.js +26 -147
- package/src/structures/Component.js +5 -21
- package/src/structures/ContextMenuCommandInteraction.js +4 -18
- package/src/structures/DMChannel.js +17 -52
- package/src/structures/DirectoryChannel.js +4 -16
- package/src/structures/Embed.js +21 -107
- package/src/structures/EmbedBuilder.js +4 -18
- package/src/structures/Emoji.js +12 -60
- package/src/structures/ForumChannel.js +30 -140
- package/src/structures/Guild.js +117 -697
- package/src/structures/GuildAuditLogs.js +7 -32
- package/src/structures/GuildAuditLogsEntry.js +27 -135
- package/src/structures/GuildBan.js +6 -26
- package/src/structures/GuildChannel.js +36 -188
- package/src/structures/GuildEmoji.js +13 -67
- package/src/structures/GuildMember.js +47 -270
- package/src/structures/GuildPreview.js +19 -84
- package/src/structures/GuildPreviewEmoji.js +3 -13
- package/src/structures/GuildScheduledEvent.js +46 -250
- package/src/structures/GuildTemplate.js +24 -108
- package/src/structures/Integration.js +25 -103
- package/src/structures/IntegrationApplication.js +8 -32
- package/src/structures/InteractionCollector.js +22 -113
- package/src/structures/InteractionResponse.js +11 -46
- package/src/structures/InteractionWebhook.js +8 -33
- package/src/structures/Invite.js +27 -131
- package/src/structures/InviteGuild.js +2 -8
- package/src/structures/InviteStageInstance.js +9 -39
- package/src/structures/MentionableSelectMenuBuilder.js +3 -14
- package/src/structures/MentionableSelectMenuComponent.js +1 -4
- package/src/structures/MentionableSelectMenuInteraction.js +5 -20
- package/src/structures/Message.js +85 -460
- package/src/structures/MessageCollector.js +14 -70
- package/src/structures/MessageComponentInteraction.js +14 -57
- package/src/structures/MessageContextMenuCommandInteraction.js +2 -9
- package/src/structures/MessageMentions.js +25 -136
- package/src/structures/MessagePayload.js +24 -94
- package/src/structures/MessageReaction.js +13 -51
- package/src/structures/ModalBuilder.js +3 -13
- package/src/structures/ModalSubmitFields.js +5 -22
- package/src/structures/ModalSubmitInteraction.js +17 -61
- package/src/structures/NewsChannel.js +2 -16
- package/src/structures/OAuth2Guild.js +3 -12
- package/src/structures/PartialGroupDMChannel.js +7 -27
- package/src/structures/PermissionOverwrites.js +20 -99
- package/src/structures/Presence.js +45 -190
- package/src/structures/ReactionCollector.js +20 -108
- package/src/structures/ReactionEmoji.js +2 -10
- package/src/structures/Role.js +39 -261
- package/src/structures/RoleSelectMenuBuilder.js +3 -13
- package/src/structures/RoleSelectMenuComponent.js +1 -4
- package/src/structures/RoleSelectMenuInteraction.js +3 -12
- package/src/structures/SelectMenuBuilder.js +1 -4
- package/src/structures/SelectMenuComponent.js +1 -4
- package/src/structures/SelectMenuInteraction.js +1 -4
- package/src/structures/SelectMenuOptionBuilder.js +1 -4
- package/src/structures/StageChannel.js +12 -84
- package/src/structures/StageInstance.js +16 -87
- package/src/structures/Sticker.js +25 -124
- package/src/structures/StickerPack.js +12 -52
- package/src/structures/StringSelectMenuBuilder.js +6 -29
- package/src/structures/StringSelectMenuComponent.js +2 -9
- package/src/structures/StringSelectMenuInteraction.js +2 -8
- package/src/structures/StringSelectMenuOptionBuilder.js +4 -18
- package/src/structures/Team.js +11 -52
- package/src/structures/TeamMember.js +7 -33
- package/src/structures/TextChannel.js +3 -14
- package/src/structures/TextInputBuilder.js +3 -13
- package/src/structures/TextInputComponent.js +3 -14
- package/src/structures/ThreadChannel.js +59 -305
- package/src/structures/ThreadMember.js +12 -55
- package/src/structures/Typing.js +8 -35
- package/src/structures/User.js +29 -151
- package/src/structures/UserContextMenuCommandInteraction.js +3 -14
- package/src/structures/UserSelectMenuBuilder.js +3 -13
- package/src/structures/UserSelectMenuComponent.js +1 -4
- package/src/structures/UserSelectMenuInteraction.js +4 -16
- package/src/structures/VoiceChannel.js +8 -67
- package/src/structures/VoiceRegion.js +6 -23
- package/src/structures/VoiceState.js +28 -140
- package/src/structures/Webhook.js +37 -227
- package/src/structures/WelcomeChannel.js +7 -29
- package/src/structures/WelcomeScreen.js +5 -20
- package/src/structures/Widget.js +9 -40
- package/src/structures/WidgetMember.js +15 -61
- package/src/structures/interfaces/Application.js +10 -49
- package/src/structures/interfaces/Collector.js +34 -155
- package/src/structures/interfaces/InteractionResponses.js +25 -164
- package/src/structures/interfaces/TextBasedChannel.js +37 -232
- package/src/util/APITypes.js +183 -456
- package/src/util/ActivityFlagsBitField.js +3 -15
- package/src/util/ApplicationFlagsBitField.js +3 -15
- package/src/util/BitField.js +17 -82
- package/src/util/ChannelFlagsBitField.js +7 -30
- package/src/util/Channels.js +5 -35
- package/src/util/Colors.js +3 -38
- package/src/util/Components.js +21 -75
- package/src/util/Constants.js +17 -144
- package/src/util/DataResolver.js +20 -77
- package/src/util/Events.js +3 -81
- package/src/util/Formatters.js +58 -305
- package/src/util/GuildMemberFlagsBitField.js +7 -30
- package/src/util/IntentsBitField.js +4 -23
- package/src/util/LimitedCollection.js +4 -21
- package/src/util/MessageFlagsBitField.js +5 -21
- package/src/util/Options.js +24 -137
- package/src/util/Partials.js +3 -30
- package/src/util/PermissionsBitField.js +12 -67
- package/src/util/ShardEvents.js +3 -15
- package/src/util/Status.js +3 -17
- package/src/util/Sweepers.js +35 -184
- package/src/util/SystemChannelFlagsBitField.js +7 -32
- package/src/util/ThreadMemberFlagsBitField.js +5 -21
- package/src/util/Transformers.js +2 -11
- package/src/util/UserFlagsBitField.js +5 -21
- package/src/util/Util.js +30 -169
- package/src/util/WebSocketShardEvents.js +3 -14
|
@@ -22,7 +22,7 @@ let zlib;
|
|
|
22
22
|
|
|
23
23
|
try {
|
|
24
24
|
zlib = require('zlib-sync');
|
|
25
|
-
} catch {}
|
|
25
|
+
} catch {}
|
|
26
26
|
|
|
27
27
|
const BeforeReadyWhitelist = [
|
|
28
28
|
GatewayDispatchEvents.Ready,
|
|
@@ -46,81 +46,40 @@ const reasonIsDeprecated = 'the reason property is deprecated, use the code prop
|
|
|
46
46
|
let deprecationEmittedForInvalidSessionEvent = false;
|
|
47
47
|
let deprecationEmittedForDestroyedEvent = false;
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
* The WebSocket manager for this client.
|
|
51
|
-
* <info>This class forwards raw dispatch events,
|
|
52
|
-
* read more about it here {@link https://discord.com/developers/docs/topics/gateway}</info>
|
|
53
|
-
* @extends {EventEmitter}
|
|
54
|
-
*/
|
|
49
|
+
|
|
55
50
|
class WebSocketManager extends EventEmitter {
|
|
56
51
|
constructor(client) {
|
|
57
52
|
super();
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
* The client that instantiated this WebSocketManager
|
|
61
|
-
* @type {Client}
|
|
62
|
-
* @readonly
|
|
63
|
-
* @name WebSocketManager#client
|
|
64
|
-
*/
|
|
54
|
+
|
|
65
55
|
Object.defineProperty(this, 'client', { value: client });
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
* The gateway this manager uses
|
|
69
|
-
* @type {?string}
|
|
70
|
-
*/
|
|
57
|
+
|
|
71
58
|
this.gateway = null;
|
|
72
59
|
|
|
73
|
-
|
|
74
|
-
* A collection of all shards this manager handles
|
|
75
|
-
* @type {Collection<number, WebSocketShard>}
|
|
76
|
-
*/
|
|
60
|
+
|
|
77
61
|
this.shards = new Collection();
|
|
78
62
|
|
|
79
|
-
|
|
80
|
-
* An array of queued events before this WebSocketManager became ready
|
|
81
|
-
* @type {Object[]}
|
|
82
|
-
* @private
|
|
83
|
-
* @name WebSocketManager#packetQueue
|
|
84
|
-
*/
|
|
63
|
+
|
|
85
64
|
Object.defineProperty(this, 'packetQueue', { value: [] });
|
|
86
65
|
|
|
87
|
-
|
|
88
|
-
* The current status of this WebSocketManager
|
|
89
|
-
* @type {Status}
|
|
90
|
-
*/
|
|
66
|
+
|
|
91
67
|
this.status = Status.Idle;
|
|
92
68
|
|
|
93
|
-
|
|
94
|
-
* If this manager was destroyed. It will prevent shards from reconnecting
|
|
95
|
-
* @type {boolean}
|
|
96
|
-
* @private
|
|
97
|
-
*/
|
|
69
|
+
|
|
98
70
|
this.destroyed = false;
|
|
99
71
|
|
|
100
|
-
|
|
101
|
-
* The internal WebSocketManager from `@discordjs/ws`.
|
|
102
|
-
* @type {WSWebSocketManager}
|
|
103
|
-
* @private
|
|
104
|
-
*/
|
|
72
|
+
|
|
105
73
|
this._ws = null;
|
|
106
74
|
}
|
|
107
75
|
|
|
108
|
-
|
|
109
|
-
* The average ping of all WebSocketShards
|
|
110
|
-
* @type {number}
|
|
111
|
-
* @readonly
|
|
112
|
-
*/
|
|
76
|
+
|
|
113
77
|
get ping() {
|
|
114
78
|
const sum = this.shards.reduce((a, b) => a + b.ping, 0);
|
|
115
79
|
return sum / this.shards.size;
|
|
116
80
|
}
|
|
117
81
|
|
|
118
|
-
|
|
119
|
-
* Emits a debug message.
|
|
120
|
-
* @param {string} message The debug message
|
|
121
|
-
* @param {?number} [shardId] The id of the shard that emitted this message, if any
|
|
122
|
-
* @private
|
|
123
|
-
*/
|
|
82
|
+
|
|
124
83
|
debug(message, shardId) {
|
|
125
84
|
this.client.emit(
|
|
126
85
|
Events.Debug,
|
|
@@ -128,10 +87,7 @@ class WebSocketManager extends EventEmitter {
|
|
|
128
87
|
);
|
|
129
88
|
}
|
|
130
89
|
|
|
131
|
-
|
|
132
|
-
* Connects this manager to the gateway.
|
|
133
|
-
* @private
|
|
134
|
-
*/
|
|
90
|
+
|
|
135
91
|
async connect() {
|
|
136
92
|
const invalidToken = new DiscordjsError(ErrorCodes.TokenInvalid);
|
|
137
93
|
const { shards, shardCount, intents, ws } = this.client.options;
|
|
@@ -189,12 +145,7 @@ class WebSocketManager extends EventEmitter {
|
|
|
189
145
|
this.shards.set(id, shard);
|
|
190
146
|
|
|
191
147
|
shard.on(WebSocketShardEvents.AllReady, unavailableGuilds => {
|
|
192
|
-
|
|
193
|
-
* Emitted when a shard turns ready.
|
|
194
|
-
* @event Client#shardReady
|
|
195
|
-
* @param {number} id The shard id that turned ready
|
|
196
|
-
* @param {?Set<Snowflake>} unavailableGuilds Set of unavailable guild ids, if any
|
|
197
|
-
*/
|
|
148
|
+
|
|
198
149
|
this.client.emit(Events.ShardReady, shard.id, unavailableGuilds);
|
|
199
150
|
|
|
200
151
|
this.checkShardsReady();
|
|
@@ -225,10 +176,7 @@ class WebSocketManager extends EventEmitter {
|
|
|
225
176
|
});
|
|
226
177
|
}
|
|
227
178
|
|
|
228
|
-
|
|
229
|
-
* Attaches event handlers to the internal WebSocketShardManager from `@discordjs/ws`.
|
|
230
|
-
* @private
|
|
231
|
-
*/
|
|
179
|
+
|
|
232
180
|
attachEvents() {
|
|
233
181
|
this._ws.on(WSWebSocketShardEvents.Debug, ({ message, shardId }) => this.debug(message, shardId));
|
|
234
182
|
this._ws.on(WSWebSocketShardEvents.Dispatch, ({ data, shardId }) => {
|
|
@@ -250,23 +198,14 @@ class WebSocketManager extends EventEmitter {
|
|
|
250
198
|
shard.emit(WebSocketShardEvents.Close, { code, reason: reasonIsDeprecated, wasClean: true });
|
|
251
199
|
if (UNRESUMABLE_CLOSE_CODES.includes(code) && this.destroyed) {
|
|
252
200
|
shard.status = Status.Disconnected;
|
|
253
|
-
|
|
254
|
-
* Emitted when a shard's WebSocket disconnects and will no longer reconnect.
|
|
255
|
-
* @event Client#shardDisconnect
|
|
256
|
-
* @param {CloseEvent} event The WebSocket close event
|
|
257
|
-
* @param {number} id The shard id that disconnected
|
|
258
|
-
*/
|
|
201
|
+
|
|
259
202
|
this.client.emit(Events.ShardDisconnect, { code, reason: reasonIsDeprecated, wasClean: true }, shardId);
|
|
260
203
|
this.debug(GatewayCloseCodes[code], shardId);
|
|
261
204
|
return;
|
|
262
205
|
}
|
|
263
206
|
|
|
264
207
|
this.shards.get(shardId).status = Status.Connecting;
|
|
265
|
-
|
|
266
|
-
* Emitted when a shard is attempting to reconnect or re-identify.
|
|
267
|
-
* @event Client#shardReconnecting
|
|
268
|
-
* @param {number} id The shard id that is attempting to reconnect
|
|
269
|
-
*/
|
|
208
|
+
|
|
270
209
|
this.client.emit(Events.ShardReconnecting, shardId);
|
|
271
210
|
});
|
|
272
211
|
this._ws.on(WSWebSocketShardEvents.Hello, ({ shardId }) => {
|
|
@@ -282,10 +221,7 @@ class WebSocketManager extends EventEmitter {
|
|
|
282
221
|
this._ws.on(WSWebSocketShardEvents.Resumed, ({ shardId }) => {
|
|
283
222
|
const shard = this.shards.get(shardId);
|
|
284
223
|
shard.status = Status.Ready;
|
|
285
|
-
|
|
286
|
-
* Emitted when the shard resumes successfully
|
|
287
|
-
* @event WebSocketShard#resumed
|
|
288
|
-
*/
|
|
224
|
+
|
|
289
225
|
shard.emit(WebSocketShardEvents.Resumed);
|
|
290
226
|
});
|
|
291
227
|
|
|
@@ -297,44 +233,26 @@ class WebSocketManager extends EventEmitter {
|
|
|
297
233
|
});
|
|
298
234
|
|
|
299
235
|
this._ws.on(WSWebSocketShardEvents.Error, ({ error, shardId }) => {
|
|
300
|
-
|
|
301
|
-
* Emitted whenever a shard's WebSocket encounters a connection error.
|
|
302
|
-
* @event Client#shardError
|
|
303
|
-
* @param {Error} error The encountered error
|
|
304
|
-
* @param {number} shardId The shard that encountered this error
|
|
305
|
-
*/
|
|
236
|
+
|
|
306
237
|
this.client.emit(Events.ShardError, error, shardId);
|
|
307
238
|
});
|
|
308
239
|
}
|
|
309
240
|
|
|
310
|
-
|
|
311
|
-
* Broadcasts a packet to every shard this manager handles.
|
|
312
|
-
* @param {Object} packet The packet to send
|
|
313
|
-
* @private
|
|
314
|
-
*/
|
|
241
|
+
|
|
315
242
|
broadcast(packet) {
|
|
316
243
|
for (const shardId of this.shards.keys()) this._ws.send(shardId, packet);
|
|
317
244
|
}
|
|
318
245
|
|
|
319
|
-
|
|
320
|
-
* Destroys this manager and all its shards.
|
|
321
|
-
* @private
|
|
322
|
-
*/
|
|
246
|
+
|
|
323
247
|
destroy() {
|
|
324
248
|
if (this.destroyed) return;
|
|
325
|
-
|
|
249
|
+
|
|
326
250
|
this.debug(`Manager was destroyed. Called by:\n${new Error().stack}`);
|
|
327
251
|
this.destroyed = true;
|
|
328
252
|
this._ws.destroy({ code: CloseCodes.Normal });
|
|
329
253
|
}
|
|
330
254
|
|
|
331
|
-
|
|
332
|
-
* Processes a packet and queues it if this WebSocketManager is not ready.
|
|
333
|
-
* @param {Object} [packet] The packet to be handled
|
|
334
|
-
* @param {WebSocketShard} [shard] The shard that will handle this packet
|
|
335
|
-
* @returns {boolean}
|
|
336
|
-
* @private
|
|
337
|
-
*/
|
|
255
|
+
|
|
338
256
|
handlePacket(packet, shard) {
|
|
339
257
|
if (packet && this.status !== Status.Ready) {
|
|
340
258
|
if (!BeforeReadyWhitelist.includes(packet.t)) {
|
|
@@ -357,10 +275,7 @@ class WebSocketManager extends EventEmitter {
|
|
|
357
275
|
return true;
|
|
358
276
|
}
|
|
359
277
|
|
|
360
|
-
|
|
361
|
-
* Checks whether the client is ready to be marked as ready.
|
|
362
|
-
* @private
|
|
363
|
-
*/
|
|
278
|
+
|
|
364
279
|
checkShardsReady() {
|
|
365
280
|
if (this.status === Status.Ready) return;
|
|
366
281
|
if (this.shards.size !== this.totalShards || this.shards.some(s => s.status !== Status.Ready)) {
|
|
@@ -370,20 +285,13 @@ class WebSocketManager extends EventEmitter {
|
|
|
370
285
|
this.triggerClientReady();
|
|
371
286
|
}
|
|
372
287
|
|
|
373
|
-
|
|
374
|
-
* Causes the client to be marked as ready and emits the ready event.
|
|
375
|
-
* @private
|
|
376
|
-
*/
|
|
288
|
+
|
|
377
289
|
triggerClientReady() {
|
|
378
290
|
this.status = Status.Ready;
|
|
379
291
|
|
|
380
292
|
this.client.readyTimestamp = Date.now();
|
|
381
293
|
|
|
382
|
-
|
|
383
|
-
* Emitted when the client becomes ready to start working.
|
|
384
|
-
* @event Client#ready
|
|
385
|
-
* @param {Client} client The client
|
|
386
|
-
*/
|
|
294
|
+
|
|
387
295
|
this.client.emit(Events.ClientReady, this.client);
|
|
388
296
|
|
|
389
297
|
this.handlePacket();
|
|
@@ -8,101 +8,49 @@ const Status = require('../../util/Status');
|
|
|
8
8
|
const WebSocketShardEvents = require('../../util/WebSocketShardEvents');
|
|
9
9
|
|
|
10
10
|
let deprecationEmittedForImportant = false;
|
|
11
|
-
|
|
12
|
-
* Represents a Shard's WebSocket connection
|
|
13
|
-
* @extends {EventEmitter}
|
|
14
|
-
*/
|
|
11
|
+
|
|
15
12
|
class WebSocketShard extends EventEmitter {
|
|
16
13
|
constructor(manager, id) {
|
|
17
14
|
super();
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
* The WebSocketManager of the shard
|
|
21
|
-
* @type {WebSocketManager}
|
|
22
|
-
*/
|
|
16
|
+
|
|
23
17
|
this.manager = manager;
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
* The shard's id
|
|
27
|
-
* @type {number}
|
|
28
|
-
*/
|
|
19
|
+
|
|
29
20
|
this.id = id;
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
* The current status of the shard
|
|
33
|
-
* @type {Status}
|
|
34
|
-
*/
|
|
22
|
+
|
|
35
23
|
this.status = Status.Idle;
|
|
36
24
|
|
|
37
|
-
|
|
38
|
-
* The sequence of the shard after close
|
|
39
|
-
* @type {number}
|
|
40
|
-
* @private
|
|
41
|
-
*/
|
|
25
|
+
|
|
42
26
|
this.closeSequence = 0;
|
|
43
27
|
|
|
44
|
-
|
|
45
|
-
* The previous heartbeat ping of the shard
|
|
46
|
-
* @type {number}
|
|
47
|
-
*/
|
|
28
|
+
|
|
48
29
|
this.ping = -1;
|
|
49
30
|
|
|
50
|
-
|
|
51
|
-
* The last time a ping was sent (a timestamp)
|
|
52
|
-
* @type {number}
|
|
53
|
-
*/
|
|
31
|
+
|
|
54
32
|
this.lastPingTimestamp = -1;
|
|
55
33
|
|
|
56
|
-
|
|
57
|
-
* A set of guild ids this shard expects to receive
|
|
58
|
-
* @name WebSocketShard#expectedGuilds
|
|
59
|
-
* @type {?Set<string>}
|
|
60
|
-
* @private
|
|
61
|
-
*/
|
|
34
|
+
|
|
62
35
|
Object.defineProperty(this, 'expectedGuilds', { value: null, writable: true });
|
|
63
36
|
|
|
64
|
-
|
|
65
|
-
* The ready timeout
|
|
66
|
-
* @name WebSocketShard#readyTimeout
|
|
67
|
-
* @type {?NodeJS.Timeout}
|
|
68
|
-
* @private
|
|
69
|
-
*/
|
|
37
|
+
|
|
70
38
|
Object.defineProperty(this, 'readyTimeout', { value: null, writable: true });
|
|
71
39
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* The session info used by `@discordjs/ws` package.
|
|
79
|
-
* @name WebSocketShard#sessionInfo
|
|
80
|
-
* @type {?SessionInfo}
|
|
81
|
-
* @private
|
|
82
|
-
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
83
43
|
Object.defineProperty(this, 'sessionInfo', { value: null, writable: true });
|
|
84
44
|
}
|
|
85
45
|
|
|
86
|
-
|
|
87
|
-
* Emits a debug event.
|
|
88
|
-
* @param {string} message The debug message
|
|
89
|
-
* @private
|
|
90
|
-
*/
|
|
46
|
+
|
|
91
47
|
debug(message) {
|
|
92
48
|
this.manager.debug(message, this.id);
|
|
93
49
|
}
|
|
94
50
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* This method is responsible to emit close event for this shard.
|
|
102
|
-
* This method helps the shard reconnect.
|
|
103
|
-
* @param {CloseEvent} [event] Close event that was received
|
|
104
|
-
* @deprecated
|
|
105
|
-
*/
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
106
54
|
emitClose(
|
|
107
55
|
event = {
|
|
108
56
|
code: 1011,
|
|
@@ -114,78 +62,51 @@ class WebSocketShard extends EventEmitter {
|
|
|
114
62
|
Event Code: ${event.code}
|
|
115
63
|
Clean : ${event.wasClean}
|
|
116
64
|
Reason : ${event.reason ?? 'No reason received'}`);
|
|
117
|
-
|
|
118
|
-
* Emitted when a shard's WebSocket closes.
|
|
119
|
-
* @private
|
|
120
|
-
* @event WebSocketShard#close
|
|
121
|
-
* @param {CloseEvent} event The received event
|
|
122
|
-
*/
|
|
65
|
+
|
|
123
66
|
this.emit(WebSocketShardEvents.Close, event);
|
|
124
67
|
}
|
|
125
68
|
|
|
126
|
-
|
|
127
|
-
* Called when the shard receives the READY payload.
|
|
128
|
-
* @param {Object} packet The received packet
|
|
129
|
-
* @private
|
|
130
|
-
*/
|
|
69
|
+
|
|
131
70
|
onReadyPacket(packet) {
|
|
132
71
|
if (!packet) {
|
|
133
72
|
this.debug(`Received broken packet: '${packet}'.`);
|
|
134
73
|
return;
|
|
135
74
|
}
|
|
136
75
|
|
|
137
|
-
|
|
138
|
-
* Emitted when the shard receives the READY payload and is now waiting for guilds
|
|
139
|
-
* @event WebSocketShard#ready
|
|
140
|
-
*/
|
|
76
|
+
|
|
141
77
|
this.emit(WebSocketShardEvents.Ready);
|
|
142
78
|
|
|
143
79
|
this.expectedGuilds = new Set(packet.guilds.map(d => d.id));
|
|
144
80
|
this.status = Status.WaitingForGuilds;
|
|
145
81
|
}
|
|
146
82
|
|
|
147
|
-
|
|
148
|
-
* Called when a GuildCreate or GuildDelete for this shard was sent after READY payload was received,
|
|
149
|
-
* but before we emitted the READY event.
|
|
150
|
-
* @param {Snowflake} guildId the id of the Guild sent in the payload
|
|
151
|
-
* @private
|
|
152
|
-
*/
|
|
83
|
+
|
|
153
84
|
gotGuild(guildId) {
|
|
154
85
|
this.expectedGuilds.delete(guildId);
|
|
155
86
|
this.checkReady();
|
|
156
87
|
}
|
|
157
88
|
|
|
158
|
-
|
|
159
|
-
* Checks if the shard can be marked as ready
|
|
160
|
-
* @private
|
|
161
|
-
*/
|
|
89
|
+
|
|
162
90
|
checkReady() {
|
|
163
|
-
|
|
91
|
+
|
|
164
92
|
if (this.readyTimeout) {
|
|
165
93
|
clearTimeout(this.readyTimeout);
|
|
166
94
|
this.readyTimeout = null;
|
|
167
95
|
}
|
|
168
|
-
|
|
96
|
+
|
|
169
97
|
if (!this.expectedGuilds.size) {
|
|
170
98
|
this.debug('Shard received all its guilds. Marking as fully ready.');
|
|
171
99
|
this.status = Status.Ready;
|
|
172
100
|
|
|
173
|
-
|
|
174
|
-
* Emitted when the shard is fully ready.
|
|
175
|
-
* This event is emitted if:
|
|
176
|
-
* * all guilds were received by this shard
|
|
177
|
-
* * the ready timeout expired, and some guilds are unavailable
|
|
178
|
-
* @event WebSocketShard#allReady
|
|
179
|
-
* @param {?Set<string>} unavailableGuilds Set of unavailable guilds, if any
|
|
180
|
-
*/
|
|
101
|
+
|
|
181
102
|
this.emit(WebSocketShardEvents.AllReady);
|
|
182
103
|
return;
|
|
183
104
|
}
|
|
184
105
|
const hasGuildsIntent = this.manager.client.options.intents.has(GatewayIntentBits.Guilds);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
189
110
|
|
|
190
111
|
const { waitGuildTimeout } = this.manager.client.options;
|
|
191
112
|
|
|
@@ -207,15 +128,7 @@ class WebSocketShard extends EventEmitter {
|
|
|
207
128
|
).unref();
|
|
208
129
|
}
|
|
209
130
|
|
|
210
|
-
|
|
211
|
-
* Adds a packet to the queue to be sent to the gateway.
|
|
212
|
-
* <warn>If you use this method, make sure you understand that you need to provide
|
|
213
|
-
* a full [Payload](https://discord.com/developers/docs/topics/gateway#commands-and-events-gateway-commands).
|
|
214
|
-
* Do not use this method if you don't know what you're doing.</warn>
|
|
215
|
-
* @param {Object} data The full packet to send
|
|
216
|
-
* @param {boolean} [important=false] If this packet should be added first in queue
|
|
217
|
-
* <warn>This parameter is **deprecated**. Important payloads are determined by their opcode instead.</warn>
|
|
218
|
-
*/
|
|
131
|
+
|
|
219
132
|
send(data, important = false) {
|
|
220
133
|
if (important && !deprecationEmittedForImportant) {
|
|
221
134
|
process.emitWarning(
|
|
@@ -7,16 +7,10 @@ module.exports = (client, { d: data }) => {
|
|
|
7
7
|
const time = data.last_pin_timestamp ? Date.parse(data.last_pin_timestamp) : null;
|
|
8
8
|
|
|
9
9
|
if (channel) {
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
channel.lastPinTimestamp = time;
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
* Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event,
|
|
15
|
-
* not much information can be provided easily here - you need to manually check the pins yourself.
|
|
16
|
-
* @event Client#channelPinsUpdate
|
|
17
|
-
* @param {TextBasedChannels} channel The channel that the pins update occurred in
|
|
18
|
-
* @param {Date} time The time of the pins update
|
|
19
|
-
*/
|
|
13
|
+
|
|
20
14
|
client.emit(Events.ChannelPinsUpdate, channel, time);
|
|
21
15
|
}
|
|
22
16
|
};
|
|
@@ -5,12 +5,7 @@ const Events = require('../../../util/Events');
|
|
|
5
5
|
module.exports = (client, packet) => {
|
|
6
6
|
const { old, updated } = client.actions.ChannelUpdate.handle(packet.d);
|
|
7
7
|
if (old && updated) {
|
|
8
|
-
|
|
9
|
-
* Emitted whenever a channel is updated - e.g. name change, topic change, channel type change.
|
|
10
|
-
* @event Client#channelUpdate
|
|
11
|
-
* @param {DMChannel|GuildChannel} oldChannel The channel before the update
|
|
12
|
-
* @param {DMChannel|GuildChannel} newChannel The channel after the update
|
|
13
|
-
*/
|
|
8
|
+
|
|
14
9
|
client.emit(Events.ChannelUpdate, old, updated);
|
|
15
10
|
}
|
|
16
11
|
};
|
|
@@ -7,19 +7,15 @@ module.exports = (client, { d: data }, shard) => {
|
|
|
7
7
|
let guild = client.guilds.cache.get(data.id);
|
|
8
8
|
if (guild) {
|
|
9
9
|
if (!guild.available && !data.unavailable) {
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
guild._patch(data);
|
|
12
12
|
}
|
|
13
13
|
} else {
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
data.shardId = shard.id;
|
|
16
16
|
guild = client.guilds._add(data);
|
|
17
17
|
if (client.ws.status === Status.Ready) {
|
|
18
|
-
|
|
19
|
-
* Emitted whenever the client joins a guild.
|
|
20
|
-
* @event Client#guildCreate
|
|
21
|
-
* @param {Guild} guild The created guild
|
|
22
|
-
*/
|
|
18
|
+
|
|
23
19
|
client.emit(Events.GuildCreate, guild);
|
|
24
20
|
}
|
|
25
21
|
}
|
|
@@ -13,23 +13,9 @@ module.exports = (client, { d: data }) => {
|
|
|
13
13
|
for (const presence of data.presences) guild.presences._add(Object.assign(presence, { guild }));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
* Represents the properties of a guild members chunk
|
|
18
|
-
* @typedef {Object} GuildMembersChunk
|
|
19
|
-
* @property {number} index Index of the received chunk
|
|
20
|
-
* @property {number} count Number of chunks the client should receive
|
|
21
|
-
* @property {Array<*>} notFound An array of whatever could not be found
|
|
22
|
-
* when using {@link GatewayOpcodes.RequestGuildMembers}
|
|
23
|
-
* @property {?string} nonce Nonce for this chunk
|
|
24
|
-
*/
|
|
16
|
+
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
* Emitted whenever a chunk of guild members is received (all members come from the same guild).
|
|
28
|
-
* @event Client#guildMembersChunk
|
|
29
|
-
* @param {Collection<Snowflake, GuildMember>} members The members in the chunk
|
|
30
|
-
* @param {Guild} guild The guild related to the member chunk
|
|
31
|
-
* @param {GuildMembersChunk} chunk Properties of the received chunk
|
|
32
|
-
*/
|
|
18
|
+
|
|
33
19
|
client.emit(Events.GuildMembersChunk, members, guild, {
|
|
34
20
|
index: data.chunk_index,
|
|
35
21
|
count: data.chunk_count,
|
|
@@ -9,11 +9,7 @@ module.exports = (client, { d: data }, shard) => {
|
|
|
9
9
|
guild.memberCount++;
|
|
10
10
|
const member = guild.members._add(data);
|
|
11
11
|
if (shard.status === Status.Ready) {
|
|
12
|
-
|
|
13
|
-
* Emitted whenever a user joins a guild.
|
|
14
|
-
* @event Client#guildMemberAdd
|
|
15
|
-
* @param {GuildMember} member The member that has joined a guild
|
|
16
|
-
*/
|
|
12
|
+
|
|
17
13
|
client.emit(Events.GuildMemberAdd, member);
|
|
18
14
|
}
|
|
19
15
|
}
|
|
@@ -5,12 +5,7 @@ const Events = require('../../../util/Events');
|
|
|
5
5
|
module.exports = (client, packet) => {
|
|
6
6
|
const { old, updated } = client.actions.MessageUpdate.handle(packet.d);
|
|
7
7
|
if (old && updated) {
|
|
8
|
-
|
|
9
|
-
* Emitted whenever a message is updated - e.g. embed or content change.
|
|
10
|
-
* @event Client#messageUpdate
|
|
11
|
-
* @param {Message} oldMessage The message before the update
|
|
12
|
-
* @param {Message} newMessage The message after the update
|
|
13
|
-
*/
|
|
8
|
+
|
|
14
9
|
client.emit(Events.MessageUpdate, old, updated);
|
|
15
10
|
}
|
|
16
11
|
};
|
|
@@ -4,11 +4,6 @@ const Events = require('../../../util/Events');
|
|
|
4
4
|
|
|
5
5
|
module.exports = (client, packet, shard) => {
|
|
6
6
|
const replayed = shard.sessionInfo.sequence - shard.closeSequence;
|
|
7
|
-
|
|
8
|
-
* Emitted when a shard resumes successfully.
|
|
9
|
-
* @event Client#shardResume
|
|
10
|
-
* @param {number} id The shard id that resumed
|
|
11
|
-
* @param {number} replayedEvents The amount of replayed events
|
|
12
|
-
*/
|
|
7
|
+
|
|
13
8
|
client.emit(Events.ShardResume, shard.id, replayed);
|
|
14
9
|
};
|
|
@@ -5,12 +5,7 @@ const Events = require('../../../util/Events');
|
|
|
5
5
|
module.exports = (client, packet) => {
|
|
6
6
|
const { old, updated } = client.actions.ChannelUpdate.handle(packet.d);
|
|
7
7
|
if (old && updated) {
|
|
8
|
-
|
|
9
|
-
* Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change.
|
|
10
|
-
* @event Client#threadUpdate
|
|
11
|
-
* @param {ThreadChannel} oldThread The thread before the update
|
|
12
|
-
* @param {ThreadChannel} newThread The thread after the update
|
|
13
|
-
*/
|
|
8
|
+
|
|
14
9
|
client.emit(Events.ThreadUpdate, old, updated);
|
|
15
10
|
}
|
|
16
11
|
};
|
package/src/errors/DJSError.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
const ErrorCodes = require('./ErrorCodes');
|
|
5
5
|
const Messages = require('./Messages');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
* Extend an error of some sort into a DiscordjsError.
|
|
9
|
-
* @param {Error} Base Base error to extend
|
|
10
|
-
* @returns {DiscordjsError}
|
|
11
|
-
* @ignore
|
|
12
|
-
*/
|
|
7
|
+
|
|
13
8
|
function makeDiscordjsError(Base) {
|
|
14
9
|
return class DiscordjsError extends Base {
|
|
15
10
|
constructor(code, ...args) {
|
|
@@ -24,13 +19,7 @@ function makeDiscordjsError(Base) {
|
|
|
24
19
|
};
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
* Format the message for an error.
|
|
29
|
-
* @param {string} code The error code
|
|
30
|
-
* @param {Array<*>} args Arguments to pass for util format or as function args
|
|
31
|
-
* @returns {string} Formatted string
|
|
32
|
-
* @ignore
|
|
33
|
-
*/
|
|
22
|
+
|
|
34
23
|
function message(code, args) {
|
|
35
24
|
if (!(code in ErrorCodes)) throw new Error('Error code must be a valid DiscordjsErrorCodes');
|
|
36
25
|
const msg = Messages[code];
|