commandkit 0.1.6-dev.20231124182258 → 0.1.6-dev.20231125121601
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/build.mjs +27 -22
- package/bin/parse-env.mjs +10 -1
- package/dist/index.d.mts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +19 -12
- package/dist/index.mjs +20 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ CommandKit is a library that makes it easy to handle commands and events in your
|
|
|
19
19
|
- Automatic command registration, edits, and deletion 🤖
|
|
20
20
|
- Supports multiple development servers 🤝
|
|
21
21
|
- Supports multiple users as bot developers 👥
|
|
22
|
-
-
|
|
22
|
+
- User friendly CLI 🖥️
|
|
23
23
|
|
|
24
24
|
## Documentation
|
|
25
25
|
|
package/bin/build.mjs
CHANGED
|
@@ -39,7 +39,7 @@ export async function bootstrapProductionBuild(config) {
|
|
|
39
39
|
entry: [src, '!dist', '!.commandkit', `!${outDir}`],
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
await injectShims(outDir, main, antiCrash);
|
|
43
43
|
|
|
44
44
|
status.succeed(
|
|
45
45
|
Colors.green(`Build completed in ${(performance.now() - start).toFixed(2)}ms!`),
|
|
@@ -55,27 +55,32 @@ export async function bootstrapProductionBuild(config) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function
|
|
58
|
+
async function injectShims(outDir, main, antiCrash) {
|
|
59
59
|
const path = join(process.cwd(), outDir, main);
|
|
60
|
-
const snippet = [
|
|
61
|
-
'\n\n// --- CommandKit Anti-Crash Monitor ---',
|
|
62
|
-
';(()=>{',
|
|
63
|
-
" 'use strict';",
|
|
64
|
-
" // 'uncaughtException' event is supposed to be used to perform synchronous cleanup before shutting down the process",
|
|
65
|
-
' // instead of using it as a means to resume operation.',
|
|
66
|
-
' // But it exists here due to compatibility reasons with discord bot ecosystem.',
|
|
67
|
-
" const p = (t) => `\\x1b[33m${t}\\x1b[0m`, b = '[CommandKit Anti-Crash Monitor]', l = console.log, e1 = 'uncaughtException', e2 = 'unhandledRejection';",
|
|
68
|
-
' if (!process.eventNames().includes(e1)) // skip if it is already handled',
|
|
69
|
-
' process.on(e1, (e, o) => {',
|
|
70
|
-
' l(p(`${b} Uncaught Exception`)); l(p(b), p(e.stack || e));',
|
|
71
|
-
' })',
|
|
72
|
-
' if (!process.eventNames().includes(e2)) // skip if it is already handled',
|
|
73
|
-
' process.on(e2, (r) => {',
|
|
74
|
-
' l(p(`${b} Unhandled promise rejection`)); l(p(`${b} ${r.stack || r}`));',
|
|
75
|
-
' });',
|
|
76
|
-
'})();',
|
|
77
|
-
'// --- CommandKit Anti-Crash Monitor ---\n',
|
|
78
|
-
].join('\n');
|
|
79
60
|
|
|
80
|
-
|
|
61
|
+
const antiCrashScript = antiCrash
|
|
62
|
+
? [
|
|
63
|
+
'\n\n// --- CommandKit Anti-Crash Monitor ---',
|
|
64
|
+
';(()=>{',
|
|
65
|
+
" 'use strict';",
|
|
66
|
+
" // 'uncaughtException' event is supposed to be used to perform synchronous cleanup before shutting down the process",
|
|
67
|
+
' // instead of using it as a means to resume operation.',
|
|
68
|
+
' // But it exists here due to compatibility reasons with discord bot ecosystem.',
|
|
69
|
+
" const p = (t) => `\\x1b[33m${t}\\x1b[0m`, b = '[CommandKit Anti-Crash Monitor]', l = console.log, e1 = 'uncaughtException', e2 = 'unhandledRejection';",
|
|
70
|
+
' if (!process.eventNames().includes(e1)) // skip if it is already handled',
|
|
71
|
+
' process.on(e1, (e) => {',
|
|
72
|
+
' l(p(`${b} Uncaught Exception`)); l(p(b), p(e.stack || e));',
|
|
73
|
+
' })',
|
|
74
|
+
' if (!process.eventNames().includes(e2)) // skip if it is already handled',
|
|
75
|
+
' process.on(e2, (r) => {',
|
|
76
|
+
' l(p(`${b} Unhandled promise rejection`)); l(p(`${b} ${r.stack || r}`));',
|
|
77
|
+
' });',
|
|
78
|
+
'})();',
|
|
79
|
+
'// --- CommandKit Anti-Crash Monitor ---\n',
|
|
80
|
+
].join('\n')
|
|
81
|
+
: '';
|
|
82
|
+
|
|
83
|
+
const finalScript = [antiCrashScript].join('\n');
|
|
84
|
+
|
|
85
|
+
return appendFile(path, finalScript);
|
|
81
86
|
}
|
package/bin/parse-env.mjs
CHANGED
|
@@ -15,6 +15,15 @@ const VALUE_PREFIXES = {
|
|
|
15
15
|
DATE: 'DATE::',
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
function catcher(fn) {
|
|
19
|
+
try {
|
|
20
|
+
fn();
|
|
21
|
+
return true;
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
export function parseEnv(src) {
|
|
19
28
|
for (const key in src) {
|
|
20
29
|
const value = src[key];
|
|
@@ -22,7 +31,7 @@ export function parseEnv(src) {
|
|
|
22
31
|
if (typeof value !== 'string') continue;
|
|
23
32
|
|
|
24
33
|
if (value.startsWith(VALUE_PREFIXES.JSON)) {
|
|
25
|
-
src[key] = JSON.parse(value.replace(VALUE_PREFIXES.JSON, ''));
|
|
34
|
+
catcher(() => (src[key] = JSON.parse(value.replace(VALUE_PREFIXES.JSON, ''))));
|
|
26
35
|
continue;
|
|
27
36
|
}
|
|
28
37
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
|
|
1
|
+
import { Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Options for instantiating a CommandKit handler.
|
|
@@ -53,7 +53,7 @@ interface CommandProps {
|
|
|
53
53
|
/**
|
|
54
54
|
* The current command interaction object.
|
|
55
55
|
*/
|
|
56
|
-
interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | UserContextMenuCommandInteraction | MessageContextMenuCommandInteraction;
|
|
56
|
+
interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | UserContextMenuCommandInteraction | MessageContextMenuCommandInteraction | AutocompleteInteraction;
|
|
57
57
|
/**
|
|
58
58
|
* The Discord.js client object that CommandKit is handling.
|
|
59
59
|
*/
|
|
@@ -63,6 +63,15 @@ interface CommandProps {
|
|
|
63
63
|
*/
|
|
64
64
|
handler: CommandKit;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Props for autocomplete command run functions.
|
|
68
|
+
*/
|
|
69
|
+
interface AutocompleteCommandProps extends CommandProps {
|
|
70
|
+
/**
|
|
71
|
+
* The current autocomplete command interaction object.
|
|
72
|
+
*/
|
|
73
|
+
interaction: AutocompleteInteraction;
|
|
74
|
+
}
|
|
66
75
|
/**
|
|
67
76
|
* Props for slash (chat input) command run functions.
|
|
68
77
|
*/
|
|
@@ -244,7 +253,11 @@ declare class CommandKit {
|
|
|
244
253
|
get devRoleIds(): string[];
|
|
245
254
|
}
|
|
246
255
|
|
|
247
|
-
|
|
256
|
+
/**
|
|
257
|
+
* The handler to run when a button is clicked. This handler is called with the interaction as the first argument.
|
|
258
|
+
* If the first argument is null, it means that the interaction collector has been destroyed.
|
|
259
|
+
*/
|
|
260
|
+
type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction | null) => Awaitable<void>;
|
|
248
261
|
type CommandKitButtonBuilderInteractionCollectorDispatchContextData = {
|
|
249
262
|
/**
|
|
250
263
|
* The message to listen for button interactions on.
|
|
@@ -358,4 +371,4 @@ declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T
|
|
|
358
371
|
*/
|
|
359
372
|
declare function createEffect(callback: CommandKitEffectCallback): void;
|
|
360
373
|
|
|
361
|
-
export { ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationFunctionProps, createEffect, createSignal, defineConfig, getConfig };
|
|
374
|
+
export { AutocompleteCommandProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationFunctionProps, createEffect, createSignal, defineConfig, getConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
|
|
1
|
+
import { Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Options for instantiating a CommandKit handler.
|
|
@@ -53,7 +53,7 @@ interface CommandProps {
|
|
|
53
53
|
/**
|
|
54
54
|
* The current command interaction object.
|
|
55
55
|
*/
|
|
56
|
-
interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | UserContextMenuCommandInteraction | MessageContextMenuCommandInteraction;
|
|
56
|
+
interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | UserContextMenuCommandInteraction | MessageContextMenuCommandInteraction | AutocompleteInteraction;
|
|
57
57
|
/**
|
|
58
58
|
* The Discord.js client object that CommandKit is handling.
|
|
59
59
|
*/
|
|
@@ -63,6 +63,15 @@ interface CommandProps {
|
|
|
63
63
|
*/
|
|
64
64
|
handler: CommandKit;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Props for autocomplete command run functions.
|
|
68
|
+
*/
|
|
69
|
+
interface AutocompleteCommandProps extends CommandProps {
|
|
70
|
+
/**
|
|
71
|
+
* The current autocomplete command interaction object.
|
|
72
|
+
*/
|
|
73
|
+
interaction: AutocompleteInteraction;
|
|
74
|
+
}
|
|
66
75
|
/**
|
|
67
76
|
* Props for slash (chat input) command run functions.
|
|
68
77
|
*/
|
|
@@ -244,7 +253,11 @@ declare class CommandKit {
|
|
|
244
253
|
get devRoleIds(): string[];
|
|
245
254
|
}
|
|
246
255
|
|
|
247
|
-
|
|
256
|
+
/**
|
|
257
|
+
* The handler to run when a button is clicked. This handler is called with the interaction as the first argument.
|
|
258
|
+
* If the first argument is null, it means that the interaction collector has been destroyed.
|
|
259
|
+
*/
|
|
260
|
+
type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction | null) => Awaitable<void>;
|
|
248
261
|
type CommandKitButtonBuilderInteractionCollectorDispatchContextData = {
|
|
249
262
|
/**
|
|
250
263
|
* The message to listen for button interactions on.
|
|
@@ -358,4 +371,4 @@ declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T
|
|
|
358
371
|
*/
|
|
359
372
|
declare function createEffect(callback: CommandKitEffectCallback): void;
|
|
360
373
|
|
|
361
|
-
export { ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationFunctionProps, createEffect, createSignal, defineConfig, getConfig };
|
|
374
|
+
export { AutocompleteCommandProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationFunctionProps, createEffect, createSignal, defineConfig, getConfig };
|
package/dist/index.js
CHANGED
|
@@ -366,6 +366,8 @@ async function registerDevCommands(client, commands, guildIds) {
|
|
|
366
366
|
|
|
367
367
|
// src/handlers/command-handler/validations/devOnly.ts
|
|
368
368
|
function devOnly_default({ interaction, targetCommand, handlerData }) {
|
|
369
|
+
if (interaction.isAutocomplete())
|
|
370
|
+
return;
|
|
369
371
|
if (targetCommand.options?.devOnly) {
|
|
370
372
|
if (interaction.inGuild() && !handlerData.devGuildIds.includes(interaction.guildId)) {
|
|
371
373
|
interaction.reply({
|
|
@@ -396,6 +398,8 @@ function devOnly_default({ interaction, targetCommand, handlerData }) {
|
|
|
396
398
|
// src/handlers/command-handler/validations/permissions.ts
|
|
397
399
|
var import_discord = require("discord.js");
|
|
398
400
|
function permissions_default({ interaction, targetCommand }) {
|
|
401
|
+
if (interaction.isAutocomplete())
|
|
402
|
+
return;
|
|
399
403
|
const userPermissions = interaction.memberPermissions;
|
|
400
404
|
let userPermissionsRequired = targetCommand.options?.userPermissions;
|
|
401
405
|
let missingUserPermissions = [];
|
|
@@ -460,9 +464,11 @@ function permissions_default({ interaction, targetCommand }) {
|
|
|
460
464
|
// src/handlers/command-handler/validations/index.ts
|
|
461
465
|
var validations_default = [devOnly_default, permissions_default];
|
|
462
466
|
|
|
463
|
-
// src/
|
|
467
|
+
// src/utils/clone.ts
|
|
464
468
|
var import_rfdc = __toESM(require("rfdc"));
|
|
465
469
|
var clone = (0, import_rfdc.default)();
|
|
470
|
+
|
|
471
|
+
// src/handlers/command-handler/CommandHandler.ts
|
|
466
472
|
var CommandHandler = class {
|
|
467
473
|
#data;
|
|
468
474
|
constructor({ ...options }) {
|
|
@@ -511,7 +517,7 @@ var CommandHandler = class {
|
|
|
511
517
|
const commandFilePaths = paths.filter((path3) => allowedExtensions.test(path3));
|
|
512
518
|
for (const commandFilePath of commandFilePaths) {
|
|
513
519
|
const modulePath = toFileURL(commandFilePath);
|
|
514
|
-
|
|
520
|
+
const importedObj = await import(`${modulePath}?t=${Date.now()}`);
|
|
515
521
|
let commandObj = clone(importedObj);
|
|
516
522
|
if (typeof module !== "undefined" && typeof require !== "undefined") {
|
|
517
523
|
delete require.cache[require.resolve(commandFilePath)];
|
|
@@ -573,14 +579,17 @@ var CommandHandler = class {
|
|
|
573
579
|
}
|
|
574
580
|
handleCommands() {
|
|
575
581
|
this.#data.client.on("interactionCreate", async (interaction) => {
|
|
576
|
-
if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
|
|
582
|
+
if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand() && !interaction.isAutocomplete())
|
|
577
583
|
return;
|
|
584
|
+
const isAutocomplete = interaction.isAutocomplete();
|
|
578
585
|
const targetCommand = this.#data.commands.find(
|
|
579
586
|
(cmd) => cmd.data.name === interaction.commandName
|
|
580
587
|
);
|
|
581
588
|
if (!targetCommand)
|
|
582
589
|
return;
|
|
583
|
-
const { data, options, run, ...rest } = targetCommand;
|
|
590
|
+
const { data, options, run, autocompleteRun, ...rest } = targetCommand;
|
|
591
|
+
if (isAutocomplete && !autocompleteRun)
|
|
592
|
+
return;
|
|
584
593
|
const commandObj = {
|
|
585
594
|
data: targetCommand.data,
|
|
586
595
|
options: targetCommand.options,
|
|
@@ -619,11 +628,12 @@ var CommandHandler = class {
|
|
|
619
628
|
}
|
|
620
629
|
if (!canRun)
|
|
621
630
|
return;
|
|
622
|
-
|
|
631
|
+
const context2 = {
|
|
623
632
|
interaction,
|
|
624
633
|
client: this.#data.client,
|
|
625
634
|
handler: this.#data.commandkitInstance
|
|
626
|
-
}
|
|
635
|
+
};
|
|
636
|
+
await targetCommand[isAutocomplete ? "autocompleteRun" : "run"](context2);
|
|
627
637
|
});
|
|
628
638
|
}
|
|
629
639
|
get commands() {
|
|
@@ -655,8 +665,6 @@ var CommandHandler = class {
|
|
|
655
665
|
};
|
|
656
666
|
|
|
657
667
|
// src/handlers/event-handler/EventHandler.ts
|
|
658
|
-
var import_rfdc2 = __toESM(require("rfdc"));
|
|
659
|
-
var clone2 = (0, import_rfdc2.default)();
|
|
660
668
|
var EventHandler = class {
|
|
661
669
|
#data;
|
|
662
670
|
constructor({ ...options }) {
|
|
@@ -684,7 +692,7 @@ var EventHandler = class {
|
|
|
684
692
|
for (const eventFilePath of eventFilePaths) {
|
|
685
693
|
const modulePath = toFileURL(eventFilePath);
|
|
686
694
|
let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
|
|
687
|
-
let eventFunction =
|
|
695
|
+
let eventFunction = clone(importedFunction);
|
|
688
696
|
if (typeof module !== "undefined" && typeof require !== "undefined") {
|
|
689
697
|
delete require.cache[require.resolve(eventFilePath)];
|
|
690
698
|
}
|
|
@@ -731,8 +739,6 @@ var EventHandler = class {
|
|
|
731
739
|
};
|
|
732
740
|
|
|
733
741
|
// src/handlers/validation-handler/ValidationHandler.ts
|
|
734
|
-
var import_rfdc3 = __toESM(require("rfdc"));
|
|
735
|
-
var clone3 = (0, import_rfdc3.default)();
|
|
736
742
|
var ValidationHandler = class {
|
|
737
743
|
#data;
|
|
738
744
|
constructor({ ...options }) {
|
|
@@ -751,7 +757,7 @@ var ValidationHandler = class {
|
|
|
751
757
|
for (const validationFilePath of validationFilePaths) {
|
|
752
758
|
const modulePath = toFileURL(validationFilePath);
|
|
753
759
|
let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
|
|
754
|
-
let validationFunction =
|
|
760
|
+
let validationFunction = clone(importedFunction);
|
|
755
761
|
if (typeof module !== "undefined" && typeof require !== "undefined") {
|
|
756
762
|
delete require.cache[require.resolve(validationFilePath)];
|
|
757
763
|
}
|
|
@@ -967,6 +973,7 @@ var ButtonKit = class extends import_discord2.ButtonBuilder {
|
|
|
967
973
|
});
|
|
968
974
|
}
|
|
969
975
|
#destroyCollector() {
|
|
976
|
+
this.#onClickHandler?.(null);
|
|
970
977
|
this.#collector?.stop("end");
|
|
971
978
|
this.#collector?.removeAllListeners();
|
|
972
979
|
this.#collector = null;
|
package/dist/index.mjs
CHANGED
|
@@ -333,6 +333,8 @@ async function registerDevCommands(client, commands, guildIds) {
|
|
|
333
333
|
|
|
334
334
|
// src/handlers/command-handler/validations/devOnly.ts
|
|
335
335
|
function devOnly_default({ interaction, targetCommand, handlerData }) {
|
|
336
|
+
if (interaction.isAutocomplete())
|
|
337
|
+
return;
|
|
336
338
|
if (targetCommand.options?.devOnly) {
|
|
337
339
|
if (interaction.inGuild() && !handlerData.devGuildIds.includes(interaction.guildId)) {
|
|
338
340
|
interaction.reply({
|
|
@@ -363,6 +365,8 @@ function devOnly_default({ interaction, targetCommand, handlerData }) {
|
|
|
363
365
|
// src/handlers/command-handler/validations/permissions.ts
|
|
364
366
|
import { EmbedBuilder } from "discord.js";
|
|
365
367
|
function permissions_default({ interaction, targetCommand }) {
|
|
368
|
+
if (interaction.isAutocomplete())
|
|
369
|
+
return;
|
|
366
370
|
const userPermissions = interaction.memberPermissions;
|
|
367
371
|
let userPermissionsRequired = targetCommand.options?.userPermissions;
|
|
368
372
|
let missingUserPermissions = [];
|
|
@@ -427,9 +431,11 @@ function permissions_default({ interaction, targetCommand }) {
|
|
|
427
431
|
// src/handlers/command-handler/validations/index.ts
|
|
428
432
|
var validations_default = [devOnly_default, permissions_default];
|
|
429
433
|
|
|
434
|
+
// src/utils/clone.ts
|
|
435
|
+
import rfdc from "rfdc";
|
|
436
|
+
var clone = rfdc();
|
|
437
|
+
|
|
430
438
|
// src/handlers/command-handler/CommandHandler.ts
|
|
431
|
-
import rdfc from "rfdc";
|
|
432
|
-
var clone = rdfc();
|
|
433
439
|
var CommandHandler = class {
|
|
434
440
|
#data;
|
|
435
441
|
constructor({ ...options }) {
|
|
@@ -478,7 +484,7 @@ var CommandHandler = class {
|
|
|
478
484
|
const commandFilePaths = paths.filter((path3) => allowedExtensions.test(path3));
|
|
479
485
|
for (const commandFilePath of commandFilePaths) {
|
|
480
486
|
const modulePath = toFileURL(commandFilePath);
|
|
481
|
-
|
|
487
|
+
const importedObj = await import(`${modulePath}?t=${Date.now()}`);
|
|
482
488
|
let commandObj = clone(importedObj);
|
|
483
489
|
if (typeof module !== "undefined" && typeof __require !== "undefined") {
|
|
484
490
|
delete __require.cache[__require.resolve(commandFilePath)];
|
|
@@ -540,14 +546,17 @@ var CommandHandler = class {
|
|
|
540
546
|
}
|
|
541
547
|
handleCommands() {
|
|
542
548
|
this.#data.client.on("interactionCreate", async (interaction) => {
|
|
543
|
-
if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
|
|
549
|
+
if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand() && !interaction.isAutocomplete())
|
|
544
550
|
return;
|
|
551
|
+
const isAutocomplete = interaction.isAutocomplete();
|
|
545
552
|
const targetCommand = this.#data.commands.find(
|
|
546
553
|
(cmd) => cmd.data.name === interaction.commandName
|
|
547
554
|
);
|
|
548
555
|
if (!targetCommand)
|
|
549
556
|
return;
|
|
550
|
-
const { data, options, run, ...rest } = targetCommand;
|
|
557
|
+
const { data, options, run, autocompleteRun, ...rest } = targetCommand;
|
|
558
|
+
if (isAutocomplete && !autocompleteRun)
|
|
559
|
+
return;
|
|
551
560
|
const commandObj = {
|
|
552
561
|
data: targetCommand.data,
|
|
553
562
|
options: targetCommand.options,
|
|
@@ -586,11 +595,12 @@ var CommandHandler = class {
|
|
|
586
595
|
}
|
|
587
596
|
if (!canRun)
|
|
588
597
|
return;
|
|
589
|
-
|
|
598
|
+
const context2 = {
|
|
590
599
|
interaction,
|
|
591
600
|
client: this.#data.client,
|
|
592
601
|
handler: this.#data.commandkitInstance
|
|
593
|
-
}
|
|
602
|
+
};
|
|
603
|
+
await targetCommand[isAutocomplete ? "autocompleteRun" : "run"](context2);
|
|
594
604
|
});
|
|
595
605
|
}
|
|
596
606
|
get commands() {
|
|
@@ -622,8 +632,6 @@ var CommandHandler = class {
|
|
|
622
632
|
};
|
|
623
633
|
|
|
624
634
|
// src/handlers/event-handler/EventHandler.ts
|
|
625
|
-
import rdfc2 from "rfdc";
|
|
626
|
-
var clone2 = rdfc2();
|
|
627
635
|
var EventHandler = class {
|
|
628
636
|
#data;
|
|
629
637
|
constructor({ ...options }) {
|
|
@@ -651,7 +659,7 @@ var EventHandler = class {
|
|
|
651
659
|
for (const eventFilePath of eventFilePaths) {
|
|
652
660
|
const modulePath = toFileURL(eventFilePath);
|
|
653
661
|
let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
|
|
654
|
-
let eventFunction =
|
|
662
|
+
let eventFunction = clone(importedFunction);
|
|
655
663
|
if (typeof module !== "undefined" && typeof __require !== "undefined") {
|
|
656
664
|
delete __require.cache[__require.resolve(eventFilePath)];
|
|
657
665
|
}
|
|
@@ -698,8 +706,6 @@ var EventHandler = class {
|
|
|
698
706
|
};
|
|
699
707
|
|
|
700
708
|
// src/handlers/validation-handler/ValidationHandler.ts
|
|
701
|
-
import rdfc3 from "rfdc";
|
|
702
|
-
var clone3 = rdfc3();
|
|
703
709
|
var ValidationHandler = class {
|
|
704
710
|
#data;
|
|
705
711
|
constructor({ ...options }) {
|
|
@@ -718,7 +724,7 @@ var ValidationHandler = class {
|
|
|
718
724
|
for (const validationFilePath of validationFilePaths) {
|
|
719
725
|
const modulePath = toFileURL(validationFilePath);
|
|
720
726
|
let importedFunction = (await import(`${modulePath}?t=${Date.now()}`)).default;
|
|
721
|
-
let validationFunction =
|
|
727
|
+
let validationFunction = clone(importedFunction);
|
|
722
728
|
if (typeof module !== "undefined" && typeof __require !== "undefined") {
|
|
723
729
|
delete __require.cache[__require.resolve(validationFilePath)];
|
|
724
730
|
}
|
|
@@ -938,6 +944,7 @@ var ButtonKit = class extends ButtonBuilder {
|
|
|
938
944
|
});
|
|
939
945
|
}
|
|
940
946
|
#destroyCollector() {
|
|
947
|
+
this.#onClickHandler?.(null);
|
|
941
948
|
this.#collector?.stop("end");
|
|
942
949
|
this.#collector?.removeAllListeners();
|
|
943
950
|
this.#collector = null;
|
package/package.json
CHANGED