commandkit 1.2.1 → 1.2.2
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/cache.cjs +2 -0
- package/cache.d.ts +1 -0
- package/dist/{ActionRow-Bt9qi0Mb.d.ts → ActionRow-DSh9roc5.d.ts} +2 -3
- package/dist/{Button-DxJLcZIU.d.ts → Button-BPsE5ju0.d.ts} +5 -6
- package/dist/{ButtonKit-BfcyvWfj.d.ts → ButtonKit-CNPmVg3h.d.ts} +2 -3
- package/dist/{ChannelSelectMenuKit-DYkudikb.d.ts → ChannelSelectMenuKit-CcOdaLQ6.d.ts} +3 -4
- package/dist/CommandTree-qu-8oAEV.d.ts +55 -0
- package/dist/CommandsRouter-Co225Ae5.d.ts +242 -0
- package/dist/{EventInterceptor-D9JKMcfi.d.ts → EventInterceptor-wg378vJp.d.ts} +1 -2
- package/dist/{EventsRouter-EuuSu6NH.d.ts → EventsRouter-Bt63ZuEF.d.ts} +21 -2
- package/dist/{MentionableSelectMenuKit-Mu4xqP6B.d.ts → MentionableSelectMenuKit-8_Nkgn_a.d.ts} +3 -4
- package/dist/{MessageCommandParser-DPCbHXCS.d.ts → MessageCommandParser-BYbxHOSK.d.ts} +7 -2
- package/dist/{Modal-v9rrcMl-.d.ts → Modal-DbWK6VmV.d.ts} +5 -6
- package/dist/{ModalKit-XJSM65SV.d.ts → ModalKit-CnmUVpw-.d.ts} +2 -3
- package/dist/{RoleSelectMenuKit-CCjcp3HY.d.ts → RoleSelectMenuKit-Bei7DHqD.d.ts} +3 -4
- package/dist/{SelectMenu-CY0vvoSu.d.ts → SelectMenu-Bce_PClo.d.ts} +8 -9
- package/dist/{StringSelectMenuKit-G5nBTicX.d.ts → StringSelectMenuKit-CBeB9HqT.d.ts} +3 -4
- package/dist/TreeArtifact-D6FZ5SVd.d.ts +27 -0
- package/dist/{UserSelectMenuKit-D3SO_fXA.d.ts → UserSelectMenuKit-DZmeZ_Tp.d.ts} +3 -4
- package/dist/analytics/analytics-engine.d.ts +1 -1
- package/dist/analytics/analytics-engine.js +1 -1
- package/dist/analytics/analytics-provider.d.ts +1 -1
- package/dist/analytics/constants.js +0 -1
- package/dist/analytics/constants.js.map +1 -1
- package/dist/analytics/utils.js +1 -1
- package/dist/{analytics-engine-DnRsHBId.d.ts → analytics-engine-Bz1p7ud3.d.ts} +178 -30
- package/dist/app/commands/AppCommandRunner.d.ts +1 -1
- package/dist/app/commands/AppCommandRunner.js +1 -1
- package/dist/app/commands/Context.d.ts +1 -1
- package/dist/app/commands/Context.js +1 -1
- package/dist/app/commands/MessageCommandParser.d.ts +1 -1
- package/dist/app/commands/MessageCommandParser.js +79 -71
- package/dist/app/commands/MessageCommandParser.js.map +1 -1
- package/dist/app/commands/helpers.d.ts +1 -1
- package/dist/app/commands/helpers.js +0 -1
- package/dist/app/commands/helpers.js.map +1 -1
- package/dist/app/events/EventWorkerContext.d.ts +3 -3
- package/dist/app/events/EventWorkerContext.js +0 -1
- package/dist/app/events/EventWorkerContext.js.map +1 -1
- package/dist/app/handlers/AppCommandHandler.d.ts +1 -1
- package/dist/app/handlers/AppCommandHandler.js +1 -1
- package/dist/app/handlers/AppEventsHandler.d.ts +1 -1
- package/dist/app/handlers/AppEventsHandler.js +1 -1
- package/dist/app/index.d.ts +5 -5
- package/dist/app/index.js +1 -1
- package/dist/app/interrupt/signals.d.ts +1 -1
- package/dist/app/interrupt/signals.js.map +1 -1
- package/dist/app/middlewares/permissions.d.ts +1 -2
- package/dist/app/middlewares/permissions.js +1 -1
- package/dist/app/register/CommandRegistrar.d.ts +1 -1
- package/dist/app/register/CommandRegistrar.js +1 -1
- package/dist/app/router/CommandTree.d.ts +2 -0
- package/dist/app/router/CommandTree.js +1 -0
- package/dist/app/router/CommandsRouter.d.ts +2 -2
- package/dist/app/router/CommandsRouter.js +445 -24
- package/dist/app/router/CommandsRouter.js.map +1 -1
- package/dist/app/router/EventsRouter.d.ts +2 -2
- package/dist/app/router/EventsRouter.js +56 -3
- package/dist/app/router/EventsRouter.js.map +1 -1
- package/dist/app/router/TreeArtifact.d.ts +2 -0
- package/dist/app/router/TreeArtifact.js +87 -0
- package/dist/app/router/TreeArtifact.js.map +1 -0
- package/dist/app/router/index.d.ts +6 -3
- package/dist/app/router/index.js +8 -1
- package/dist/checkbox-DoR0Pcxm.d.ts +27 -0
- package/dist/cli/app-process.d.ts +2 -3
- package/dist/cli/app-process.js +15 -4
- package/dist/cli/app-process.js.map +1 -1
- package/dist/cli/build.d.ts +4 -9
- package/dist/cli/build.js +33 -5
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/common.d.ts +3 -6
- package/dist/cli/common.js +2 -2
- package/dist/cli/common.js.map +1 -1
- package/dist/cli/development.d.ts +5 -6
- package/dist/cli/development.js +12 -12
- package/dist/cli/development.js.map +1 -1
- package/dist/cli/env.js.map +1 -1
- package/dist/cli/generators.js +0 -1
- package/dist/cli/generators.js.map +1 -1
- package/dist/cli/information.js +5 -5
- package/dist/cli/information.js.map +1 -1
- package/dist/cli/init.d.ts +1 -3
- package/dist/cli/init.js +37 -12
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/production.d.ts +1 -3
- package/dist/cli/production.js +4 -4
- package/dist/cli/production.js.map +1 -1
- package/dist/cli/type-checker.js +0 -1
- package/dist/cli/type-checker.js.map +1 -1
- package/dist/cli/utils.d.ts +0 -1
- package/dist/cli/utils.js.map +1 -1
- package/dist/{commandkit-Bh7C1_c7.js → commandkit-DNbfLwyR.js} +786 -200
- package/dist/commandkit-DNbfLwyR.js.map +1 -0
- package/dist/commandkit.d.ts +1 -1
- package/dist/commandkit.js +1 -1
- package/dist/{common-CCvvgnxi.d.ts → common-CIbPzguv.d.ts} +2 -3
- package/dist/components/common/EventInterceptor.d.ts +1 -1
- package/dist/components/common/EventInterceptor.js +1 -0
- package/dist/components/common/EventInterceptor.js.map +1 -1
- package/dist/components/common/element.d.ts +1 -1
- package/dist/components/common/element.js +1 -1
- package/dist/components/common/types.d.ts +1 -1
- package/dist/components/display/common.d.ts +0 -1
- package/dist/components/display/common.js +1 -1
- package/dist/components/display/container.d.ts +1 -1
- package/dist/components/display/container.js +1 -1
- package/dist/components/display/file.d.ts +1 -1
- package/dist/components/display/file.js +0 -1
- package/dist/components/display/file.js.map +1 -1
- package/dist/components/display/index.d.ts +9 -8
- package/dist/components/display/index.js +1 -1
- package/dist/components/display/label.d.ts +1 -1
- package/dist/components/display/label.js +1 -1
- package/dist/components/display/media-gallery.d.ts +1 -1
- package/dist/components/display/media-gallery.js +1 -1
- package/dist/components/display/poll.d.ts +1 -1
- package/dist/components/display/poll.js +4 -10
- package/dist/components/display/poll.js.map +1 -1
- package/dist/components/display/section.d.ts +1 -1
- package/dist/components/display/section.js +1 -1
- package/dist/components/display/separator.d.ts +1 -1
- package/dist/components/display/separator.js +0 -1
- package/dist/components/display/separator.js.map +1 -1
- package/dist/components/display/text-display.d.ts +1 -1
- package/dist/components/display/text-display.js +0 -1
- package/dist/components/display/text-display.js.map +1 -1
- package/dist/components/index.d.ts +26 -23
- package/dist/components/index.js +6 -1
- package/dist/components/interactive/action-row/ActionRow.d.ts +1 -1
- package/dist/components/interactive/action-row/ActionRow.js +0 -1
- package/dist/components/interactive/action-row/ActionRow.js.map +1 -1
- package/dist/components/interactive/button/Button.d.ts +1 -1
- package/dist/components/interactive/button/Button.js +1 -1
- package/dist/components/interactive/button/ButtonKit.d.ts +1 -1
- package/dist/components/interactive/button/ButtonKit.js +1 -1
- package/dist/components/interactive/checkbox/checkbox.d.ts +2 -0
- package/dist/components/interactive/checkbox/checkbox.js +6 -0
- package/dist/components/interactive/modal/Modal.d.ts +1 -1
- package/dist/components/interactive/modal/Modal.js +1 -1
- package/dist/components/interactive/modal/ModalKit.d.ts +1 -1
- package/dist/components/interactive/modal/ModalKit.js +1 -1
- package/dist/components/interactive/radio/radio.d.ts +2 -0
- package/dist/components/interactive/radio/radio.js +5 -0
- package/dist/components/interactive/select-menu/ChannelSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/ChannelSelectMenuKit.js +1 -1
- package/dist/components/interactive/select-menu/MentionableSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/MentionableSelectMenuKit.js +1 -1
- package/dist/components/interactive/select-menu/RoleSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/RoleSelectMenuKit.js +1 -1
- package/dist/components/interactive/select-menu/SelectMenu.d.ts +1 -1
- package/dist/components/interactive/select-menu/SelectMenu.js +1 -1
- package/dist/components/interactive/select-menu/StringSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/StringSelectMenuKit.js +1 -1
- package/dist/components/interactive/select-menu/UserSelectMenuKit.d.ts +1 -1
- package/dist/components/interactive/select-menu/UserSelectMenuKit.js +1 -1
- package/dist/components/interactive/select-menu/common.d.ts +1 -1
- package/dist/config/config.d.ts +1 -2
- package/dist/config/config.js +1 -1
- package/dist/config/default.d.ts +1 -2
- package/dist/config/default.js +1 -1
- package/dist/config/loader.d.ts +1 -2
- package/dist/config/loader.js +1 -1
- package/dist/config/types.d.ts +2 -2
- package/dist/config/utils.d.ts +1 -1
- package/dist/config/utils.js.map +1 -1
- package/dist/{constants-DqtJY0t-.d.ts → constants-B7AfnOFa.d.ts} +1 -1
- package/dist/{constants-DwxpkIeH.d.ts → constants-kWgE3L9F.d.ts} +15 -2
- package/dist/{container-CYojOA9d.d.ts → container-NVgblXmw.d.ts} +1 -2
- package/dist/context/async-context.d.ts +1 -1
- package/dist/context/async-context.js +1 -1
- package/dist/context/environment.d.ts +1 -1
- package/dist/context/environment.js +1 -1
- package/dist/{element-DeLvTMfZ.d.ts → element-BMZYAAQ-.d.ts} +3 -4
- package/dist/events/CommandKitEventsChannel.d.ts +1 -1
- package/dist/events/CommandKitEventsChannel.js +3 -2
- package/dist/events/CommandKitEventsChannel.js.map +1 -1
- package/dist/{file-DLO1zEcH.d.ts → file-DYAmr697.d.ts} +1 -2
- package/dist/flags/FlagProvider.d.ts +1 -1
- package/dist/flags/FlagProvider.js +1 -0
- package/dist/flags/FlagProvider.js.map +1 -1
- package/dist/flags/feature-flags.d.ts +1 -1
- package/dist/flags/feature-flags.js +1 -1
- package/dist/flags/store.d.ts +1 -1
- package/dist/flags/store.js +0 -1
- package/dist/flags/store.js.map +1 -1
- package/dist/{helpers-zmC44Mcu.d.ts → helpers-vlnRvNJv.d.ts} +1 -2
- package/dist/index-CAFaKBs_.d.ts +8 -0
- package/dist/index-COt7nfC9.d.ts +2 -0
- package/dist/index-DvqHpiuh.d.ts +16 -0
- package/dist/index.d.ts +37 -31
- package/dist/index.js +14 -2
- package/dist/kv/constants.d.ts +1 -1
- package/dist/kv/constants.js.map +1 -1
- package/dist/kv/dotprops.js.map +1 -1
- package/dist/kv/kv.d.ts +0 -1
- package/dist/kv/kv.js +1 -1
- package/dist/kv/kv.js.map +1 -1
- package/dist/kv/serde.d.ts +1 -2
- package/dist/kv/serde.js +27 -27
- package/dist/kv/serde.js.map +1 -1
- package/dist/{label-DqGRqodo.d.ts → label-DClaYktn.d.ts} +1 -2
- package/dist/logger/DefaultLogger.d.ts +0 -1
- package/dist/logger/DefaultLogger.js +1 -1
- package/dist/logger/Logger.d.ts +0 -1
- package/dist/logger/Logger.js +1 -1
- package/dist/logger/NoopLogger.d.ts +0 -1
- package/dist/logger/NoopLogger.js.map +1 -1
- package/dist/{media-gallery-Ca8es-eB.d.ts → media-gallery-z2Snzz-u.d.ts} +1 -2
- package/dist/plugins/CompilerPlugin.d.ts +1 -1
- package/dist/plugins/CompilerPlugin.js +2 -2
- package/dist/plugins/CompilerPlugin.js.map +1 -1
- package/dist/plugins/PluginCommon.d.ts +1 -1
- package/dist/plugins/PluginCommon.js +1 -1
- package/dist/plugins/PluginCommon.js.map +1 -1
- package/dist/plugins/RuntimePlugin.d.ts +1 -1
- package/dist/plugins/RuntimePlugin.js +2 -2
- package/dist/plugins/RuntimePlugin.js.map +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.d.ts +1 -1
- package/dist/plugins/plugin-runtime/CommandKitPluginRuntime.js +1 -1
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.d.ts +1 -1
- package/dist/plugins/plugin-runtime/CompilerPluginRuntime.js +1 -1
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.d.ts +1 -1
- package/dist/plugins/plugin-runtime/builtin/CommonDirectiveTransformer.js +1 -1
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.d.ts +1 -2
- package/dist/plugins/plugin-runtime/builtin/MacroPlugin.js +1 -1
- package/dist/plugins/plugin-runtime/runtime.d.ts +1 -1
- package/dist/plugins/types.d.ts +1 -1
- package/dist/{poll-DQ6DX_Tt.d.ts → poll-D2QDStsw.d.ts} +4 -14
- package/dist/radio-CJH_N4lq.d.ts +20 -0
- package/dist/{section-Q8nwx_-q.d.ts → section-DrFBT5b-.d.ts} +1 -2
- package/dist/{separator-B8P-kdIK.d.ts → separator-BVm3w6yd.d.ts} +1 -2
- package/dist/{signals-CBXwugBW.d.ts → signals-DRMDrCOn.d.ts} +1 -1
- package/dist/{text-display-CL9C2yMc.d.ts → text-display-BG0nNqy3.d.ts} +1 -2
- package/dist/{types-DZy7U-Ld.d.ts → types-ur7SvktF.d.ts} +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/colors.d.ts +1 -3
- package/dist/utils/colors.js +0 -1
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.js +19 -0
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/dev-hooks.d.ts +1 -1
- package/dist/utils/dev-hooks.js +1 -1
- package/dist/utils/error-codes.js +15 -0
- package/dist/utils/error-codes.js.map +1 -1
- package/dist/utils/resolve-file-url.js +2 -2
- package/dist/utils/resolve-file-url.js.map +1 -1
- package/dist/utils/types-package.d.ts +6 -2
- package/dist/utils/types-package.js +31 -38
- package/dist/utils/types-package.js.map +1 -1
- package/dist/utils/useful-stuff/async-queue.js.map +1 -1
- package/dist/utils/useful-stuff/mutex.js.map +1 -1
- package/dist/utils/useful-stuff/ratelimiter.js +4 -1
- package/dist/utils/useful-stuff/ratelimiter.js.map +1 -1
- package/dist/utils/useful-stuff/semaphore.js.map +1 -1
- package/dist/utils/utilities.js +1 -1
- package/dist/utils/warning.d.ts +1 -5
- package/dist/utils/warning.js.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +17 -17
- package/dist/CommandsRouter-DiNoF0dq.d.ts +0 -145
- package/dist/commandkit-Bh7C1_c7.js.map +0 -1
- package/dist/index-BIsCUWAs.d.ts +0 -1
- package/dist/index-CwHYpK-f.d.ts +0 -1
- package/dist/index-DHrsNvX1.d.ts +0 -1
- /package/dist/{chunk-BE-pF4vm.js → rolldown-runtime-C_NdSu1c.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./rolldown-runtime-C_NdSu1c.js');
|
|
2
2
|
const require_utils_colors = require('./utils/colors.js');
|
|
3
|
+
require('./components/interactive/action-row/ActionRow.js');
|
|
3
4
|
const require_utils_error_codes = require('./utils/error-codes.js');
|
|
4
5
|
const require_plugins_CompilerPlugin = require('./plugins/CompilerPlugin.js');
|
|
5
6
|
const require_plugins_RuntimePlugin = require('./plugins/RuntimePlugin.js');
|
|
@@ -16,17 +17,26 @@ const require_app_commands_helpers = require('./app/commands/helpers.js');
|
|
|
16
17
|
const require_app_commands_MessageCommandParser = require('./app/commands/MessageCommandParser.js');
|
|
17
18
|
const require_app_router_CommandsRouter = require('./app/router/CommandsRouter.js');
|
|
18
19
|
const require_app_router_EventsRouter = require('./app/router/EventsRouter.js');
|
|
20
|
+
const require_app_router_TreeArtifact = require('./app/router/TreeArtifact.js');
|
|
21
|
+
require('./app/router/index.js');
|
|
22
|
+
const require_version = require('./version.js');
|
|
23
|
+
require('./components/display/file.js');
|
|
24
|
+
require('./components/display/separator.js');
|
|
25
|
+
require('./components/display/text-display.js');
|
|
26
|
+
require('./components/display/poll.js');
|
|
19
27
|
const require_cli_common = require('./cli/common.js');
|
|
20
28
|
const require_events_CommandKitEventsChannel = require('./events/CommandKitEventsChannel.js');
|
|
21
29
|
const require_flags_store = require('./flags/store.js');
|
|
22
30
|
let node_events = require("node:events");
|
|
23
|
-
node_events =
|
|
31
|
+
node_events = require_rolldown_runtime.__toESM(node_events);
|
|
24
32
|
let discord_js = require("discord.js");
|
|
25
33
|
let node_async_hooks = require("node:async_hooks");
|
|
26
34
|
let node_crypto = require("node:crypto");
|
|
35
|
+
let node_console = require("node:console");
|
|
27
36
|
let util = require("util");
|
|
28
37
|
let node_fs = require("node:fs");
|
|
29
38
|
let node_path = require("node:path");
|
|
39
|
+
let node_fs_promises = require("node:fs/promises");
|
|
30
40
|
|
|
31
41
|
//#region src/context/async-context.ts
|
|
32
42
|
const kCommandWorker = Symbol("commandkitCommandWorker");
|
|
@@ -386,17 +396,6 @@ var ModalKit = class extends discord_js.ModalBuilder {
|
|
|
386
396
|
|
|
387
397
|
//#endregion
|
|
388
398
|
//#region src/logger/DefaultLogger.ts
|
|
389
|
-
/**
|
|
390
|
-
* Log levels for the logger.
|
|
391
|
-
*/
|
|
392
|
-
var LogLevel = /* @__PURE__ */ function(LogLevel) {
|
|
393
|
-
LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
|
|
394
|
-
LogLevel[LogLevel["INFO"] = 1] = "INFO";
|
|
395
|
-
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
396
|
-
LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
|
|
397
|
-
LogLevel[LogLevel["DEFAULT"] = 4] = "DEFAULT";
|
|
398
|
-
return LogLevel;
|
|
399
|
-
}(LogLevel || {});
|
|
400
399
|
const execHandlerKind = {
|
|
401
400
|
autocomplete: "Autocomplete",
|
|
402
401
|
messageContextMenu: "MessageContextMenu",
|
|
@@ -405,18 +404,18 @@ const execHandlerKind = {
|
|
|
405
404
|
message: "Message"
|
|
406
405
|
};
|
|
407
406
|
const TextColorMap = {
|
|
408
|
-
[
|
|
409
|
-
[
|
|
410
|
-
[
|
|
411
|
-
[
|
|
412
|
-
[
|
|
407
|
+
[0]: require_utils_colors.default.blue,
|
|
408
|
+
[1]: require_utils_colors.default.green,
|
|
409
|
+
[2]: require_utils_colors.default.yellow,
|
|
410
|
+
[3]: require_utils_colors.default.red,
|
|
411
|
+
[4]: require_utils_colors.default.white
|
|
413
412
|
};
|
|
414
413
|
const TextBgColorMap = {
|
|
415
|
-
[
|
|
416
|
-
[
|
|
417
|
-
[
|
|
418
|
-
[
|
|
419
|
-
[
|
|
414
|
+
[0]: require_utils_colors.default.bgBlue,
|
|
415
|
+
[1]: require_utils_colors.default.bgGreen,
|
|
416
|
+
[2]: require_utils_colors.default.bgYellow,
|
|
417
|
+
[3]: require_utils_colors.default.bgRed,
|
|
418
|
+
[4]: require_utils_colors.default.bgWhite
|
|
420
419
|
};
|
|
421
420
|
const BoxChars = {
|
|
422
421
|
vertical: "│",
|
|
@@ -430,6 +429,8 @@ const BoxChars = {
|
|
|
430
429
|
* It formats the log messages with timestamps, log levels, and context information.
|
|
431
430
|
*/
|
|
432
431
|
var DefaultLogger = class {
|
|
432
|
+
stdout;
|
|
433
|
+
stderr;
|
|
433
434
|
logger;
|
|
434
435
|
/**
|
|
435
436
|
* Creates a new instance of DefaultLogger.
|
|
@@ -439,7 +440,7 @@ var DefaultLogger = class {
|
|
|
439
440
|
constructor(stdout = process.stdout, stderr = process.stderr) {
|
|
440
441
|
this.stdout = stdout;
|
|
441
442
|
this.stderr = stderr;
|
|
442
|
-
this.logger = new
|
|
443
|
+
this.logger = new node_console.Console(this.stdout, this.stderr);
|
|
443
444
|
}
|
|
444
445
|
_formatTime(date) {
|
|
445
446
|
return `${date.getHours().toString().padStart(2, "0")}:${date.getMinutes().toString().padStart(2, "0")}:${date.getSeconds().toString().padStart(2, "0")}.${date.getMilliseconds().toString().padStart(3, "0")}`;
|
|
@@ -462,16 +463,16 @@ var DefaultLogger = class {
|
|
|
462
463
|
_getLevelLabel(level) {
|
|
463
464
|
let label;
|
|
464
465
|
switch (level) {
|
|
465
|
-
case
|
|
466
|
+
case 0:
|
|
466
467
|
label = "[DEBUG]";
|
|
467
468
|
break;
|
|
468
|
-
case
|
|
469
|
+
case 1:
|
|
469
470
|
label = "[INFO]";
|
|
470
471
|
break;
|
|
471
|
-
case
|
|
472
|
+
case 2:
|
|
472
473
|
label = "[WARN]";
|
|
473
474
|
break;
|
|
474
|
-
case
|
|
475
|
+
case 3:
|
|
475
476
|
label = "[ERROR]";
|
|
476
477
|
break;
|
|
477
478
|
default: label = "[LOG]";
|
|
@@ -512,24 +513,24 @@ var DefaultLogger = class {
|
|
|
512
513
|
else this.logger.log(`${prefix} ${require_utils_colors.default.dim(BoxChars.corner)}`, colorFn(result));
|
|
513
514
|
}
|
|
514
515
|
debug(messageOrStrings, ...values) {
|
|
515
|
-
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(
|
|
516
|
-
else this._log(
|
|
516
|
+
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(0, messageOrStrings, ...values);
|
|
517
|
+
else this._log(0, messageOrStrings);
|
|
517
518
|
}
|
|
518
519
|
error(messageOrStrings, ...values) {
|
|
519
|
-
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(
|
|
520
|
-
else this._log(
|
|
520
|
+
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(3, messageOrStrings, ...values);
|
|
521
|
+
else this._log(3, messageOrStrings);
|
|
521
522
|
}
|
|
522
523
|
log(messageOrStrings, ...values) {
|
|
523
|
-
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(
|
|
524
|
-
else this._log(
|
|
524
|
+
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(4, messageOrStrings, ...values);
|
|
525
|
+
else this._log(4, messageOrStrings);
|
|
525
526
|
}
|
|
526
527
|
info(messageOrStrings, ...values) {
|
|
527
|
-
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(
|
|
528
|
-
else this._log(
|
|
528
|
+
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(1, messageOrStrings, ...values);
|
|
529
|
+
else this._log(1, messageOrStrings);
|
|
529
530
|
}
|
|
530
531
|
warn(messageOrStrings, ...values) {
|
|
531
|
-
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(
|
|
532
|
-
else this._log(
|
|
532
|
+
if (this._isTemplateStringsArray(messageOrStrings)) this._logTemplate(2, messageOrStrings, ...values);
|
|
533
|
+
else this._log(2, messageOrStrings);
|
|
533
534
|
}
|
|
534
535
|
_isTemplateStringsArray(value) {
|
|
535
536
|
return Array.isArray(value) && "raw" in value && Array.isArray(value.raw);
|
|
@@ -630,20 +631,30 @@ function findAppDirectory() {
|
|
|
630
631
|
*/
|
|
631
632
|
function debounce(fn, ms) {
|
|
632
633
|
let timer = null;
|
|
633
|
-
let
|
|
634
|
+
let sharedPromise = null;
|
|
635
|
+
let sharedResolve = null;
|
|
636
|
+
let sharedReject = null;
|
|
634
637
|
return ((...args) => {
|
|
635
|
-
if (timer)
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
return new Promise((res) => {
|
|
640
|
-
resolve = res;
|
|
641
|
-
timer = setTimeout(() => {
|
|
642
|
-
res(fn(...args));
|
|
643
|
-
timer = null;
|
|
644
|
-
resolve = null;
|
|
645
|
-
}, ms);
|
|
638
|
+
if (timer) clearTimeout(timer);
|
|
639
|
+
if (!sharedPromise) sharedPromise = new Promise((res, rej) => {
|
|
640
|
+
sharedResolve = res;
|
|
641
|
+
sharedReject = rej;
|
|
646
642
|
});
|
|
643
|
+
timer = setTimeout(async () => {
|
|
644
|
+
const currentResolve = sharedResolve;
|
|
645
|
+
const currentReject = sharedReject;
|
|
646
|
+
timer = null;
|
|
647
|
+
sharedPromise = null;
|
|
648
|
+
sharedResolve = null;
|
|
649
|
+
sharedReject = null;
|
|
650
|
+
try {
|
|
651
|
+
const result = await fn(...args);
|
|
652
|
+
if (currentResolve) currentResolve(result);
|
|
653
|
+
} catch (err) {
|
|
654
|
+
if (currentReject) currentReject(err);
|
|
655
|
+
}
|
|
656
|
+
}, ms);
|
|
657
|
+
return sharedPromise;
|
|
647
658
|
});
|
|
648
659
|
}
|
|
649
660
|
/**
|
|
@@ -790,6 +801,7 @@ function createProxy(target) {
|
|
|
790
801
|
* Represents the runtime environment for CommandKit plugins.
|
|
791
802
|
*/
|
|
792
803
|
var CommandKitPluginRuntime = class {
|
|
804
|
+
commandkit;
|
|
793
805
|
plugins = new discord_js.Collection();
|
|
794
806
|
/**
|
|
795
807
|
* Creates a new instance of CommandKitPluginRuntime.
|
|
@@ -825,7 +837,12 @@ var CommandKitPluginRuntime = class {
|
|
|
825
837
|
* @param plugin The plugin to pre-load.
|
|
826
838
|
*/
|
|
827
839
|
async preload(plugin) {
|
|
828
|
-
for (const entrypoint of plugin.preload)
|
|
840
|
+
for (const entrypoint of plugin.preload) {
|
|
841
|
+
const path = entrypoint.startsWith("module:") ? entrypoint.slice(7) : require_utils_resolve_file_url.toFileURL(`${getCurrentDirectory()}/${entrypoint}`);
|
|
842
|
+
Logger.debug`Preloading plugin entrypoint: ${path}`;
|
|
843
|
+
const result = await import(path);
|
|
844
|
+
Logger.debug`Preloaded plugin entrypoint: ${path} with result: ${result}`;
|
|
845
|
+
}
|
|
829
846
|
}
|
|
830
847
|
/**
|
|
831
848
|
* Soft registers a plugin in the runtime.
|
|
@@ -907,19 +924,11 @@ var CommandKitPluginRuntime = class {
|
|
|
907
924
|
//#endregion
|
|
908
925
|
//#region src/plugins/plugin-runtime/CompilerPluginRuntime.ts
|
|
909
926
|
/**
|
|
910
|
-
* Enum representing the execution mode of a plugin.
|
|
911
|
-
* It can be either 'activate' or 'deactivate'.
|
|
912
|
-
* @private
|
|
913
|
-
*/
|
|
914
|
-
var PluginExecutionMode = /* @__PURE__ */ function(PluginExecutionMode) {
|
|
915
|
-
PluginExecutionMode["Activate"] = "activate";
|
|
916
|
-
PluginExecutionMode["Deactivate"] = "deactivate";
|
|
917
|
-
return PluginExecutionMode;
|
|
918
|
-
}(PluginExecutionMode || {});
|
|
919
|
-
/**
|
|
920
927
|
* CompilerPluginRuntime is a runtime for managing compiler plugins in CommandKit.
|
|
921
928
|
*/
|
|
922
929
|
var CompilerPluginRuntime = class {
|
|
930
|
+
plugins;
|
|
931
|
+
isDevMode;
|
|
923
932
|
name = "CompilerPluginRuntime";
|
|
924
933
|
initialized = false;
|
|
925
934
|
templates = /* @__PURE__ */ new Map();
|
|
@@ -954,7 +963,7 @@ var CompilerPluginRuntime = class {
|
|
|
954
963
|
*/
|
|
955
964
|
registerTemplate(name, handler) {
|
|
956
965
|
const ctx = this.#pluginContext.getStore();
|
|
957
|
-
if (!ctx || ctx.mode !==
|
|
966
|
+
if (!ctx || ctx.mode !== "activate") throw new Error("registerTemplate() must be called inside activate() method");
|
|
958
967
|
if (this.templates.has(name)) throw new Error(`Template "${name}" already exists`);
|
|
959
968
|
this.templates.set(name, {
|
|
960
969
|
handler,
|
|
@@ -968,7 +977,7 @@ var CompilerPluginRuntime = class {
|
|
|
968
977
|
*/
|
|
969
978
|
unregisterTemplate(name) {
|
|
970
979
|
const ctx = this.#pluginContext.getStore();
|
|
971
|
-
if (!ctx || ctx.mode !==
|
|
980
|
+
if (!ctx || ctx.mode !== "deactivate") throw new Error("unregisterTemplate() must be called inside deactivate() method");
|
|
972
981
|
const template = this.templates.get(name);
|
|
973
982
|
if (!template) throw new Error(`Template "${name}" does not exist`);
|
|
974
983
|
if (template.plugin !== ctx.plugin) throw new Error(`Template "${name}" is owned by plugin "${template.plugin.name}" and cannot be unregistered by "${ctx.plugin.name}"`);
|
|
@@ -1032,7 +1041,7 @@ var CompilerPluginRuntime = class {
|
|
|
1032
1041
|
for (const plugin of this.plugins) try {
|
|
1033
1042
|
await this.#pluginContext.run({
|
|
1034
1043
|
plugin,
|
|
1035
|
-
mode:
|
|
1044
|
+
mode: "activate"
|
|
1036
1045
|
}, async () => {
|
|
1037
1046
|
var _plugin$activate;
|
|
1038
1047
|
await ((_plugin$activate = plugin.activate) === null || _plugin$activate === void 0 ? void 0 : _plugin$activate.call(plugin, this));
|
|
@@ -1051,7 +1060,7 @@ var CompilerPluginRuntime = class {
|
|
|
1051
1060
|
for (const plugin of this.plugins) try {
|
|
1052
1061
|
await this.#pluginContext.run({
|
|
1053
1062
|
plugin,
|
|
1054
|
-
mode:
|
|
1063
|
+
mode: "deactivate"
|
|
1055
1064
|
}, async () => {
|
|
1056
1065
|
var _plugin$deactivate;
|
|
1057
1066
|
await ((_plugin$deactivate = plugin.deactivate) === null || _plugin$deactivate === void 0 ? void 0 : _plugin$deactivate.call(plugin, this));
|
|
@@ -1118,7 +1127,8 @@ var MacroPlugin = class extends require_plugins_CompilerPlugin.CompilerPlugin {
|
|
|
1118
1127
|
name = "MacroPlugin";
|
|
1119
1128
|
macroTransformer;
|
|
1120
1129
|
async activate() {
|
|
1121
|
-
|
|
1130
|
+
const transform = await import("use-macro");
|
|
1131
|
+
this.macroTransformer = new transform.MacroTransformer();
|
|
1122
1132
|
}
|
|
1123
1133
|
async deactivate() {
|
|
1124
1134
|
this.macroTransformer = null;
|
|
@@ -1165,7 +1175,12 @@ const defaultConfig = {
|
|
|
1165
1175
|
development: true,
|
|
1166
1176
|
production: false
|
|
1167
1177
|
},
|
|
1168
|
-
jsxDefaultOptionalComponents: true
|
|
1178
|
+
jsxDefaultOptionalComponents: true,
|
|
1179
|
+
experimental: {
|
|
1180
|
+
devServerRuntime: null,
|
|
1181
|
+
pregenerateCommands: false,
|
|
1182
|
+
incrementalRouter: false
|
|
1183
|
+
}
|
|
1169
1184
|
};
|
|
1170
1185
|
|
|
1171
1186
|
//#endregion
|
|
@@ -1182,7 +1197,7 @@ function getConfig() {
|
|
|
1182
1197
|
* @param config The configuration to use.
|
|
1183
1198
|
*/
|
|
1184
1199
|
function defineConfig(config = {}) {
|
|
1185
|
-
var _config$compilerOptio, _config$compilerOptio2, _config$compilerOptio3;
|
|
1200
|
+
var _config$compilerOptio, _config$compilerOptio2, _config$compilerOptio3, _config$experimental, _config$experimental2;
|
|
1186
1201
|
defined = require_config_utils.mergeDeep(config, require_config_utils.mergeDeep({}, defaultConfig));
|
|
1187
1202
|
defined = {
|
|
1188
1203
|
compilerOptions: {
|
|
@@ -1221,7 +1236,13 @@ function defineConfig(config = {}) {
|
|
|
1221
1236
|
...config.antiCrashScript
|
|
1222
1237
|
},
|
|
1223
1238
|
disablePermissionsMiddleware: config.disablePermissionsMiddleware ?? defaultConfig.disablePermissionsMiddleware,
|
|
1224
|
-
jsxDefaultOptionalComponents: config.jsxDefaultOptionalComponents ?? defaultConfig.jsxDefaultOptionalComponents
|
|
1239
|
+
jsxDefaultOptionalComponents: config.jsxDefaultOptionalComponents ?? defaultConfig.jsxDefaultOptionalComponents,
|
|
1240
|
+
experimental: {
|
|
1241
|
+
...defaultConfig.experimental,
|
|
1242
|
+
...config.experimental,
|
|
1243
|
+
pregenerateCommands: ((_config$experimental = config.experimental) === null || _config$experimental === void 0 ? void 0 : _config$experimental.pregenerateCommands) ?? defaultConfig.experimental.pregenerateCommands,
|
|
1244
|
+
incrementalRouter: ((_config$experimental2 = config.experimental) === null || _config$experimental2 === void 0 ? void 0 : _config$experimental2.incrementalRouter) ?? defaultConfig.experimental.incrementalRouter
|
|
1245
|
+
}
|
|
1225
1246
|
};
|
|
1226
1247
|
return defined;
|
|
1227
1248
|
}
|
|
@@ -1289,6 +1310,7 @@ function applyDefaultOptionalComponentBehavior(props) {
|
|
|
1289
1310
|
* Represents the execution environment for CommandKit commands.
|
|
1290
1311
|
*/
|
|
1291
1312
|
var CommandKitEnvironment = class {
|
|
1313
|
+
commandkit;
|
|
1292
1314
|
#data = {
|
|
1293
1315
|
executionError: null,
|
|
1294
1316
|
type: null,
|
|
@@ -1496,6 +1518,8 @@ const CommandExecutionMode = {
|
|
|
1496
1518
|
* command metadata, and various utility methods for command execution.
|
|
1497
1519
|
*/
|
|
1498
1520
|
var Context = class Context {
|
|
1521
|
+
commandkit;
|
|
1522
|
+
config;
|
|
1499
1523
|
/**
|
|
1500
1524
|
* The interaction that triggered the command.
|
|
1501
1525
|
*/
|
|
@@ -1578,9 +1602,12 @@ var Context = class Context {
|
|
|
1578
1602
|
* Gets the name of the current command.
|
|
1579
1603
|
*/
|
|
1580
1604
|
get commandName() {
|
|
1605
|
+
const routeKey = this.command.data.command.__routeKey;
|
|
1606
|
+
if (typeof routeKey === "string" && routeKey.length) return routeKey;
|
|
1607
|
+
if (this.command.data.command.name) return this.command.data.command.name;
|
|
1581
1608
|
if (this.isInteraction()) return this.interaction.commandName;
|
|
1582
|
-
const
|
|
1583
|
-
return this.commandkit.commandHandler.resolveMessageCommandName(
|
|
1609
|
+
const parser = this.config.messageCommandParser;
|
|
1610
|
+
return this.commandkit.commandHandler.resolveMessageCommandName(parser.getFullCommand());
|
|
1584
1611
|
}
|
|
1585
1612
|
/**
|
|
1586
1613
|
* Gets the invoked command name (could be an alias for message commands)
|
|
@@ -1674,7 +1701,7 @@ var Context = class Context {
|
|
|
1674
1701
|
*/
|
|
1675
1702
|
getCommandIdentifier() {
|
|
1676
1703
|
if (this.isInteraction()) return this.interaction.commandName;
|
|
1677
|
-
else return this.
|
|
1704
|
+
else return this.commandName;
|
|
1678
1705
|
}
|
|
1679
1706
|
/**
|
|
1680
1707
|
* Returns the locale of the guild where this command was triggered.
|
|
@@ -1764,6 +1791,7 @@ var MiddlewareContext = class extends Context {
|
|
|
1764
1791
|
* Manages middleware execution, environment setup, and command invocation.
|
|
1765
1792
|
*/
|
|
1766
1793
|
var AppCommandRunner = class {
|
|
1794
|
+
handler;
|
|
1767
1795
|
/**
|
|
1768
1796
|
* Creates a new AppCommandRunner instance.
|
|
1769
1797
|
* @param handler - The app command handler instance to use for command execution
|
|
@@ -1784,9 +1812,9 @@ var AppCommandRunner = class {
|
|
|
1784
1812
|
const executionMode = this.getExecutionMode(source);
|
|
1785
1813
|
let runCommand = null;
|
|
1786
1814
|
const env = new CommandKitEnvironment(commandkit);
|
|
1787
|
-
env.setType(
|
|
1815
|
+
env.setType("COMMAND_HANDLER");
|
|
1788
1816
|
env.variables.set("commandHandlerType", "app");
|
|
1789
|
-
env.variables.set("currentCommandName", prepared.command.command.name);
|
|
1817
|
+
env.variables.set("currentCommandName", prepared.command.data.command.__routeKey ?? prepared.command.command.name);
|
|
1790
1818
|
env.variables.set("execHandlerKind", executionMode);
|
|
1791
1819
|
env.variables.set("customHandler", (options === null || options === void 0 ? void 0 : options.handler) ?? null);
|
|
1792
1820
|
try {
|
|
@@ -1826,15 +1854,15 @@ var AppCommandRunner = class {
|
|
|
1826
1854
|
if (fn) try {
|
|
1827
1855
|
const _executeCommand = makeContextAwareFunction(env, async () => {
|
|
1828
1856
|
env.registerDeferredFunction(async (env) => {
|
|
1829
|
-
var _prepared$
|
|
1857
|
+
var _prepared$command3, _prepared$command4;
|
|
1830
1858
|
env.markEnd();
|
|
1831
1859
|
const error = env.getExecutionError();
|
|
1832
1860
|
const marker = env.getMarker();
|
|
1833
1861
|
const time = `${env.getExecutionTime().toFixed(2)}ms`;
|
|
1834
1862
|
if (error) {
|
|
1835
|
-
var _prepared$command;
|
|
1863
|
+
var _prepared$command, _prepared$command2;
|
|
1836
1864
|
Logger.error`[${marker} - ${time}] Error executing command: ${error}`;
|
|
1837
|
-
const commandName = ((_prepared$command = prepared.command) === null || _prepared$command === void 0 || (_prepared$command = _prepared$command.data) === null || _prepared$command === void 0 || (_prepared$command = _prepared$command.command) === null || _prepared$command === void 0 ? void 0 : _prepared$command.name) ?? prepared.command.command.name;
|
|
1865
|
+
const commandName = ((_prepared$command = prepared.command) === null || _prepared$command === void 0 || (_prepared$command = _prepared$command.data) === null || _prepared$command === void 0 || (_prepared$command = _prepared$command.command) === null || _prepared$command === void 0 ? void 0 : _prepared$command.__routeKey) ?? ((_prepared$command2 = prepared.command) === null || _prepared$command2 === void 0 || (_prepared$command2 = _prepared$command2.data) === null || _prepared$command2 === void 0 || (_prepared$command2 = _prepared$command2.command) === null || _prepared$command2 === void 0 ? void 0 : _prepared$command2.name) ?? prepared.command.command.name;
|
|
1838
1866
|
await analytics.track({
|
|
1839
1867
|
name: require_analytics_constants.AnalyticsEvents.COMMAND_EXECUTION,
|
|
1840
1868
|
id: commandName,
|
|
@@ -1848,7 +1876,7 @@ var AppCommandRunner = class {
|
|
|
1848
1876
|
return;
|
|
1849
1877
|
}
|
|
1850
1878
|
Logger.info(`[${marker} - ${time}] Command executed successfully`);
|
|
1851
|
-
const commandName = ((_prepared$
|
|
1879
|
+
const commandName = ((_prepared$command3 = prepared.command) === null || _prepared$command3 === void 0 || (_prepared$command3 = _prepared$command3.data) === null || _prepared$command3 === void 0 || (_prepared$command3 = _prepared$command3.command) === null || _prepared$command3 === void 0 ? void 0 : _prepared$command3.__routeKey) ?? ((_prepared$command4 = prepared.command) === null || _prepared$command4 === void 0 || (_prepared$command4 = _prepared$command4.data) === null || _prepared$command4 === void 0 || (_prepared$command4 = _prepared$command4.command) === null || _prepared$command4 === void 0 ? void 0 : _prepared$command4.name) ?? prepared.command.command.name;
|
|
1852
1880
|
await analytics.track({
|
|
1853
1881
|
name: require_analytics_constants.AnalyticsEvents.COMMAND_EXECUTION,
|
|
1854
1882
|
id: commandName,
|
|
@@ -1863,7 +1891,7 @@ var AppCommandRunner = class {
|
|
|
1863
1891
|
return fn(middlewareCtx.clone());
|
|
1864
1892
|
}, this.#finalizer.bind(this));
|
|
1865
1893
|
const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
|
|
1866
|
-
env.markStart(prepared.command.data.command.name);
|
|
1894
|
+
env.markStart(prepared.command.data.command.__routeKey ?? prepared.command.data.command.name);
|
|
1867
1895
|
if (!await commandkit.plugins.execute(async (ctx, plugin) => {
|
|
1868
1896
|
return plugin.executeCommand(ctx, env, source, prepared, executeCommand);
|
|
1869
1897
|
})) result = await executeCommand();
|
|
@@ -2006,6 +2034,7 @@ async function beforeExecute(ctx) {
|
|
|
2006
2034
|
* Handles registration of Discord application commands (slash commands, context menus).
|
|
2007
2035
|
*/
|
|
2008
2036
|
var CommandRegistrar = class {
|
|
2037
|
+
commandkit;
|
|
2009
2038
|
/**
|
|
2010
2039
|
* @private
|
|
2011
2040
|
* @internal
|
|
@@ -2020,23 +2049,41 @@ var CommandRegistrar = class {
|
|
|
2020
2049
|
this.api.setToken(this.commandkit.client.token ?? process.env.DISCORD_TOKEN ?? process.env.TOKEN ?? "");
|
|
2021
2050
|
}
|
|
2022
2051
|
/**
|
|
2023
|
-
* Gets the commands data.
|
|
2052
|
+
* Gets the commands data, consuming pre-generated context menu entries when available.
|
|
2024
2053
|
*/
|
|
2025
2054
|
getCommandsData() {
|
|
2026
|
-
return this.
|
|
2027
|
-
|
|
2055
|
+
return [...this.getFlatCommandsData(), ...this.getHierarchicalCommandsData()];
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Gets flat command data, consuming pre-generated context menu entries when available.
|
|
2059
|
+
*/
|
|
2060
|
+
getFlatCommandsData() {
|
|
2061
|
+
const commands = this.commandkit.commandHandler.getCommandsArray();
|
|
2062
|
+
const commandIds = new Set(commands.map((command) => command.command.id));
|
|
2063
|
+
return commands.flatMap((cmd) => {
|
|
2064
|
+
const isPreGeneratedCtx = cmd.command.id.endsWith("::user-ctx") || cmd.command.id.endsWith("::message-ctx");
|
|
2065
|
+
const json = this.sanitizeCommandData("toJSON" in cmd.data.command ? cmd.data.command.toJSON() : cmd.data.command);
|
|
2028
2066
|
const __metadata = cmd.metadata ?? cmd.data.metadata;
|
|
2067
|
+
const isContextMenuType = json.type === discord_js.ApplicationCommandType.User || json.type === discord_js.ApplicationCommandType.Message;
|
|
2068
|
+
const applyId = (id) => {
|
|
2069
|
+
cmd.discordId = id;
|
|
2070
|
+
};
|
|
2071
|
+
if (isPreGeneratedCtx || isContextMenuType) return [{
|
|
2072
|
+
...json,
|
|
2073
|
+
__metadata,
|
|
2074
|
+
__applyId: applyId
|
|
2075
|
+
}];
|
|
2029
2076
|
const collections = [];
|
|
2077
|
+
const hasPreGeneratedUserContextMenu = commandIds.has(`${cmd.command.id}::user-ctx`);
|
|
2078
|
+
const hasPreGeneratedMessageContextMenu = commandIds.has(`${cmd.command.id}::message-ctx`);
|
|
2030
2079
|
if (cmd.data.chatInput) collections.push({
|
|
2031
2080
|
...json,
|
|
2032
2081
|
type: discord_js.ApplicationCommandType.ChatInput,
|
|
2033
2082
|
description: json.description ?? "No command description set.",
|
|
2034
2083
|
__metadata,
|
|
2035
|
-
__applyId:
|
|
2036
|
-
cmd.discordId = id;
|
|
2037
|
-
}
|
|
2084
|
+
__applyId: applyId
|
|
2038
2085
|
});
|
|
2039
|
-
if (cmd.data.userContextMenu) {
|
|
2086
|
+
if (cmd.data.userContextMenu && !hasPreGeneratedUserContextMenu) {
|
|
2040
2087
|
var _metadata$nameAliases;
|
|
2041
2088
|
collections.push({
|
|
2042
2089
|
...json,
|
|
@@ -2046,12 +2093,10 @@ var CommandRegistrar = class {
|
|
|
2046
2093
|
description_localizations: void 0,
|
|
2047
2094
|
description: void 0,
|
|
2048
2095
|
__metadata,
|
|
2049
|
-
__applyId:
|
|
2050
|
-
cmd.discordId = id;
|
|
2051
|
-
}
|
|
2096
|
+
__applyId: applyId
|
|
2052
2097
|
});
|
|
2053
2098
|
}
|
|
2054
|
-
if (cmd.data.messageContextMenu) {
|
|
2099
|
+
if (cmd.data.messageContextMenu && !hasPreGeneratedMessageContextMenu) {
|
|
2055
2100
|
var _metadata$nameAliases2;
|
|
2056
2101
|
collections.push({
|
|
2057
2102
|
...json,
|
|
@@ -2061,15 +2106,126 @@ var CommandRegistrar = class {
|
|
|
2061
2106
|
description: void 0,
|
|
2062
2107
|
options: void 0,
|
|
2063
2108
|
__metadata,
|
|
2064
|
-
__applyId:
|
|
2065
|
-
cmd.discordId = id;
|
|
2066
|
-
}
|
|
2109
|
+
__applyId: applyId
|
|
2067
2110
|
});
|
|
2068
2111
|
}
|
|
2069
2112
|
return collections;
|
|
2070
2113
|
});
|
|
2071
2114
|
}
|
|
2072
2115
|
/**
|
|
2116
|
+
* Gets hierarchical chat-input command payloads compiled from cached tree nodes.
|
|
2117
|
+
*/
|
|
2118
|
+
getHierarchicalCommandsData() {
|
|
2119
|
+
const router = this.commandkit.commandsRouter;
|
|
2120
|
+
if (!router) return [];
|
|
2121
|
+
const { treeNodes } = router.getData();
|
|
2122
|
+
const hierarchicalNodes = new Map(this.commandkit.commandHandler.getHierarchicalNodesArray().map((node) => [node.command.id, node]));
|
|
2123
|
+
const rootNodes = Array.from(treeNodes.values()).filter((node) => {
|
|
2124
|
+
return node.source !== "flat" && node.kind === "command" && node.route.length === 1;
|
|
2125
|
+
});
|
|
2126
|
+
const commands = [];
|
|
2127
|
+
for (const rootNode of rootNodes) {
|
|
2128
|
+
const payload = this.buildHierarchicalRootPayload(rootNode.id, treeNodes, hierarchicalNodes);
|
|
2129
|
+
if (payload) commands.push(payload);
|
|
2130
|
+
}
|
|
2131
|
+
return commands;
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Removes internal runtime-only fields before Discord registration data is emitted.
|
|
2135
|
+
*/
|
|
2136
|
+
sanitizeCommandData(command) {
|
|
2137
|
+
const { __routeKey, ...json } = command;
|
|
2138
|
+
return json;
|
|
2139
|
+
}
|
|
2140
|
+
/**
|
|
2141
|
+
* Builds a top-level Discord payload for a hierarchical command root.
|
|
2142
|
+
*/
|
|
2143
|
+
buildHierarchicalRootPayload(rootNodeId, treeNodes, hierarchicalNodes) {
|
|
2144
|
+
const rootNode = treeNodes.get(rootNodeId);
|
|
2145
|
+
const rootLoaded = hierarchicalNodes.get(rootNodeId);
|
|
2146
|
+
if (!rootNode || !rootLoaded) return null;
|
|
2147
|
+
const rootJson = this.sanitizeCommandData("toJSON" in rootLoaded.data.command ? rootLoaded.data.command.toJSON() : rootLoaded.data.command);
|
|
2148
|
+
if (rootNode.executable) {
|
|
2149
|
+
if (!rootLoaded.data.chatInput) return null;
|
|
2150
|
+
return {
|
|
2151
|
+
...rootJson,
|
|
2152
|
+
type: discord_js.ApplicationCommandType.ChatInput,
|
|
2153
|
+
description: rootJson.description ?? "No command description set.",
|
|
2154
|
+
__metadata: rootLoaded.metadata ?? rootLoaded.data.metadata,
|
|
2155
|
+
__applyId: (id) => {
|
|
2156
|
+
rootLoaded.discordId = id;
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
const options = rootNode.childIds.map((childId) => this.buildHierarchicalOption(childId, treeNodes, hierarchicalNodes)).filter(Boolean);
|
|
2161
|
+
if (!options.length) return null;
|
|
2162
|
+
const scopeKeys = new Set(this.collectHierarchicalGuildScopes(rootNode.childIds, treeNodes, hierarchicalNodes));
|
|
2163
|
+
if (scopeKeys.size > 1) {
|
|
2164
|
+
Logger.error(`Failed to register hierarchical command "${rootJson.name ?? rootNode.token}": all chat-input leaves under the same root must use the same guild scope in v1.`);
|
|
2165
|
+
return null;
|
|
2166
|
+
}
|
|
2167
|
+
const scopeKey = scopeKeys.values().next().value;
|
|
2168
|
+
const scopeGuilds = scopeKey ? scopeKey.split(",").filter(Boolean) : [];
|
|
2169
|
+
const metadata = {
|
|
2170
|
+
...rootLoaded.metadata ?? rootLoaded.data.metadata,
|
|
2171
|
+
guilds: scopeGuilds.length ? scopeGuilds : void 0
|
|
2172
|
+
};
|
|
2173
|
+
return {
|
|
2174
|
+
...rootJson,
|
|
2175
|
+
type: discord_js.ApplicationCommandType.ChatInput,
|
|
2176
|
+
description: rootJson.description ?? "No command description set.",
|
|
2177
|
+
options,
|
|
2178
|
+
__metadata: metadata,
|
|
2179
|
+
__applyId: (id) => {
|
|
2180
|
+
rootLoaded.discordId = id;
|
|
2181
|
+
}
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
/**
|
|
2185
|
+
* Builds a nested subcommand or subcommand-group option from a hierarchical node.
|
|
2186
|
+
*/
|
|
2187
|
+
buildHierarchicalOption(nodeId, treeNodes, hierarchicalNodes) {
|
|
2188
|
+
const node = treeNodes.get(nodeId);
|
|
2189
|
+
const loadedNode = hierarchicalNodes.get(nodeId);
|
|
2190
|
+
if (!node || !loadedNode) return null;
|
|
2191
|
+
const json = this.sanitizeCommandData("toJSON" in loadedNode.data.command ? loadedNode.data.command.toJSON() : loadedNode.data.command);
|
|
2192
|
+
if (node.kind === "group") {
|
|
2193
|
+
const options = node.childIds.map((childId) => this.buildHierarchicalOption(childId, treeNodes, hierarchicalNodes)).filter(Boolean);
|
|
2194
|
+
if (!options.length) return null;
|
|
2195
|
+
return {
|
|
2196
|
+
...json,
|
|
2197
|
+
type: discord_js.ApplicationCommandOptionType.SubcommandGroup,
|
|
2198
|
+
description: json.description ?? "No command description set.",
|
|
2199
|
+
options
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
if (!node.executable || !loadedNode.data.chatInput) return null;
|
|
2203
|
+
return {
|
|
2204
|
+
...json,
|
|
2205
|
+
type: discord_js.ApplicationCommandOptionType.Subcommand,
|
|
2206
|
+
description: json.description ?? "No command description set."
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Collects normalized guild scopes for all chat-input leaves within a hierarchical subtree.
|
|
2211
|
+
*/
|
|
2212
|
+
collectHierarchicalGuildScopes(nodeIds, treeNodes, hierarchicalNodes) {
|
|
2213
|
+
const scopes = [];
|
|
2214
|
+
for (const nodeId of nodeIds) {
|
|
2215
|
+
var _loadedNode$metadata;
|
|
2216
|
+
const node = treeNodes.get(nodeId);
|
|
2217
|
+
const loadedNode = hierarchicalNodes.get(nodeId);
|
|
2218
|
+
if (!node || !loadedNode) continue;
|
|
2219
|
+
if (node.kind === "group") {
|
|
2220
|
+
scopes.push(...this.collectHierarchicalGuildScopes(node.childIds, treeNodes, hierarchicalNodes));
|
|
2221
|
+
continue;
|
|
2222
|
+
}
|
|
2223
|
+
if (!node.executable || !loadedNode.data.chatInput) continue;
|
|
2224
|
+
scopes.push((((_loadedNode$metadata = loadedNode.metadata) === null || _loadedNode$metadata === void 0 ? void 0 : _loadedNode$metadata.guilds) ?? []).filter(Boolean).slice().sort().join(","));
|
|
2225
|
+
}
|
|
2226
|
+
return scopes;
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2073
2229
|
* Registers loaded commands.
|
|
2074
2230
|
*/
|
|
2075
2231
|
async register() {
|
|
@@ -2234,12 +2390,27 @@ const middlewareDataSchema = {
|
|
|
2234
2390
|
* Manages both slash commands and message commands with middleware support.
|
|
2235
2391
|
*/
|
|
2236
2392
|
var AppCommandHandler = class {
|
|
2393
|
+
commandkit;
|
|
2237
2394
|
/**
|
|
2238
2395
|
* @private
|
|
2239
2396
|
* @internal
|
|
2240
2397
|
*/
|
|
2241
2398
|
loadedCommands = new discord_js.Collection();
|
|
2242
2399
|
/**
|
|
2400
|
+
* Executable runtime commands indexed by canonical route key.
|
|
2401
|
+
* This includes flat commands and hierarchical executable leaves.
|
|
2402
|
+
* @private
|
|
2403
|
+
* @internal
|
|
2404
|
+
*/
|
|
2405
|
+
runtimeRouteIndex = new discord_js.Collection();
|
|
2406
|
+
/**
|
|
2407
|
+
* Loaded hierarchical command nodes keyed by tree node id.
|
|
2408
|
+
* Container nodes are cached here for registration compilation.
|
|
2409
|
+
* @private
|
|
2410
|
+
* @internal
|
|
2411
|
+
*/
|
|
2412
|
+
hierarchicalNodes = new discord_js.Collection();
|
|
2413
|
+
/**
|
|
2243
2414
|
* @private
|
|
2244
2415
|
* @internal
|
|
2245
2416
|
*/
|
|
@@ -2282,31 +2453,56 @@ var AppCommandHandler = class {
|
|
|
2282
2453
|
* Prints a formatted banner showing all loaded commands organized by category.
|
|
2283
2454
|
*/
|
|
2284
2455
|
printBanner() {
|
|
2456
|
+
var _this$commandkit$comm;
|
|
2285
2457
|
const uncategorized = crypto.randomUUID();
|
|
2286
|
-
const
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2458
|
+
const flatCommands = this.getCommandsArray();
|
|
2459
|
+
const treeNodes = Array.from(((_this$commandkit$comm = this.commandkit.commandsRouter) === null || _this$commandkit$comm === void 0 ? void 0 : _this$commandkit$comm.getData().treeNodes.values()) ?? []);
|
|
2460
|
+
const hierarchicalRoots = treeNodes.filter((n) => n.kind === "command" && n.source !== "root");
|
|
2461
|
+
const totalCount = flatCommands.length + hierarchicalRoots.length;
|
|
2462
|
+
console.log(require_utils_colors.default.green(`Loaded ${require_utils_colors.default.magenta(totalCount.toString())} commands:`));
|
|
2463
|
+
const printHierarchicalNode = (nodeId, prefix, indent) => {
|
|
2464
|
+
const node = treeNodes.find((n) => n.id === nodeId);
|
|
2465
|
+
if (!node || node.kind === "root") return;
|
|
2466
|
+
const loadedNode = this.hierarchicalNodes.get(nodeId);
|
|
2467
|
+
const hasMw = loadedNode && loadedNode.command.middlewares.length > 0 ? require_utils_colors.default.magenta(" (λ)") : "";
|
|
2468
|
+
const kindLabel = node.kind === "group" ? require_utils_colors.default.cyan(` [group]`) : node.kind === "command" ? "" : "";
|
|
2469
|
+
console.log(`${require_utils_colors.default.green(prefix)} ${require_utils_colors.default.yellow(node.token)}${kindLabel}${hasMw}`);
|
|
2470
|
+
const children = node.childIds;
|
|
2471
|
+
children.forEach((childId, idx) => {
|
|
2472
|
+
const isLastChild = idx === children.length - 1;
|
|
2473
|
+
const childPrefix = indent + (isLastChild ? "└─" : "├─");
|
|
2474
|
+
const childIndent = indent + (isLastChild ? " " : "│ ");
|
|
2475
|
+
printHierarchicalNode(childId, childPrefix, childIndent);
|
|
2476
|
+
});
|
|
2477
|
+
};
|
|
2478
|
+
const categoryBuckets = {};
|
|
2479
|
+
const ensureBucket = (cat) => {
|
|
2480
|
+
categoryBuckets[cat] ??= {
|
|
2481
|
+
flat: [],
|
|
2482
|
+
hierarchical: []
|
|
2483
|
+
};
|
|
2484
|
+
};
|
|
2485
|
+
for (const cmd of flatCommands) {
|
|
2486
|
+
const cat = cmd.command.category || uncategorized;
|
|
2487
|
+
ensureBucket(cat);
|
|
2488
|
+
categoryBuckets[cat].flat.push(cmd);
|
|
2489
|
+
}
|
|
2490
|
+
for (const root of hierarchicalRoots) {
|
|
2491
|
+
const cat = root.category || uncategorized;
|
|
2492
|
+
ensureBucket(cat);
|
|
2493
|
+
categoryBuckets[cat].hierarchical.push(root);
|
|
2494
|
+
}
|
|
2495
|
+
const categories = Object.keys(categoryBuckets).sort();
|
|
2294
2496
|
const categoryTree = {};
|
|
2295
2497
|
categories.forEach((category) => {
|
|
2296
|
-
if (category === uncategorized) return;
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
break;
|
|
2305
|
-
}
|
|
2306
|
-
}
|
|
2307
|
-
if (bestParent) {
|
|
2308
|
-
categoryTree[bestParent] = categoryTree[bestParent] || [];
|
|
2309
|
-
categoryTree[bestParent].push(category);
|
|
2498
|
+
if (category === uncategorized || !category.includes(":")) return;
|
|
2499
|
+
const parts = category.split(":");
|
|
2500
|
+
for (let i = parts.length - 1; i > 0; i--) {
|
|
2501
|
+
const potentialParent = parts.slice(0, i).join(":");
|
|
2502
|
+
if (categories.includes(potentialParent)) {
|
|
2503
|
+
categoryTree[potentialParent] ??= [];
|
|
2504
|
+
categoryTree[potentialParent].push(category);
|
|
2505
|
+
break;
|
|
2310
2506
|
}
|
|
2311
2507
|
}
|
|
2312
2508
|
});
|
|
@@ -2314,25 +2510,45 @@ var AppCommandHandler = class {
|
|
|
2314
2510
|
const printCategory = (category, indent = "", isLast = false, parentPrefix = "") => {
|
|
2315
2511
|
if (processedCategories.has(category)) return;
|
|
2316
2512
|
processedCategories.add(category);
|
|
2317
|
-
const
|
|
2513
|
+
const bucket = categoryBuckets[category];
|
|
2318
2514
|
const hasChildren = categoryTree[category] && categoryTree[category].length > 0;
|
|
2515
|
+
const allEntries = [...bucket.flat, ...bucket.hierarchical];
|
|
2319
2516
|
const thisPrefix = isLast ? "└─" : "├─";
|
|
2320
2517
|
const childIndent = parentPrefix + (isLast ? " " : "│ ");
|
|
2321
2518
|
if (category !== uncategorized) {
|
|
2322
2519
|
const displayName = category.includes(":") ? category.split(":").pop() : category;
|
|
2323
2520
|
console.log(require_utils_colors.default.cyan(`${indent}${thisPrefix} ${require_utils_colors.default.bold(displayName)}`));
|
|
2324
2521
|
}
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2522
|
+
const cmdIndent = category !== uncategorized ? childIndent : indent;
|
|
2523
|
+
const totalEntries = allEntries.length;
|
|
2524
|
+
let entryIndex = 0;
|
|
2525
|
+
bucket.flat.forEach((cmd) => {
|
|
2526
|
+
const cmdPrefix = entryIndex === totalEntries - 1 && !hasChildren ? "└─" : "├─";
|
|
2328
2527
|
const name = cmd.data.command.name;
|
|
2329
2528
|
const middlewareIcon = cmd.command.middlewares.length > 0 ? require_utils_colors.default.magenta(" (λ)") : "";
|
|
2330
2529
|
console.log(`${require_utils_colors.default.green(`${cmdIndent}${cmdPrefix}`)} ${require_utils_colors.default.yellow(name)}${middlewareIcon}`);
|
|
2530
|
+
entryIndex++;
|
|
2531
|
+
});
|
|
2532
|
+
bucket.hierarchical.forEach((root) => {
|
|
2533
|
+
const isLastEntry = entryIndex === totalEntries - 1 && !hasChildren;
|
|
2534
|
+
const rootPrefix = cmdIndent + (isLastEntry ? "└─" : "├─");
|
|
2535
|
+
const rootChildIndent = cmdIndent + (isLastEntry ? " " : "│ ");
|
|
2536
|
+
const loadedNode = this.hierarchicalNodes.get(root.id);
|
|
2537
|
+
const hasMw = loadedNode && loadedNode.command.middlewares.length > 0 ? require_utils_colors.default.magenta(" (λ)") : "";
|
|
2538
|
+
console.log(`${require_utils_colors.default.green(rootPrefix)} ${require_utils_colors.default.yellow(root.token)}${hasMw}`);
|
|
2539
|
+
root.childIds.forEach((childId, idx) => {
|
|
2540
|
+
const isLastChild = idx === root.childIds.length - 1;
|
|
2541
|
+
const childPrefix = rootChildIndent + (isLastChild ? "└─" : "├─");
|
|
2542
|
+
const childIndentNext = rootChildIndent + (isLastChild ? " " : "│ ");
|
|
2543
|
+
printHierarchicalNode(childId, childPrefix, childIndentNext);
|
|
2544
|
+
});
|
|
2545
|
+
entryIndex++;
|
|
2331
2546
|
});
|
|
2332
2547
|
if (hasChildren) {
|
|
2333
2548
|
const children = categoryTree[category].sort();
|
|
2334
2549
|
children.forEach((childCategory, idx) => {
|
|
2335
|
-
|
|
2550
|
+
const childIsLast = idx === children.length - 1;
|
|
2551
|
+
printCategory(childCategory, childIndent, childIsLast, childIndent);
|
|
2336
2552
|
});
|
|
2337
2553
|
}
|
|
2338
2554
|
};
|
|
@@ -2349,17 +2565,32 @@ var AppCommandHandler = class {
|
|
|
2349
2565
|
return true;
|
|
2350
2566
|
}).sort();
|
|
2351
2567
|
topLevelCategories.forEach((category, index) => {
|
|
2352
|
-
|
|
2568
|
+
const isLast = index === topLevelCategories.length - 1;
|
|
2569
|
+
printCategory(category, "", isLast);
|
|
2353
2570
|
});
|
|
2354
2571
|
}
|
|
2355
2572
|
/**
|
|
2356
|
-
* Gets an array of all loaded commands.
|
|
2573
|
+
* Gets an array of all loaded commands, including pre-generated context menu entries.
|
|
2357
2574
|
* @returns Array of loaded commands
|
|
2358
2575
|
*/
|
|
2359
2576
|
getCommandsArray() {
|
|
2360
2577
|
return Array.from(this.loadedCommands.values());
|
|
2361
2578
|
}
|
|
2362
2579
|
/**
|
|
2580
|
+
* Gets all executable runtime routes, including hierarchical leaves.
|
|
2581
|
+
* @returns Array of route-indexed commands
|
|
2582
|
+
*/
|
|
2583
|
+
getRuntimeCommandsArray() {
|
|
2584
|
+
return Array.from(this.runtimeRouteIndex.values());
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* Gets loaded hierarchical command nodes, including non-executable containers.
|
|
2588
|
+
* @returns Array of hierarchical node definitions
|
|
2589
|
+
*/
|
|
2590
|
+
getHierarchicalNodesArray() {
|
|
2591
|
+
return Array.from(this.hierarchicalNodes.values());
|
|
2592
|
+
}
|
|
2593
|
+
/**
|
|
2363
2594
|
* Registers event handlers for Discord interactions and messages.
|
|
2364
2595
|
*/
|
|
2365
2596
|
registerCommandHandler() {
|
|
@@ -2385,6 +2616,35 @@ var AppCommandHandler = class {
|
|
|
2385
2616
|
this.commandkit.client.on(discord_js.Events.MessageCreate, this.onMessageCreate);
|
|
2386
2617
|
}
|
|
2387
2618
|
/**
|
|
2619
|
+
* @private
|
|
2620
|
+
* @internal
|
|
2621
|
+
*/
|
|
2622
|
+
normalizeRouteKey(input) {
|
|
2623
|
+
return input.trim().replace(/[.:]/g, " ").split(/\s+/).filter(Boolean).join(".");
|
|
2624
|
+
}
|
|
2625
|
+
/**
|
|
2626
|
+
* @private
|
|
2627
|
+
* @internal
|
|
2628
|
+
*/
|
|
2629
|
+
buildInteractionRouteKey(source) {
|
|
2630
|
+
if (!source.isCommand() && !source.isAutocomplete()) return "";
|
|
2631
|
+
const segments = [source.commandName];
|
|
2632
|
+
if (source.isChatInputCommand() || source.isAutocomplete()) {
|
|
2633
|
+
const group = source.options.getSubcommandGroup(false);
|
|
2634
|
+
const subcommand = source.options.getSubcommand(false);
|
|
2635
|
+
if (group) segments.push(group);
|
|
2636
|
+
if (subcommand) segments.push(subcommand);
|
|
2637
|
+
}
|
|
2638
|
+
return segments.filter(Boolean).join(".");
|
|
2639
|
+
}
|
|
2640
|
+
/**
|
|
2641
|
+
* @private
|
|
2642
|
+
* @internal
|
|
2643
|
+
*/
|
|
2644
|
+
buildMessageRouteKey(parser) {
|
|
2645
|
+
return parser.getFullRoute().join(".");
|
|
2646
|
+
}
|
|
2647
|
+
/**
|
|
2388
2648
|
* Prepares a command for execution by resolving the command and its middleware.
|
|
2389
2649
|
* @param source - The interaction or message that triggered the command
|
|
2390
2650
|
* @param cmdName - Optional command name override
|
|
@@ -2394,13 +2654,15 @@ var AppCommandHandler = class {
|
|
|
2394
2654
|
var _loadedCommand$metada3, _loadedCommand$metada4;
|
|
2395
2655
|
if (getConfig().disablePrefixCommands && source instanceof discord_js.Message) return null;
|
|
2396
2656
|
let parser;
|
|
2397
|
-
|
|
2657
|
+
let routeKey;
|
|
2658
|
+
if (cmdName) routeKey = this.normalizeRouteKey(cmdName);
|
|
2659
|
+
if (!routeKey) if (source instanceof discord_js.Message) {
|
|
2398
2660
|
if (source.author.bot) return null;
|
|
2399
2661
|
const prefix = await this.commandkit.appConfig.getMessageCommandPrefix(source);
|
|
2400
2662
|
if (!prefix || (typeof prefix === "string" || Array.isArray(prefix)) && !prefix.length) return null;
|
|
2401
2663
|
parser = new require_app_commands_MessageCommandParser.MessageCommandParser(source, prefix instanceof RegExp ? prefix : Array.isArray(prefix) ? prefix : [prefix], (command) => {
|
|
2402
2664
|
var _loadedCommand$metada, _loadedCommand$metada2, _json$options;
|
|
2403
|
-
const loadedCommand = this.
|
|
2665
|
+
const loadedCommand = this.findCommandByRoute(command);
|
|
2404
2666
|
if (!loadedCommand) {
|
|
2405
2667
|
if (require_utils_constants.COMMANDKIT_IS_DEV && this.commandkit.config.showUnknownPrefixCommandsWarning) Logger.error`Prefix command "${command}" was not found.\nNote: This warning is only shown in development mode as an alert to help you find the command. If you wish to remove this warning, set \`showUnknownPrefixCommandsWarning\` to \`false\` in your commandkit config.`;
|
|
2406
2668
|
return null;
|
|
@@ -2412,7 +2674,7 @@ var AppCommandHandler = class {
|
|
|
2412
2674
|
}, {})) ?? {};
|
|
2413
2675
|
});
|
|
2414
2676
|
try {
|
|
2415
|
-
|
|
2677
|
+
routeKey = this.buildMessageRouteKey(parser);
|
|
2416
2678
|
} catch (e) {
|
|
2417
2679
|
if (require_utils_error_codes.isErrorType(e, require_utils_error_codes.CommandKitErrorCodes.InvalidCommandPrefix)) return null;
|
|
2418
2680
|
Logger.error`${e}`;
|
|
@@ -2420,10 +2682,10 @@ var AppCommandHandler = class {
|
|
|
2420
2682
|
}
|
|
2421
2683
|
} else {
|
|
2422
2684
|
if (!(source.isChatInputCommand() || source.isAutocomplete() || source.isContextMenuCommand())) return null;
|
|
2423
|
-
|
|
2685
|
+
routeKey = this.buildInteractionRouteKey(source);
|
|
2424
2686
|
}
|
|
2425
2687
|
const hint = require_app_commands_helpers.isInteractionSource(source) ? source.isUserContextMenuCommand() ? "user" : source.isMessageContextMenuCommand() ? "message" : void 0 : void 0;
|
|
2426
|
-
const loadedCommand = this.findCommandByName(
|
|
2688
|
+
const loadedCommand = hint ? this.findCommandByName(routeKey, hint) : this.findCommandByRoute(routeKey);
|
|
2427
2689
|
if (!loadedCommand) return null;
|
|
2428
2690
|
if ((source instanceof discord_js.CommandInteraction || source instanceof discord_js.AutocompleteInteraction) && source.guildId && ((_loadedCommand$metada3 = loadedCommand.metadata) === null || _loadedCommand$metada3 === void 0 || (_loadedCommand$metada3 = _loadedCommand$metada3.guilds) === null || _loadedCommand$metada3 === void 0 ? void 0 : _loadedCommand$metada3.length) && !((_loadedCommand$metada4 = loadedCommand.metadata) === null || _loadedCommand$metada4 === void 0 ? void 0 : _loadedCommand$metada4.guilds.includes(source.guildId))) return null;
|
|
2429
2691
|
if (source instanceof discord_js.Message) {
|
|
@@ -2474,21 +2736,51 @@ var AppCommandHandler = class {
|
|
|
2474
2736
|
}
|
|
2475
2737
|
return null;
|
|
2476
2738
|
}
|
|
2477
|
-
|
|
2478
|
-
|
|
2739
|
+
/**
|
|
2740
|
+
* Finds a command by its canonical route key.
|
|
2741
|
+
* @param route - The command route or command name
|
|
2742
|
+
* @param allowFlatAliasFallback - Whether to check flat aliases if the route key was not found
|
|
2743
|
+
* @returns The loaded command or null if not found
|
|
2744
|
+
*/
|
|
2745
|
+
findCommandByRoute(route, allowFlatAliasFallback = true) {
|
|
2746
|
+
const normalizedRoute = this.normalizeRouteKey(route);
|
|
2747
|
+
const directMatch = this.runtimeRouteIndex.get(normalizedRoute);
|
|
2748
|
+
if (directMatch) return directMatch;
|
|
2749
|
+
if (!allowFlatAliasFallback || normalizedRoute.includes(".")) return null;
|
|
2750
|
+
for (const loadedCommand of this.runtimeRouteIndex.values()) {
|
|
2479
2751
|
var _loadedCommand$data$m3;
|
|
2480
|
-
if (loadedCommand.data.command.name === name) return loadedCommand.data.command.name;
|
|
2481
2752
|
const aliases = (_loadedCommand$data$m3 = loadedCommand.data.metadata) === null || _loadedCommand$data$m3 === void 0 ? void 0 : _loadedCommand$data$m3.aliases;
|
|
2482
|
-
if (aliases && Array.isArray(aliases) && aliases.includes(
|
|
2753
|
+
if (aliases && Array.isArray(aliases) && aliases.includes(normalizedRoute)) return loadedCommand;
|
|
2483
2754
|
}
|
|
2755
|
+
return null;
|
|
2756
|
+
}
|
|
2757
|
+
/**
|
|
2758
|
+
* @private
|
|
2759
|
+
* @internal
|
|
2760
|
+
*/
|
|
2761
|
+
getRouteKeyFor(command) {
|
|
2762
|
+
return command.data.command.__routeKey ?? this.normalizeRouteKey(command.data.command.name);
|
|
2763
|
+
}
|
|
2764
|
+
resolveMessageCommandName(name) {
|
|
2765
|
+
const loadedCommand = this.findCommandByRoute(name);
|
|
2766
|
+
if (loadedCommand) return this.getRouteKeyFor(loadedCommand);
|
|
2484
2767
|
return name;
|
|
2485
2768
|
}
|
|
2486
2769
|
/**
|
|
2487
2770
|
* Reloads all commands and middleware from scratch.
|
|
2488
2771
|
*/
|
|
2489
|
-
async reloadCommands() {
|
|
2772
|
+
async reloadCommands(path, changeType) {
|
|
2773
|
+
if (this.commandkit.config.experimental.incrementalRouter && path) {
|
|
2774
|
+
var _this$commandkit$comm2;
|
|
2775
|
+
await ((_this$commandkit$comm2 = this.commandkit.commandsRouter) === null || _this$commandkit$comm2 === void 0 ? void 0 : _this$commandkit$comm2.scanIncremental(path, changeType));
|
|
2776
|
+
} else {
|
|
2777
|
+
var _this$commandkit$comm3;
|
|
2778
|
+
await ((_this$commandkit$comm3 = this.commandkit.commandsRouter) === null || _this$commandkit$comm3 === void 0 ? void 0 : _this$commandkit$comm3.scan());
|
|
2779
|
+
}
|
|
2490
2780
|
this.loadedCommands.clear();
|
|
2491
2781
|
this.loadedMiddlewares.clear();
|
|
2782
|
+
this.runtimeRouteIndex.clear();
|
|
2783
|
+
this.hierarchicalNodes.clear();
|
|
2492
2784
|
this.externalCommandData.clear();
|
|
2493
2785
|
this.externalMiddlewareData.clear();
|
|
2494
2786
|
await this.loadCommands();
|
|
@@ -2525,7 +2817,10 @@ var AppCommandHandler = class {
|
|
|
2525
2817
|
* @param data - Array of loaded commands to register
|
|
2526
2818
|
*/
|
|
2527
2819
|
async registerExternalLoadedCommands(data) {
|
|
2528
|
-
for (const command of data)
|
|
2820
|
+
for (const command of data) {
|
|
2821
|
+
this.loadedCommands.set(command.command.id, command);
|
|
2822
|
+
this.registerRuntimeRoute(command);
|
|
2823
|
+
}
|
|
2529
2824
|
}
|
|
2530
2825
|
/**
|
|
2531
2826
|
* Loads all commands and middleware from the router.
|
|
@@ -2536,15 +2831,20 @@ var AppCommandHandler = class {
|
|
|
2536
2831
|
});
|
|
2537
2832
|
const commandsRouter = this.commandkit.commandsRouter;
|
|
2538
2833
|
if (!commandsRouter) throw new Error("Commands router has not yet initialized");
|
|
2539
|
-
const { commands, middlewares } = commandsRouter.getData();
|
|
2834
|
+
const { commands, middlewares, treeNodes, compiledRoutes } = commandsRouter.getData();
|
|
2540
2835
|
const combinedCommands = this.externalCommandData.size ? commands.concat(this.externalCommandData) : commands;
|
|
2541
2836
|
const combinedMiddlewares = this.externalMiddlewareData.size ? middlewares.concat(this.externalMiddlewareData) : middlewares;
|
|
2542
2837
|
for (const [id, middleware] of combinedMiddlewares) await this.loadMiddleware(id, middleware);
|
|
2543
2838
|
for (const [id, command] of combinedCommands) await this.loadCommand(id, command);
|
|
2839
|
+
const hierarchicalNodes = Array.from(treeNodes.values()).filter((node) => node.source !== "flat" && !!node.definitionPath).sort((left, right) => left.route.length - right.route.length);
|
|
2840
|
+
for (const node of hierarchicalNodes) {
|
|
2841
|
+
const routeKey = node.route.join(".");
|
|
2842
|
+
await this.loadHierarchicalNode(node, compiledRoutes.get(routeKey) ?? void 0);
|
|
2843
|
+
}
|
|
2544
2844
|
if (require_utils_constants.COMMANDKIT_IS_DEV) {
|
|
2545
|
-
const commandNames = Array.from(this.
|
|
2546
|
-
const aliases = Array.from(this.
|
|
2547
|
-
await require_utils_types_package.rewriteCommandDeclaration(
|
|
2845
|
+
const commandNames = Array.from(this.runtimeRouteIndex.keys());
|
|
2846
|
+
const aliases = Array.from(this.runtimeRouteIndex.values()).flatMap((v) => v.metadata.aliases || []);
|
|
2847
|
+
await require_utils_types_package.rewriteCommandDeclaration(Array.from(/* @__PURE__ */ new Set([...commandNames, ...aliases])));
|
|
2548
2848
|
}
|
|
2549
2849
|
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
2550
2850
|
return plugin.onAfterCommandsLoad(ctx);
|
|
@@ -2575,10 +2875,84 @@ var AppCommandHandler = class {
|
|
|
2575
2875
|
* @private
|
|
2576
2876
|
* @internal
|
|
2577
2877
|
*/
|
|
2878
|
+
shouldIndexAsRuntimeRoute(command) {
|
|
2879
|
+
return !!(command.data.chatInput || command.data.message || command.data.autocomplete);
|
|
2880
|
+
}
|
|
2881
|
+
/**
|
|
2882
|
+
* @private
|
|
2883
|
+
* @internal
|
|
2884
|
+
*/
|
|
2885
|
+
registerRuntimeRoute(command, routeKey) {
|
|
2886
|
+
if (!this.shouldIndexAsRuntimeRoute(command)) return;
|
|
2887
|
+
const key = this.normalizeRouteKey(routeKey ?? command.data.command.name);
|
|
2888
|
+
if (!key) return;
|
|
2889
|
+
const commandData = command.data.command;
|
|
2890
|
+
commandData.__routeKey ??= key;
|
|
2891
|
+
this.runtimeRouteIndex.set(key, command);
|
|
2892
|
+
}
|
|
2893
|
+
/**
|
|
2894
|
+
* @private
|
|
2895
|
+
* @internal
|
|
2896
|
+
*/
|
|
2897
|
+
async processCommandFile(fileUrl, identifier, fallbackName, isHierarchical) {
|
|
2898
|
+
const commandFileData = await import(`${require_utils_resolve_file_url.toFileURL(fileUrl)}?t=${Date.now()}`);
|
|
2899
|
+
if (!commandFileData.command) throw new Error(`Invalid export for ${isHierarchical ? "hierarchical node" : "command"} ${identifier}: no command definition found`);
|
|
2900
|
+
const metadataFunc = commandFileData.generateMetadata;
|
|
2901
|
+
const metadataObj = commandFileData.metadata;
|
|
2902
|
+
if (metadataFunc && metadataObj) throw new Error("A command may only export either `generateMetadata` or `metadata`, not both");
|
|
2903
|
+
const metadata = (metadataFunc ? await metadataFunc() : metadataObj) ?? {
|
|
2904
|
+
aliases: [],
|
|
2905
|
+
guilds: [],
|
|
2906
|
+
userPermissions: [],
|
|
2907
|
+
botPermissions: []
|
|
2908
|
+
};
|
|
2909
|
+
let commandName = commandFileData.command.name;
|
|
2910
|
+
if (isHierarchical) {
|
|
2911
|
+
if (typeof commandName === "string" && commandName !== fallbackName) Logger.warn(`Hierarchical node \`${identifier}\` overrides its command name with \`${commandName}\`. The filesystem token \`${fallbackName}\` will be used instead.`);
|
|
2912
|
+
commandName = fallbackName;
|
|
2913
|
+
} else commandName = commandName || fallbackName;
|
|
2914
|
+
let commandDescription = commandFileData.command.description;
|
|
2915
|
+
if (!commandDescription && commandFileData.chatInput) commandDescription = "No command description set.";
|
|
2916
|
+
const updatedCommandData = {
|
|
2917
|
+
...commandFileData.command,
|
|
2918
|
+
name: commandName,
|
|
2919
|
+
description: commandDescription
|
|
2920
|
+
};
|
|
2921
|
+
let handlerCount = 0;
|
|
2922
|
+
for (const [key, propValidator] of Object.entries(commandDataSchema)) {
|
|
2923
|
+
const exportedProp = commandFileData[key];
|
|
2924
|
+
if (exportedProp) {
|
|
2925
|
+
if (!await propValidator(exportedProp)) throw new Error(`Invalid export for ${isHierarchical ? "hierarchical node" : "command"} ${identifier}: ${key} does not match expected value`);
|
|
2926
|
+
if (!KNOWN_NON_HANDLER_KEYS.includes(key)) handlerCount++;
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
let lastUpdated = updatedCommandData;
|
|
2930
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
2931
|
+
const res = await plugin.prepareCommand(ctx, lastUpdated);
|
|
2932
|
+
if (res) lastUpdated = res;
|
|
2933
|
+
});
|
|
2934
|
+
const commandJson = "toJSON" in lastUpdated && typeof lastUpdated.toJSON === "function" ? lastUpdated.toJSON() : lastUpdated;
|
|
2935
|
+
if ("guilds" in commandJson || "aliases" in commandJson) Logger.warn(`Command \`${identifier}\` uses deprecated metadata properties. Please update to use the new \`metadata\` object or \`generateMetadata\` function.`);
|
|
2936
|
+
const resolvedMetadata = {
|
|
2937
|
+
guilds: commandJson.guilds,
|
|
2938
|
+
aliases: commandJson.aliases,
|
|
2939
|
+
...metadata
|
|
2940
|
+
};
|
|
2941
|
+
return {
|
|
2942
|
+
commandFileData,
|
|
2943
|
+
handlerCount,
|
|
2944
|
+
commandJson,
|
|
2945
|
+
resolvedMetadata
|
|
2946
|
+
};
|
|
2947
|
+
}
|
|
2948
|
+
/**
|
|
2949
|
+
* @private
|
|
2950
|
+
* @internal
|
|
2951
|
+
*/
|
|
2578
2952
|
async loadCommand(id, command) {
|
|
2579
2953
|
try {
|
|
2580
2954
|
if (command.path === null) {
|
|
2581
|
-
|
|
2955
|
+
const loadedCommand = {
|
|
2582
2956
|
discordId: null,
|
|
2583
2957
|
command,
|
|
2584
2958
|
metadata: {
|
|
@@ -2588,74 +2962,90 @@ var AppCommandHandler = class {
|
|
|
2588
2962
|
botPermissions: []
|
|
2589
2963
|
},
|
|
2590
2964
|
data: { command: { name: command.name } }
|
|
2591
|
-
}
|
|
2965
|
+
};
|
|
2966
|
+
this.loadedCommands.set(id, loadedCommand);
|
|
2967
|
+
this.registerRuntimeRoute(loadedCommand);
|
|
2592
2968
|
return;
|
|
2593
2969
|
}
|
|
2594
|
-
const commandFileData = await
|
|
2595
|
-
if (!commandFileData.command) throw new Error(`Invalid export for command ${command.name}: no command definition found`);
|
|
2596
|
-
const metadataFunc = commandFileData.generateMetadata;
|
|
2597
|
-
const metadataObj = commandFileData.metadata;
|
|
2598
|
-
if (metadataFunc && metadataObj) throw new Error("A command may only export either `generateMetadata` or `metadata`, not both");
|
|
2599
|
-
const metadata = (metadataFunc ? await metadataFunc() : metadataObj) ?? {
|
|
2600
|
-
aliases: [],
|
|
2601
|
-
guilds: [],
|
|
2602
|
-
userPermissions: [],
|
|
2603
|
-
botPermissions: []
|
|
2604
|
-
};
|
|
2605
|
-
const commandName = commandFileData.command.name || command.name;
|
|
2606
|
-
let commandDescription = commandFileData.command.description;
|
|
2607
|
-
if (!commandDescription && commandFileData.chatInput) commandDescription = "No command description set.";
|
|
2608
|
-
const updatedCommandData = {
|
|
2609
|
-
...commandFileData.command,
|
|
2610
|
-
name: commandName,
|
|
2611
|
-
description: commandDescription
|
|
2612
|
-
};
|
|
2613
|
-
let handlerCount = 0;
|
|
2614
|
-
for (const [key, propValidator] of Object.entries(commandDataSchema)) {
|
|
2615
|
-
const exportedProp = commandFileData[key];
|
|
2616
|
-
if (exportedProp) {
|
|
2617
|
-
if (!await propValidator(exportedProp)) throw new Error(`Invalid export for command ${command.name}: ${key} does not match expected value`);
|
|
2618
|
-
if (!KNOWN_NON_HANDLER_KEYS.includes(key)) handlerCount++;
|
|
2619
|
-
}
|
|
2620
|
-
}
|
|
2970
|
+
const { commandFileData, handlerCount, commandJson, resolvedMetadata } = await this.processCommandFile(command.path, command.name, command.name, false);
|
|
2621
2971
|
if (handlerCount === 0) throw new Error(`Invalid export for command ${command.name}: at least one handler function must be provided`);
|
|
2622
|
-
|
|
2623
|
-
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
2624
|
-
const res = await plugin.prepareCommand(ctx, lastUpdated);
|
|
2625
|
-
if (res) lastUpdated = res;
|
|
2626
|
-
});
|
|
2627
|
-
const commandJson = "toJSON" in lastUpdated && typeof lastUpdated.toJSON === "function" ? lastUpdated.toJSON() : lastUpdated;
|
|
2628
|
-
if ("guilds" in commandJson || "aliases" in commandJson) Logger.warn(`Command \`${command.name}\` uses deprecated metadata properties. Please update to use the new \`metadata\` object or \`generateMetadata\` function.`);
|
|
2629
|
-
this.loadedCommands.set(id, {
|
|
2972
|
+
const loadedCommand = {
|
|
2630
2973
|
discordId: null,
|
|
2631
2974
|
command,
|
|
2632
|
-
metadata:
|
|
2633
|
-
guilds: commandJson.guilds,
|
|
2634
|
-
aliases: commandJson.aliases,
|
|
2635
|
-
...metadata
|
|
2636
|
-
},
|
|
2975
|
+
metadata: resolvedMetadata,
|
|
2637
2976
|
data: {
|
|
2638
2977
|
...commandFileData,
|
|
2639
|
-
metadata:
|
|
2640
|
-
guilds: commandJson.guilds,
|
|
2641
|
-
aliases: commandJson.aliases,
|
|
2642
|
-
...metadata
|
|
2643
|
-
},
|
|
2978
|
+
metadata: resolvedMetadata,
|
|
2644
2979
|
command: commandJson
|
|
2645
2980
|
}
|
|
2646
|
-
}
|
|
2981
|
+
};
|
|
2982
|
+
this.loadedCommands.set(id, loadedCommand);
|
|
2983
|
+
this.registerRuntimeRoute(loadedCommand);
|
|
2984
|
+
this.generateContextMenuCommands(id, command, commandFileData, commandJson, resolvedMetadata);
|
|
2647
2985
|
} catch (error) {
|
|
2648
2986
|
Logger.error`Failed to load command ${command.name} (${id}): ${error}`;
|
|
2649
2987
|
}
|
|
2650
2988
|
}
|
|
2651
2989
|
/**
|
|
2990
|
+
* Loads a hierarchical command node into the hierarchical cache.
|
|
2991
|
+
* Executable leaves are also added to the runtime route index.
|
|
2992
|
+
* @private
|
|
2993
|
+
* @internal
|
|
2994
|
+
*/
|
|
2995
|
+
async loadHierarchicalNode(node, compiledRoute) {
|
|
2996
|
+
if (!node.definitionPath) return;
|
|
2997
|
+
const routeKey = node.route.join(".");
|
|
2998
|
+
const command = {
|
|
2999
|
+
id: node.id,
|
|
3000
|
+
name: routeKey,
|
|
3001
|
+
path: node.definitionPath,
|
|
3002
|
+
relativePath: (compiledRoute === null || compiledRoute === void 0 ? void 0 : compiledRoute.relativePath) ?? node.relativePath,
|
|
3003
|
+
parentPath: (0, node_path.dirname)(node.definitionPath),
|
|
3004
|
+
middlewares: compiledRoute ? [...compiledRoute.middlewares] : [],
|
|
3005
|
+
category: node.category
|
|
3006
|
+
};
|
|
3007
|
+
try {
|
|
3008
|
+
const { commandFileData, handlerCount, commandJson, resolvedMetadata } = await this.processCommandFile(command.path, routeKey, node.token, true);
|
|
3009
|
+
const isRootHierarchyLeaf = node.kind === "command";
|
|
3010
|
+
const hasContextMenuHandlers = !!(commandFileData.userContextMenu || commandFileData.messageContextMenu);
|
|
3011
|
+
const hasExecutableSlashHandlers = !!(commandFileData.chatInput || commandFileData.message || commandFileData.autocomplete);
|
|
3012
|
+
const sanitizedCommandFileData = { ...commandFileData };
|
|
3013
|
+
if (!isRootHierarchyLeaf && hasContextMenuHandlers) throw new Error(`Invalid export for hierarchical node ${routeKey}: context menu handlers are only supported for top-level root commands.`);
|
|
3014
|
+
if (node.executable && handlerCount === 0) throw new Error(`Invalid export for hierarchical node ${routeKey}: executable leaves must provide at least one handler function`);
|
|
3015
|
+
if (!node.executable && hasExecutableSlashHandlers) {
|
|
3016
|
+
Logger.warn`Ignoring ${require_utils_colors.default.yellow("executable handlers")} exported by ${require_utils_colors.default.cyan("[non-leaf]")} hierarchical node ${require_utils_colors.default.magenta(`[${routeKey}]`)}. Move ${require_utils_colors.default.yellow("chatInput")}, ${require_utils_colors.default.yellow("message")}, or ${require_utils_colors.default.yellow("autocomplete")} handlers to a ${require_utils_colors.default.green("[leaf]")} command node.`;
|
|
3017
|
+
delete sanitizedCommandFileData.chatInput;
|
|
3018
|
+
delete sanitizedCommandFileData.message;
|
|
3019
|
+
delete sanitizedCommandFileData.autocomplete;
|
|
3020
|
+
}
|
|
3021
|
+
const loadedCommand = {
|
|
3022
|
+
discordId: null,
|
|
3023
|
+
command,
|
|
3024
|
+
metadata: resolvedMetadata,
|
|
3025
|
+
data: {
|
|
3026
|
+
...sanitizedCommandFileData,
|
|
3027
|
+
metadata: resolvedMetadata,
|
|
3028
|
+
command: {
|
|
3029
|
+
...commandJson,
|
|
3030
|
+
__routeKey: routeKey
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
};
|
|
3034
|
+
this.hierarchicalNodes.set(node.id, loadedCommand);
|
|
3035
|
+
if (node.executable) this.registerRuntimeRoute(loadedCommand, routeKey);
|
|
3036
|
+
if (isRootHierarchyLeaf && hasContextMenuHandlers) this.generateContextMenuCommands(node.id, command, commandFileData, commandJson, resolvedMetadata);
|
|
3037
|
+
} catch (error) {
|
|
3038
|
+
Logger.error`Failed to load hierarchical node ${routeKey} (${node.id}): ${error}`;
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
/**
|
|
2652
3042
|
* Gets the metadata for a command.
|
|
2653
3043
|
* @param command - The command name to get metadata for
|
|
2654
3044
|
* @param hint - The hint for the command type (user or message)
|
|
2655
3045
|
* @returns The command metadata or null if not found
|
|
2656
3046
|
*/
|
|
2657
3047
|
getMetadataFor(command, hint) {
|
|
2658
|
-
const loadedCommand = this.findCommandByName(command, hint);
|
|
3048
|
+
const loadedCommand = hint ? this.findCommandByName(command, hint) : this.findCommandByRoute(command);
|
|
2659
3049
|
if (!loadedCommand) return null;
|
|
2660
3050
|
return loadedCommand.metadata ??= {
|
|
2661
3051
|
aliases: [],
|
|
@@ -2664,6 +3054,63 @@ var AppCommandHandler = class {
|
|
|
2664
3054
|
botPermissions: []
|
|
2665
3055
|
};
|
|
2666
3056
|
}
|
|
3057
|
+
/**
|
|
3058
|
+
* Generates context menu commands for the loaded command.
|
|
3059
|
+
* @private
|
|
3060
|
+
* @internal
|
|
3061
|
+
*/
|
|
3062
|
+
generateContextMenuCommands(id, command, commandFileData, commandJson, metadata) {
|
|
3063
|
+
if (commandFileData.userContextMenu) {
|
|
3064
|
+
var _metadata$nameAliases;
|
|
3065
|
+
const userCtxId = `${id}::user-ctx`;
|
|
3066
|
+
const userCtxName = ((_metadata$nameAliases = metadata.nameAliases) === null || _metadata$nameAliases === void 0 ? void 0 : _metadata$nameAliases.user) ?? commandJson.name;
|
|
3067
|
+
this.loadedCommands.set(userCtxId, {
|
|
3068
|
+
discordId: null,
|
|
3069
|
+
command: {
|
|
3070
|
+
...command,
|
|
3071
|
+
id: userCtxId,
|
|
3072
|
+
name: userCtxName
|
|
3073
|
+
},
|
|
3074
|
+
metadata,
|
|
3075
|
+
data: {
|
|
3076
|
+
...commandFileData,
|
|
3077
|
+
metadata,
|
|
3078
|
+
command: {
|
|
3079
|
+
...commandJson,
|
|
3080
|
+
name: userCtxName,
|
|
3081
|
+
type: discord_js.ApplicationCommandType.User,
|
|
3082
|
+
description: void 0,
|
|
3083
|
+
options: void 0
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
});
|
|
3087
|
+
}
|
|
3088
|
+
if (commandFileData.messageContextMenu) {
|
|
3089
|
+
var _metadata$nameAliases2;
|
|
3090
|
+
const messageCtxId = `${id}::message-ctx`;
|
|
3091
|
+
const messageCtxName = ((_metadata$nameAliases2 = metadata.nameAliases) === null || _metadata$nameAliases2 === void 0 ? void 0 : _metadata$nameAliases2.message) ?? commandJson.name;
|
|
3092
|
+
this.loadedCommands.set(messageCtxId, {
|
|
3093
|
+
discordId: null,
|
|
3094
|
+
command: {
|
|
3095
|
+
...command,
|
|
3096
|
+
id: messageCtxId,
|
|
3097
|
+
name: messageCtxName
|
|
3098
|
+
},
|
|
3099
|
+
metadata,
|
|
3100
|
+
data: {
|
|
3101
|
+
...commandFileData,
|
|
3102
|
+
metadata,
|
|
3103
|
+
command: {
|
|
3104
|
+
...commandJson,
|
|
3105
|
+
name: messageCtxName,
|
|
3106
|
+
type: discord_js.ApplicationCommandType.Message,
|
|
3107
|
+
description: void 0,
|
|
3108
|
+
options: void 0
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
});
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
2667
3114
|
};
|
|
2668
3115
|
|
|
2669
3116
|
//#endregion
|
|
@@ -2679,6 +3126,7 @@ function setFlagProvider(provider) {
|
|
|
2679
3126
|
* Class representing a feature flag in CommandKit.
|
|
2680
3127
|
*/
|
|
2681
3128
|
var FeatureFlag = class {
|
|
3129
|
+
options;
|
|
2682
3130
|
commandkit;
|
|
2683
3131
|
/**
|
|
2684
3132
|
* Create a new feature flag.
|
|
@@ -3643,6 +4091,61 @@ function ChannelSelectMenu(props) {
|
|
|
3643
4091
|
return builder;
|
|
3644
4092
|
}
|
|
3645
4093
|
|
|
4094
|
+
//#endregion
|
|
4095
|
+
//#region src/components/interactive/checkbox/checkbox.ts
|
|
4096
|
+
function Checkbox(props) {
|
|
4097
|
+
const checkbox = new discord_js.CheckboxBuilder();
|
|
4098
|
+
applyId(props, checkbox);
|
|
4099
|
+
if (props.customId != null) checkbox.setCustomId(props.customId);
|
|
4100
|
+
if (props.default != null) checkbox.setDefault(props.default);
|
|
4101
|
+
return checkbox;
|
|
4102
|
+
}
|
|
4103
|
+
function CheckboxGroupOption(props) {
|
|
4104
|
+
const option = new discord_js.CheckboxGroupOptionBuilder();
|
|
4105
|
+
option.setLabel(props.label);
|
|
4106
|
+
option.setValue(props.value);
|
|
4107
|
+
if (props.description != null) option.setDescription(props.description);
|
|
4108
|
+
if (props.default != null) option.setDefault(props.default);
|
|
4109
|
+
return option;
|
|
4110
|
+
}
|
|
4111
|
+
function CheckboxGroup(props) {
|
|
4112
|
+
const checkboxGroup = new discord_js.CheckboxGroupBuilder();
|
|
4113
|
+
applyId(props, checkboxGroup);
|
|
4114
|
+
if (props.customId != null) checkboxGroup.setCustomId(props.customId);
|
|
4115
|
+
if (props.required != null) checkboxGroup.setRequired(props.required);
|
|
4116
|
+
if (props.minValues != null) checkboxGroup.setMinValues(props.minValues);
|
|
4117
|
+
if (props.maxValues != null) checkboxGroup.setMaxValues(props.maxValues);
|
|
4118
|
+
if (props.children != null) {
|
|
4119
|
+
const options = (Array.isArray(props.children) ? props.children : [props.children]).filter((option) => option != null);
|
|
4120
|
+
if (options.length === 0) throw new Error("CheckboxGroup requires at least 1 option. Use <CheckboxGroupOption label=... value=... /> as a child.");
|
|
4121
|
+
checkboxGroup.setOptions(options);
|
|
4122
|
+
}
|
|
4123
|
+
return checkboxGroup;
|
|
4124
|
+
}
|
|
4125
|
+
|
|
4126
|
+
//#endregion
|
|
4127
|
+
//#region src/components/interactive/radio/radio.ts
|
|
4128
|
+
function RadioGroup(props) {
|
|
4129
|
+
const radioGroup = new discord_js.RadioGroupBuilder();
|
|
4130
|
+
applyId(props, radioGroup);
|
|
4131
|
+
radioGroup.setCustomId(props.customId);
|
|
4132
|
+
if (props.children != null) {
|
|
4133
|
+
const options = (Array.isArray(props.children) ? props.children : [props.children]).filter((option) => option != null);
|
|
4134
|
+
if (options.length === 0) throw new Error("RadioGroup requires at least 1 option. Use <RadioGroupOption label=... value=... /> as a child.");
|
|
4135
|
+
radioGroup.setOptions(options);
|
|
4136
|
+
}
|
|
4137
|
+
if (props.required != null) radioGroup.setRequired(props.required);
|
|
4138
|
+
return radioGroup;
|
|
4139
|
+
}
|
|
4140
|
+
function RadioGroupOption(props) {
|
|
4141
|
+
const option = new discord_js.RadioGroupOptionBuilder();
|
|
4142
|
+
option.setLabel(props.label);
|
|
4143
|
+
option.setValue(props.value);
|
|
4144
|
+
if (props.description != null) option.setDescription(props.description);
|
|
4145
|
+
if (props.default != null) option.setDefault(props.default);
|
|
4146
|
+
return option;
|
|
4147
|
+
}
|
|
4148
|
+
|
|
3646
4149
|
//#endregion
|
|
3647
4150
|
//#region src/components/display/container.ts
|
|
3648
4151
|
/**
|
|
@@ -3791,6 +4294,7 @@ function Label(props) {
|
|
|
3791
4294
|
* Handles Discord.js events and CommandKit custom events with support for namespacing and middleware.
|
|
3792
4295
|
*/
|
|
3793
4296
|
var AppEventsHandler = class {
|
|
4297
|
+
commandkit;
|
|
3794
4298
|
/**
|
|
3795
4299
|
* @private
|
|
3796
4300
|
* @internal
|
|
@@ -3820,8 +4324,19 @@ var AppEventsHandler = class {
|
|
|
3820
4324
|
/**
|
|
3821
4325
|
* Reloads all events by unregistering existing ones and loading them again.
|
|
3822
4326
|
*/
|
|
3823
|
-
async reloadEvents() {
|
|
4327
|
+
async reloadEvents(path, changeType) {
|
|
3824
4328
|
this.unregisterAll();
|
|
4329
|
+
if (this.commandkit.config.experimental.incrementalRouter && path) {
|
|
4330
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
4331
|
+
return plugin.onBeforeEventsLoad(ctx);
|
|
4332
|
+
});
|
|
4333
|
+
await this.commandkit.eventsRouter.scanIncremental(path, changeType);
|
|
4334
|
+
await this.loadEventsFromTree(this.commandkit.eventsRouter.toJSON());
|
|
4335
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
4336
|
+
return plugin.onAfterEventsLoad(ctx);
|
|
4337
|
+
});
|
|
4338
|
+
return;
|
|
4339
|
+
}
|
|
3825
4340
|
await this.loadEvents();
|
|
3826
4341
|
}
|
|
3827
4342
|
/**
|
|
@@ -3832,6 +4347,17 @@ var AppEventsHandler = class {
|
|
|
3832
4347
|
return plugin.onBeforeEventsLoad(ctx);
|
|
3833
4348
|
});
|
|
3834
4349
|
const events = await this.commandkit.eventsRouter.scan();
|
|
4350
|
+
await this.loadEventsFromTree(events);
|
|
4351
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
4352
|
+
return plugin.onAfterEventsLoad(ctx);
|
|
4353
|
+
});
|
|
4354
|
+
}
|
|
4355
|
+
/**
|
|
4356
|
+
* @private
|
|
4357
|
+
* @internal
|
|
4358
|
+
*/
|
|
4359
|
+
async loadEventsFromTree(events) {
|
|
4360
|
+
this.loadedEvents.clear();
|
|
3835
4361
|
for (const event of Object.values(events)) {
|
|
3836
4362
|
const listeners = [];
|
|
3837
4363
|
for (const listener of event.listeners) {
|
|
@@ -3858,9 +4384,6 @@ var AppEventsHandler = class {
|
|
|
3858
4384
|
Logger.info(`✨ Loaded event ${event.event}${event.namespace ? ` of namespace ${event.namespace}` : ""} with ${len} listener${len === 1 ? "" : "s"}`);
|
|
3859
4385
|
}
|
|
3860
4386
|
this.registerAllClientEvents();
|
|
3861
|
-
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
3862
|
-
return plugin.onAfterEventsLoad(ctx);
|
|
3863
|
-
});
|
|
3864
4387
|
}
|
|
3865
4388
|
/**
|
|
3866
4389
|
* Unregisters all event listeners and clears loaded events.
|
|
@@ -3999,6 +4522,11 @@ var AppEventsHandler = class {
|
|
|
3999
4522
|
once: false,
|
|
4000
4523
|
parallel: false
|
|
4001
4524
|
} : void 0,
|
|
4525
|
+
onceListener: onceListeners.length > 0 ? {
|
|
4526
|
+
handler: onceHandler,
|
|
4527
|
+
once: true,
|
|
4528
|
+
parallel: false
|
|
4529
|
+
} : void 0,
|
|
4002
4530
|
executedOnceListeners
|
|
4003
4531
|
});
|
|
4004
4532
|
if (namespace) {
|
|
@@ -4016,11 +4544,11 @@ var AppEventsHandler = class {
|
|
|
4016
4544
|
*/
|
|
4017
4545
|
unregisterAllClientListeners() {
|
|
4018
4546
|
const client = this.commandkit.client;
|
|
4019
|
-
for (const [key, { name, mainListener, namespace }] of this.loadedEvents.entries()) {
|
|
4547
|
+
for (const [key, { name, mainListener, onceListener, namespace }] of this.loadedEvents.entries()) {
|
|
4020
4548
|
if (mainListener) if (namespace) this.commandkit.events.off(namespace, name, mainListener.handler);
|
|
4021
4549
|
else client.off(name, mainListener.handler);
|
|
4022
|
-
|
|
4023
|
-
else client.
|
|
4550
|
+
if (onceListener) if (namespace) this.commandkit.events.off(namespace, name, onceListener.handler);
|
|
4551
|
+
else client.off(name, onceListener.handler);
|
|
4024
4552
|
this.loadedEvents.delete(key);
|
|
4025
4553
|
Logger.info(`🗑️ Unregistered event ${name}${namespace ? ` of namespace ${namespace}` : ""}`);
|
|
4026
4554
|
}
|
|
@@ -4076,8 +4604,9 @@ function registerDevHooks(commandkit) {
|
|
|
4076
4604
|
if (!require_utils_constants.COMMANDKIT_IS_DEV) return;
|
|
4077
4605
|
process.on("message", async (message) => {
|
|
4078
4606
|
if (typeof message !== "object" || message === null) return;
|
|
4079
|
-
const { event, path, id } = message;
|
|
4607
|
+
const { event, path: maybePath, id, changeType } = message;
|
|
4080
4608
|
if (!event) return;
|
|
4609
|
+
const path = maybePath ?? "";
|
|
4081
4610
|
if (process.env.COMMANDKIT_DEBUG_HMR === "true") Logger.info(`Received HMR event: ${event}${path ? ` for ${path}` : ""}`);
|
|
4082
4611
|
let accepted = false, prevented = false, handled = false;
|
|
4083
4612
|
const hmrEvent = {
|
|
@@ -4088,7 +4617,8 @@ function registerDevHooks(commandkit) {
|
|
|
4088
4617
|
prevented = true;
|
|
4089
4618
|
},
|
|
4090
4619
|
path,
|
|
4091
|
-
event
|
|
4620
|
+
event,
|
|
4621
|
+
changeType
|
|
4092
4622
|
};
|
|
4093
4623
|
try {
|
|
4094
4624
|
await commandkit.plugins.execute(async (ctx, plugin) => {
|
|
@@ -4099,11 +4629,11 @@ function registerDevHooks(commandkit) {
|
|
|
4099
4629
|
if (prevented) return;
|
|
4100
4630
|
switch (event) {
|
|
4101
4631
|
case require_utils_constants.HMREventType.ReloadCommands:
|
|
4102
|
-
commandkit.commandHandler.reloadCommands();
|
|
4632
|
+
await commandkit.commandHandler.reloadCommands(path, changeType);
|
|
4103
4633
|
handled = true;
|
|
4104
4634
|
break;
|
|
4105
4635
|
case require_utils_constants.HMREventType.ReloadEvents:
|
|
4106
|
-
commandkit.eventHandler.reloadEvents();
|
|
4636
|
+
await commandkit.eventHandler.reloadEvents(path, changeType);
|
|
4107
4637
|
handled = true;
|
|
4108
4638
|
break;
|
|
4109
4639
|
case require_utils_constants.HMREventType.Unknown:
|
|
@@ -4166,6 +4696,7 @@ function noAnalytics() {
|
|
|
4166
4696
|
* This class allows you to register a provider, set a filter for events, and track or identify events.
|
|
4167
4697
|
*/
|
|
4168
4698
|
var AnalyticsEngine = class {
|
|
4699
|
+
commandkit;
|
|
4169
4700
|
#provider = null;
|
|
4170
4701
|
#filter = null;
|
|
4171
4702
|
/**
|
|
@@ -4285,6 +4816,7 @@ function onApplicationBootstrap(fn) {
|
|
|
4285
4816
|
*/
|
|
4286
4817
|
var CommandKit = class CommandKit extends node_events.default {
|
|
4287
4818
|
#started = false;
|
|
4819
|
+
#hydratedFromArtifact = false;
|
|
4288
4820
|
#clientProxy = createProxy({});
|
|
4289
4821
|
#client;
|
|
4290
4822
|
/**
|
|
@@ -4489,11 +5021,35 @@ var CommandKit = class CommandKit extends node_events.default {
|
|
|
4489
5021
|
await this.plugins.execute((ctx, plugin) => {
|
|
4490
5022
|
return plugin.onEventsRouterInit(ctx);
|
|
4491
5023
|
});
|
|
5024
|
+
this.#hydratedFromArtifact = await this.#hydrateRoutersFromArtifact();
|
|
4492
5025
|
await this.#initEvents();
|
|
4493
5026
|
await this.#initCommands();
|
|
4494
5027
|
}
|
|
5028
|
+
async #hydrateRoutersFromArtifact() {
|
|
5029
|
+
if (require_utils_constants.COMMANDKIT_IS_DEV) return false;
|
|
5030
|
+
if (require_utils_constants.COMMANDKIT_BOOTSTRAP_MODE !== "production") return false;
|
|
5031
|
+
if (!this.config.experimental.pregenerateCommands) return false;
|
|
5032
|
+
const outputRoot = getCurrentDirectory();
|
|
5033
|
+
const artifactPath = (0, node_path.join)(outputRoot, require_app_router_TreeArtifact.ROUTER_TREE_ARTIFACT_DIRECTORY, require_app_router_TreeArtifact.ROUTER_TREE_ARTIFACT_FILE);
|
|
5034
|
+
if (!(0, node_fs.existsSync)(artifactPath)) return false;
|
|
5035
|
+
try {
|
|
5036
|
+
const json = await (0, node_fs_promises.readFile)(artifactPath, "utf8");
|
|
5037
|
+
const parsed = JSON.parse(json);
|
|
5038
|
+
if (!require_app_router_TreeArtifact.validateRouterTreeArtifact(parsed, "1.2.2")) {
|
|
5039
|
+
Logger.warn(`Ignoring router tree artifact at ${artifactPath}: schema/version mismatch. Falling back to dynamic filesystem resolution.`);
|
|
5040
|
+
return false;
|
|
5041
|
+
}
|
|
5042
|
+
const hydrated = require_app_router_TreeArtifact.hydrateRouterTreeArtifact(parsed, outputRoot);
|
|
5043
|
+
this.commandsRouter.populate(hydrated.commands);
|
|
5044
|
+
this.eventsRouter.populate(hydrated.events);
|
|
5045
|
+
return true;
|
|
5046
|
+
} catch (error) {
|
|
5047
|
+
Logger.warn(`Failed to load router tree artifact at ${artifactPath}. Falling back to dynamic filesystem resolution. ${error}`);
|
|
5048
|
+
return false;
|
|
5049
|
+
}
|
|
5050
|
+
}
|
|
4495
5051
|
async #initCommands() {
|
|
4496
|
-
if (this.commandsRouter.isValidPath()) {
|
|
5052
|
+
if (!this.#hydratedFromArtifact && this.commandsRouter.isValidPath()) {
|
|
4497
5053
|
const result = await this.commandsRouter.scan();
|
|
4498
5054
|
if (require_utils_constants.COMMANDKIT_IS_DEV) (0, node_fs.writeFileSync)("./.commandkit/commands.json", JSON.stringify(result, null, 2));
|
|
4499
5055
|
}
|
|
@@ -4501,7 +5057,7 @@ var CommandKit = class CommandKit extends node_events.default {
|
|
|
4501
5057
|
this.commandHandler.printBanner();
|
|
4502
5058
|
}
|
|
4503
5059
|
async #initEvents() {
|
|
4504
|
-
if (this.eventsRouter.isValidPath()) await this.eventsRouter.scan();
|
|
5060
|
+
if (!this.#hydratedFromArtifact && this.eventsRouter.isValidPath()) await this.eventsRouter.scan();
|
|
4505
5061
|
await this.eventHandler.loadEvents();
|
|
4506
5062
|
}
|
|
4507
5063
|
/**
|
|
@@ -4606,6 +5162,24 @@ Object.defineProperty(exports, 'ChannelSelectMenuKit', {
|
|
|
4606
5162
|
return ChannelSelectMenuKit;
|
|
4607
5163
|
}
|
|
4608
5164
|
});
|
|
5165
|
+
Object.defineProperty(exports, 'Checkbox', {
|
|
5166
|
+
enumerable: true,
|
|
5167
|
+
get: function () {
|
|
5168
|
+
return Checkbox;
|
|
5169
|
+
}
|
|
5170
|
+
});
|
|
5171
|
+
Object.defineProperty(exports, 'CheckboxGroup', {
|
|
5172
|
+
enumerable: true,
|
|
5173
|
+
get: function () {
|
|
5174
|
+
return CheckboxGroup;
|
|
5175
|
+
}
|
|
5176
|
+
});
|
|
5177
|
+
Object.defineProperty(exports, 'CheckboxGroupOption', {
|
|
5178
|
+
enumerable: true,
|
|
5179
|
+
get: function () {
|
|
5180
|
+
return CheckboxGroupOption;
|
|
5181
|
+
}
|
|
5182
|
+
});
|
|
4609
5183
|
Object.defineProperty(exports, 'CommandExecutionMode', {
|
|
4610
5184
|
enumerable: true,
|
|
4611
5185
|
get: function () {
|
|
@@ -4768,6 +5342,18 @@ Object.defineProperty(exports, 'ParagraphInput', {
|
|
|
4768
5342
|
return ParagraphInput;
|
|
4769
5343
|
}
|
|
4770
5344
|
});
|
|
5345
|
+
Object.defineProperty(exports, 'RadioGroup', {
|
|
5346
|
+
enumerable: true,
|
|
5347
|
+
get: function () {
|
|
5348
|
+
return RadioGroup;
|
|
5349
|
+
}
|
|
5350
|
+
});
|
|
5351
|
+
Object.defineProperty(exports, 'RadioGroupOption', {
|
|
5352
|
+
enumerable: true,
|
|
5353
|
+
get: function () {
|
|
5354
|
+
return RadioGroupOption;
|
|
5355
|
+
}
|
|
5356
|
+
});
|
|
4771
5357
|
Object.defineProperty(exports, 'RoleSelectMenu', {
|
|
4772
5358
|
enumerable: true,
|
|
4773
5359
|
get: function () {
|
|
@@ -5080,4 +5666,4 @@ Object.defineProperty(exports, 'useStore', {
|
|
|
5080
5666
|
return useStore;
|
|
5081
5667
|
}
|
|
5082
5668
|
});
|
|
5083
|
-
//# sourceMappingURL=commandkit-
|
|
5669
|
+
//# sourceMappingURL=commandkit-DNbfLwyR.js.map
|