@velliajs/discord 1.0.3 → 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/package.json +1 -1
- 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
|
@@ -10,41 +10,13 @@ const Shard = require('./Shard');
|
|
|
10
10
|
const { DiscordjsError, DiscordjsTypeError, DiscordjsRangeError, ErrorCodes } = require('../errors');
|
|
11
11
|
const { mergeDefault, fetchRecommendedShardCount } = require('../util/Util');
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
* This is a utility class that makes multi-process sharding of a bot an easy and painless experience.
|
|
15
|
-
* It works by spawning a self-contained {@link ChildProcess} or {@link Worker} for each individual shard, each
|
|
16
|
-
* containing its own instance of your bot's {@link Client}. They all have a line of communication with the master
|
|
17
|
-
* process, and there are several useful methods that utilise it in order to simplify tasks that are normally difficult
|
|
18
|
-
* with sharding. It can spawn a specific number of shards or the amount that Discord suggests for the bot, and takes a
|
|
19
|
-
* path to your main bot script to launch for each one.
|
|
20
|
-
* @extends {EventEmitter}
|
|
21
|
-
*/
|
|
13
|
+
|
|
22
14
|
class ShardingManager extends EventEmitter {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The options to spawn shards with for a {@link ShardingManager}.
|
|
32
|
-
* @typedef {Object} ShardingManagerOptions
|
|
33
|
-
* @property {string|number} [totalShards='auto'] Number of total shards of all shard managers or "auto"
|
|
34
|
-
* @property {string|number[]} [shardList='auto'] List of shards to spawn or "auto"
|
|
35
|
-
* @property {ShardingManagerMode} [mode='process'] Which mode to use for shards
|
|
36
|
-
* @property {boolean} [respawn=true] Whether shards should automatically respawn upon exiting
|
|
37
|
-
* @property {string[]} [shardArgs=[]] Arguments to pass to the shard script when spawning
|
|
38
|
-
* (only available when mode is set to 'process')
|
|
39
|
-
* @property {string[]} [execArgv=[]] Arguments to pass to the shard script executable when spawning
|
|
40
|
-
* (only available when mode is set to 'process')
|
|
41
|
-
* @property {string} [token] Token to use for automatic shard count and passing to shards
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @param {string} file Path to your shard script file
|
|
46
|
-
* @param {ShardingManagerOptions} [options] Options for the sharding manager
|
|
47
|
-
*/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
48
20
|
constructor(file, options = {}) {
|
|
49
21
|
super();
|
|
50
22
|
options = mergeDefault(
|
|
@@ -59,20 +31,14 @@ class ShardingManager extends EventEmitter {
|
|
|
59
31
|
options,
|
|
60
32
|
);
|
|
61
33
|
|
|
62
|
-
|
|
63
|
-
* Path to the shard script file
|
|
64
|
-
* @type {string}
|
|
65
|
-
*/
|
|
34
|
+
|
|
66
35
|
this.file = file;
|
|
67
36
|
if (!file) throw new DiscordjsError(ErrorCodes.ClientInvalidOption, 'File', 'specified.');
|
|
68
37
|
if (!path.isAbsolute(file)) this.file = path.resolve(process.cwd(), file);
|
|
69
38
|
const stats = fs.statSync(this.file);
|
|
70
39
|
if (!stats.isFile()) throw new DiscordjsError(ErrorCodes.ClientInvalidOption, 'File', 'a file');
|
|
71
40
|
|
|
72
|
-
|
|
73
|
-
* List of shards this sharding manager spawns
|
|
74
|
-
* @type {string|number[]}
|
|
75
|
-
*/
|
|
41
|
+
|
|
76
42
|
this.shardList = options.shardList ?? 'auto';
|
|
77
43
|
if (this.shardList !== 'auto') {
|
|
78
44
|
if (!Array.isArray(this.shardList)) {
|
|
@@ -91,10 +57,7 @@ class ShardingManager extends EventEmitter {
|
|
|
91
57
|
}
|
|
92
58
|
}
|
|
93
59
|
|
|
94
|
-
|
|
95
|
-
* Amount of shards that all sharding managers spawn in total
|
|
96
|
-
* @type {number}
|
|
97
|
-
*/
|
|
60
|
+
|
|
98
61
|
this.totalShards = options.totalShards || 'auto';
|
|
99
62
|
if (this.totalShards !== 'auto') {
|
|
100
63
|
if (typeof this.totalShards !== 'number' || isNaN(this.totalShards)) {
|
|
@@ -108,43 +71,25 @@ class ShardingManager extends EventEmitter {
|
|
|
108
71
|
}
|
|
109
72
|
}
|
|
110
73
|
|
|
111
|
-
|
|
112
|
-
* Mode for shards to spawn with
|
|
113
|
-
* @type {ShardingManagerMode}
|
|
114
|
-
*/
|
|
74
|
+
|
|
115
75
|
this.mode = options.mode;
|
|
116
76
|
if (this.mode !== 'process' && this.mode !== 'worker') {
|
|
117
77
|
throw new DiscordjsRangeError(ErrorCodes.ClientInvalidOption, 'Sharding mode', '"process" or "worker"');
|
|
118
78
|
}
|
|
119
79
|
|
|
120
|
-
|
|
121
|
-
* Whether shards should automatically respawn upon exiting
|
|
122
|
-
* @type {boolean}
|
|
123
|
-
*/
|
|
80
|
+
|
|
124
81
|
this.respawn = options.respawn;
|
|
125
82
|
|
|
126
|
-
|
|
127
|
-
* An array of arguments to pass to shards (only when {@link ShardingManager#mode} is `process`)
|
|
128
|
-
* @type {string[]}
|
|
129
|
-
*/
|
|
83
|
+
|
|
130
84
|
this.shardArgs = options.shardArgs;
|
|
131
85
|
|
|
132
|
-
|
|
133
|
-
* An array of arguments to pass to the executable (only when {@link ShardingManager#mode} is `process`)
|
|
134
|
-
* @type {string[]}
|
|
135
|
-
*/
|
|
86
|
+
|
|
136
87
|
this.execArgv = options.execArgv;
|
|
137
88
|
|
|
138
|
-
|
|
139
|
-
* Token to use for obtaining the automatic shard count, and passing to shards
|
|
140
|
-
* @type {?string}
|
|
141
|
-
*/
|
|
89
|
+
|
|
142
90
|
this.token = options.token?.replace(/^Bot\s*/i, '') ?? null;
|
|
143
91
|
|
|
144
|
-
|
|
145
|
-
* A collection of shards that this manager has spawned
|
|
146
|
-
* @type {Collection<number, Shard>}
|
|
147
|
-
*/
|
|
92
|
+
|
|
148
93
|
this.shards = new Collection();
|
|
149
94
|
|
|
150
95
|
process.env.SHARDING_MANAGER = true;
|
|
@@ -152,40 +97,20 @@ class ShardingManager extends EventEmitter {
|
|
|
152
97
|
process.env.DISCORD_TOKEN = this.token;
|
|
153
98
|
}
|
|
154
99
|
|
|
155
|
-
|
|
156
|
-
* Creates a single shard.
|
|
157
|
-
* <warn>Using this method is usually not necessary if you use the spawn method.</warn>
|
|
158
|
-
* @param {number} [id=this.shards.size] Id of the shard to create
|
|
159
|
-
* <info>This is usually not necessary to manually specify.</info>
|
|
160
|
-
* @returns {Shard} Note that the created shard needs to be explicitly spawned using its spawn method.
|
|
161
|
-
*/
|
|
100
|
+
|
|
162
101
|
createShard(id = this.shards.size) {
|
|
163
102
|
const shard = new Shard(this, id);
|
|
164
103
|
this.shards.set(id, shard);
|
|
165
|
-
|
|
166
|
-
* Emitted upon creating a shard.
|
|
167
|
-
* @event ShardingManager#shardCreate
|
|
168
|
-
* @param {Shard} shard Shard that was created
|
|
169
|
-
*/
|
|
104
|
+
|
|
170
105
|
this.emit('shardCreate', shard);
|
|
171
106
|
return shard;
|
|
172
107
|
}
|
|
173
108
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
* @property {number|string} [amount=this.totalShards] Number of shards to spawn
|
|
178
|
-
* @property {number} [delay=5500] How long to wait in between spawning each shard (in milliseconds)
|
|
179
|
-
* @property {number} [timeout=30000] The amount in milliseconds to wait until the {@link Client} has become ready
|
|
180
|
-
*/
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Spawns multiple shards.
|
|
184
|
-
* @param {MultipleShardSpawnOptions} [options] Options for spawning shards
|
|
185
|
-
* @returns {Promise<Collection<number, Shard>>}
|
|
186
|
-
*/
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
187
112
|
async spawn({ amount = this.totalShards, delay = 5500, timeout = 30_000 } = {}) {
|
|
188
|
-
|
|
113
|
+
|
|
189
114
|
if (amount === 'auto') {
|
|
190
115
|
amount = await fetchRecommendedShardCount(this.token);
|
|
191
116
|
} else {
|
|
@@ -198,7 +123,7 @@ class ShardingManager extends EventEmitter {
|
|
|
198
123
|
}
|
|
199
124
|
}
|
|
200
125
|
|
|
201
|
-
|
|
126
|
+
|
|
202
127
|
if (this.shards.size >= amount) throw new DiscordjsError(ErrorCodes.ShardingAlreadySpawned, this.shards.size);
|
|
203
128
|
if (this.shardList === 'auto' || this.totalShards === 'auto' || this.totalShards !== amount) {
|
|
204
129
|
this.shardList = [...Array(amount).keys()];
|
|
@@ -215,42 +140,28 @@ class ShardingManager extends EventEmitter {
|
|
|
215
140
|
);
|
|
216
141
|
}
|
|
217
142
|
|
|
218
|
-
|
|
143
|
+
|
|
219
144
|
for (const shardId of this.shardList) {
|
|
220
145
|
const promises = [];
|
|
221
146
|
const shard = this.createShard(shardId);
|
|
222
147
|
promises.push(shard.spawn(timeout));
|
|
223
148
|
if (delay > 0 && this.shards.size !== this.shardList.length) promises.push(sleep(delay));
|
|
224
|
-
await Promise.all(promises);
|
|
149
|
+
await Promise.all(promises);
|
|
225
150
|
}
|
|
226
151
|
|
|
227
152
|
return this.shards;
|
|
228
153
|
}
|
|
229
154
|
|
|
230
|
-
|
|
231
|
-
* Sends a message to all shards.
|
|
232
|
-
* @param {*} message Message to be sent to the shards
|
|
233
|
-
* @returns {Promise<Shard[]>}
|
|
234
|
-
*/
|
|
155
|
+
|
|
235
156
|
broadcast(message) {
|
|
236
157
|
const promises = [];
|
|
237
158
|
for (const shard of this.shards.values()) promises.push(shard.send(message));
|
|
238
159
|
return Promise.all(promises);
|
|
239
160
|
}
|
|
240
161
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
* @property {number} [shard] Shard to run script on, all if undefined
|
|
245
|
-
* @property {*} [context] The JSON-serializable values to call the script with
|
|
246
|
-
*/
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Evaluates a script on all shards, or a given shard, in the context of the {@link Client}s.
|
|
250
|
-
* @param {Function} script JavaScript to run on each shard
|
|
251
|
-
* @param {BroadcastEvalOptions} [options={}] The options for the broadcast
|
|
252
|
-
* @returns {Promise<*|Array<*>>} Results of the script execution
|
|
253
|
-
*/
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
254
165
|
broadcastEval(script, options = {}) {
|
|
255
166
|
if (typeof script !== 'function') {
|
|
256
167
|
return Promise.reject(new DiscordjsTypeError(ErrorCodes.ShardingInvalidEvalBroadcast));
|
|
@@ -258,28 +169,12 @@ class ShardingManager extends EventEmitter {
|
|
|
258
169
|
return this._performOnShards('eval', [`(${script})(this, ${JSON.stringify(options.context)})`], options.shard);
|
|
259
170
|
}
|
|
260
171
|
|
|
261
|
-
|
|
262
|
-
* Fetches a client property value of each shard, or a given shard.
|
|
263
|
-
* @param {string} prop Name of the client property to get, using periods for nesting
|
|
264
|
-
* @param {number} [shard] Shard to fetch property from, all if undefined
|
|
265
|
-
* @returns {Promise<*|Array<*>>}
|
|
266
|
-
* @example
|
|
267
|
-
* manager.fetchClientValues('guilds.cache.size')
|
|
268
|
-
* .then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`))
|
|
269
|
-
* .catch(console.error);
|
|
270
|
-
*/
|
|
172
|
+
|
|
271
173
|
fetchClientValues(prop, shard) {
|
|
272
174
|
return this._performOnShards('fetchClientValue', [prop], shard);
|
|
273
175
|
}
|
|
274
176
|
|
|
275
|
-
|
|
276
|
-
* Runs a method with given arguments on all shards, or a given shard.
|
|
277
|
-
* @param {string} method Method name to run on each shard
|
|
278
|
-
* @param {Array<*>} args Arguments to pass through to the method call
|
|
279
|
-
* @param {number} [shard] Shard to run on, all if undefined
|
|
280
|
-
* @returns {Promise<*|Array<*>>} Results of the method execution
|
|
281
|
-
* @private
|
|
282
|
-
*/
|
|
177
|
+
|
|
283
178
|
_performOnShards(method, args, shard) {
|
|
284
179
|
if (this.shards.size === 0) return Promise.reject(new DiscordjsError(ErrorCodes.ShardingNoShards));
|
|
285
180
|
|
|
@@ -297,27 +192,15 @@ class ShardingManager extends EventEmitter {
|
|
|
297
192
|
return Promise.all(promises);
|
|
298
193
|
}
|
|
299
194
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
* @property {number} [shardDelay=5000] How long to wait between shards (in milliseconds)
|
|
304
|
-
* @property {number} [respawnDelay=500] How long to wait between killing a shard's process and restarting it
|
|
305
|
-
* (in milliseconds)
|
|
306
|
-
* @property {number} [timeout=30000] The amount in milliseconds to wait for a shard to become ready before
|
|
307
|
-
* continuing to another (`-1` or `Infinity` for no wait)
|
|
308
|
-
*/
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Kills all running shards and respawns them.
|
|
312
|
-
* @param {MultipleShardRespawnOptions} [options] Options for respawning shards
|
|
313
|
-
* @returns {Promise<Collection<number, Shard>>}
|
|
314
|
-
*/
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
315
198
|
async respawnAll({ shardDelay = 5_000, respawnDelay = 500, timeout = 30_000 } = {}) {
|
|
316
199
|
let s = 0;
|
|
317
200
|
for (const shard of this.shards.values()) {
|
|
318
201
|
const promises = [shard.respawn({ delay: respawnDelay, timeout })];
|
|
319
202
|
if (++s < this.shards.size && shardDelay > 0) promises.push(sleep(shardDelay));
|
|
320
|
-
await Promise.all(promises);
|
|
203
|
+
await Promise.all(promises);
|
|
321
204
|
}
|
|
322
205
|
return this.shards;
|
|
323
206
|
}
|
|
@@ -5,39 +5,22 @@ const { isJSONEncodable } = require('@discordjs/util');
|
|
|
5
5
|
const Component = require('./Component');
|
|
6
6
|
const { createComponent } = require('../util/Components');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
* Represents an action row
|
|
10
|
-
* @extends {Component}
|
|
11
|
-
*/
|
|
8
|
+
|
|
12
9
|
class ActionRow extends Component {
|
|
13
10
|
constructor({ components, ...data }) {
|
|
14
11
|
super(data);
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
* The components in this action row
|
|
18
|
-
* @type {Component[]}
|
|
19
|
-
* @readonly
|
|
20
|
-
*/
|
|
13
|
+
|
|
21
14
|
this.components = components.map(c => createComponent(c));
|
|
22
15
|
}
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
* Creates a new action row builder from JSON data
|
|
26
|
-
* @method from
|
|
27
|
-
* @memberof ActionRow
|
|
28
|
-
* @param {ActionRowBuilder|ActionRow|APIActionRowComponent} other The other data
|
|
29
|
-
* @returns {ActionRowBuilder}
|
|
30
|
-
* @deprecated Use {@link ActionRowBuilder.from} instead.
|
|
31
|
-
*/
|
|
17
|
+
|
|
32
18
|
static from = deprecate(
|
|
33
19
|
other => new this(isJSONEncodable(other) ? other.toJSON() : other),
|
|
34
20
|
'ActionRow.from() is deprecated. Use ActionRowBuilder.from() instead.',
|
|
35
21
|
);
|
|
36
22
|
|
|
37
|
-
|
|
38
|
-
* Returns the API-compatible JSON for this component
|
|
39
|
-
* @returns {APIActionRowComponent}
|
|
40
|
-
*/
|
|
23
|
+
|
|
41
24
|
toJSON() {
|
|
42
25
|
return { ...this.data, components: this.components.map(c => c.toJSON()) };
|
|
43
26
|
}
|
|
@@ -5,10 +5,7 @@ const { isJSONEncodable } = require('@discordjs/util');
|
|
|
5
5
|
const { createComponentBuilder } = require('../util/Components');
|
|
6
6
|
const { toSnakeCase } = require('../util/Transformers');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
* Represents an action row builder.
|
|
10
|
-
* @extends {BuildersActionRow}
|
|
11
|
-
*/
|
|
8
|
+
|
|
12
9
|
class ActionRowBuilder extends BuildersActionRow {
|
|
13
10
|
constructor({ components, ...data } = {}) {
|
|
14
11
|
super({
|
|
@@ -17,11 +14,7 @@ class ActionRowBuilder extends BuildersActionRow {
|
|
|
17
14
|
});
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
* Creates a new action row builder from JSON data
|
|
22
|
-
* @param {ActionRow|ActionRowBuilder|APIActionRowComponent} other The other data
|
|
23
|
-
* @returns {ActionRowBuilder}
|
|
24
|
-
*/
|
|
17
|
+
|
|
25
18
|
static from(other) {
|
|
26
19
|
return new this(isJSONEncodable(other) ? other.toJSON() : other);
|
|
27
20
|
}
|
|
@@ -29,7 +22,4 @@ class ActionRowBuilder extends BuildersActionRow {
|
|
|
29
22
|
|
|
30
23
|
module.exports = ActionRowBuilder;
|
|
31
24
|
|
|
32
|
-
|
|
33
|
-
* @external BuildersActionRow
|
|
34
|
-
* @see {@link https://discord.js.org/docs/packages/builders/stable/ActionRowBuilder:Class}
|
|
35
|
-
*/
|
|
25
|
+
|
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const BaseGuild = require('./BaseGuild');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
* Bundles common attributes and methods between {@link Guild} and {@link InviteGuild}
|
|
7
|
-
* @extends {BaseGuild}
|
|
8
|
-
* @abstract
|
|
9
|
-
*/
|
|
5
|
+
|
|
10
6
|
class AnonymousGuild extends BaseGuild {
|
|
11
7
|
constructor(client, data, immediatePatch = true) {
|
|
12
8
|
super(client, data);
|
|
@@ -17,78 +13,49 @@ class AnonymousGuild extends BaseGuild {
|
|
|
17
13
|
if ('features' in data) this.features = data.features;
|
|
18
14
|
|
|
19
15
|
if ('splash' in data) {
|
|
20
|
-
|
|
21
|
-
* The hash of the guild invite splash image
|
|
22
|
-
* @type {?string}
|
|
23
|
-
*/
|
|
16
|
+
|
|
24
17
|
this.splash = data.splash;
|
|
25
18
|
}
|
|
26
19
|
|
|
27
20
|
if ('banner' in data) {
|
|
28
|
-
|
|
29
|
-
* The hash of the guild banner
|
|
30
|
-
* @type {?string}
|
|
31
|
-
*/
|
|
21
|
+
|
|
32
22
|
this.banner = data.banner;
|
|
33
23
|
}
|
|
34
24
|
|
|
35
25
|
if ('description' in data) {
|
|
36
|
-
|
|
37
|
-
* The description of the guild, if any
|
|
38
|
-
* @type {?string}
|
|
39
|
-
*/
|
|
26
|
+
|
|
40
27
|
this.description = data.description;
|
|
41
28
|
}
|
|
42
29
|
|
|
43
30
|
if ('verification_level' in data) {
|
|
44
|
-
|
|
45
|
-
* The verification level of the guild
|
|
46
|
-
* @type {GuildVerificationLevel}
|
|
47
|
-
*/
|
|
31
|
+
|
|
48
32
|
this.verificationLevel = data.verification_level;
|
|
49
33
|
}
|
|
50
34
|
|
|
51
35
|
if ('vanity_url_code' in data) {
|
|
52
|
-
|
|
53
|
-
* The vanity invite code of the guild, if any
|
|
54
|
-
* @type {?string}
|
|
55
|
-
*/
|
|
36
|
+
|
|
56
37
|
this.vanityURLCode = data.vanity_url_code;
|
|
57
38
|
}
|
|
58
39
|
|
|
59
40
|
if ('nsfw_level' in data) {
|
|
60
|
-
|
|
61
|
-
* The NSFW level of this guild
|
|
62
|
-
* @type {GuildNSFWLevel}
|
|
63
|
-
*/
|
|
41
|
+
|
|
64
42
|
this.nsfwLevel = data.nsfw_level;
|
|
65
43
|
}
|
|
66
44
|
|
|
67
45
|
if ('premium_subscription_count' in data) {
|
|
68
|
-
|
|
69
|
-
* The total number of boosts for this server
|
|
70
|
-
* @type {?number}
|
|
71
|
-
*/
|
|
46
|
+
|
|
72
47
|
this.premiumSubscriptionCount = data.premium_subscription_count;
|
|
73
48
|
} else {
|
|
74
49
|
this.premiumSubscriptionCount ??= null;
|
|
75
50
|
}
|
|
76
51
|
}
|
|
77
52
|
|
|
78
|
-
|
|
79
|
-
* The URL to this guild's banner.
|
|
80
|
-
* @param {ImageURLOptions} [options={}] Options for the image URL
|
|
81
|
-
* @returns {?string}
|
|
82
|
-
*/
|
|
53
|
+
|
|
83
54
|
bannerURL(options = {}) {
|
|
84
55
|
return this.banner && this.client.rest.cdn.banner(this.id, this.banner, options);
|
|
85
56
|
}
|
|
86
57
|
|
|
87
|
-
|
|
88
|
-
* The URL to this guild's invite splash image.
|
|
89
|
-
* @param {ImageURLOptions} [options={}] Options for the image URL
|
|
90
|
-
* @returns {?string}
|
|
91
|
-
*/
|
|
58
|
+
|
|
92
59
|
splashURL(options = {}) {
|
|
93
60
|
return this.splash && this.client.rest.cdn.splash(this.id, this.splash, options);
|
|
94
61
|
}
|