seyfert 1.0.1 → 1.1.0
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/lib/api/CDN.d.ts +1 -1
- package/lib/api/CDN.js +0 -2
- package/lib/api/Router.js +2 -2
- package/lib/api/Routes/applications.d.ts +29 -33
- package/lib/api/Routes/channels.d.ts +11 -17
- package/lib/api/Routes/interactions.d.ts +3 -7
- package/lib/api/Routes/webhooks.d.ts +4 -6
- package/lib/builders/Attachment.d.ts +2 -3
- package/lib/cache/adapters/redis.js +6 -0
- package/lib/cache/adapters/workeradapter.d.ts +4 -4
- package/lib/cache/adapters/workeradapter.js +10 -5
- package/lib/cache/index.d.ts +4 -5
- package/lib/cache/index.js +4 -3
- package/lib/cache/resources/default/base.d.ts +2 -1
- package/lib/cache/resources/default/guild-based.d.ts +2 -1
- package/lib/cache/resources/default/guild-based.js +6 -6
- package/lib/cache/resources/default/guild-related.d.ts +2 -1
- package/lib/cache/resources/default/guild-related.js +1 -1
- package/lib/cache/resources/guilds.js +2 -1
- package/lib/cache/resources/overwrites.d.ts +1 -1
- package/lib/cache/resources/overwrites.js +7 -1
- package/lib/client/base.d.ts +18 -170
- package/lib/client/base.js +11 -14
- package/lib/client/client.d.ts +5 -0
- package/lib/client/client.js +4 -1
- package/lib/client/oninteractioncreate.js +2 -2
- package/lib/client/onmessagecreate.js +188 -152
- package/lib/client/workerclient.d.ts +1 -0
- package/lib/client/workerclient.js +36 -15
- package/lib/collection.js +2 -2
- package/lib/commands/applications/chat.d.ts +15 -7
- package/lib/commands/applications/chat.js +7 -7
- package/lib/commands/applications/chatcontext.d.ts +5 -3
- package/lib/commands/applications/chatcontext.js +6 -1
- package/lib/commands/applications/menu.d.ts +5 -1
- package/lib/commands/applications/menu.js +4 -0
- package/lib/commands/applications/menucontext.d.ts +4 -2
- package/lib/commands/applications/menucontext.js +6 -1
- package/lib/commands/applications/options.d.ts +1 -2
- package/lib/commands/decorators.d.ts +17 -5
- package/lib/commands/decorators.js +17 -7
- package/lib/commands/handler.d.ts +5 -5
- package/lib/commands/handler.js +40 -36
- package/lib/commands/optionresolver.d.ts +11 -4
- package/lib/commands/optionresolver.js +6 -4
- package/lib/common/index.d.ts +7 -0
- package/lib/common/index.js +7 -0
- package/lib/common/it/utils.js +2 -0
- package/lib/common/shorters/channels.d.ts +67 -129
- package/lib/common/shorters/channels.js +119 -135
- package/lib/common/shorters/emojis.d.ts +47 -0
- package/lib/common/shorters/emojis.js +80 -0
- package/lib/common/shorters/guilds.d.ts +22 -249
- package/lib/common/shorters/guilds.js +51 -140
- package/lib/common/shorters/members.d.ts +82 -108
- package/lib/common/shorters/members.js +151 -166
- package/lib/common/shorters/messages.d.ts +11 -23
- package/lib/common/shorters/messages.js +58 -104
- package/lib/common/shorters/reactions.d.ts +10 -0
- package/lib/common/shorters/reactions.js +45 -0
- package/lib/common/shorters/roles.d.ts +39 -7
- package/lib/common/shorters/roles.js +74 -42
- package/lib/common/shorters/templates.d.ts +6 -8
- package/lib/common/shorters/templates.js +17 -21
- package/lib/common/shorters/users.d.ts +4 -0
- package/lib/common/shorters/users.js +30 -0
- package/lib/common/shorters/webhook.d.ts +62 -26
- package/lib/common/shorters/webhook.js +113 -58
- package/lib/common/types/options.d.ts +2 -2
- package/lib/components/handler.d.ts +10 -7
- package/lib/components/handler.js +20 -5
- package/lib/index.d.ts +4 -2
- package/lib/langs/handler.js +7 -2
- package/lib/structures/AutoModerationRule.d.ts +2 -2
- package/lib/structures/ClientUser.d.ts +2 -2
- package/lib/structures/Guild.d.ts +2 -2
- package/lib/structures/GuildEmoji.d.ts +4 -4
- package/lib/structures/GuildEmoji.js +7 -7
- package/lib/structures/GuildMember.d.ts +6 -6
- package/lib/structures/GuildMember.js +2 -2
- package/lib/structures/GuildPreview.d.ts +2 -2
- package/lib/structures/GuildRole.d.ts +2 -2
- package/lib/structures/GuildTemplate.d.ts +2 -2
- package/lib/structures/Interaction.d.ts +7 -8
- package/lib/structures/Interaction.js +1 -1
- package/lib/structures/Message.d.ts +7 -6
- package/lib/structures/Message.js +7 -4
- package/lib/structures/Sticker.d.ts +2 -2
- package/lib/structures/Webhook.d.ts +2 -2
- package/lib/structures/Webhook.js +3 -3
- package/lib/structures/channels.d.ts +19 -20
- package/lib/structures/channels.js +13 -25
- package/lib/structures/extra/Base.d.ts +1 -2
- package/lib/structures/extra/DiscordBase.d.ts +2 -2
- package/lib/websocket/constants/index.js +1 -0
- package/lib/websocket/discord/shard.js +4 -2
- package/lib/websocket/discord/sharder.d.ts +3 -0
- package/lib/websocket/discord/sharder.js +12 -5
- package/lib/websocket/discord/shared.d.ts +1 -0
- package/lib/websocket/discord/worker.d.ts +2 -1
- package/lib/websocket/discord/workermanager.d.ts +8 -3
- package/lib/websocket/discord/workermanager.js +78 -30
- package/package.json +8 -6
|
@@ -9,11 +9,11 @@ function getCommandFromContent(commandRaw, self) {
|
|
|
9
9
|
const groupName = commandRaw.length === 3 ? commandRaw[1] : undefined;
|
|
10
10
|
const subcommandName = groupName ? commandRaw[2] : commandRaw[1];
|
|
11
11
|
const parent = self.commands.values.find(x => x.name === parentName);
|
|
12
|
-
const fullCommandName = `${parentName}${groupName ? ` ${groupName} ${subcommandName}` : ` ${subcommandName
|
|
12
|
+
const fullCommandName = `${parentName}${groupName ? ` ${groupName} ${subcommandName}` : `${subcommandName ? ` ${subcommandName}` : ''}`}`;
|
|
13
13
|
if (!(parent instanceof __1.Command))
|
|
14
14
|
return { fullCommandName };
|
|
15
15
|
if (groupName && !parent.groups?.[groupName])
|
|
16
|
-
return getCommandFromContent([parentName,
|
|
16
|
+
return getCommandFromContent([parentName, groupName], self);
|
|
17
17
|
if (subcommandName && !parent.options?.some(x => x instanceof __1.SubCommand && x.name === subcommandName))
|
|
18
18
|
return getCommandFromContent([parentName], self);
|
|
19
19
|
const command = groupName || subcommandName
|
|
@@ -50,7 +50,8 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
50
50
|
return;
|
|
51
51
|
if (!command.run)
|
|
52
52
|
return self.logger.warn(`${fullCommandName} command does not have 'run' callback`);
|
|
53
|
-
if (
|
|
53
|
+
if ([__1.InteractionContextTypes.BOT_DM, __1.InteractionContextTypes.PRIVATE_CHANNEL].some(i => command.contexts?.includes(i)) &&
|
|
54
|
+
!message.guildId)
|
|
54
55
|
return;
|
|
55
56
|
if (command.guild_id && !command.guild_id?.includes(message.guildId))
|
|
56
57
|
return;
|
|
@@ -64,7 +65,10 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
64
65
|
const args = (self.options?.commands?.argsParser ?? defaultArgsParser)(content, command);
|
|
65
66
|
const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved);
|
|
66
67
|
const optionsResolver = new __1.OptionResolver(self, options, parent, message.guildId, resolved);
|
|
67
|
-
const context = new __1.CommandContext(self, message, optionsResolver, shardId);
|
|
68
|
+
const context = new __1.CommandContext(self, message, optionsResolver, shardId, command);
|
|
69
|
+
//@ts-expect-error
|
|
70
|
+
const extendContext = self.options?.context?.(message) ?? {};
|
|
71
|
+
Object.assign(context, extendContext);
|
|
68
72
|
try {
|
|
69
73
|
if (command.botPermissions && message.guildId) {
|
|
70
74
|
const meMember = await self.cache.members?.get(self.botId, message.guildId);
|
|
@@ -128,119 +132,192 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
128
132
|
const options = [];
|
|
129
133
|
const errors = [];
|
|
130
134
|
for (const i of (command.options ?? [])) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
135
|
+
try {
|
|
136
|
+
let value;
|
|
137
|
+
let indexAttachment = -1;
|
|
138
|
+
switch (i.type) {
|
|
139
|
+
case v10_1.ApplicationCommandOptionType.Attachment:
|
|
140
|
+
if (message.attachments[++indexAttachment]) {
|
|
141
|
+
value = message.attachments[indexAttachment].id;
|
|
142
|
+
resolved.attachments[value] = message.attachments[indexAttachment];
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
case v10_1.ApplicationCommandOptionType.Boolean:
|
|
146
|
+
if (args[i.name]) {
|
|
147
|
+
value = ['yes', 'y', 'true', 'treu'].includes(args[i.name].toLowerCase());
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
case v10_1.ApplicationCommandOptionType.Channel:
|
|
151
|
+
{
|
|
152
|
+
const rawId = message.content.match(/(?<=<#)[0-9]{17,19}(?=>)/g)?.find(x => args[i.name]?.includes(x)) ||
|
|
153
|
+
args[i.name]?.match(/[0-9]{17,19}/g)?.[0];
|
|
154
|
+
if (rawId) {
|
|
155
|
+
const channel = (await self.cache.channels?.get(rawId)) ?? (i.required ? await self.channels.fetch(rawId) : undefined);
|
|
156
|
+
if (channel) {
|
|
157
|
+
if ('channel_types' in i) {
|
|
158
|
+
if (!i.channel_types.includes(channel.type)) {
|
|
159
|
+
errors.push({
|
|
160
|
+
name: i.name,
|
|
161
|
+
error: `The entered channel type is not one of ${i
|
|
162
|
+
.channel_types.map(t => v10_1.ChannelType[t])
|
|
163
|
+
.join(', ')}`,
|
|
164
|
+
});
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
160
167
|
}
|
|
168
|
+
value = rawId;
|
|
169
|
+
resolved.channels[rawId] = channel;
|
|
161
170
|
}
|
|
162
|
-
value = rawId;
|
|
163
|
-
//@ts-expect-error
|
|
164
|
-
resolved.channels[rawId] = channel;
|
|
165
171
|
}
|
|
166
172
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
break;
|
|
174
|
+
case v10_1.ApplicationCommandOptionType.Mentionable:
|
|
175
|
+
{
|
|
176
|
+
const matches = message.content.match(/<@[0-9]{17,19}(?=>)|<@&[0-9]{17,19}(?=>)/g) ?? [];
|
|
177
|
+
for (const match of matches) {
|
|
178
|
+
if (match.includes('&')) {
|
|
179
|
+
const rawId = match.slice(3);
|
|
180
|
+
if (rawId) {
|
|
181
|
+
const role = (await self.cache.roles?.get(rawId)) ??
|
|
182
|
+
(i.required ? (await self.roles.list(message.guild_id)).find(x => x.id === rawId) : undefined);
|
|
183
|
+
if (role) {
|
|
184
|
+
value = rawId;
|
|
185
|
+
resolved.roles[rawId] = role;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
const rawId = match.slice(2);
|
|
192
|
+
const raw = message.mentions.find(x => rawId === x.id);
|
|
193
|
+
if (raw) {
|
|
194
|
+
const { member, ...user } = raw;
|
|
195
|
+
value = raw.id;
|
|
196
|
+
resolved.users[raw.id] = user;
|
|
197
|
+
if (member)
|
|
198
|
+
resolved.members[raw.id] = member;
|
|
183
199
|
break;
|
|
184
200
|
}
|
|
185
201
|
}
|
|
186
202
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case v10_1.ApplicationCommandOptionType.Role:
|
|
206
|
+
{
|
|
207
|
+
const rawId = message.mention_roles.find(x => args[i.name]?.includes(x)) || args[i.name]?.match(/[0-9]{17,19}/g)?.[0];
|
|
208
|
+
if (rawId) {
|
|
209
|
+
const role = (await self.cache.roles?.get(rawId)) ??
|
|
210
|
+
(i.required ? (await self.roles.list(message.guild_id)).find(x => x.id === rawId) : undefined);
|
|
211
|
+
if (role) {
|
|
212
|
+
value = rawId;
|
|
213
|
+
resolved.roles[rawId] = role;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
case v10_1.ApplicationCommandOptionType.User:
|
|
219
|
+
{
|
|
220
|
+
const rawId = message.mentions.find(x => args[i.name]?.includes(x.id))?.id || args[i.name]?.match(/[0-9]{17,19}/g)?.[0];
|
|
221
|
+
if (rawId) {
|
|
222
|
+
const raw = message.mentions.find(x => args[i.name]?.includes(x.id)) ??
|
|
223
|
+
(await self.cache.users?.get(rawId)) ??
|
|
224
|
+
(i.required ? await self.users.fetch(rawId) : undefined);
|
|
190
225
|
if (raw) {
|
|
191
226
|
value = raw.id;
|
|
192
|
-
|
|
193
|
-
|
|
227
|
+
if (raw instanceof __1.User) {
|
|
228
|
+
resolved.users[raw.id] = raw;
|
|
229
|
+
if (message.guild_id) {
|
|
230
|
+
const member = message.mentions.find(x => args[i.name]?.includes(x.id))?.member ??
|
|
231
|
+
(await self.cache.members?.get(rawId, message.guild_id)) ??
|
|
232
|
+
(i.required ? await self.members.fetch(rawId, message.guild_id) : undefined);
|
|
233
|
+
if (member)
|
|
234
|
+
resolved.members[raw.id] = member;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const { member, ...user } = raw;
|
|
239
|
+
resolved.users[user.id] = user;
|
|
240
|
+
if (member)
|
|
241
|
+
resolved.members[user.id] = member;
|
|
242
|
+
}
|
|
194
243
|
}
|
|
195
244
|
}
|
|
196
245
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
246
|
+
break;
|
|
247
|
+
case v10_1.ApplicationCommandOptionType.String:
|
|
248
|
+
{
|
|
249
|
+
value = args[i.name];
|
|
250
|
+
const option = i;
|
|
251
|
+
if (value) {
|
|
252
|
+
if (option.min_length) {
|
|
253
|
+
if (value.length < option.min_length) {
|
|
254
|
+
value = undefined;
|
|
255
|
+
errors.push({
|
|
256
|
+
name: i.name,
|
|
257
|
+
error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
|
|
258
|
+
});
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (option.max_length) {
|
|
263
|
+
if (value.length > option.max_length) {
|
|
264
|
+
value = undefined;
|
|
265
|
+
errors.push({
|
|
266
|
+
name: i.name,
|
|
267
|
+
error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
|
|
268
|
+
});
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (option.choices?.length) {
|
|
273
|
+
if (!option.choices.some(x => x.name === value)) {
|
|
274
|
+
value = undefined;
|
|
275
|
+
errors.push({
|
|
276
|
+
name: i.name,
|
|
277
|
+
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
278
|
+
.map(x => x.name)
|
|
279
|
+
.join(', ')}.`,
|
|
280
|
+
});
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
value = option.choices.find(x => x.name === value).value;
|
|
284
|
+
}
|
|
210
285
|
}
|
|
211
286
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
287
|
+
break;
|
|
288
|
+
case v10_1.ApplicationCommandOptionType.Number:
|
|
289
|
+
case v10_1.ApplicationCommandOptionType.Integer:
|
|
290
|
+
{
|
|
291
|
+
value = Number(args[i.name]);
|
|
292
|
+
if (args[i.name] === undefined) {
|
|
293
|
+
value = undefined;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
if (Number.isNaN(value)) {
|
|
297
|
+
value = undefined;
|
|
298
|
+
errors.push({
|
|
299
|
+
name: i.name,
|
|
300
|
+
error: 'The entered choice is an invalid number.',
|
|
301
|
+
});
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
const option = i;
|
|
305
|
+
if (option.min_value) {
|
|
306
|
+
if (value < option.min_value) {
|
|
230
307
|
value = undefined;
|
|
231
308
|
errors.push({
|
|
232
309
|
name: i.name,
|
|
233
|
-
error: `The entered
|
|
310
|
+
error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
|
|
234
311
|
});
|
|
235
312
|
break;
|
|
236
313
|
}
|
|
237
314
|
}
|
|
238
|
-
if (option.
|
|
239
|
-
if (value
|
|
315
|
+
if (option.max_value) {
|
|
316
|
+
if (value > option.max_value) {
|
|
240
317
|
value = undefined;
|
|
241
318
|
errors.push({
|
|
242
319
|
name: i.name,
|
|
243
|
-
error: `The entered
|
|
320
|
+
error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
|
|
244
321
|
});
|
|
245
322
|
break;
|
|
246
323
|
}
|
|
@@ -259,68 +336,27 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
259
336
|
value = option.choices.find(x => x.name === value).value;
|
|
260
337
|
}
|
|
261
338
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
break;
|
|
279
|
-
}
|
|
280
|
-
const option = i;
|
|
281
|
-
if (option.min_value) {
|
|
282
|
-
if (value < option.min_value) {
|
|
283
|
-
value = undefined;
|
|
284
|
-
errors.push({
|
|
285
|
-
name: i.name,
|
|
286
|
-
error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
|
|
287
|
-
});
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
if (option.max_value) {
|
|
292
|
-
if (value > option.max_value) {
|
|
293
|
-
value = undefined;
|
|
294
|
-
errors.push({
|
|
295
|
-
name: i.name,
|
|
296
|
-
error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
|
|
297
|
-
});
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
if (option.choices?.length) {
|
|
302
|
-
if (!option.choices.some(x => x.name === value)) {
|
|
303
|
-
value = undefined;
|
|
304
|
-
errors.push({
|
|
305
|
-
name: i.name,
|
|
306
|
-
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
307
|
-
.map(x => x.name)
|
|
308
|
-
.join(', ')}.`,
|
|
309
|
-
});
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
value = option.choices.find(x => x.name === value).value;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
break;
|
|
316
|
-
default:
|
|
317
|
-
break;
|
|
339
|
+
break;
|
|
340
|
+
default:
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
if (value !== undefined) {
|
|
344
|
+
options.push({
|
|
345
|
+
name: i.name,
|
|
346
|
+
type: i.type,
|
|
347
|
+
value,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
else if (i.required)
|
|
351
|
+
errors.push({
|
|
352
|
+
error: 'Option is required but returned undefined',
|
|
353
|
+
name: i.name,
|
|
354
|
+
});
|
|
318
355
|
}
|
|
319
|
-
|
|
320
|
-
|
|
356
|
+
catch (e) {
|
|
357
|
+
errors.push({
|
|
358
|
+
error: e && typeof e === 'object' && 'message' in e ? e.message : `${e}`,
|
|
321
359
|
name: i.name,
|
|
322
|
-
type: i.type,
|
|
323
|
-
value,
|
|
324
360
|
});
|
|
325
361
|
}
|
|
326
362
|
}
|
|
@@ -30,6 +30,7 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
|
|
|
30
30
|
get latency(): number;
|
|
31
31
|
start(options?: Omit<DeepPartial<StartOptions>, 'httpConnection' | 'token' | 'connection'>): Promise<void>;
|
|
32
32
|
loadEvents(dir?: string): Promise<void>;
|
|
33
|
+
postMessage(body: any): boolean | void;
|
|
33
34
|
protected handleManagerMessages(data: ManagerMessages): Promise<any>;
|
|
34
35
|
private generateNonce;
|
|
35
36
|
private generateSendPromise;
|
|
@@ -12,7 +12,19 @@ const websocket_1 = require("../websocket");
|
|
|
12
12
|
const base_1 = require("./base");
|
|
13
13
|
const oninteractioncreate_1 = require("./oninteractioncreate");
|
|
14
14
|
const onmessagecreate_1 = require("./onmessagecreate");
|
|
15
|
-
|
|
15
|
+
let workerData;
|
|
16
|
+
try {
|
|
17
|
+
workerData = {
|
|
18
|
+
debug: process.env.SEYFERT_WORKER_DEBUG === 'true',
|
|
19
|
+
intents: Number.parseInt(process.env.SEYFERT_WORKER_INTENTS),
|
|
20
|
+
path: process.env.SEYFERT_WORKER_PATH,
|
|
21
|
+
shards: process.env.SEYFERT_WORKER_SHARDS.split(',').map(id => Number.parseInt(id)),
|
|
22
|
+
token: process.env.SEYFERT_WORKER_TOKEN,
|
|
23
|
+
workerId: Number.parseInt(process.env.SEYFERT_WORKER_WORKERID),
|
|
24
|
+
workerProxy: process.env.SEYFERT_WORKER_WORKERPROXY === 'true',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
16
28
|
class WorkerClient extends base_1.BaseClient {
|
|
17
29
|
__handleGuilds = new Set();
|
|
18
30
|
logger = new common_1.Logger({
|
|
@@ -24,13 +36,17 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
24
36
|
shards = new Map();
|
|
25
37
|
constructor(options) {
|
|
26
38
|
super(options);
|
|
27
|
-
if (!
|
|
39
|
+
if (!process.env.SEYFERT_SPAWNING) {
|
|
28
40
|
throw new Error('WorkerClient cannot spawn without manager');
|
|
29
41
|
}
|
|
30
|
-
|
|
42
|
+
this.postMessage({
|
|
43
|
+
type: 'WORKER_START',
|
|
44
|
+
workerId: workerData.workerId,
|
|
45
|
+
});
|
|
46
|
+
(node_worker_threads_1.parentPort ?? process).on('message', (data) => this.handleManagerMessages(data));
|
|
31
47
|
this.setServices({
|
|
32
48
|
cache: {
|
|
33
|
-
adapter: new cache_1.WorkerAdapter(
|
|
49
|
+
adapter: new cache_1.WorkerAdapter(workerData),
|
|
34
50
|
disabledCache: options?.disabledCache,
|
|
35
51
|
},
|
|
36
52
|
});
|
|
@@ -70,6 +86,11 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
70
86
|
this.logger.info('EventHandler loaded');
|
|
71
87
|
}
|
|
72
88
|
}
|
|
89
|
+
postMessage(body) {
|
|
90
|
+
if (node_worker_threads_1.parentPort)
|
|
91
|
+
return node_worker_threads_1.parentPort.postMessage(body);
|
|
92
|
+
return process.send(body);
|
|
93
|
+
}
|
|
73
94
|
async handleManagerMessages(data) {
|
|
74
95
|
switch (data.type) {
|
|
75
96
|
case 'CACHE_RESULT':
|
|
@@ -90,7 +111,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
90
111
|
await shard.send(0, {
|
|
91
112
|
...data,
|
|
92
113
|
});
|
|
93
|
-
|
|
114
|
+
this.postMessage({
|
|
94
115
|
type: 'RESULT_PAYLOAD',
|
|
95
116
|
nonce: data.nonce,
|
|
96
117
|
workerId: this.workerId,
|
|
@@ -110,9 +131,9 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
110
131
|
break;
|
|
111
132
|
case 'SPAWN_SHARDS':
|
|
112
133
|
{
|
|
113
|
-
const cache = this.cache;
|
|
114
134
|
const onPacket = this.onPacket.bind(this);
|
|
115
135
|
const handlePayload = this.options?.handlePayload?.bind(this);
|
|
136
|
+
const self = this;
|
|
116
137
|
for (const id of workerData.shards) {
|
|
117
138
|
let shard = this.shards.get(id);
|
|
118
139
|
if (!shard) {
|
|
@@ -124,9 +145,9 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
124
145
|
debugger: this.debugger,
|
|
125
146
|
async handlePayload(shardId, payload) {
|
|
126
147
|
await handlePayload?.(shardId, payload);
|
|
127
|
-
await cache.onPacket(payload);
|
|
148
|
+
await self.cache.onPacket(payload);
|
|
128
149
|
await onPacket?.(payload, shardId);
|
|
129
|
-
|
|
150
|
+
self.postMessage({
|
|
130
151
|
workerId: workerData.workerId,
|
|
131
152
|
shardId,
|
|
132
153
|
type: 'RECEIVE_PAYLOAD',
|
|
@@ -136,7 +157,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
136
157
|
});
|
|
137
158
|
this.shards.set(id, shard);
|
|
138
159
|
}
|
|
139
|
-
|
|
160
|
+
this.postMessage({
|
|
140
161
|
type: 'CONNECT_QUEUE',
|
|
141
162
|
shardId: id,
|
|
142
163
|
workerId: workerData.workerId,
|
|
@@ -151,7 +172,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
151
172
|
this.logger.fatal('Worker trying get non-existent shard');
|
|
152
173
|
return;
|
|
153
174
|
}
|
|
154
|
-
|
|
175
|
+
this.postMessage({
|
|
155
176
|
...generateShardInfo(shard),
|
|
156
177
|
nonce: data.nonce,
|
|
157
178
|
type: 'SHARD_INFO',
|
|
@@ -161,7 +182,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
161
182
|
break;
|
|
162
183
|
case 'WORKER_INFO':
|
|
163
184
|
{
|
|
164
|
-
|
|
185
|
+
this.postMessage({
|
|
165
186
|
shards: [...this.shards.values()].map(generateShardInfo),
|
|
166
187
|
workerId: workerData.workerId,
|
|
167
188
|
type: 'WORKER_INFO',
|
|
@@ -195,7 +216,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
195
216
|
catch (e) {
|
|
196
217
|
result = e;
|
|
197
218
|
}
|
|
198
|
-
|
|
219
|
+
this.postMessage({
|
|
199
220
|
type: 'EVAL_RESPONSE',
|
|
200
221
|
response: result,
|
|
201
222
|
workerId: workerData.workerId,
|
|
@@ -239,7 +260,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
239
260
|
}
|
|
240
261
|
tellWorker(workerId, func) {
|
|
241
262
|
const nonce = this.generateNonce();
|
|
242
|
-
|
|
263
|
+
this.postMessage({
|
|
243
264
|
type: 'EVAL',
|
|
244
265
|
func: func.toString(),
|
|
245
266
|
toWorkerId: workerId,
|
|
@@ -273,7 +294,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
273
294
|
if (!this.__handleGuilds?.size ||
|
|
274
295
|
!((workerData.intents & common_1.GatewayIntentBits.Guilds) === common_1.GatewayIntentBits.Guilds)) {
|
|
275
296
|
if ([...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
276
|
-
|
|
297
|
+
this.postMessage({
|
|
277
298
|
type: 'WORKER_READY',
|
|
278
299
|
workerId: this.workerId,
|
|
279
300
|
});
|
|
@@ -293,7 +314,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
293
314
|
if (this.__handleGuilds?.has(packet.d.id)) {
|
|
294
315
|
this.__handleGuilds.delete(packet.d.id);
|
|
295
316
|
if (!this.__handleGuilds.size && [...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
296
|
-
|
|
317
|
+
this.postMessage({
|
|
297
318
|
type: 'WORKER_READY',
|
|
298
319
|
workerId: this.workerId,
|
|
299
320
|
});
|
package/lib/collection.js
CHANGED
|
@@ -197,7 +197,7 @@ exports.Collection = Collection;
|
|
|
197
197
|
class LimitedCollection {
|
|
198
198
|
static default = {
|
|
199
199
|
resetOnDemand: false,
|
|
200
|
-
limit:
|
|
200
|
+
limit: Number.POSITIVE_INFINITY,
|
|
201
201
|
expire: 0,
|
|
202
202
|
};
|
|
203
203
|
data = new Map();
|
|
@@ -233,7 +233,7 @@ class LimitedCollection {
|
|
|
233
233
|
this.delete(iter.next().value);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
if (this.closer
|
|
236
|
+
if (this.closer?.expireOn === expireOn) {
|
|
237
237
|
this.resetTimeout();
|
|
238
238
|
}
|
|
239
239
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SeyfertNumberOption, SeyfertStringOption } from '../..';
|
|
2
2
|
import type { Attachment } from '../../builders';
|
|
3
|
-
import type { APIApplicationCommandBasicOption, APIApplicationCommandOption, LocaleString, PermissionStrings } from '../../common';
|
|
3
|
+
import type { APIApplicationCommandBasicOption, APIApplicationCommandOption, FlatObjectKeys, LocaleString, PermissionStrings } from '../../common';
|
|
4
4
|
import { ApplicationCommandOptionType, ApplicationCommandType } from '../../common';
|
|
5
5
|
import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures';
|
|
6
|
-
import type { Groups, RegisteredMiddlewares } from '../decorators';
|
|
6
|
+
import type { Groups, IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
|
|
7
7
|
import type { CommandContext } from './chatcontext';
|
|
8
|
-
import type { OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
|
|
8
|
+
import type { DefaultLocale, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
|
|
9
9
|
export interface ReturnOptionsTypes {
|
|
10
10
|
1: never;
|
|
11
11
|
2: never;
|
|
@@ -29,6 +29,10 @@ type Wrap<N extends ApplicationCommandOptionType> = N extends ApplicationCommand
|
|
|
29
29
|
description: string;
|
|
30
30
|
description_localizations?: APIApplicationCommandBasicOption['description_localizations'];
|
|
31
31
|
name_localizations?: APIApplicationCommandBasicOption['name_localizations'];
|
|
32
|
+
locales?: {
|
|
33
|
+
name?: FlatObjectKeys<DefaultLocale>;
|
|
34
|
+
description?: FlatObjectKeys<DefaultLocale>;
|
|
35
|
+
};
|
|
32
36
|
};
|
|
33
37
|
export type __TypeWrapper<T extends ApplicationCommandOptionType> = Wrap<T>;
|
|
34
38
|
export type __TypesWrapper = {
|
|
@@ -79,8 +83,9 @@ declare class BaseCommand {
|
|
|
79
83
|
nsfw?: boolean;
|
|
80
84
|
description: string;
|
|
81
85
|
default_member_permissions?: string;
|
|
86
|
+
integration_types?: IntegrationTypes[];
|
|
87
|
+
contexts?: InteractionContextTypes[];
|
|
82
88
|
botPermissions?: bigint;
|
|
83
|
-
dm?: boolean;
|
|
84
89
|
name_localizations?: Partial<Record<LocaleString, string>>;
|
|
85
90
|
description_localizations?: Partial<Record<LocaleString, string>>;
|
|
86
91
|
options?: CommandOption[] | SubCommand[];
|
|
@@ -93,7 +98,8 @@ declare class BaseCommand {
|
|
|
93
98
|
description_localizations: BaseCommand['description_localizations'];
|
|
94
99
|
guild_id: BaseCommand['guild_id'];
|
|
95
100
|
default_member_permissions: BaseCommand['default_member_permissions'];
|
|
96
|
-
|
|
101
|
+
contexts: BaseCommand['contexts'];
|
|
102
|
+
integration_types: BaseCommand['integration_types'];
|
|
97
103
|
};
|
|
98
104
|
reload(): Promise<void>;
|
|
99
105
|
run?(context: CommandContext<any>): any;
|
|
@@ -117,7 +123,8 @@ export declare class Command extends BaseCommand {
|
|
|
117
123
|
description_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
|
|
118
124
|
guild_id: string[] | undefined;
|
|
119
125
|
default_member_permissions: string | undefined;
|
|
120
|
-
|
|
126
|
+
contexts: InteractionContextTypes[] | undefined;
|
|
127
|
+
integration_types: IntegrationTypes[] | undefined;
|
|
121
128
|
};
|
|
122
129
|
onRunError(context: CommandContext<any>, error: unknown): any;
|
|
123
130
|
onOptionsError(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
@@ -139,7 +146,8 @@ export declare abstract class SubCommand extends BaseCommand {
|
|
|
139
146
|
description_localizations: Partial<Record<"id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi", string>> | undefined;
|
|
140
147
|
guild_id: string[] | undefined;
|
|
141
148
|
default_member_permissions: string | undefined;
|
|
142
|
-
|
|
149
|
+
contexts: InteractionContextTypes[] | undefined;
|
|
150
|
+
integration_types: IntegrationTypes[] | undefined;
|
|
143
151
|
};
|
|
144
152
|
abstract run(context: CommandContext<any>): any;
|
|
145
153
|
}
|