seyfert 1.3.3 → 1.4.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/api.js +13 -7
- package/lib/builders/Attachment.d.ts +1 -4
- package/lib/builders/Attachment.js +4 -4
- package/lib/cache/adapters/workeradapter.js +7 -3
- package/lib/cache/resources/default/base.d.ts +1 -2
- package/lib/cache/resources/default/guild-based.d.ts +1 -2
- package/lib/client/base.d.ts +26 -4
- package/lib/client/base.js +42 -2
- package/lib/client/client.d.ts +3 -3
- package/lib/client/client.js +18 -6
- package/lib/client/httpclient.d.ts +7 -8
- package/lib/client/httpclient.js +92 -13
- package/lib/client/oninteractioncreate.d.ts +2 -2
- package/lib/client/oninteractioncreate.js +15 -7
- package/lib/client/onmessagecreate.js +74 -66
- package/lib/client/workerclient.d.ts +1 -1
- package/lib/client/workerclient.js +18 -7
- package/lib/commands/applications/chat.d.ts +1 -1
- package/lib/commands/applications/chat.js +2 -1
- package/lib/commands/applications/chatcontext.d.ts +1 -1
- package/lib/commands/applications/chatcontext.js +2 -2
- package/lib/commands/applications/menu.js +0 -48
- package/lib/commands/applications/menucontext.d.ts +1 -1
- package/lib/commands/applications/menucontext.js +3 -3
- package/lib/commands/applications/options.d.ts +3 -1
- package/lib/commands/basecontext.d.ts +26 -0
- package/lib/commands/{basecontex.js → basecontext.js} +24 -0
- package/lib/commands/handler.d.ts +6 -1
- package/lib/commands/handler.js +125 -3
- package/lib/common/bot/watcher.d.ts +1 -2
- package/lib/common/bot/watcher.js +9 -4
- package/lib/common/it/logger.d.ts +1 -1
- package/lib/common/it/logger.js +9 -8
- package/lib/common/it/utils.d.ts +2 -0
- package/lib/common/it/utils.js +19 -5
- package/lib/common/shorters/interaction.js +3 -3
- package/lib/common/shorters/messages.js +2 -2
- package/lib/common/shorters/webhook.js +2 -2
- package/lib/components/componentcommand.d.ts +21 -0
- package/lib/components/{command.js → componentcommand.js} +2 -5
- package/lib/components/componentcontext.d.ts +20 -16
- package/lib/components/componentcontext.js +27 -9
- package/lib/components/handler.d.ts +10 -5
- package/lib/components/handler.js +94 -17
- package/lib/components/index.d.ts +3 -1
- package/lib/components/index.js +3 -1
- package/lib/components/modalcommand.d.ts +15 -0
- package/lib/components/modalcommand.js +9 -0
- package/lib/components/modalcontext.d.ts +104 -0
- package/lib/components/modalcontext.js +132 -0
- package/lib/events/handler.d.ts +4 -1
- package/lib/events/handler.js +2 -7
- package/lib/events/hooks/application_command.d.ts +2 -2
- package/lib/events/hooks/auto_moderation.d.ts +5 -5
- package/lib/events/hooks/channel.d.ts +5 -5
- package/lib/events/hooks/custom.d.ts +3 -3
- package/lib/events/hooks/dispatch.d.ts +4 -4
- package/lib/events/hooks/entitlement.d.ts +4 -4
- package/lib/events/hooks/guild.d.ts +23 -23
- package/lib/events/hooks/guild.js +6 -6
- package/lib/events/hooks/integration.d.ts +4 -4
- package/lib/events/hooks/interactions.d.ts +2 -2
- package/lib/events/hooks/invite.d.ts +3 -3
- package/lib/events/hooks/message.d.ts +13 -13
- package/lib/events/hooks/message.js +1 -1
- package/lib/events/hooks/presence.d.ts +7 -3
- package/lib/events/hooks/presence.js +2 -2
- package/lib/events/hooks/stage.d.ts +7 -13
- package/lib/events/hooks/stage.js +2 -2
- package/lib/events/hooks/thread.d.ts +7 -7
- package/lib/events/hooks/thread.js +2 -2
- package/lib/events/hooks/typing.d.ts +2 -2
- package/lib/events/hooks/user.d.ts +2 -2
- package/lib/events/hooks/user.js +2 -2
- package/lib/events/hooks/voice.d.ts +5 -45
- package/lib/events/hooks/voice.js +4 -7
- package/lib/events/hooks/webhook.d.ts +2 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +9 -4
- package/lib/langs/handler.d.ts +4 -1
- package/lib/langs/handler.js +3 -3
- package/lib/structures/Interaction.d.ts +3 -3
- package/lib/structures/Interaction.js +11 -6
- package/lib/structures/VoiceState.d.ts +6 -5
- package/lib/structures/VoiceState.js +6 -3
- package/lib/structures/channels.d.ts +1 -1
- package/lib/structures/channels.js +2 -1
- package/lib/websocket/discord/sharder.js +10 -3
- package/lib/websocket/discord/shared.d.ts +1 -0
- package/lib/websocket/discord/workermanager.d.ts +2 -3
- package/lib/websocket/discord/workermanager.js +4 -2
- package/package.json +3 -3
- package/lib/commands/basecontex.d.ts +0 -15
- package/lib/components/command.d.ts +0 -24
|
@@ -4,6 +4,7 @@ exports.onInteractionCreate = void 0;
|
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const commands_1 = require("../commands");
|
|
6
6
|
const structures_1 = require("../structures");
|
|
7
|
+
const components_1 = require("../components");
|
|
7
8
|
async function onInteractionCreate(self, body, shardId, __reply) {
|
|
8
9
|
self.debugger?.debug(`[${v10_1.InteractionType[body.type] ?? body.type}] Interaction received.`);
|
|
9
10
|
switch (body.type) {
|
|
@@ -16,7 +17,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
16
17
|
return x.name === body.data.name;
|
|
17
18
|
});
|
|
18
19
|
const optionsResolver = new commands_1.OptionResolver(self, body.data.options ?? [], parentCommand, body.guild_id, body.data.resolved);
|
|
19
|
-
const interaction = new structures_1.AutocompleteInteraction(self, body, __reply);
|
|
20
|
+
const interaction = new structures_1.AutocompleteInteraction(self, body, optionsResolver, __reply);
|
|
20
21
|
const command = optionsResolver.getAutocomplete();
|
|
21
22
|
// idc, is a YOU problem
|
|
22
23
|
if (!command?.autocomplete)
|
|
@@ -64,17 +65,17 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
64
65
|
if (command.botPermissions && interaction.appPermissions) {
|
|
65
66
|
const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values([command.botPermissions]));
|
|
66
67
|
if (!interaction.appPermissions.has('Administrator') && permissions.length) {
|
|
67
|
-
return command.onBotPermissionsFail
|
|
68
|
+
return command.onBotPermissionsFail(context, interaction.appPermissions.keys(permissions));
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
const resultRunGlobalMiddlewares = await
|
|
71
|
+
const resultRunGlobalMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, (self.options?.globalMiddlewares ?? []), true);
|
|
71
72
|
if (resultRunGlobalMiddlewares.pass) {
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
if ('error' in resultRunGlobalMiddlewares) {
|
|
75
76
|
return command.onMiddlewaresError(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
|
|
76
77
|
}
|
|
77
|
-
const resultRunMiddlewares = await
|
|
78
|
+
const resultRunMiddlewares = await commands_1.BaseCommand.__runMiddlewares(context, command.middlewares, false);
|
|
78
79
|
if (resultRunMiddlewares.pass) {
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
@@ -86,7 +87,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
86
87
|
await command.onAfterRun?.(context, undefined);
|
|
87
88
|
}
|
|
88
89
|
catch (error) {
|
|
89
|
-
await command.onRunError
|
|
90
|
+
await command.onRunError(context, error);
|
|
90
91
|
await command.onAfterRun?.(context, error);
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -170,7 +171,10 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
170
171
|
await self.components.onModalSubmit(interaction);
|
|
171
172
|
}
|
|
172
173
|
else {
|
|
173
|
-
|
|
174
|
+
const context = new components_1.ModalContext(self, interaction);
|
|
175
|
+
const extended = self.options?.context?.(interaction) ?? {};
|
|
176
|
+
Object.assign(context, extended);
|
|
177
|
+
await self.components?.executeModal(context);
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
break;
|
|
@@ -181,7 +185,11 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
181
185
|
await self.components.onComponent(body.message.id, interaction);
|
|
182
186
|
}
|
|
183
187
|
else {
|
|
184
|
-
|
|
188
|
+
//@ts-expect-error
|
|
189
|
+
const context = new components_1.ComponentContext(self, interaction);
|
|
190
|
+
const extended = self.options?.context?.(interaction) ?? {};
|
|
191
|
+
Object.assign(context, extended);
|
|
192
|
+
await self.components?.executeComponent(context);
|
|
185
193
|
}
|
|
186
194
|
}
|
|
187
195
|
break;
|
|
@@ -67,7 +67,11 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
67
67
|
members: {},
|
|
68
68
|
attachments: {},
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
let newContent = content;
|
|
71
|
+
for (const i of fullCommandName.split(' ')) {
|
|
72
|
+
newContent = newContent.slice(newContent.indexOf(i) + i.length);
|
|
73
|
+
}
|
|
74
|
+
const args = (self.options?.commands?.argsParser ?? defaultArgsParser)(newContent.slice(1), command, message);
|
|
71
75
|
const { options, errors } = await parseOptions(self, command, rawMessage, args, resolved);
|
|
72
76
|
const optionsResolver = new __1.OptionResolver(self, options, parent, message.guildId, resolved);
|
|
73
77
|
const context = new __1.CommandContext(self, message, optionsResolver, shardId, command);
|
|
@@ -262,82 +266,31 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
262
266
|
{
|
|
263
267
|
value = args[i.name];
|
|
264
268
|
const option = i;
|
|
265
|
-
if (value)
|
|
266
|
-
if (option.min_length) {
|
|
267
|
-
if (value.length < option.min_length) {
|
|
268
|
-
value = undefined;
|
|
269
|
-
errors.push({
|
|
270
|
-
name: i.name,
|
|
271
|
-
error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
|
|
272
|
-
});
|
|
273
|
-
break;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (option.max_length) {
|
|
277
|
-
if (value.length > option.max_length) {
|
|
278
|
-
value = undefined;
|
|
279
|
-
errors.push({
|
|
280
|
-
name: i.name,
|
|
281
|
-
error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
|
|
282
|
-
});
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
if (option.choices?.length) {
|
|
287
|
-
if (!option.choices.some(x => x.name === value)) {
|
|
288
|
-
value = undefined;
|
|
289
|
-
errors.push({
|
|
290
|
-
name: i.name,
|
|
291
|
-
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
292
|
-
.map(x => x.name)
|
|
293
|
-
.join(', ')}.`,
|
|
294
|
-
});
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
value = option.choices.find(x => x.name === value).value;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
break;
|
|
302
|
-
case v10_1.ApplicationCommandOptionType.Number:
|
|
303
|
-
case v10_1.ApplicationCommandOptionType.Integer:
|
|
304
|
-
{
|
|
305
|
-
value = Number(args[i.name]);
|
|
306
|
-
if (args[i.name] === undefined) {
|
|
307
|
-
value = undefined;
|
|
269
|
+
if (!value)
|
|
308
270
|
break;
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
value = undefined;
|
|
312
|
-
errors.push({
|
|
313
|
-
name: i.name,
|
|
314
|
-
error: 'The entered choice is an invalid number.',
|
|
315
|
-
});
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
const option = i;
|
|
319
|
-
if (option.min_value) {
|
|
320
|
-
if (value < option.min_value) {
|
|
271
|
+
if (option.min_length) {
|
|
272
|
+
if (value.length < option.min_length) {
|
|
321
273
|
value = undefined;
|
|
322
274
|
errors.push({
|
|
323
275
|
name: i.name,
|
|
324
|
-
error: `The entered
|
|
276
|
+
error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
|
|
325
277
|
});
|
|
326
278
|
break;
|
|
327
279
|
}
|
|
328
280
|
}
|
|
329
|
-
if (option.
|
|
330
|
-
if (value > option.
|
|
281
|
+
if (option.max_length) {
|
|
282
|
+
if (value.length > option.max_length) {
|
|
331
283
|
value = undefined;
|
|
332
284
|
errors.push({
|
|
333
285
|
name: i.name,
|
|
334
|
-
error: `The entered
|
|
286
|
+
error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
|
|
335
287
|
});
|
|
336
288
|
break;
|
|
337
289
|
}
|
|
338
290
|
}
|
|
339
291
|
if (option.choices?.length) {
|
|
340
|
-
|
|
292
|
+
const choice = option.choices.find(x => x.name === value);
|
|
293
|
+
if (!choice) {
|
|
341
294
|
value = undefined;
|
|
342
295
|
errors.push({
|
|
343
296
|
name: i.name,
|
|
@@ -347,8 +300,62 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
347
300
|
});
|
|
348
301
|
break;
|
|
349
302
|
}
|
|
350
|
-
value =
|
|
303
|
+
value = choice.value;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
break;
|
|
307
|
+
case v10_1.ApplicationCommandOptionType.Number:
|
|
308
|
+
case v10_1.ApplicationCommandOptionType.Integer:
|
|
309
|
+
{
|
|
310
|
+
const option = i;
|
|
311
|
+
if (!option.choices?.length) {
|
|
312
|
+
value = Number(args[i.name]);
|
|
313
|
+
if (args[i.name] === undefined) {
|
|
314
|
+
value = undefined;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
if (Number.isNaN(value)) {
|
|
318
|
+
value = undefined;
|
|
319
|
+
errors.push({
|
|
320
|
+
name: i.name,
|
|
321
|
+
error: 'The entered choice is an invalid number.',
|
|
322
|
+
});
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
if (option.min_value) {
|
|
326
|
+
if (value < option.min_value) {
|
|
327
|
+
value = undefined;
|
|
328
|
+
errors.push({
|
|
329
|
+
name: i.name,
|
|
330
|
+
error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
|
|
331
|
+
});
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (option.max_value) {
|
|
336
|
+
if (value > option.max_value) {
|
|
337
|
+
value = undefined;
|
|
338
|
+
errors.push({
|
|
339
|
+
name: i.name,
|
|
340
|
+
error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
|
|
341
|
+
});
|
|
342
|
+
break;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
break;
|
|
351
346
|
}
|
|
347
|
+
const choice = option.choices.find(x => x.name === args[i.name]);
|
|
348
|
+
if (!choice) {
|
|
349
|
+
value = undefined;
|
|
350
|
+
errors.push({
|
|
351
|
+
name: i.name,
|
|
352
|
+
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
353
|
+
.map(x => x.name)
|
|
354
|
+
.join(', ')}.`,
|
|
355
|
+
});
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
value = choice.value;
|
|
352
359
|
}
|
|
353
360
|
break;
|
|
354
361
|
default:
|
|
@@ -362,10 +369,11 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
362
369
|
});
|
|
363
370
|
}
|
|
364
371
|
else if (i.required)
|
|
365
|
-
errors.
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
372
|
+
if (!errors.some(x => x.name === i.name))
|
|
373
|
+
errors.push({
|
|
374
|
+
error: 'Option is required but returned undefined',
|
|
375
|
+
name: i.name,
|
|
376
|
+
});
|
|
369
377
|
}
|
|
370
378
|
catch (e) {
|
|
371
379
|
errors.push({
|
|
@@ -25,7 +25,7 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
|
|
|
25
25
|
timeout: NodeJS.Timeout;
|
|
26
26
|
}>;
|
|
27
27
|
shards: Map<number, Shard>;
|
|
28
|
-
options: WorkerClientOptions
|
|
28
|
+
options: WorkerClientOptions;
|
|
29
29
|
constructor(options?: WorkerClientOptions);
|
|
30
30
|
get workerId(): number;
|
|
31
31
|
get latency(): number;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateShardInfo = exports.WorkerClient = void 0;
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
|
-
const node_worker_threads_1 = require("node:worker_threads");
|
|
7
6
|
const __1 = require("..");
|
|
8
7
|
const cache_1 = require("../cache");
|
|
9
8
|
const common_1 = require("../common");
|
|
@@ -14,6 +13,7 @@ const base_1 = require("./base");
|
|
|
14
13
|
const oninteractioncreate_1 = require("./oninteractioncreate");
|
|
15
14
|
const onmessagecreate_1 = require("./onmessagecreate");
|
|
16
15
|
let workerData;
|
|
16
|
+
let manager;
|
|
17
17
|
try {
|
|
18
18
|
workerData = {
|
|
19
19
|
debug: process.env.SEYFERT_WORKER_DEBUG === 'true',
|
|
@@ -44,7 +44,11 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
44
44
|
type: 'WORKER_START',
|
|
45
45
|
workerId: workerData.workerId,
|
|
46
46
|
});
|
|
47
|
-
|
|
47
|
+
const worker_threads = (0, common_1.lazyLoadPackage)('node:worker_threads');
|
|
48
|
+
if (worker_threads?.parentPort) {
|
|
49
|
+
manager = worker_threads?.parentPort;
|
|
50
|
+
}
|
|
51
|
+
(manager ?? process).on('message', (data) => this.handleManagerMessages(data));
|
|
48
52
|
this.setServices({
|
|
49
53
|
cache: {
|
|
50
54
|
adapter: new cache_1.WorkerAdapter(workerData),
|
|
@@ -105,8 +109,8 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
postMessage(body) {
|
|
108
|
-
if (
|
|
109
|
-
return
|
|
112
|
+
if (manager)
|
|
113
|
+
return manager.postMessage(body);
|
|
110
114
|
return process.send(body);
|
|
111
115
|
}
|
|
112
116
|
async handleManagerMessages(data) {
|
|
@@ -289,12 +293,19 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
289
293
|
case 'MESSAGE_UPDATE':
|
|
290
294
|
case 'MESSAGE_DELETE_BULK':
|
|
291
295
|
case 'MESSAGE_DELETE':
|
|
292
|
-
await this.events?.execute(packet.t, packet, this, shardId);
|
|
293
|
-
await this.cache.onPacket(packet);
|
|
294
|
-
break;
|
|
295
296
|
case 'GUILD_DELETE':
|
|
296
297
|
case 'CHANNEL_UPDATE':
|
|
298
|
+
case 'GUILD_EMOJIS_UPDATE':
|
|
299
|
+
case 'GUILD_UPDATE':
|
|
300
|
+
case 'GUILD_ROLE_UPDATE':
|
|
301
|
+
case 'GUILD_ROLE_DELETE':
|
|
302
|
+
case 'THREAD_UPDATE':
|
|
303
|
+
case 'USER_UPDATE':
|
|
304
|
+
case 'VOICE_STATE_UPDATE':
|
|
305
|
+
case 'STAGE_INSTANCE_UPDATE':
|
|
306
|
+
case 'GUILD_STICKERS_UPDATE':
|
|
297
307
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
308
|
+
await this.cache.onPacket(packet);
|
|
298
309
|
break;
|
|
299
310
|
//rest of the events
|
|
300
311
|
default:
|
|
@@ -64,7 +64,7 @@ type ContextOptionsAux<T extends OptionsRecord> = {
|
|
|
64
64
|
[K in KeysWithoutRequired<T>]?: T[K]['value'] extends (...args: any) => any ? Parameters<Parameters<T[K]['value']>[1]>[0] : T[K] extends SeyfertStringOption | SeyfertNumberOption ? T[K]['choices'] extends NonNullable<SeyfertStringOption['choices'] | SeyfertNumberOption['choices']> ? T[K]['choices'][number]['value'] : ReturnOptionsTypes[T[K]['type']] : ReturnOptionsTypes[T[K]['type']];
|
|
65
65
|
};
|
|
66
66
|
export type ContextOptions<T extends OptionsRecord> = ContextOptionsAux<T>;
|
|
67
|
-
declare class BaseCommand {
|
|
67
|
+
export declare class BaseCommand {
|
|
68
68
|
middlewares: (keyof RegisteredMiddlewares)[];
|
|
69
69
|
__filePath?: string;
|
|
70
70
|
__t?: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubCommand = exports.Command = void 0;
|
|
3
|
+
exports.SubCommand = exports.Command = exports.BaseCommand = void 0;
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const common_1 = require("../../common");
|
|
6
6
|
class BaseCommand {
|
|
@@ -137,6 +137,7 @@ class BaseCommand {
|
|
|
137
137
|
Object.setPrototypeOf(this, __tempCommand.prototype);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
exports.BaseCommand = BaseCommand;
|
|
140
141
|
class Command extends BaseCommand {
|
|
141
142
|
type = v10_1.ApplicationCommandType.ChatInput;
|
|
142
143
|
groups;
|
|
@@ -2,7 +2,7 @@ import type { AllChannels, Guild, InferWithPrefix, ReturnCache, WebhookMessage }
|
|
|
2
2
|
import type { If, UnionToTuple, When } from '../../common';
|
|
3
3
|
import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write';
|
|
4
4
|
import { Message, type ChatInputCommandInteraction, type GuildMember, type InteractionGuildMember } from '../../structures';
|
|
5
|
-
import { BaseContext } from '../
|
|
5
|
+
import { BaseContext } from '../basecontext';
|
|
6
6
|
import type { RegisteredMiddlewares } from '../decorators';
|
|
7
7
|
import type { OptionResolver } from '../optionresolver';
|
|
8
8
|
import type { Command, ContextOptions, OptionsRecord, SubCommand } from './chat';
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CommandContext = void 0;
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const structures_1 = require("../../structures");
|
|
6
|
-
const
|
|
7
|
-
class CommandContext extends
|
|
6
|
+
const basecontext_1 = require("../basecontext");
|
|
7
|
+
class CommandContext extends basecontext_1.BaseContext {
|
|
8
8
|
client;
|
|
9
9
|
resolver;
|
|
10
10
|
shardId;
|
|
@@ -18,54 +18,6 @@ class ContextMenuCommand {
|
|
|
18
18
|
dm;
|
|
19
19
|
name_localizations;
|
|
20
20
|
description_localizations;
|
|
21
|
-
/** @internal */
|
|
22
|
-
static __runMiddlewares(context, middlewares, global) {
|
|
23
|
-
if (!middlewares.length) {
|
|
24
|
-
return Promise.resolve({});
|
|
25
|
-
}
|
|
26
|
-
let index = 0;
|
|
27
|
-
return new Promise(res => {
|
|
28
|
-
let running = true;
|
|
29
|
-
const pass = () => {
|
|
30
|
-
if (!running) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
running = false;
|
|
34
|
-
return res({ pass: true });
|
|
35
|
-
};
|
|
36
|
-
function next(obj) {
|
|
37
|
-
if (!running) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
// biome-ignore lint/style/noArguments: yes
|
|
41
|
-
if (arguments.length) {
|
|
42
|
-
// @ts-expect-error
|
|
43
|
-
context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
|
|
44
|
-
}
|
|
45
|
-
if (++index >= middlewares.length) {
|
|
46
|
-
running = false;
|
|
47
|
-
return res({});
|
|
48
|
-
}
|
|
49
|
-
context.client.middlewares[middlewares[index]]({ context, next, stop, pass });
|
|
50
|
-
}
|
|
51
|
-
const stop = err => {
|
|
52
|
-
if (!running) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
running = false;
|
|
56
|
-
return res({ error: err });
|
|
57
|
-
};
|
|
58
|
-
context.client.middlewares[middlewares[0]]({ context, next, stop, pass });
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
/** @internal */
|
|
62
|
-
__runMiddlewares(context) {
|
|
63
|
-
return ContextMenuCommand.__runMiddlewares(context, this.middlewares, false);
|
|
64
|
-
}
|
|
65
|
-
/** @internal */
|
|
66
|
-
__runGlobalMiddlewares(context) {
|
|
67
|
-
return ContextMenuCommand.__runMiddlewares(context, (context.client.options?.globalMiddlewares ?? []), true);
|
|
68
|
-
}
|
|
69
21
|
toJSON() {
|
|
70
22
|
return {
|
|
71
23
|
name: this.name,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ContextMenuCommand, ReturnCache, WebhookMessage } from '../..';
|
|
2
2
|
import { type InteractionCreateBodyRequest, type InteractionMessageUpdateBodyRequest, type ModalCreateBodyRequest, type UnionToTuple, type When } from '../../common';
|
|
3
3
|
import { Message, User, type AllChannels, type Guild, type GuildMember, type MessageCommandInteraction, type UserCommandInteraction } from '../../structures';
|
|
4
|
-
import { BaseContext } from '../
|
|
4
|
+
import { BaseContext } from '../basecontext';
|
|
5
5
|
import type { RegisteredMiddlewares } from '../decorators';
|
|
6
6
|
import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
|
|
7
7
|
export type InteractionTarget<T> = T extends MessageCommandInteraction ? Message : User;
|
|
@@ -4,8 +4,8 @@ exports.MenuCommandContext = void 0;
|
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const common_1 = require("../../common");
|
|
6
6
|
const structures_1 = require("../../structures");
|
|
7
|
-
const
|
|
8
|
-
class MenuCommandContext extends
|
|
7
|
+
const basecontext_1 = require("../basecontext");
|
|
8
|
+
class MenuCommandContext extends basecontext_1.BaseContext {
|
|
9
9
|
client;
|
|
10
10
|
interaction;
|
|
11
11
|
shardId;
|
|
@@ -33,7 +33,7 @@ class MenuCommandContext extends basecontex_1.BaseContext {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
get t() {
|
|
36
|
-
return this.client.
|
|
36
|
+
return this.client.t(this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US');
|
|
37
37
|
}
|
|
38
38
|
get fullCommandName() {
|
|
39
39
|
return this.command.name;
|
|
@@ -3,6 +3,8 @@ import type { AutocompleteCallback, MenuCommandContext, OnAutocompleteErrorCallb
|
|
|
3
3
|
import type { MessageCommandInteraction, UserCommandInteraction } from '../../structures';
|
|
4
4
|
import type { CommandContext } from './chatcontext';
|
|
5
5
|
import type { MiddlewareContext } from './shared';
|
|
6
|
+
import type { ModalContext } from '../../components';
|
|
7
|
+
import type { ComponentContext } from '../../components/componentcontext';
|
|
6
8
|
export type SeyfertBasicOption<T extends keyof __TypesWrapper, D = {}> = __TypesWrapper[T] & D;
|
|
7
9
|
export type SeyfertStringOption = SeyfertBasicOption<'String'> & {
|
|
8
10
|
autocomplete?: AutocompleteCallback;
|
|
@@ -63,4 +65,4 @@ export declare function createNumberOption<T extends SeyfertNumberOption = Seyfe
|
|
|
63
65
|
export declare function createAttachmentOption<T extends SeyfertAttachmentOption = SeyfertAttachmentOption>(data: T): T & {
|
|
64
66
|
readonly type: ApplicationCommandOptionType.Attachment;
|
|
65
67
|
};
|
|
66
|
-
export declare function createMiddleware<T = any, C extends CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> = CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean
|
|
68
|
+
export declare function createMiddleware<T = any, C extends CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> | ComponentContext | ModalContext = CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> | ComponentContext | ModalContext>(data: MiddlewareContext<T, C>): MiddlewareContext<T, C>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ModalContext } from '../components';
|
|
2
|
+
import type { ContextComponentCommandInteractionMap, ComponentContext } from '../components/componentcontext';
|
|
3
|
+
import type { MessageCommandInteraction, UserCommandInteraction } from '../structures';
|
|
4
|
+
import type { CommandContext } from './applications/chatcontext';
|
|
5
|
+
import type { MenuCommandContext } from './applications/menucontext';
|
|
6
|
+
import type { UsingClient } from './applications/shared';
|
|
7
|
+
export declare class BaseContext {
|
|
8
|
+
readonly client: UsingClient;
|
|
9
|
+
constructor(client: UsingClient);
|
|
10
|
+
/**
|
|
11
|
+
* Gets the proxy object.
|
|
12
|
+
*/
|
|
13
|
+
get proxy(): import("..").APIRoutes;
|
|
14
|
+
isChat(): this is CommandContext;
|
|
15
|
+
isMenu(): this is MenuCommandContext<UserCommandInteraction | MessageCommandInteraction>;
|
|
16
|
+
isMenuUser(): this is MenuCommandContext<UserCommandInteraction>;
|
|
17
|
+
isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction>;
|
|
18
|
+
isComponent(): this is ComponentContext<keyof ContextComponentCommandInteractionMap>;
|
|
19
|
+
isModal(): this is ModalContext;
|
|
20
|
+
isButton(): this is ComponentContext<'Button'>;
|
|
21
|
+
isChannelSelectMenu(): this is ComponentContext<'ChannelSelect'>;
|
|
22
|
+
isRoleSelectMenu(): this is ComponentContext<'RoleSelect'>;
|
|
23
|
+
isMentionableSelectMenu(): this is ComponentContext<'MentionableSelect'>;
|
|
24
|
+
isUserSelectMenu(): this is ComponentContext<'UserSelect'>;
|
|
25
|
+
isStringSelectMenu(): this is ComponentContext<'StringSelect'>;
|
|
26
|
+
}
|
|
@@ -6,6 +6,9 @@ class BaseContext {
|
|
|
6
6
|
constructor(client) {
|
|
7
7
|
this.client = client;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Gets the proxy object.
|
|
11
|
+
*/
|
|
9
12
|
get proxy() {
|
|
10
13
|
return this.client.proxy;
|
|
11
14
|
}
|
|
@@ -24,5 +27,26 @@ class BaseContext {
|
|
|
24
27
|
isComponent() {
|
|
25
28
|
return false;
|
|
26
29
|
}
|
|
30
|
+
isModal() {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
isButton() {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
isChannelSelectMenu() {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
isRoleSelectMenu() {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
isMentionableSelectMenu() {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
isUserSelectMenu() {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
isStringSelectMenu() {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
27
51
|
}
|
|
28
52
|
exports.BaseContext = BaseContext;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type APIApplicationCommandOption } from 'discord-api-types/v10';
|
|
1
2
|
import type { Logger } from '../common';
|
|
2
3
|
import { BaseHandler } from '../common';
|
|
3
4
|
import { Command, SubCommand } from './applications/chat';
|
|
@@ -11,7 +12,11 @@ export declare class CommandHandler extends BaseHandler {
|
|
|
11
12
|
constructor(logger: Logger, client: UsingClient);
|
|
12
13
|
reload(resolve: string | Command): Promise<void>;
|
|
13
14
|
reloadAll(stopIfFail?: boolean): Promise<void>;
|
|
14
|
-
|
|
15
|
+
protected shouldUploadOption(option: APIApplicationCommandOption, cached: APIApplicationCommandOption): boolean | undefined;
|
|
16
|
+
shouldUpload(file: string): Promise<boolean>;
|
|
17
|
+
load(commandsDir: string, client: UsingClient, instances?: {
|
|
18
|
+
new (): Command | ContextMenuCommand;
|
|
19
|
+
}[]): Promise<(Command | ContextMenuCommand)[]>;
|
|
15
20
|
private __parseCommandLocales;
|
|
16
21
|
setHandlers({ onCommand, onSubCommand, }: {
|
|
17
22
|
onCommand?: CommandHandler['onCommand'];
|