commandkit 0.1.11-dev.20250328083250 → 0.1.11-dev.20250330063035
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/dist/index.d.ts +15 -258
- package/dist/index.js +270 -320
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -176,8 +176,6 @@ var init_error_codes = __esm({
|
|
|
176
176
|
"use strict";
|
|
177
177
|
init_cjs_shims();
|
|
178
178
|
CommandKitErrorCodes = {
|
|
179
|
-
GuildOnlyException: Symbol("kGuildOnlyException"),
|
|
180
|
-
DMOnlyException: Symbol("kDMOnlyException"),
|
|
181
179
|
ExitMiddleware: Symbol("kExitMiddleware"),
|
|
182
180
|
ForwardedCommand: Symbol("kForwardedCommand"),
|
|
183
181
|
InvalidCommandPrefix: Symbol("kInvalidCommandPrefix"),
|
|
@@ -193,40 +191,19 @@ var init_error_codes = __esm({
|
|
|
193
191
|
function exitContext(fn) {
|
|
194
192
|
return context.exit(fn);
|
|
195
193
|
}
|
|
194
|
+
function provideContext(value, receiver) {
|
|
195
|
+
return context.run(value, receiver);
|
|
196
|
+
}
|
|
196
197
|
function makeContextAwareFunction(env, fn, finalizer) {
|
|
197
198
|
const _fn = /* @__PURE__ */ __name((...args) => {
|
|
198
|
-
return
|
|
199
|
+
return provideContext(env, async () => {
|
|
199
200
|
try {
|
|
200
201
|
const result = await fn(...args);
|
|
201
202
|
return result;
|
|
202
203
|
} catch (e) {
|
|
203
|
-
if (isCommandKitError(e)) {
|
|
204
|
-
|
|
205
|
-
const interaction = env.variables.get("interaction");
|
|
206
|
-
if (!interaction) return;
|
|
207
|
-
switch (code) {
|
|
208
|
-
case CommandKitErrorCodes.GuildOnlyException: {
|
|
209
|
-
if (interaction.isRepliable()) {
|
|
210
|
-
await interaction.reply({
|
|
211
|
-
content: "This command is only available in guilds.",
|
|
212
|
-
flags: import_discord2.MessageFlags.Ephemeral
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
case CommandKitErrorCodes.DMOnlyException: {
|
|
218
|
-
if (interaction.isRepliable()) {
|
|
219
|
-
await interaction.reply({
|
|
220
|
-
content: "This command is only available in DMs.",
|
|
221
|
-
flags: import_discord2.MessageFlags.Ephemeral
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return;
|
|
204
|
+
if (!isCommandKitError(e)) {
|
|
205
|
+
env.setExecutionError(e);
|
|
228
206
|
}
|
|
229
|
-
env.setExecutionError(e);
|
|
230
207
|
} finally {
|
|
231
208
|
if (typeof finalizer === "function") {
|
|
232
209
|
try {
|
|
@@ -260,59 +237,33 @@ function useEnvironment() {
|
|
|
260
237
|
}
|
|
261
238
|
return ctx;
|
|
262
239
|
}
|
|
263
|
-
|
|
264
|
-
const env = useEnvironment();
|
|
265
|
-
const interaction = env.variables.get("interaction");
|
|
266
|
-
if (!interaction) {
|
|
267
|
-
throw new Error("No interaction found in environment.");
|
|
268
|
-
}
|
|
269
|
-
if (!interaction.guild) {
|
|
270
|
-
const error = new Error("This command is only available in guilds.");
|
|
271
|
-
Reflect.set(error, "code", CommandKitErrorCodes.GuildOnlyException);
|
|
272
|
-
throw error;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
function dmOnly() {
|
|
276
|
-
const env = useEnvironment();
|
|
277
|
-
const interaction = env.variables.get("interaction");
|
|
278
|
-
if (!interaction) {
|
|
279
|
-
throw new Error("No interaction found in environment.");
|
|
280
|
-
}
|
|
281
|
-
if (interaction.guild) {
|
|
282
|
-
const error = new Error("This command is only available in DMs.");
|
|
283
|
-
Reflect.set(error, "code", CommandKitErrorCodes.DMOnlyException);
|
|
284
|
-
throw error;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
var import_node_async_hooks, import_discord2, context;
|
|
240
|
+
var import_node_async_hooks, context;
|
|
288
241
|
var init_async_context = __esm({
|
|
289
242
|
"src/context/async-context.ts"() {
|
|
290
243
|
"use strict";
|
|
291
244
|
init_cjs_shims();
|
|
292
245
|
import_node_async_hooks = require("async_hooks");
|
|
293
|
-
init_error_codes();
|
|
294
|
-
import_discord2 = require("discord.js");
|
|
295
246
|
init_CommandKit();
|
|
247
|
+
init_error_codes();
|
|
296
248
|
context = new import_node_async_hooks.AsyncLocalStorage();
|
|
297
249
|
__name(exitContext, "exitContext");
|
|
250
|
+
__name(provideContext, "provideContext");
|
|
298
251
|
__name(makeContextAwareFunction, "makeContextAwareFunction");
|
|
299
252
|
__name(getCommandKit, "getCommandKit");
|
|
300
253
|
__name(getContext, "getContext");
|
|
301
254
|
__name(useEnvironment, "useEnvironment");
|
|
302
|
-
__name(guildOnly, "guildOnly");
|
|
303
|
-
__name(dmOnly, "dmOnly");
|
|
304
255
|
}
|
|
305
256
|
});
|
|
306
257
|
|
|
307
258
|
// src/components/button/ButtonKit.ts
|
|
308
|
-
var
|
|
259
|
+
var import_discord2, _onClickHandler, _contextData, _unsub, _ButtonKit_instances, getEventInterceptor_fn, setupInteractionCollector_fn, destroyCollector_fn, _ButtonKit, ButtonKit;
|
|
309
260
|
var init_ButtonKit = __esm({
|
|
310
261
|
"src/components/button/ButtonKit.ts"() {
|
|
311
262
|
"use strict";
|
|
312
263
|
init_cjs_shims();
|
|
313
|
-
|
|
264
|
+
import_discord2 = require("discord.js");
|
|
314
265
|
init_async_context();
|
|
315
|
-
_ButtonKit = class _ButtonKit extends
|
|
266
|
+
_ButtonKit = class _ButtonKit extends import_discord2.ButtonBuilder {
|
|
316
267
|
constructor() {
|
|
317
268
|
super(...arguments);
|
|
318
269
|
__privateAdd(this, _ButtonKit_instances);
|
|
@@ -351,7 +302,7 @@ var init_ButtonKit = __esm({
|
|
|
351
302
|
*/
|
|
352
303
|
onClick(handler, data) {
|
|
353
304
|
var _a, _b, _c, _d;
|
|
354
|
-
if (this.data.style ===
|
|
305
|
+
if (this.data.style === import_discord2.ButtonStyle.Link) {
|
|
355
306
|
throw new TypeError('Cannot setup "onClick" handler on link buttons.');
|
|
356
307
|
}
|
|
357
308
|
if (!handler) {
|
|
@@ -375,7 +326,7 @@ var init_ButtonKit = __esm({
|
|
|
375
326
|
return this;
|
|
376
327
|
}
|
|
377
328
|
onEnd(handler) {
|
|
378
|
-
if (this.data.style ===
|
|
329
|
+
if (this.data.style === import_discord2.ButtonStyle.Link) {
|
|
379
330
|
throw new TypeError('Cannot setup "onEnd" handler on link buttons.');
|
|
380
331
|
}
|
|
381
332
|
if (!handler) {
|
|
@@ -432,7 +383,7 @@ var init_ButtonKit = __esm({
|
|
|
432
383
|
return exitContext(() => ctx.commandkit.eventInterceptor);
|
|
433
384
|
}, "#getEventInterceptor");
|
|
434
385
|
setupInteractionCollector_fn = /* @__PURE__ */ __name(function() {
|
|
435
|
-
if (this.data.style ===
|
|
386
|
+
if (this.data.style === import_discord2.ButtonStyle.Link || !__privateGet(this, _contextData) || !__privateGet(this, _onClickHandler))
|
|
436
387
|
return;
|
|
437
388
|
const myCustomId = this.customId ?? null;
|
|
438
389
|
if (myCustomId === null) {
|
|
@@ -442,7 +393,7 @@ var init_ButtonKit = __esm({
|
|
|
442
393
|
}
|
|
443
394
|
const interceptor = __privateMethod(this, _ButtonKit_instances, getEventInterceptor_fn).call(this);
|
|
444
395
|
__privateSet(this, _unsub, interceptor.subscribe(
|
|
445
|
-
|
|
396
|
+
import_discord2.Events.InteractionCreate,
|
|
446
397
|
async (interaction) => {
|
|
447
398
|
var _a, _b;
|
|
448
399
|
if (!interaction.isButton()) return;
|
|
@@ -473,7 +424,7 @@ var init_ButtonKit = __esm({
|
|
|
473
424
|
// src/components/button/Button.ts
|
|
474
425
|
function Button(props) {
|
|
475
426
|
const button = new ButtonKit();
|
|
476
|
-
props.style ??=
|
|
427
|
+
props.style ??= import_discord3.ButtonStyle.Primary;
|
|
477
428
|
if (props.onClick) {
|
|
478
429
|
props.customId ??= `buttonkit::${crypto.randomUUID()}`;
|
|
479
430
|
}
|
|
@@ -512,26 +463,26 @@ function Button(props) {
|
|
|
512
463
|
}
|
|
513
464
|
return button;
|
|
514
465
|
}
|
|
515
|
-
var
|
|
466
|
+
var import_discord3;
|
|
516
467
|
var init_Button = __esm({
|
|
517
468
|
"src/components/button/Button.ts"() {
|
|
518
469
|
"use strict";
|
|
519
470
|
init_cjs_shims();
|
|
520
|
-
|
|
471
|
+
import_discord3 = require("discord.js");
|
|
521
472
|
init_ButtonKit();
|
|
522
473
|
__name(Button, "Button");
|
|
523
474
|
}
|
|
524
475
|
});
|
|
525
476
|
|
|
526
477
|
// src/components/modal/ModalKit.ts
|
|
527
|
-
var
|
|
478
|
+
var import_discord4, _onSubmitHandler, _contextData2, _unsub2, _ModalKit_instances, getEventInterceptor_fn2, setupCollector_fn, destroyCollector_fn2, _ModalKit, ModalKit;
|
|
528
479
|
var init_ModalKit = __esm({
|
|
529
480
|
"src/components/modal/ModalKit.ts"() {
|
|
530
481
|
"use strict";
|
|
531
482
|
init_cjs_shims();
|
|
532
|
-
|
|
483
|
+
import_discord4 = require("discord.js");
|
|
533
484
|
init_async_context();
|
|
534
|
-
_ModalKit = class _ModalKit extends
|
|
485
|
+
_ModalKit = class _ModalKit extends import_discord4.ModalBuilder {
|
|
535
486
|
constructor() {
|
|
536
487
|
super(...arguments);
|
|
537
488
|
__privateAdd(this, _ModalKit_instances);
|
|
@@ -652,7 +603,7 @@ var init_ModalKit = __esm({
|
|
|
652
603
|
const interceptor = __privateMethod(this, _ModalKit_instances, getEventInterceptor_fn2).call(this);
|
|
653
604
|
if (!interceptor) return;
|
|
654
605
|
__privateSet(this, _unsub2, interceptor.subscribe(
|
|
655
|
-
|
|
606
|
+
import_discord4.Events.InteractionCreate,
|
|
656
607
|
async (interaction) => {
|
|
657
608
|
var _a, _b;
|
|
658
609
|
if (!interaction.isModalSubmit()) return;
|
|
@@ -697,9 +648,9 @@ function Modal(props) {
|
|
|
697
648
|
}
|
|
698
649
|
if (props.children) {
|
|
699
650
|
const childs = (Array.isArray(props.children) ? props.children : [props.children]).map((c) => {
|
|
700
|
-
if (c instanceof
|
|
701
|
-
if (c instanceof
|
|
702
|
-
return new
|
|
651
|
+
if (c instanceof import_discord5.ActionRowBuilder) return c;
|
|
652
|
+
if (c instanceof import_discord5.TextInputBuilder)
|
|
653
|
+
return new import_discord5.ActionRowBuilder().addComponents(c);
|
|
703
654
|
}).filter((c) => c != null);
|
|
704
655
|
modal.addComponents(childs);
|
|
705
656
|
}
|
|
@@ -712,7 +663,7 @@ function Modal(props) {
|
|
|
712
663
|
return modal;
|
|
713
664
|
}
|
|
714
665
|
function TextInput(props) {
|
|
715
|
-
const input = new
|
|
666
|
+
const input = new import_discord5.TextInputBuilder().setStyle(props.style);
|
|
716
667
|
if (props.customId) {
|
|
717
668
|
input.setCustomId(props.customId);
|
|
718
669
|
}
|
|
@@ -737,17 +688,17 @@ function TextInput(props) {
|
|
|
737
688
|
return input;
|
|
738
689
|
}
|
|
739
690
|
function ShortInput(props) {
|
|
740
|
-
return TextInput({ ...props, style:
|
|
691
|
+
return TextInput({ ...props, style: import_discord5.TextInputStyle.Short });
|
|
741
692
|
}
|
|
742
693
|
function ParagraphInput(props) {
|
|
743
|
-
return TextInput({ ...props, style:
|
|
694
|
+
return TextInput({ ...props, style: import_discord5.TextInputStyle.Paragraph });
|
|
744
695
|
}
|
|
745
|
-
var
|
|
696
|
+
var import_discord5;
|
|
746
697
|
var init_Modal = __esm({
|
|
747
698
|
"src/components/modal/Modal.ts"() {
|
|
748
699
|
"use strict";
|
|
749
700
|
init_cjs_shims();
|
|
750
|
-
|
|
701
|
+
import_discord5 = require("discord.js");
|
|
751
702
|
init_ModalKit();
|
|
752
703
|
__name(Modal, "Modal");
|
|
753
704
|
__name(TextInput, "TextInput");
|
|
@@ -1128,12 +1079,6 @@ var init_RuntimePlugin = __esm({
|
|
|
1128
1079
|
*/
|
|
1129
1080
|
async onBeforeInteraction(ctx, interaction) {
|
|
1130
1081
|
}
|
|
1131
|
-
/**
|
|
1132
|
-
* Called after interaction is handled
|
|
1133
|
-
* @param interaction The interaction that was handled
|
|
1134
|
-
*/
|
|
1135
|
-
async onAfterInteraction(ctx, interaction) {
|
|
1136
|
-
}
|
|
1137
1082
|
/**
|
|
1138
1083
|
* Called before message command is processed
|
|
1139
1084
|
* @param message The message
|
|
@@ -1152,7 +1097,7 @@ var init_RuntimePlugin = __esm({
|
|
|
1152
1097
|
* @param command The command
|
|
1153
1098
|
* @param execute The function that executes the command
|
|
1154
1099
|
*/
|
|
1155
|
-
async executeCommand(ctx, source, command, execute) {
|
|
1100
|
+
async executeCommand(ctx, env, source, command, execute) {
|
|
1156
1101
|
return false;
|
|
1157
1102
|
}
|
|
1158
1103
|
};
|
|
@@ -1229,10 +1174,12 @@ var init_DefaultLogger = __esm({
|
|
|
1229
1174
|
if (!kind && !commandHandler) return "";
|
|
1230
1175
|
const h = execHandlerKind[kind];
|
|
1231
1176
|
if (!h && !commandHandler) return "";
|
|
1232
|
-
const
|
|
1177
|
+
const forwardedBy = ctx.variables.get("forwardedBy");
|
|
1178
|
+
const forwardedTo = ctx.variables.get("forwardedTo");
|
|
1233
1179
|
const cmdText = command ? colors_default.magenta(`/${command}`) + " " : "";
|
|
1180
|
+
const forward = forwardedTo ? `${colors_default.yellowBright(`(${forwardedBy || command} \u2192 ${forwardedTo})`)} ` : "";
|
|
1234
1181
|
return colors_default.dim(`${BoxChars.vertical} `) + colors_default.cyanBright(
|
|
1235
|
-
`${
|
|
1182
|
+
`${cmdText}${forward}${h ? colors_default.gray(`[${h}]`) : ""}`.trim()
|
|
1236
1183
|
);
|
|
1237
1184
|
}
|
|
1238
1185
|
_getLevelLabel(level) {
|
|
@@ -1333,53 +1280,20 @@ var init_Logger = __esm({
|
|
|
1333
1280
|
}
|
|
1334
1281
|
});
|
|
1335
1282
|
|
|
1336
|
-
// src/plugins/runtime/runtime-events/index.ts
|
|
1337
|
-
var CommandKitPluginEvents, PluginEvents;
|
|
1338
|
-
var init_runtime_events = __esm({
|
|
1339
|
-
"src/plugins/runtime/runtime-events/index.ts"() {
|
|
1340
|
-
"use strict";
|
|
1341
|
-
init_cjs_shims();
|
|
1342
|
-
CommandKitPluginEvents = {
|
|
1343
|
-
"client-login": {
|
|
1344
|
-
name: "ClientLogin",
|
|
1345
|
-
cancelable: false
|
|
1346
|
-
}
|
|
1347
|
-
};
|
|
1348
|
-
PluginEvents = Object.fromEntries(
|
|
1349
|
-
Object.entries(CommandKitPluginEvents).map(
|
|
1350
|
-
([key, value]) => [
|
|
1351
|
-
value.name,
|
|
1352
|
-
class extends Event {
|
|
1353
|
-
target;
|
|
1354
|
-
constructor() {
|
|
1355
|
-
super(key, { cancelable: value.cancelable });
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
]
|
|
1359
|
-
)
|
|
1360
|
-
);
|
|
1361
|
-
}
|
|
1362
|
-
});
|
|
1363
|
-
|
|
1364
1283
|
// src/plugins/runtime/CommandKitPluginRuntime.ts
|
|
1365
|
-
var
|
|
1284
|
+
var import_discord6, _CommandKitPluginRuntime, CommandKitPluginRuntime;
|
|
1366
1285
|
var init_CommandKitPluginRuntime = __esm({
|
|
1367
1286
|
"src/plugins/runtime/CommandKitPluginRuntime.ts"() {
|
|
1368
1287
|
"use strict";
|
|
1369
1288
|
init_cjs_shims();
|
|
1370
|
-
|
|
1289
|
+
import_discord6 = require("discord.js");
|
|
1371
1290
|
init_error_codes();
|
|
1372
1291
|
init_Logger();
|
|
1373
|
-
|
|
1374
|
-
_CommandKitPluginRuntime = class _CommandKitPluginRuntime extends EventTarget {
|
|
1292
|
+
_CommandKitPluginRuntime = class _CommandKitPluginRuntime {
|
|
1375
1293
|
constructor(commandkit2) {
|
|
1376
|
-
super();
|
|
1377
1294
|
this.commandkit = commandkit2;
|
|
1378
1295
|
}
|
|
1379
|
-
plugins = new
|
|
1380
|
-
onClientLogin = /* @__PURE__ */ __name(() => {
|
|
1381
|
-
this.dispatchEvent(new PluginEvents.ClientLogin());
|
|
1382
|
-
}, "onClientLogin");
|
|
1296
|
+
plugins = new import_discord6.Collection();
|
|
1383
1297
|
getPlugin(pluginName) {
|
|
1384
1298
|
return this.plugins.get(pluginName) ?? null;
|
|
1385
1299
|
}
|
|
@@ -2205,12 +2119,12 @@ var init_resolve_file_url = __esm({
|
|
|
2205
2119
|
});
|
|
2206
2120
|
|
|
2207
2121
|
// src/app/commands/MessageCommandParser.ts
|
|
2208
|
-
var
|
|
2122
|
+
var import_discord7, _parsed, _options, _args, _MessageCommandParser, MessageCommandParser, _MessageCommandOptions, MessageCommandOptions;
|
|
2209
2123
|
var init_MessageCommandParser = __esm({
|
|
2210
2124
|
"src/app/commands/MessageCommandParser.ts"() {
|
|
2211
2125
|
"use strict";
|
|
2212
2126
|
init_cjs_shims();
|
|
2213
|
-
|
|
2127
|
+
import_discord7 = require("discord.js");
|
|
2214
2128
|
init_error_codes();
|
|
2215
2129
|
_MessageCommandParser = class _MessageCommandParser {
|
|
2216
2130
|
constructor(message, prefix, schema) {
|
|
@@ -2285,36 +2199,36 @@ var init_MessageCommandParser = __esm({
|
|
|
2285
2199
|
const [name, value] = part.split(":");
|
|
2286
2200
|
if (!(name in schema)) return null;
|
|
2287
2201
|
switch (schema[name]) {
|
|
2288
|
-
case
|
|
2202
|
+
case import_discord7.ApplicationCommandOptionType.Boolean:
|
|
2289
2203
|
return { name, value: value === "true" };
|
|
2290
|
-
case
|
|
2204
|
+
case import_discord7.ApplicationCommandOptionType.Integer:
|
|
2291
2205
|
return { name, value: parseInt(value, 10) };
|
|
2292
|
-
case
|
|
2206
|
+
case import_discord7.ApplicationCommandOptionType.Number:
|
|
2293
2207
|
return { name, value: parseFloat(value) };
|
|
2294
|
-
case
|
|
2208
|
+
case import_discord7.ApplicationCommandOptionType.String:
|
|
2295
2209
|
return { name, value };
|
|
2296
|
-
case
|
|
2210
|
+
case import_discord7.ApplicationCommandOptionType.User:
|
|
2297
2211
|
return {
|
|
2298
2212
|
name,
|
|
2299
2213
|
value: this.message.mentions.users.find((u) => {
|
|
2300
2214
|
return u.id === value.replace(/[<@!>]/g, "");
|
|
2301
2215
|
})
|
|
2302
2216
|
};
|
|
2303
|
-
case
|
|
2217
|
+
case import_discord7.ApplicationCommandOptionType.Channel:
|
|
2304
2218
|
return {
|
|
2305
2219
|
name,
|
|
2306
2220
|
value: this.message.mentions.channels.find((c) => {
|
|
2307
2221
|
return c.id === value.replace(/[<#>]/g, "");
|
|
2308
2222
|
})
|
|
2309
2223
|
};
|
|
2310
|
-
case
|
|
2224
|
+
case import_discord7.ApplicationCommandOptionType.Role:
|
|
2311
2225
|
return {
|
|
2312
2226
|
name,
|
|
2313
2227
|
value: this.message.mentions.roles.find((r) => {
|
|
2314
2228
|
return r.id === value.replace(/[<@&>]/g, "");
|
|
2315
2229
|
})
|
|
2316
2230
|
};
|
|
2317
|
-
case
|
|
2231
|
+
case import_discord7.ApplicationCommandOptionType.Attachment:
|
|
2318
2232
|
return {
|
|
2319
2233
|
name,
|
|
2320
2234
|
value: this.message.attachments.find((a) => {
|
|
@@ -2388,7 +2302,7 @@ var init_MessageCommandParser = __esm({
|
|
|
2388
2302
|
}
|
|
2389
2303
|
getMentionable(name, required = false) {
|
|
2390
2304
|
const target = this.assertOption(name, required);
|
|
2391
|
-
if (target instanceof
|
|
2305
|
+
if (target instanceof import_discord7.GuildMember || target instanceof import_discord7.User || target instanceof import_discord7.Role) {
|
|
2392
2306
|
return target;
|
|
2393
2307
|
}
|
|
2394
2308
|
if (required) {
|
|
@@ -2417,12 +2331,12 @@ var init_MessageCommandParser = __esm({
|
|
|
2417
2331
|
});
|
|
2418
2332
|
|
|
2419
2333
|
// src/app/register/CommandRegistrar.ts
|
|
2420
|
-
var
|
|
2334
|
+
var import_discord8, _CommandRegistrar, CommandRegistrar;
|
|
2421
2335
|
var init_CommandRegistrar = __esm({
|
|
2422
2336
|
"src/app/register/CommandRegistrar.ts"() {
|
|
2423
2337
|
"use strict";
|
|
2424
2338
|
init_cjs_shims();
|
|
2425
|
-
|
|
2339
|
+
import_discord8 = require("discord.js");
|
|
2426
2340
|
init_Logger();
|
|
2427
2341
|
_CommandRegistrar = class _CommandRegistrar {
|
|
2428
2342
|
/**
|
|
@@ -2435,7 +2349,7 @@ var init_CommandRegistrar = __esm({
|
|
|
2435
2349
|
this.commandkit.client.token ?? process.env.DISCORD_TOKEN ?? process.env.TOKEN ?? ""
|
|
2436
2350
|
);
|
|
2437
2351
|
}
|
|
2438
|
-
api = new
|
|
2352
|
+
api = new import_discord8.REST();
|
|
2439
2353
|
/**
|
|
2440
2354
|
* Gets the commands data.
|
|
2441
2355
|
*/
|
|
@@ -2445,20 +2359,20 @@ var init_CommandRegistrar = __esm({
|
|
|
2445
2359
|
return commands.flatMap((cmd) => {
|
|
2446
2360
|
const json = "toJSON" in cmd.data.command ? cmd.data.command.toJSON() : cmd.data.command;
|
|
2447
2361
|
const collections = [json];
|
|
2448
|
-
if (cmd.data.userContextMenu && json.type !==
|
|
2362
|
+
if (cmd.data.userContextMenu && json.type !== import_discord8.ApplicationCommandType.User) {
|
|
2449
2363
|
collections.push({
|
|
2450
2364
|
...json,
|
|
2451
|
-
type:
|
|
2365
|
+
type: import_discord8.ApplicationCommandType.User,
|
|
2452
2366
|
options: void 0,
|
|
2453
2367
|
description_localizations: void 0,
|
|
2454
2368
|
// @ts-ignore
|
|
2455
2369
|
description: void 0
|
|
2456
2370
|
});
|
|
2457
2371
|
}
|
|
2458
|
-
if (cmd.data.messageContextMenu && json.type !==
|
|
2372
|
+
if (cmd.data.messageContextMenu && json.type !== import_discord8.ApplicationCommandType.Message) {
|
|
2459
2373
|
collections.push({
|
|
2460
2374
|
...json,
|
|
2461
|
-
type:
|
|
2375
|
+
type: import_discord8.ApplicationCommandType.Message,
|
|
2462
2376
|
description_localizations: void 0,
|
|
2463
2377
|
// @ts-ignore
|
|
2464
2378
|
description: void 0,
|
|
@@ -2502,7 +2416,7 @@ var init_CommandRegistrar = __esm({
|
|
|
2502
2416
|
if (!commands.length) return;
|
|
2503
2417
|
try {
|
|
2504
2418
|
const data = await this.api.put(
|
|
2505
|
-
|
|
2419
|
+
import_discord8.Routes.applicationCommands(this.commandkit.client.user.id),
|
|
2506
2420
|
{
|
|
2507
2421
|
body: commands.map((c) => ({
|
|
2508
2422
|
...c,
|
|
@@ -2537,7 +2451,7 @@ var init_CommandRegistrar = __esm({
|
|
|
2537
2451
|
let count = 0;
|
|
2538
2452
|
for (const [guild, guildCommands] of guildCommandsMap) {
|
|
2539
2453
|
const data = await this.api.put(
|
|
2540
|
-
|
|
2454
|
+
import_discord8.Routes.applicationGuildCommands(
|
|
2541
2455
|
this.commandkit.client.user.id,
|
|
2542
2456
|
guild
|
|
2543
2457
|
),
|
|
@@ -2697,7 +2611,9 @@ var init_environment = __esm({
|
|
|
2697
2611
|
* @internal
|
|
2698
2612
|
*/
|
|
2699
2613
|
markEnd() {
|
|
2700
|
-
if (!__privateGet(this, _data).markEnd)
|
|
2614
|
+
if (!__privateGet(this, _data).markEnd) {
|
|
2615
|
+
__privateGet(this, _data).markEnd = performance.now();
|
|
2616
|
+
}
|
|
2701
2617
|
}
|
|
2702
2618
|
/**
|
|
2703
2619
|
* Get the marker.
|
|
@@ -3038,12 +2954,11 @@ var init_Context = __esm({
|
|
|
3038
2954
|
*/
|
|
3039
2955
|
async forwardCommand(command) {
|
|
3040
2956
|
const target = await this.commandkit.commandHandler.prepareCommandRun(
|
|
3041
|
-
this.isInteraction() ? this.interaction : this.message
|
|
2957
|
+
this.isInteraction() ? this.interaction : this.message,
|
|
2958
|
+
command
|
|
3042
2959
|
);
|
|
3043
2960
|
if (!target) {
|
|
3044
|
-
throw new Error(
|
|
3045
|
-
`Command ${command} not found! If you are trying to forward to a legacy command, ctx.forwardCommand is not compatible with legacy commands.`
|
|
3046
|
-
);
|
|
2961
|
+
throw new Error(`Command ${command} not found`);
|
|
3047
2962
|
}
|
|
3048
2963
|
const env = this.config.environment ?? getContext();
|
|
3049
2964
|
if (!env) {
|
|
@@ -3066,6 +2981,8 @@ var init_Context = __esm({
|
|
|
3066
2981
|
if (!handler) {
|
|
3067
2982
|
throw new Error(`No handler found for ${handlerKind}`);
|
|
3068
2983
|
}
|
|
2984
|
+
env.variables.set("forwardedBy", this.commandName);
|
|
2985
|
+
env.variables.set("forwardedTo", command);
|
|
3069
2986
|
await handler(this.clone({ forwarded: true }));
|
|
3070
2987
|
redirect();
|
|
3071
2988
|
}
|
|
@@ -3271,23 +3188,24 @@ var init_Context = __esm({
|
|
|
3271
3188
|
});
|
|
3272
3189
|
|
|
3273
3190
|
// src/app/commands/AppCommandRunner.ts
|
|
3274
|
-
var
|
|
3191
|
+
var import_discord9, _AppCommandRunner_instances, finalizer_fn, _AppCommandRunner, AppCommandRunner;
|
|
3275
3192
|
var init_AppCommandRunner = __esm({
|
|
3276
3193
|
"src/app/commands/AppCommandRunner.ts"() {
|
|
3277
3194
|
"use strict";
|
|
3278
3195
|
init_cjs_shims();
|
|
3279
|
-
|
|
3196
|
+
import_discord9 = require("discord.js");
|
|
3280
3197
|
init_environment();
|
|
3281
3198
|
init_Logger();
|
|
3282
3199
|
init_Context();
|
|
3283
3200
|
init_async_context();
|
|
3201
|
+
init_error_codes();
|
|
3284
3202
|
_AppCommandRunner = class _AppCommandRunner {
|
|
3285
3203
|
constructor(handler) {
|
|
3286
3204
|
this.handler = handler;
|
|
3287
3205
|
__privateAdd(this, _AppCommandRunner_instances);
|
|
3288
3206
|
}
|
|
3289
3207
|
async runCommand(prepared, source) {
|
|
3290
|
-
if (source instanceof
|
|
3208
|
+
if (source instanceof import_discord9.Message && (source.editedTimestamp || source.partial)) {
|
|
3291
3209
|
return;
|
|
3292
3210
|
}
|
|
3293
3211
|
const { commandkit: commandkit2 } = this.handler;
|
|
@@ -3301,70 +3219,113 @@ var init_AppCommandRunner = __esm({
|
|
|
3301
3219
|
const ctx = new MiddlewareContext(commandkit2, {
|
|
3302
3220
|
environment: env,
|
|
3303
3221
|
executionMode,
|
|
3304
|
-
interaction: !(source instanceof
|
|
3305
|
-
message: source instanceof
|
|
3222
|
+
interaction: !(source instanceof import_discord9.Message) ? source : null,
|
|
3223
|
+
message: source instanceof import_discord9.Message ? source : null,
|
|
3306
3224
|
forwarded: false,
|
|
3307
3225
|
customArgs: {
|
|
3308
|
-
setCommandRunner: /* @__PURE__ */ __name((
|
|
3309
|
-
runCommand =
|
|
3226
|
+
setCommandRunner: /* @__PURE__ */ __name((fn) => {
|
|
3227
|
+
runCommand = fn;
|
|
3310
3228
|
}, "setCommandRunner")
|
|
3311
|
-
}
|
|
3229
|
+
},
|
|
3230
|
+
messageCommandParser: prepared.messageCommandParser
|
|
3312
3231
|
});
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3232
|
+
let middlewaresCanceled = false;
|
|
3233
|
+
if (prepared.middlewares.length) {
|
|
3234
|
+
await provideContext(env, async () => {
|
|
3235
|
+
for (const middleware of prepared.middlewares) {
|
|
3236
|
+
try {
|
|
3237
|
+
await middleware.data.beforeExecute(ctx);
|
|
3238
|
+
} catch (e) {
|
|
3239
|
+
if (isErrorType(e, CommandKitErrorCodes.ExitMiddleware)) {
|
|
3240
|
+
middlewaresCanceled = true;
|
|
3241
|
+
return;
|
|
3242
|
+
}
|
|
3243
|
+
if (isErrorType(
|
|
3244
|
+
e,
|
|
3245
|
+
[
|
|
3246
|
+
CommandKitErrorCodes.ForwardedCommand,
|
|
3247
|
+
CommandKitErrorCodes.InvalidCommandPrefix
|
|
3248
|
+
]
|
|
3249
|
+
)) {
|
|
3250
|
+
continue;
|
|
3251
|
+
}
|
|
3252
|
+
throw e;
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
});
|
|
3322
3256
|
}
|
|
3323
|
-
if (
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
const error = env2.getExecutionError();
|
|
3330
|
-
const marker = env2.getMarker();
|
|
3331
|
-
const time = `${env2.getExecutionTime().toFixed(2)}ms`;
|
|
3332
|
-
if (error) {
|
|
3333
|
-
Logger.error(
|
|
3334
|
-
`[${marker} - ${time}] Error executing command: ${error.stack || error}`
|
|
3335
|
-
);
|
|
3336
|
-
return;
|
|
3337
|
-
}
|
|
3338
|
-
Logger.info(
|
|
3339
|
-
`[${marker} - ${time}] Command executed successfully`
|
|
3340
|
-
);
|
|
3341
|
-
});
|
|
3342
|
-
return fn(ctx.clone());
|
|
3343
|
-
},
|
|
3344
|
-
__privateMethod(this, _AppCommandRunner_instances, finalizer_fn).bind(this)
|
|
3257
|
+
if (!ctx.cancelled) {
|
|
3258
|
+
const targetData = prepared.command.data;
|
|
3259
|
+
const fn = targetData[executionMode];
|
|
3260
|
+
if (!fn) {
|
|
3261
|
+
Logger.warn(
|
|
3262
|
+
`Command ${prepared.command.command.name} has no handler for ${executionMode}`
|
|
3345
3263
|
);
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3264
|
+
}
|
|
3265
|
+
if (fn) {
|
|
3266
|
+
try {
|
|
3267
|
+
const _executeCommand = makeContextAwareFunction(
|
|
3268
|
+
env,
|
|
3269
|
+
async () => {
|
|
3270
|
+
env.registerDeferredFunction((env2) => {
|
|
3271
|
+
env2.markEnd();
|
|
3272
|
+
const error = env2.getExecutionError();
|
|
3273
|
+
const marker = env2.getMarker();
|
|
3274
|
+
const time = `${env2.getExecutionTime().toFixed(2)}ms`;
|
|
3275
|
+
if (error) {
|
|
3276
|
+
Logger.error(
|
|
3277
|
+
`[${marker} - ${time}] Error executing command: ${error.stack || error}`
|
|
3278
|
+
);
|
|
3279
|
+
return;
|
|
3280
|
+
}
|
|
3281
|
+
Logger.info(
|
|
3282
|
+
`[${marker} - ${time}] Command executed successfully`
|
|
3283
|
+
);
|
|
3284
|
+
});
|
|
3285
|
+
return fn(ctx.clone());
|
|
3286
|
+
},
|
|
3287
|
+
__privateMethod(this, _AppCommandRunner_instances, finalizer_fn).bind(this)
|
|
3288
|
+
);
|
|
3289
|
+
const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
|
|
3290
|
+
env.markStart(prepared.command.data.command.name);
|
|
3291
|
+
const res = await commandkit2.plugins.execute(async (ctx2, plugin) => {
|
|
3292
|
+
return plugin.executeCommand(
|
|
3293
|
+
ctx2,
|
|
3294
|
+
env,
|
|
3295
|
+
source,
|
|
3296
|
+
prepared,
|
|
3297
|
+
executeCommand
|
|
3298
|
+
);
|
|
3299
|
+
});
|
|
3300
|
+
if (!res) {
|
|
3301
|
+
await executeCommand();
|
|
3302
|
+
}
|
|
3303
|
+
} catch (e) {
|
|
3304
|
+
if (isErrorType(e, CommandKitErrorCodes.ExitMiddleware)) {
|
|
3305
|
+
middlewaresCanceled = true;
|
|
3306
|
+
}
|
|
3307
|
+
if (!isErrorType(
|
|
3308
|
+
e,
|
|
3309
|
+
[
|
|
3310
|
+
CommandKitErrorCodes.ForwardedCommand,
|
|
3311
|
+
CommandKitErrorCodes.ExitMiddleware
|
|
3312
|
+
]
|
|
3313
|
+
)) {
|
|
3314
|
+
Logger.error(e);
|
|
3315
|
+
}
|
|
3353
3316
|
}
|
|
3354
|
-
} catch (e) {
|
|
3355
|
-
Logger.error(e);
|
|
3356
3317
|
}
|
|
3357
3318
|
}
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3319
|
+
if (!middlewaresCanceled && prepared.middlewares.length) {
|
|
3320
|
+
await provideContext(env, async () => {
|
|
3321
|
+
for (const middleware of prepared.middlewares) {
|
|
3322
|
+
await middleware.data.afterExecute(ctx);
|
|
3323
|
+
}
|
|
3324
|
+
});
|
|
3364
3325
|
}
|
|
3365
3326
|
}
|
|
3366
3327
|
getExecutionMode(source) {
|
|
3367
|
-
if (source instanceof
|
|
3328
|
+
if (source instanceof import_discord9.Message) return CommandExecutionMode.Message;
|
|
3368
3329
|
if (source.isChatInputCommand()) return CommandExecutionMode.SlashCommand;
|
|
3369
3330
|
if (source.isAutocomplete()) {
|
|
3370
3331
|
return CommandExecutionMode.Autocomplete;
|
|
@@ -3462,12 +3423,12 @@ var init_types_package = __esm({
|
|
|
3462
3423
|
});
|
|
3463
3424
|
|
|
3464
3425
|
// src/app/handlers/AppCommandHandler.ts
|
|
3465
|
-
var
|
|
3426
|
+
var import_discord10, commandDataSchema, middlewareDataSchema, _AppCommandHandler, AppCommandHandler;
|
|
3466
3427
|
var init_AppCommandHandler = __esm({
|
|
3467
3428
|
"src/app/handlers/AppCommandHandler.ts"() {
|
|
3468
3429
|
"use strict";
|
|
3469
3430
|
init_cjs_shims();
|
|
3470
|
-
|
|
3431
|
+
import_discord10 = require("discord.js");
|
|
3471
3432
|
init_resolve_file_url();
|
|
3472
3433
|
init_MessageCommandParser();
|
|
3473
3434
|
init_error_codes();
|
|
@@ -3477,7 +3438,7 @@ var init_AppCommandHandler = __esm({
|
|
|
3477
3438
|
init_constants();
|
|
3478
3439
|
init_types_package();
|
|
3479
3440
|
commandDataSchema = {
|
|
3480
|
-
command: /* @__PURE__ */ __name((c) => c instanceof
|
|
3441
|
+
command: /* @__PURE__ */ __name((c) => c instanceof import_discord10.SlashCommandBuilder || c instanceof import_discord10.ContextMenuCommandBuilder || c && typeof c === "object", "command"),
|
|
3481
3442
|
chatInput: /* @__PURE__ */ __name((c) => typeof c === "function", "chatInput"),
|
|
3482
3443
|
autocomplete: /* @__PURE__ */ __name((c) => typeof c === "function", "autocomplete"),
|
|
3483
3444
|
message: /* @__PURE__ */ __name((c) => typeof c === "function", "message"),
|
|
@@ -3493,8 +3454,8 @@ var init_AppCommandHandler = __esm({
|
|
|
3493
3454
|
this.commandkit = commandkit2;
|
|
3494
3455
|
this.registrar = new CommandRegistrar(this.commandkit);
|
|
3495
3456
|
}
|
|
3496
|
-
loadedCommands = new
|
|
3497
|
-
loadedMiddlewares = new
|
|
3457
|
+
loadedCommands = new import_discord10.Collection();
|
|
3458
|
+
loadedMiddlewares = new import_discord10.Collection();
|
|
3498
3459
|
// Name-to-ID mapping for easier lookup
|
|
3499
3460
|
commandNameToId = /* @__PURE__ */ new Map();
|
|
3500
3461
|
subcommandPathToId = /* @__PURE__ */ new Map();
|
|
@@ -3549,59 +3510,60 @@ var init_AppCommandHandler = __esm({
|
|
|
3549
3510
|
if (!prepared) return;
|
|
3550
3511
|
return this.commandRunner.runCommand(prepared, newMessage);
|
|
3551
3512
|
};
|
|
3552
|
-
this.commandkit.client.on(
|
|
3553
|
-
this.commandkit.client.on(
|
|
3554
|
-
this.commandkit.client.on(
|
|
3513
|
+
this.commandkit.client.on(import_discord10.Events.InteractionCreate, this.onInteraction);
|
|
3514
|
+
this.commandkit.client.on(import_discord10.Events.MessageCreate, this.onMessageCreate);
|
|
3515
|
+
this.commandkit.client.on(import_discord10.Events.MessageUpdate, this.onMessageUpdate);
|
|
3555
3516
|
}
|
|
3556
|
-
async prepareCommandRun(source) {
|
|
3517
|
+
async prepareCommandRun(source, cmdName) {
|
|
3557
3518
|
var _a;
|
|
3558
|
-
let cmdName;
|
|
3559
3519
|
let parser2;
|
|
3560
|
-
if (
|
|
3561
|
-
if (source.
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3520
|
+
if (!cmdName) {
|
|
3521
|
+
if (source instanceof import_discord10.Message) {
|
|
3522
|
+
if (source.author.bot) return null;
|
|
3523
|
+
const prefix = await this.commandkit.config.getMessageCommandPrefix(source);
|
|
3524
|
+
parser2 = new MessageCommandParser(
|
|
3525
|
+
source,
|
|
3526
|
+
Array.isArray(prefix) ? prefix : [prefix],
|
|
3527
|
+
(command) => {
|
|
3528
|
+
var _a2, _b;
|
|
3529
|
+
const commandId2 = this.commandNameToId.get(command);
|
|
3530
|
+
if (!commandId2) return null;
|
|
3531
|
+
const loadedCommand2 = this.loadedCommands.get(commandId2);
|
|
3532
|
+
if (!loadedCommand2) return null;
|
|
3533
|
+
if (source.guildId && ((_a2 = loadedCommand2.guilds) == null ? void 0 : _a2.length) && !loadedCommand2.guilds.includes(source.guildId)) {
|
|
3534
|
+
return null;
|
|
3535
|
+
}
|
|
3536
|
+
const json = "toJSON" in loadedCommand2.data.command ? loadedCommand2.data.command.toJSON() : loadedCommand2.data.command;
|
|
3537
|
+
return ((_b = json.options) == null ? void 0 : _b.reduce(
|
|
3538
|
+
(acc, opt) => {
|
|
3539
|
+
acc[opt.name] = opt.type;
|
|
3540
|
+
return acc;
|
|
3541
|
+
},
|
|
3542
|
+
{}
|
|
3543
|
+
)) ?? {};
|
|
3544
|
+
}
|
|
3545
|
+
);
|
|
3546
|
+
try {
|
|
3547
|
+
const fullCommand = parser2.getFullCommand();
|
|
3548
|
+
const parts = fullCommand.split(" ");
|
|
3549
|
+
cmdName = parts[0];
|
|
3550
|
+
} catch (e) {
|
|
3551
|
+
if (isErrorType(e, CommandKitErrorCodes.InvalidCommandPrefix)) {
|
|
3573
3552
|
return null;
|
|
3574
3553
|
}
|
|
3575
|
-
|
|
3576
|
-
return ((_b = json.options) == null ? void 0 : _b.reduce(
|
|
3577
|
-
(acc, opt) => {
|
|
3578
|
-
acc[opt.name] = opt.type;
|
|
3579
|
-
return acc;
|
|
3580
|
-
},
|
|
3581
|
-
{}
|
|
3582
|
-
)) ?? {};
|
|
3583
|
-
}
|
|
3584
|
-
);
|
|
3585
|
-
try {
|
|
3586
|
-
const fullCommand = parser2.getFullCommand();
|
|
3587
|
-
const parts = fullCommand.split(" ");
|
|
3588
|
-
cmdName = parts[0];
|
|
3589
|
-
} catch (e) {
|
|
3590
|
-
if (isErrorType(e, CommandKitErrorCodes.InvalidCommandPrefix)) {
|
|
3554
|
+
Logger.error(e);
|
|
3591
3555
|
return null;
|
|
3592
3556
|
}
|
|
3593
|
-
|
|
3594
|
-
return null;
|
|
3557
|
+
} else {
|
|
3558
|
+
if (!source.isCommand()) return null;
|
|
3559
|
+
cmdName = source.commandName;
|
|
3595
3560
|
}
|
|
3596
|
-
} else {
|
|
3597
|
-
if (!source.isCommand()) return null;
|
|
3598
|
-
cmdName = source.commandName;
|
|
3599
3561
|
}
|
|
3600
3562
|
const commandId = this.commandNameToId.get(cmdName);
|
|
3601
3563
|
if (!commandId) return null;
|
|
3602
3564
|
const loadedCommand = this.loadedCommands.get(commandId);
|
|
3603
3565
|
if (!loadedCommand) return null;
|
|
3604
|
-
if (source instanceof
|
|
3566
|
+
if (source instanceof import_discord10.CommandInteraction && source.guildId && ((_a = loadedCommand.guilds) == null ? void 0 : _a.length) && !loadedCommand.guilds.includes(source.guildId)) {
|
|
3605
3567
|
return null;
|
|
3606
3568
|
}
|
|
3607
3569
|
const middlewares = [];
|
|
@@ -3720,7 +3682,7 @@ var init_AppCommandHandler = __esm({
|
|
|
3720
3682
|
async applyLocalizations(command) {
|
|
3721
3683
|
var _a, _b, _c, _d, _e;
|
|
3722
3684
|
const localization = this.commandkit.config.localizationStrategy;
|
|
3723
|
-
const validLocales = Object.values(
|
|
3685
|
+
const validLocales = Object.values(import_discord10.Locale).filter(
|
|
3724
3686
|
(v) => typeof v === "string"
|
|
3725
3687
|
);
|
|
3726
3688
|
const localizationKey = command.name;
|
|
@@ -3730,7 +3692,7 @@ var init_AppCommandHandler = __esm({
|
|
|
3730
3692
|
locale
|
|
3731
3693
|
);
|
|
3732
3694
|
if (!(translation == null ? void 0 : translation.command)) continue;
|
|
3733
|
-
if (command instanceof
|
|
3695
|
+
if (command instanceof import_discord10.SlashCommandBuilder) {
|
|
3734
3696
|
if (translation.command.name) {
|
|
3735
3697
|
command.setNameLocalization(locale, translation.command.name);
|
|
3736
3698
|
}
|
|
@@ -3776,7 +3738,7 @@ var init_AppCommandHandler = __esm({
|
|
|
3776
3738
|
});
|
|
3777
3739
|
}
|
|
3778
3740
|
}
|
|
3779
|
-
} else if (command instanceof
|
|
3741
|
+
} else if (command instanceof import_discord10.ContextMenuCommandBuilder) {
|
|
3780
3742
|
if (translation.command.name) {
|
|
3781
3743
|
command.setNameLocalization(locale, translation.command.name);
|
|
3782
3744
|
}
|
|
@@ -3831,11 +3793,12 @@ var init_AppCommandHandler = __esm({
|
|
|
3831
3793
|
});
|
|
3832
3794
|
|
|
3833
3795
|
// src/app/router/CommandsRouter.ts
|
|
3834
|
-
var import_node_fs4, import_promises4, import_node_path4, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
3796
|
+
var import_discord11, import_node_fs4, import_promises4, import_node_path4, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
3835
3797
|
var init_CommandsRouter = __esm({
|
|
3836
3798
|
"src/app/router/CommandsRouter.ts"() {
|
|
3837
3799
|
"use strict";
|
|
3838
3800
|
init_cjs_shims();
|
|
3801
|
+
import_discord11 = require("discord.js");
|
|
3839
3802
|
import_node_fs4 = require("fs");
|
|
3840
3803
|
import_promises4 = require("fs/promises");
|
|
3841
3804
|
import_node_path4 = require("path");
|
|
@@ -3846,8 +3809,8 @@ var init_CommandsRouter = __esm({
|
|
|
3846
3809
|
constructor(options) {
|
|
3847
3810
|
this.options = options;
|
|
3848
3811
|
}
|
|
3849
|
-
commands =
|
|
3850
|
-
middlewares =
|
|
3812
|
+
commands = new import_discord11.Collection();
|
|
3813
|
+
middlewares = new import_discord11.Collection();
|
|
3851
3814
|
populate(data) {
|
|
3852
3815
|
for (const [id, command] of Object.entries(data.commands)) {
|
|
3853
3816
|
this.commands.set(id, command);
|
|
@@ -3961,11 +3924,12 @@ var init_CommandsRouter = __esm({
|
|
|
3961
3924
|
});
|
|
3962
3925
|
|
|
3963
3926
|
// src/app/router/EventsRouter.ts
|
|
3964
|
-
var import_node_fs5, import_promises5, import_node_path5, _EventsRouter, EventsRouter;
|
|
3927
|
+
var import_discord12, import_node_fs5, import_promises5, import_node_path5, _EventsRouter, EventsRouter;
|
|
3965
3928
|
var init_EventsRouter = __esm({
|
|
3966
3929
|
"src/app/router/EventsRouter.ts"() {
|
|
3967
3930
|
"use strict";
|
|
3968
3931
|
init_cjs_shims();
|
|
3932
|
+
import_discord12 = require("discord.js");
|
|
3969
3933
|
import_node_fs5 = require("fs");
|
|
3970
3934
|
import_promises5 = require("fs/promises");
|
|
3971
3935
|
import_node_path5 = require("path");
|
|
@@ -3982,7 +3946,7 @@ var init_EventsRouter = __esm({
|
|
|
3982
3946
|
}
|
|
3983
3947
|
}
|
|
3984
3948
|
/** Internal storage of parsed events */
|
|
3985
|
-
events =
|
|
3949
|
+
events = new import_discord12.Collection();
|
|
3986
3950
|
/**
|
|
3987
3951
|
* Find a parsed event by its name
|
|
3988
3952
|
* @param event - Name of the event to find
|
|
@@ -4033,7 +3997,7 @@ var init_EventsRouter = __esm({
|
|
|
4033
3997
|
return Object.fromEntries(this.events);
|
|
4034
3998
|
}
|
|
4035
3999
|
/**
|
|
4036
|
-
* Convert the internal events
|
|
4000
|
+
* Convert the internal events Collection to a plain object
|
|
4037
4001
|
* @returns Events tree as a plain object
|
|
4038
4002
|
*/
|
|
4039
4003
|
toJSON() {
|
|
@@ -4425,7 +4389,7 @@ var init_CommandKitEventsChannel = __esm({
|
|
|
4425
4389
|
});
|
|
4426
4390
|
|
|
4427
4391
|
// src/CommandKit.ts
|
|
4428
|
-
var import_node_events2,
|
|
4392
|
+
var import_node_events2, import_discord13, import_node_path8, import_node_fs8, commandkit, _started, _CommandKit_instances, init_fn, initCommands_fn, initEvents_fn, _CommandKit, CommandKit;
|
|
4429
4393
|
var init_CommandKit = __esm({
|
|
4430
4394
|
"src/CommandKit.ts"() {
|
|
4431
4395
|
"use strict";
|
|
@@ -4436,7 +4400,7 @@ var init_CommandKit = __esm({
|
|
|
4436
4400
|
init_MemoryCache();
|
|
4437
4401
|
init_components();
|
|
4438
4402
|
init_EventInterceptor();
|
|
4439
|
-
|
|
4403
|
+
import_discord13 = require("discord.js");
|
|
4440
4404
|
init_DefaultLocalizationStrategy();
|
|
4441
4405
|
init_utilities();
|
|
4442
4406
|
import_node_path8 = require("path");
|
|
@@ -4473,18 +4437,13 @@ var init_CommandKit = __esm({
|
|
|
4473
4437
|
colors_default.red('"client" is required when instantiating CommandKit.')
|
|
4474
4438
|
);
|
|
4475
4439
|
}
|
|
4476
|
-
if (options.validationsPath && !options.commandsPath) {
|
|
4477
|
-
throw new Error(
|
|
4478
|
-
colors_default.red('"commandsPath" is required when "validationsPath" is set.')
|
|
4479
|
-
);
|
|
4480
|
-
}
|
|
4481
4440
|
super();
|
|
4482
4441
|
this.options = options;
|
|
4483
4442
|
__privateAdd(this, _CommandKit_instances);
|
|
4484
4443
|
__privateAdd(this, _started, false);
|
|
4485
4444
|
__publicField(this, "eventInterceptor");
|
|
4486
4445
|
__publicField(this, "config", {
|
|
4487
|
-
defaultLocale:
|
|
4446
|
+
defaultLocale: import_discord13.Locale.EnglishUS,
|
|
4488
4447
|
localizationStrategy: new DefaultLocalizationStrategy(this),
|
|
4489
4448
|
getMessageCommandPrefix: /* @__PURE__ */ __name(() => "!", "getMessageCommandPrefix")
|
|
4490
4449
|
});
|
|
@@ -4494,7 +4453,6 @@ var init_CommandKit = __esm({
|
|
|
4494
4453
|
__publicField(this, "eventHandler", new AppEventsHandler(this));
|
|
4495
4454
|
__publicField(this, "plugins");
|
|
4496
4455
|
__publicField(this, "events", new CommandKitEventsChannel(this));
|
|
4497
|
-
options.debugCommands ??= process.env.NODE_ENV !== "production";
|
|
4498
4456
|
if (options.cacheProvider !== null && (!options.cacheProvider || !(options.cacheProvider instanceof CacheProvider))) {
|
|
4499
4457
|
options.cacheProvider = new MemoryCache();
|
|
4500
4458
|
}
|
|
@@ -4526,12 +4484,20 @@ var init_CommandKit = __esm({
|
|
|
4526
4484
|
this.commandHandler.registerCommandHandler();
|
|
4527
4485
|
this.incrementClientListenersCount();
|
|
4528
4486
|
if (token !== false && !this.options.client.isReady()) {
|
|
4529
|
-
this.client.once(
|
|
4487
|
+
this.client.once(import_discord13.Events.ClientReady, async () => {
|
|
4530
4488
|
await this.commandHandler.registrar.register();
|
|
4531
4489
|
});
|
|
4490
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
4491
|
+
var _a;
|
|
4492
|
+
return (_a = plugin.onBeforeClientLogin) == null ? void 0 : _a.call(plugin, ctx);
|
|
4493
|
+
});
|
|
4532
4494
|
await this.options.client.login(
|
|
4533
4495
|
token ?? process.env.TOKEN ?? process.env.DISCORD_TOKEN
|
|
4534
4496
|
);
|
|
4497
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
4498
|
+
var _a;
|
|
4499
|
+
return (_a = plugin.onAfterClientLogin) == null ? void 0 : _a.call(plugin, ctx);
|
|
4500
|
+
});
|
|
4535
4501
|
} else if (this.options.client.isReady()) {
|
|
4536
4502
|
await this.commandHandler.registrar.register();
|
|
4537
4503
|
}
|
|
@@ -4585,12 +4551,6 @@ var init_CommandKit = __esm({
|
|
|
4585
4551
|
const provider = this.options.cacheProvider;
|
|
4586
4552
|
return provider ?? null;
|
|
4587
4553
|
}
|
|
4588
|
-
/**
|
|
4589
|
-
* Whether or not to debug the command handler.
|
|
4590
|
-
*/
|
|
4591
|
-
isDebuggingCommands() {
|
|
4592
|
-
return this.options.debugCommands || false;
|
|
4593
|
-
}
|
|
4594
4554
|
/**
|
|
4595
4555
|
* Get the client attached to this CommandKit instance.
|
|
4596
4556
|
*/
|
|
@@ -4609,42 +4569,6 @@ var init_CommandKit = __esm({
|
|
|
4609
4569
|
async reloadEvents() {
|
|
4610
4570
|
await this.eventHandler.reloadEvents();
|
|
4611
4571
|
}
|
|
4612
|
-
/**
|
|
4613
|
-
* @returns The path to the commands folder which was set when instantiating CommandKit.
|
|
4614
|
-
*/
|
|
4615
|
-
get commandsPath() {
|
|
4616
|
-
return this.options.commandsPath;
|
|
4617
|
-
}
|
|
4618
|
-
/**
|
|
4619
|
-
* @returns The path to the events folder which was set when instantiating CommandKit.
|
|
4620
|
-
*/
|
|
4621
|
-
get eventsPath() {
|
|
4622
|
-
return this.options.eventsPath;
|
|
4623
|
-
}
|
|
4624
|
-
/**
|
|
4625
|
-
* @returns The path to the validations folder which was set when instantiating CommandKit.
|
|
4626
|
-
*/
|
|
4627
|
-
get validationsPath() {
|
|
4628
|
-
return this.options.validationsPath;
|
|
4629
|
-
}
|
|
4630
|
-
/**
|
|
4631
|
-
* @returns An array of all the developer user IDs which was set when instantiating CommandKit.
|
|
4632
|
-
*/
|
|
4633
|
-
get devUserIds() {
|
|
4634
|
-
return this.options.devUserIds || [];
|
|
4635
|
-
}
|
|
4636
|
-
/**
|
|
4637
|
-
* @returns An array of all the developer guild IDs which was set when instantiating CommandKit.
|
|
4638
|
-
*/
|
|
4639
|
-
get devGuildIds() {
|
|
4640
|
-
return this.options.devGuildIds || [];
|
|
4641
|
-
}
|
|
4642
|
-
/**
|
|
4643
|
-
* @returns An array of all the developer role IDs which was set when instantiating CommandKit.
|
|
4644
|
-
*/
|
|
4645
|
-
get devRoleIds() {
|
|
4646
|
-
return this.options.devRoleIds || [];
|
|
4647
|
-
}
|
|
4648
4572
|
/**
|
|
4649
4573
|
* Increment the client listeners count.
|
|
4650
4574
|
*/
|
|
@@ -4702,6 +4626,9 @@ var init_CommandKit = __esm({
|
|
|
4702
4626
|
await __privateMethod(this, _CommandKit_instances, initCommands_fn).call(this);
|
|
4703
4627
|
}, "#init");
|
|
4704
4628
|
initCommands_fn = /* @__PURE__ */ __name(async function() {
|
|
4629
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
4630
|
+
return plugin.onBeforeCommandsLoad(ctx);
|
|
4631
|
+
});
|
|
4705
4632
|
if (this.commandsRouter.isValidPath()) {
|
|
4706
4633
|
const result = await this.commandsRouter.scan();
|
|
4707
4634
|
if (COMMANDKIT_IS_DEV) {
|
|
@@ -4712,12 +4639,21 @@ var init_CommandKit = __esm({
|
|
|
4712
4639
|
}
|
|
4713
4640
|
}
|
|
4714
4641
|
await this.commandHandler.loadCommands();
|
|
4642
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
4643
|
+
return plugin.onAfterCommandsLoad(ctx);
|
|
4644
|
+
});
|
|
4715
4645
|
}, "#initCommands");
|
|
4716
4646
|
initEvents_fn = /* @__PURE__ */ __name(async function() {
|
|
4647
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
4648
|
+
return plugin.onBeforeEventsLoad(ctx);
|
|
4649
|
+
});
|
|
4717
4650
|
if (this.eventsRouter.isValidPath()) {
|
|
4718
4651
|
await this.eventsRouter.scan();
|
|
4719
4652
|
}
|
|
4720
4653
|
await this.eventHandler.loadEvents();
|
|
4654
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
4655
|
+
return plugin.onAfterEventsLoad(ctx);
|
|
4656
|
+
});
|
|
4721
4657
|
}, "#initEvents");
|
|
4722
4658
|
__name(_CommandKit, "CommandKit");
|
|
4723
4659
|
__publicField(_CommandKit, "createElement", createElement);
|
|
@@ -4738,7 +4674,7 @@ var init_version = __esm({
|
|
|
4738
4674
|
"use strict";
|
|
4739
4675
|
init_cjs_shims();
|
|
4740
4676
|
version = /* @__MACRO__ $version */
|
|
4741
|
-
"0.1.11-dev.
|
|
4677
|
+
"0.1.11-dev.20250330063035";
|
|
4742
4678
|
}
|
|
4743
4679
|
});
|
|
4744
4680
|
|
|
@@ -5217,7 +5153,7 @@ export default async function on${name[0].toUpperCase() + name.slice(1)}() {
|
|
|
5217
5153
|
}
|
|
5218
5154
|
async function generateLocale(locale, commandName, customPath) {
|
|
5219
5155
|
const localeNames = Object.fromEntries(
|
|
5220
|
-
Object.entries(
|
|
5156
|
+
Object.entries(import_discord15.Locale).map(([k, v]) => [v, k])
|
|
5221
5157
|
);
|
|
5222
5158
|
if (!localeNames[locale]) {
|
|
5223
5159
|
panic(`Invalid locale: ${locale}`);
|
|
@@ -5249,14 +5185,14 @@ async function generateLocale(locale, commandName, customPath) {
|
|
|
5249
5185
|
)
|
|
5250
5186
|
);
|
|
5251
5187
|
}
|
|
5252
|
-
var import_promises7, import_path4,
|
|
5188
|
+
var import_promises7, import_path4, import_discord15, import_fs2, BASE_PATH, COMMANDS_DIR, EVENTS_DIR, LOCALES_DIR, formatPath;
|
|
5253
5189
|
var init_generators = __esm({
|
|
5254
5190
|
"src/cli/generators.ts"() {
|
|
5255
5191
|
"use strict";
|
|
5256
5192
|
init_cjs_shims();
|
|
5257
5193
|
import_promises7 = require("fs/promises");
|
|
5258
5194
|
import_path4 = require("path");
|
|
5259
|
-
|
|
5195
|
+
import_discord15 = require("discord.js");
|
|
5260
5196
|
init_common();
|
|
5261
5197
|
import_fs2 = require("fs");
|
|
5262
5198
|
init_colors();
|
|
@@ -5317,7 +5253,6 @@ __export(index_exports, {
|
|
|
5317
5253
|
createLogger: () => createLogger,
|
|
5318
5254
|
default: () => index_default,
|
|
5319
5255
|
defineConfig: () => defineConfig,
|
|
5320
|
-
dmOnly: () => dmOnly,
|
|
5321
5256
|
exitContext: () => exitContext,
|
|
5322
5257
|
exitMiddleware: () => exitMiddleware,
|
|
5323
5258
|
fromEsbuildPlugin: () => fromEsbuildPlugin,
|
|
@@ -5325,13 +5260,15 @@ __export(index_exports, {
|
|
|
5325
5260
|
getConfig: () => getConfig,
|
|
5326
5261
|
getContext: () => getContext,
|
|
5327
5262
|
getElement: () => getElement,
|
|
5328
|
-
guildOnly: () => guildOnly,
|
|
5329
5263
|
invalidate: () => invalidate,
|
|
5330
5264
|
isCachedFunction: () => isCachedFunction,
|
|
5331
5265
|
isCommandKitElement: () => isCommandKitElement,
|
|
5332
5266
|
isCompilerPlugin: () => isCompilerPlugin,
|
|
5267
|
+
isInteractionSource: () => isInteractionSource,
|
|
5268
|
+
isMessageSource: () => isMessageSource,
|
|
5333
5269
|
isRuntimePlugin: () => isRuntimePlugin,
|
|
5334
5270
|
makeContextAwareFunction: () => makeContextAwareFunction,
|
|
5271
|
+
provideContext: () => provideContext,
|
|
5335
5272
|
redirect: () => redirect,
|
|
5336
5273
|
rethrow: () => rethrow,
|
|
5337
5274
|
revalidate: () => revalidate,
|
|
@@ -5366,6 +5303,18 @@ init_cjs_shims();
|
|
|
5366
5303
|
// src/app/index.ts
|
|
5367
5304
|
init_signals();
|
|
5368
5305
|
|
|
5306
|
+
// src/app/commands/helpers.ts
|
|
5307
|
+
init_cjs_shims();
|
|
5308
|
+
var import_discord14 = require("discord.js");
|
|
5309
|
+
function isMessageSource(source) {
|
|
5310
|
+
return source instanceof import_discord14.Message;
|
|
5311
|
+
}
|
|
5312
|
+
__name(isMessageSource, "isMessageSource");
|
|
5313
|
+
function isInteractionSource(source) {
|
|
5314
|
+
return !isMessageSource(source);
|
|
5315
|
+
}
|
|
5316
|
+
__name(isInteractionSource, "isInteractionSource");
|
|
5317
|
+
|
|
5369
5318
|
// src/index.ts
|
|
5370
5319
|
init_DefaultLogger();
|
|
5371
5320
|
|
|
@@ -5484,7 +5433,6 @@ var index_default = CommandKit;
|
|
|
5484
5433
|
createElement,
|
|
5485
5434
|
createLogger,
|
|
5486
5435
|
defineConfig,
|
|
5487
|
-
dmOnly,
|
|
5488
5436
|
exitContext,
|
|
5489
5437
|
exitMiddleware,
|
|
5490
5438
|
fromEsbuildPlugin,
|
|
@@ -5492,13 +5440,15 @@ var index_default = CommandKit;
|
|
|
5492
5440
|
getConfig,
|
|
5493
5441
|
getContext,
|
|
5494
5442
|
getElement,
|
|
5495
|
-
guildOnly,
|
|
5496
5443
|
invalidate,
|
|
5497
5444
|
isCachedFunction,
|
|
5498
5445
|
isCommandKitElement,
|
|
5499
5446
|
isCompilerPlugin,
|
|
5447
|
+
isInteractionSource,
|
|
5448
|
+
isMessageSource,
|
|
5500
5449
|
isRuntimePlugin,
|
|
5501
5450
|
makeContextAwareFunction,
|
|
5451
|
+
provideContext,
|
|
5502
5452
|
redirect,
|
|
5503
5453
|
rethrow,
|
|
5504
5454
|
revalidate,
|