commandkit 0.1.11-dev.20250330132756 → 0.1.11-dev.20250331145527
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +32 -3
- package/dist/index.js +120 -34
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -907,6 +907,7 @@ declare const CommandExecutionMode: {
|
|
|
907
907
|
};
|
|
908
908
|
type CommandExecutionMode = (typeof CommandExecutionMode)[keyof typeof CommandExecutionMode];
|
|
909
909
|
interface ContextParameters<T extends CommandExecutionMode, Args = Record<string, any>> {
|
|
910
|
+
command: LoadedCommand;
|
|
910
911
|
environment?: CommandKitEnvironment;
|
|
911
912
|
executionMode: T;
|
|
912
913
|
interaction: T extends 'chatInput' ? ChatInputCommandInteraction : T extends 'messageContextMenu' ? MessageContextMenuCommandInteraction : T extends 'userContextMenu' ? UserContextMenuCommandInteraction : T extends 'autocomplete' ? AutocompleteInteraction : never;
|
|
@@ -954,6 +955,10 @@ declare class Context<ExecutionMode extends CommandExecutionMode = CommandExecut
|
|
|
954
955
|
* The client instance.
|
|
955
956
|
*/
|
|
956
957
|
readonly client: Client;
|
|
958
|
+
/**
|
|
959
|
+
* The command that this context belongs to.
|
|
960
|
+
*/
|
|
961
|
+
readonly command: LoadedCommand;
|
|
957
962
|
private _locale;
|
|
958
963
|
/**
|
|
959
964
|
* Creates a new command context.
|
|
@@ -1255,6 +1260,7 @@ interface Middleware {
|
|
|
1255
1260
|
path: string;
|
|
1256
1261
|
relativePath: string;
|
|
1257
1262
|
parentPath: string;
|
|
1263
|
+
global: boolean;
|
|
1258
1264
|
}
|
|
1259
1265
|
interface ParsedCommandData {
|
|
1260
1266
|
commands: Record<string, Command>;
|
|
@@ -1306,7 +1312,7 @@ declare class CommandsRouter {
|
|
|
1306
1312
|
*/
|
|
1307
1313
|
interface EventsRouterOptions {
|
|
1308
1314
|
/** Root directory path where event handlers are located */
|
|
1309
|
-
|
|
1315
|
+
entrypoints: string[];
|
|
1310
1316
|
}
|
|
1311
1317
|
/**
|
|
1312
1318
|
* Represents a parsed event with its handlers
|
|
@@ -1338,6 +1344,11 @@ declare class EventsRouter {
|
|
|
1338
1344
|
* @throws Error if entrypoint is not provided
|
|
1339
1345
|
*/
|
|
1340
1346
|
constructor(options: EventsRouterOptions);
|
|
1347
|
+
/**
|
|
1348
|
+
* Adds new entrypoints to the router
|
|
1349
|
+
* @param entrypoints - Array of new entrypoint paths
|
|
1350
|
+
*/
|
|
1351
|
+
addEntrypoints(entrypoints: string[]): void;
|
|
1341
1352
|
/**
|
|
1342
1353
|
* Find a parsed event by its name
|
|
1343
1354
|
* @param event - Name of the event to find
|
|
@@ -1348,7 +1359,7 @@ declare class EventsRouter {
|
|
|
1348
1359
|
* Get the entrypoint directory path
|
|
1349
1360
|
* @returns Entrypoint directory path
|
|
1350
1361
|
*/
|
|
1351
|
-
get
|
|
1362
|
+
get entrypoints(): string[];
|
|
1352
1363
|
/**
|
|
1353
1364
|
* Checks if the entrypoint path is valid
|
|
1354
1365
|
*/
|
|
@@ -1431,12 +1442,18 @@ declare class AppCommandHandler {
|
|
|
1431
1442
|
private onMessageCreate;
|
|
1432
1443
|
private onMessageUpdate;
|
|
1433
1444
|
readonly commandRunner: AppCommandRunner;
|
|
1445
|
+
readonly externalCommandData: Collection<string, Command>;
|
|
1446
|
+
readonly externalMiddlewareData: Collection<string, Middleware>;
|
|
1434
1447
|
constructor(commandkit: CommandKit);
|
|
1435
1448
|
printBanner(): void;
|
|
1436
1449
|
getCommandsArray(): LoadedCommand[];
|
|
1437
1450
|
registerCommandHandler(): void;
|
|
1438
1451
|
prepareCommandRun(source: Interaction | Message$1, cmdName?: string): Promise<PreparedAppCommandExecution | null>;
|
|
1439
1452
|
reloadCommands(): Promise<void>;
|
|
1453
|
+
addExternalMiddleware(data: Middleware[]): Promise<void>;
|
|
1454
|
+
addExternalCommands(data: Command[]): Promise<void>;
|
|
1455
|
+
registerExternalLoadedMiddleware(data: LoadedMiddleware[]): Promise<void>;
|
|
1456
|
+
registerExternalLoadedCommands(data: LoadedCommand[]): Promise<void>;
|
|
1440
1457
|
loadCommands(): Promise<void>;
|
|
1441
1458
|
private loadMiddleware;
|
|
1442
1459
|
private loadCommand;
|
|
@@ -1703,6 +1720,16 @@ declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> ex
|
|
|
1703
1720
|
* @param execute The function that executes the command
|
|
1704
1721
|
*/
|
|
1705
1722
|
executeCommand(ctx: CommandKitPluginRuntime, env: CommandKitEnvironment, source: Interaction | Message$1, command: PreparedAppCommandExecution, execute: () => Promise<any>): Promise<boolean>;
|
|
1723
|
+
/**
|
|
1724
|
+
* Called after events router is initialized
|
|
1725
|
+
* @param ctx The context
|
|
1726
|
+
*/
|
|
1727
|
+
onEventsRouterInit(ctx: CommandKitPluginRuntime): Promise<void>;
|
|
1728
|
+
/**
|
|
1729
|
+
* Called after commands router is initialized
|
|
1730
|
+
* @param ctx The context
|
|
1731
|
+
*/
|
|
1732
|
+
onCommandsRouterInit(ctx: CommandKitPluginRuntime): Promise<void>;
|
|
1706
1733
|
}
|
|
1707
1734
|
declare function isRuntimePlugin(plugin: unknown): plugin is RuntimePlugin;
|
|
1708
1735
|
|
|
@@ -1958,6 +1985,8 @@ declare const Logger: LoggerImpl;
|
|
|
1958
1985
|
*/
|
|
1959
1986
|
declare const version: string;
|
|
1960
1987
|
|
|
1988
|
+
declare function getCurrentDirectory(): string;
|
|
1989
|
+
|
|
1961
1990
|
/**
|
|
1962
1991
|
* Creates a command line interface for CommandKit.
|
|
1963
1992
|
* @param argv The arguments passed to the CLI.
|
|
@@ -1965,4 +1994,4 @@ declare const version: string;
|
|
|
1965
1994
|
*/
|
|
1966
1995
|
declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
|
|
1967
1996
|
|
|
1968
|
-
export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, type ApiTranslatableCommandOptions, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, ChannelSelectMenu, ChannelSelectMenuKit, type ChannelSelectMenuKitPredicate, type ChannelSelectMenuProps, type Command, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandKitPlugin, CommandKitPluginRuntime, type CommandKitSelectMenuBuilderInteractionCollectorDispatch, type CommandKitSelectMenuBuilderInteractionCollectorDispatchContextData, type CommandKitSelectMenuBuilderOnEnd, type CommandLocalizationTypeData, type CommandSource, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonBuilderKit, type CommonPluginRuntime, type CommonSelectMenuProps, CompilerPlugin, CompilerPluginRuntime, Context, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, type Loader, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, type Location, Logger, type LoggerImpl, type MaybeArray, type MaybeFalsey, MemoryCache, MentionableSelectMenu, MentionableSelectMenuKit, type MentionableSelectMenuKitPredicate, type MentionableSelectMenuProps, type Message, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type Middleware, MiddlewareContext, type MiddlewareContextArgs, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnChannelSelectMenuKitSubmit, type OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnMentionableSelectMenuKitSubmit, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, type OnRoleSelectMenuKitSubmit, type OnSelectMenuKitEnd, type OnSelectMenuKitSubmit, type OnStringSelectMenuKitSubmit, type OnUserSelectMenuKitSubmit, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreparedAppCommandExecution, type ResolvableCommand, type ResolveBuilderInteraction, type ResolveKind, type ResolveResult, RoleSelectMenu, RoleSelectMenuKit, type RoleSelectMenuKitPredicate, type RoleSelectMenuProps, type RunCommand, RuntimePlugin, type SelectMenuKitPredicate, type SelectMenuProps, type Setup, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, StringSelectMenu, StringSelectMenuKit, type StringSelectMenuKitPredicate, StringSelectMenuOption, type StringSelectMenuOptionProps, type StringSelectMenuProps, TextInput, type TextInputProps, type TransformedResult, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandName, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, UserSelectMenu, UserSelectMenuKit, type UserSelectMenuKitPredicate, type UserSelectMenuProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, commandkit, createElement, createLogger, CommandKit as default, defineConfig, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getElement, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isInteractionSource, isMessageSource, isRuntimePlugin, makeContextAwareFunction, provideContext, redirect, rethrow, revalidate, useCache as super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai, useEnvironment, version };
|
|
1997
|
+
export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, type ApiTranslatableCommandOptions, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, ChannelSelectMenu, ChannelSelectMenuKit, type ChannelSelectMenuKitPredicate, type ChannelSelectMenuProps, type Command, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, CommandKit, type CommandKitButtonBuilderInteractionCollectorDispatch, type CommandKitButtonBuilderInteractionCollectorDispatchContextData, type CommandKitButtonBuilderOnEnd, type CommandKitConfiguration, type CommandKitElement, type CommandKitElementData, CommandKitEnvironment, type CommandKitEnvironmentInternalData, CommandKitEnvironmentType, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandKitPlugin, CommandKitPluginRuntime, type CommandKitSelectMenuBuilderInteractionCollectorDispatch, type CommandKitSelectMenuBuilderInteractionCollectorDispatchContextData, type CommandKitSelectMenuBuilderOnEnd, type CommandLocalizationTypeData, type CommandSource, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonBuilderKit, type CommonPluginRuntime, type CommonSelectMenuProps, CompilerPlugin, CompilerPluginRuntime, Context, type ContextParameters, DefaultLocalizationStrategy, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, type Loader, Localization, type LocalizationConfig, type LocalizationStrategy, type LocalizationTranslationRequest, type Location, Logger, type LoggerImpl, type MaybeArray, type MaybeFalsey, MemoryCache, MentionableSelectMenu, MentionableSelectMenuKit, type MentionableSelectMenuKitPredicate, type MentionableSelectMenuProps, type Message, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type Middleware, MiddlewareContext, type MiddlewareContextArgs, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnChannelSelectMenuKitSubmit, type OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnMentionableSelectMenuKitSubmit, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, type OnRoleSelectMenuKitSubmit, type OnSelectMenuKitEnd, type OnSelectMenuKitSubmit, type OnStringSelectMenuKitSubmit, type OnUserSelectMenuKitSubmit, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreparedAppCommandExecution, type ResolvableCommand, type ResolveBuilderInteraction, type ResolveKind, type ResolveResult, RoleSelectMenu, RoleSelectMenuKit, type RoleSelectMenuKitPredicate, type RoleSelectMenuProps, type RunCommand, RuntimePlugin, type SelectMenuKitPredicate, type SelectMenuProps, type Setup, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, StringSelectMenu, StringSelectMenuKit, type StringSelectMenuKitPredicate, StringSelectMenuOption, type StringSelectMenuOptionProps, type StringSelectMenuProps, TextInput, type TextInputProps, type TransformedResult, type TranslatableArguments, type TranslatableCommand, type TranslatableCommandName, type TranslatableCommandOptions, type Translation, type TranslationResult, type Translator, type UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, UserSelectMenu, UserSelectMenuKit, type UserSelectMenuKitPredicate, type UserSelectMenuProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, commandkit, createElement, createLogger, CommandKit as default, defineConfig, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getCurrentDirectory, getElement, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isInteractionSource, isMessageSource, isRuntimePlugin, makeContextAwareFunction, provideContext, redirect, rethrow, revalidate, useCache as super_duper_secret_internal_for_use_cache_directive_of_commandkit_cli_do_not_use_it_directly_or_you_will_be_fired_from_your_job_kthxbai, useEnvironment, version };
|
package/dist/index.js
CHANGED
|
@@ -41,9 +41,9 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
|
41
41
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
42
42
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
43
43
|
|
|
44
|
-
// ../../node_modules/.pnpm/tsup@8.4.
|
|
44
|
+
// ../../node_modules/.pnpm/tsup@8.4.0_@swc+core@1.11.13_@swc+helpers@0.5.15__jiti@2.4.2_postcss@8.5.3_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js
|
|
45
45
|
var init_cjs_shims = __esm({
|
|
46
|
-
"../../node_modules/.pnpm/tsup@8.4.
|
|
46
|
+
"../../node_modules/.pnpm/tsup@8.4.0_@swc+core@1.11.13_@swc+helpers@0.5.15__jiti@2.4.2_postcss@8.5.3_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js"() {
|
|
47
47
|
"use strict";
|
|
48
48
|
}
|
|
49
49
|
});
|
|
@@ -2009,6 +2009,18 @@ var init_RuntimePlugin = __esm({
|
|
|
2009
2009
|
async executeCommand(ctx, env, source, command, execute) {
|
|
2010
2010
|
return false;
|
|
2011
2011
|
}
|
|
2012
|
+
/**
|
|
2013
|
+
* Called after events router is initialized
|
|
2014
|
+
* @param ctx The context
|
|
2015
|
+
*/
|
|
2016
|
+
async onEventsRouterInit(ctx) {
|
|
2017
|
+
}
|
|
2018
|
+
/**
|
|
2019
|
+
* Called after commands router is initialized
|
|
2020
|
+
* @param ctx The context
|
|
2021
|
+
*/
|
|
2022
|
+
async onCommandsRouterInit(ctx) {
|
|
2023
|
+
}
|
|
2012
2024
|
};
|
|
2013
2025
|
__name(_RuntimePlugin, "RuntimePlugin");
|
|
2014
2026
|
RuntimePlugin = _RuntimePlugin;
|
|
@@ -2960,6 +2972,16 @@ ${translationTypes}
|
|
|
2960
2972
|
});
|
|
2961
2973
|
|
|
2962
2974
|
// src/utils/utilities.ts
|
|
2975
|
+
function getCurrentDirectory() {
|
|
2976
|
+
if (currentDir) return currentDir;
|
|
2977
|
+
let root = (0, import_node_path2.join)(
|
|
2978
|
+
process.cwd(),
|
|
2979
|
+
COMMANDKIT_IS_DEV ? ".commandkit" : getConfig().distDir
|
|
2980
|
+
);
|
|
2981
|
+
if (!(0, import_node_fs2.existsSync)(root)) root = process.cwd();
|
|
2982
|
+
currentDir = root;
|
|
2983
|
+
return root;
|
|
2984
|
+
}
|
|
2963
2985
|
function findAppDirectory() {
|
|
2964
2986
|
if (appDir) return appDir;
|
|
2965
2987
|
let root = (0, import_node_path2.join)(
|
|
@@ -2997,7 +3019,7 @@ function debounce(fn, ms2) {
|
|
|
2997
3019
|
});
|
|
2998
3020
|
};
|
|
2999
3021
|
}
|
|
3000
|
-
var import_node_fs2, import_node_path2, appDir;
|
|
3022
|
+
var import_node_fs2, import_node_path2, appDir, currentDir;
|
|
3001
3023
|
var init_utilities = __esm({
|
|
3002
3024
|
"src/utils/utilities.ts"() {
|
|
3003
3025
|
"use strict";
|
|
@@ -3007,6 +3029,8 @@ var init_utilities = __esm({
|
|
|
3007
3029
|
init_constants();
|
|
3008
3030
|
init_config();
|
|
3009
3031
|
appDir = null;
|
|
3032
|
+
currentDir = null;
|
|
3033
|
+
__name(getCurrentDirectory, "getCurrentDirectory");
|
|
3010
3034
|
__name(findAppDirectory, "findAppDirectory");
|
|
3011
3035
|
__name(debounce, "debounce");
|
|
3012
3036
|
}
|
|
@@ -3821,12 +3845,17 @@ var init_Context = __esm({
|
|
|
3821
3845
|
* The client instance.
|
|
3822
3846
|
*/
|
|
3823
3847
|
__publicField(this, "client");
|
|
3848
|
+
/**
|
|
3849
|
+
* The command that this context belongs to.
|
|
3850
|
+
*/
|
|
3851
|
+
__publicField(this, "command");
|
|
3824
3852
|
__privateAdd(this, _store);
|
|
3825
3853
|
__publicField(this, "_locale", null);
|
|
3826
3854
|
this.interaction = config.interaction;
|
|
3827
3855
|
this.message = config.message;
|
|
3828
3856
|
this.client = commandkit2.client;
|
|
3829
3857
|
__privateSet(this, _store, config.store ?? /* @__PURE__ */ new Map());
|
|
3858
|
+
this.command = config.command;
|
|
3830
3859
|
}
|
|
3831
3860
|
/**
|
|
3832
3861
|
* The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands.
|
|
@@ -4126,6 +4155,7 @@ var init_AppCommandRunner = __esm({
|
|
|
4126
4155
|
env.variables.set("currentCommandName", prepared.command.command.name);
|
|
4127
4156
|
env.variables.set("execHandlerKind", executionMode);
|
|
4128
4157
|
const ctx = new MiddlewareContext(commandkit2, {
|
|
4158
|
+
command: prepared.command,
|
|
4129
4159
|
environment: env,
|
|
4130
4160
|
executionMode,
|
|
4131
4161
|
interaction: !(source instanceof import_discord15.Message) ? source : null,
|
|
@@ -4374,6 +4404,8 @@ var init_AppCommandHandler = __esm({
|
|
|
4374
4404
|
onMessageCreate = null;
|
|
4375
4405
|
onMessageUpdate = null;
|
|
4376
4406
|
commandRunner = new AppCommandRunner(this);
|
|
4407
|
+
externalCommandData = new import_discord16.Collection();
|
|
4408
|
+
externalMiddlewareData = new import_discord16.Collection();
|
|
4377
4409
|
printBanner() {
|
|
4378
4410
|
const categorizedCommands = this.getCommandsArray().reduce(
|
|
4379
4411
|
(acc, cmd) => {
|
|
@@ -4500,7 +4532,8 @@ var init_AppCommandHandler = __esm({
|
|
|
4500
4532
|
return null;
|
|
4501
4533
|
}
|
|
4502
4534
|
} else {
|
|
4503
|
-
|
|
4535
|
+
const isAnyCommand = source.isChatInputCommand() || source.isAutocomplete() || source.isContextMenuCommand();
|
|
4536
|
+
if (!isAnyCommand) return null;
|
|
4504
4537
|
cmdName = source.commandName;
|
|
4505
4538
|
}
|
|
4506
4539
|
}
|
|
@@ -4508,7 +4541,7 @@ var init_AppCommandHandler = __esm({
|
|
|
4508
4541
|
if (!commandId) return null;
|
|
4509
4542
|
const loadedCommand = this.loadedCommands.get(commandId);
|
|
4510
4543
|
if (!loadedCommand) return null;
|
|
4511
|
-
if (source instanceof import_discord16.CommandInteraction && source.guildId && ((_a = loadedCommand.guilds) == null ? void 0 : _a.length) && !loadedCommand.guilds.includes(source.guildId)) {
|
|
4544
|
+
if ((source instanceof import_discord16.CommandInteraction || source instanceof import_discord16.AutocompleteInteraction) && source.guildId && ((_a = loadedCommand.guilds) == null ? void 0 : _a.length) && !loadedCommand.guilds.includes(source.guildId)) {
|
|
4512
4545
|
return null;
|
|
4513
4546
|
}
|
|
4514
4547
|
const middlewares = [];
|
|
@@ -4529,18 +4562,48 @@ var init_AppCommandHandler = __esm({
|
|
|
4529
4562
|
this.loadedMiddlewares.clear();
|
|
4530
4563
|
this.commandNameToId.clear();
|
|
4531
4564
|
this.subcommandPathToId.clear();
|
|
4565
|
+
this.externalCommandData.clear();
|
|
4566
|
+
this.externalMiddlewareData.clear();
|
|
4532
4567
|
await this.loadCommands();
|
|
4533
4568
|
}
|
|
4569
|
+
async addExternalMiddleware(data) {
|
|
4570
|
+
for (const middleware of data) {
|
|
4571
|
+
if (!middleware.id) continue;
|
|
4572
|
+
this.externalMiddlewareData.set(middleware.id, middleware);
|
|
4573
|
+
}
|
|
4574
|
+
}
|
|
4575
|
+
async addExternalCommands(data) {
|
|
4576
|
+
for (const command of data) {
|
|
4577
|
+
if (!command.id) continue;
|
|
4578
|
+
this.externalCommandData.set(command.id, command);
|
|
4579
|
+
}
|
|
4580
|
+
}
|
|
4581
|
+
async registerExternalLoadedMiddleware(data) {
|
|
4582
|
+
for (const middleware of data) {
|
|
4583
|
+
this.loadedMiddlewares.set(middleware.middleware.id, middleware);
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
async registerExternalLoadedCommands(data) {
|
|
4587
|
+
for (const command of data) {
|
|
4588
|
+
this.loadedCommands.set(command.command.id, command);
|
|
4589
|
+
this.commandNameToId.set(command.command.name, command.command.id);
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4534
4592
|
async loadCommands() {
|
|
4593
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
4594
|
+
return plugin.onBeforeCommandsLoad(ctx);
|
|
4595
|
+
});
|
|
4535
4596
|
const commandsRouter = this.commandkit.commandsRouter;
|
|
4536
4597
|
if (!commandsRouter) {
|
|
4537
4598
|
throw new Error("Commands router has not yet initialized");
|
|
4538
4599
|
}
|
|
4539
4600
|
const { commands, middlewares } = commandsRouter.getData();
|
|
4540
|
-
|
|
4601
|
+
const combinedCommands = this.externalCommandData.size ? commands.concat(this.externalCommandData) : commands;
|
|
4602
|
+
const combinedMiddlewares = this.externalMiddlewareData.size ? middlewares.concat(this.externalMiddlewareData) : middlewares;
|
|
4603
|
+
for (const [id, middleware] of combinedMiddlewares) {
|
|
4541
4604
|
await this.loadMiddleware(id, middleware);
|
|
4542
4605
|
}
|
|
4543
|
-
for (const [id, command] of
|
|
4606
|
+
for (const [id, command] of combinedCommands) {
|
|
4544
4607
|
await this.loadCommand(id, command);
|
|
4545
4608
|
}
|
|
4546
4609
|
if (COMMANDKIT_IS_DEV) {
|
|
@@ -4550,6 +4613,9 @@ var init_AppCommandHandler = __esm({
|
|
|
4550
4613
|
).join(" | ")}`
|
|
4551
4614
|
);
|
|
4552
4615
|
}
|
|
4616
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
4617
|
+
return plugin.onAfterCommandsLoad(ctx);
|
|
4618
|
+
});
|
|
4553
4619
|
}
|
|
4554
4620
|
async loadMiddleware(id, middleware) {
|
|
4555
4621
|
try {
|
|
@@ -4738,7 +4804,7 @@ var init_AppCommandHandler = __esm({
|
|
|
4738
4804
|
});
|
|
4739
4805
|
|
|
4740
4806
|
// src/app/router/CommandsRouter.ts
|
|
4741
|
-
var import_discord17, import_node_fs4, import_promises4, import_node_path4, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
4807
|
+
var import_discord17, import_node_fs4, import_promises4, import_node_path4, MIDDLEWARE_PATTERN, GLOBAL_MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
4742
4808
|
var init_CommandsRouter = __esm({
|
|
4743
4809
|
"src/app/router/CommandsRouter.ts"() {
|
|
4744
4810
|
"use strict";
|
|
@@ -4748,6 +4814,7 @@ var init_CommandsRouter = __esm({
|
|
|
4748
4814
|
import_promises4 = require("fs/promises");
|
|
4749
4815
|
import_node_path4 = require("path");
|
|
4750
4816
|
MIDDLEWARE_PATTERN = /^\+middleware\.(m|c)?(j|t)sx?$/;
|
|
4817
|
+
GLOBAL_MIDDLEWARE_PATTERN = /^\+global-middleware\.(m|c)?(j|t)sx?$/;
|
|
4751
4818
|
COMMAND_PATTERN = /^([^+().][^().]*)\.(m|c)?(j|t)sx?$/;
|
|
4752
4819
|
CATEGORY_PATTERN = /^\(.+\)$/;
|
|
4753
4820
|
_CommandsRouter = class _CommandsRouter {
|
|
@@ -4771,7 +4838,7 @@ var init_CommandsRouter = __esm({
|
|
|
4771
4838
|
return COMMAND_PATTERN.test(name);
|
|
4772
4839
|
}
|
|
4773
4840
|
isMiddleware(name) {
|
|
4774
|
-
return MIDDLEWARE_PATTERN.test(name);
|
|
4841
|
+
return MIDDLEWARE_PATTERN.test(name) || GLOBAL_MIDDLEWARE_PATTERN.test(name);
|
|
4775
4842
|
}
|
|
4776
4843
|
isCategory(name) {
|
|
4777
4844
|
return CATEGORY_PATTERN.test(name);
|
|
@@ -4842,7 +4909,8 @@ var init_CommandsRouter = __esm({
|
|
|
4842
4909
|
name: (0, import_node_path4.basename)(path2, (0, import_node_path4.extname)(path2)),
|
|
4843
4910
|
path: path2,
|
|
4844
4911
|
relativePath: this.replaceEntrypoint(path2),
|
|
4845
|
-
parentPath: entry.parentPath
|
|
4912
|
+
parentPath: entry.parentPath,
|
|
4913
|
+
global: GLOBAL_MIDDLEWARE_PATTERN.test(name)
|
|
4846
4914
|
};
|
|
4847
4915
|
this.middlewares.set(middleware.id, middleware);
|
|
4848
4916
|
}
|
|
@@ -4851,7 +4919,7 @@ var init_CommandsRouter = __esm({
|
|
|
4851
4919
|
this.commands.forEach((command) => {
|
|
4852
4920
|
const commandPath = command.parentPath;
|
|
4853
4921
|
const samePathMiddlewares = Array.from(this.middlewares.values()).filter((middleware) => {
|
|
4854
|
-
return middleware.parentPath === commandPath;
|
|
4922
|
+
return middleware.parentPath === commandPath || middleware.global;
|
|
4855
4923
|
}).map((middleware) => middleware.id);
|
|
4856
4924
|
command.middlewares = Array.from(
|
|
4857
4925
|
/* @__PURE__ */ new Set([...command.middlewares, ...samePathMiddlewares])
|
|
@@ -4886,12 +4954,25 @@ var init_EventsRouter = __esm({
|
|
|
4886
4954
|
*/
|
|
4887
4955
|
constructor(options) {
|
|
4888
4956
|
this.options = options;
|
|
4889
|
-
|
|
4957
|
+
var _a;
|
|
4958
|
+
if (options.entrypoints) {
|
|
4959
|
+
options.entrypoints = Array.from(new Set(options.entrypoints));
|
|
4960
|
+
}
|
|
4961
|
+
if (!((_a = options.entrypoints) == null ? void 0 : _a.length)) {
|
|
4890
4962
|
throw new Error("Entrypoint directory must be provided");
|
|
4891
4963
|
}
|
|
4892
4964
|
}
|
|
4893
4965
|
/** Internal storage of parsed events */
|
|
4894
4966
|
events = new import_discord18.Collection();
|
|
4967
|
+
/**
|
|
4968
|
+
* Adds new entrypoints to the router
|
|
4969
|
+
* @param entrypoints - Array of new entrypoint paths
|
|
4970
|
+
*/
|
|
4971
|
+
addEntrypoints(entrypoints) {
|
|
4972
|
+
this.options.entrypoints = Array.from(
|
|
4973
|
+
/* @__PURE__ */ new Set([...this.options.entrypoints, ...entrypoints])
|
|
4974
|
+
);
|
|
4975
|
+
}
|
|
4895
4976
|
/**
|
|
4896
4977
|
* Find a parsed event by its name
|
|
4897
4978
|
* @param event - Name of the event to find
|
|
@@ -4904,14 +4985,14 @@ var init_EventsRouter = __esm({
|
|
|
4904
4985
|
* Get the entrypoint directory path
|
|
4905
4986
|
* @returns Entrypoint directory path
|
|
4906
4987
|
*/
|
|
4907
|
-
get
|
|
4908
|
-
return this.options.
|
|
4988
|
+
get entrypoints() {
|
|
4989
|
+
return this.options.entrypoints;
|
|
4909
4990
|
}
|
|
4910
4991
|
/**
|
|
4911
4992
|
* Checks if the entrypoint path is valid
|
|
4912
4993
|
*/
|
|
4913
4994
|
isValidPath() {
|
|
4914
|
-
return (0, import_node_fs5.existsSync)(
|
|
4995
|
+
return this.entrypoints.every((entrypoint) => (0, import_node_fs5.existsSync)(entrypoint));
|
|
4915
4996
|
}
|
|
4916
4997
|
/**
|
|
4917
4998
|
* Clear all parsed events
|
|
@@ -4932,11 +5013,13 @@ var init_EventsRouter = __esm({
|
|
|
4932
5013
|
* @returns Promise resolving to the events tree
|
|
4933
5014
|
*/
|
|
4934
5015
|
async scan() {
|
|
4935
|
-
const
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
5016
|
+
for (const entrypoint of this.entrypoints) {
|
|
5017
|
+
const dirs = await (0, import_promises5.readdir)(entrypoint, { withFileTypes: true });
|
|
5018
|
+
for (const dir of dirs) {
|
|
5019
|
+
if (dir.isDirectory()) {
|
|
5020
|
+
const path2 = (0, import_node_path5.join)(entrypoint, dir.name);
|
|
5021
|
+
await this.scanEvent(dir.name, path2, null, [], true);
|
|
5022
|
+
}
|
|
4940
5023
|
}
|
|
4941
5024
|
}
|
|
4942
5025
|
return Object.fromEntries(this.events);
|
|
@@ -5008,6 +5091,9 @@ var init_AppEventsHandler = __esm({
|
|
|
5008
5091
|
await this.loadEvents();
|
|
5009
5092
|
}
|
|
5010
5093
|
async loadEvents() {
|
|
5094
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
5095
|
+
return plugin.onBeforeEventsLoad(ctx);
|
|
5096
|
+
});
|
|
5011
5097
|
const router = this.commandkit.eventsRouter;
|
|
5012
5098
|
const events = await router.scan();
|
|
5013
5099
|
for (const event of Object.values(events)) {
|
|
@@ -5042,6 +5128,9 @@ var init_AppEventsHandler = __esm({
|
|
|
5042
5128
|
);
|
|
5043
5129
|
}
|
|
5044
5130
|
this.registerAllClientEvents();
|
|
5131
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
5132
|
+
return plugin.onAfterEventsLoad(ctx);
|
|
5133
|
+
});
|
|
5045
5134
|
}
|
|
5046
5135
|
unregisterAll() {
|
|
5047
5136
|
this.unregisterAllClientListeners();
|
|
@@ -5577,16 +5666,19 @@ var init_CommandKit = __esm({
|
|
|
5577
5666
|
this.commandsRouter = new CommandsRouter({
|
|
5578
5667
|
entrypoint: commandsPath
|
|
5579
5668
|
});
|
|
5669
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
5670
|
+
return plugin.onCommandsRouterInit(ctx);
|
|
5671
|
+
});
|
|
5580
5672
|
this.eventsRouter = new EventsRouter({
|
|
5581
|
-
|
|
5673
|
+
entrypoints: [events]
|
|
5674
|
+
});
|
|
5675
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
5676
|
+
return plugin.onEventsRouterInit(ctx);
|
|
5582
5677
|
});
|
|
5583
5678
|
await __privateMethod(this, _CommandKit_instances, initEvents_fn).call(this);
|
|
5584
5679
|
await __privateMethod(this, _CommandKit_instances, initCommands_fn).call(this);
|
|
5585
5680
|
}, "#init");
|
|
5586
5681
|
initCommands_fn = /* @__PURE__ */ __name(async function() {
|
|
5587
|
-
await this.plugins.execute((ctx, plugin) => {
|
|
5588
|
-
return plugin.onBeforeCommandsLoad(ctx);
|
|
5589
|
-
});
|
|
5590
5682
|
if (this.commandsRouter.isValidPath()) {
|
|
5591
5683
|
const result = await this.commandsRouter.scan();
|
|
5592
5684
|
if (COMMANDKIT_IS_DEV) {
|
|
@@ -5597,22 +5689,13 @@ var init_CommandKit = __esm({
|
|
|
5597
5689
|
}
|
|
5598
5690
|
}
|
|
5599
5691
|
await this.commandHandler.loadCommands();
|
|
5600
|
-
await this.plugins.execute((ctx, plugin) => {
|
|
5601
|
-
return plugin.onAfterCommandsLoad(ctx);
|
|
5602
|
-
});
|
|
5603
5692
|
this.commandHandler.printBanner();
|
|
5604
5693
|
}, "#initCommands");
|
|
5605
5694
|
initEvents_fn = /* @__PURE__ */ __name(async function() {
|
|
5606
|
-
await this.plugins.execute((ctx, plugin) => {
|
|
5607
|
-
return plugin.onBeforeEventsLoad(ctx);
|
|
5608
|
-
});
|
|
5609
5695
|
if (this.eventsRouter.isValidPath()) {
|
|
5610
5696
|
await this.eventsRouter.scan();
|
|
5611
5697
|
}
|
|
5612
5698
|
await this.eventHandler.loadEvents();
|
|
5613
|
-
await this.plugins.execute((ctx, plugin) => {
|
|
5614
|
-
return plugin.onAfterEventsLoad(ctx);
|
|
5615
|
-
});
|
|
5616
5699
|
}, "#initEvents");
|
|
5617
5700
|
__name(_CommandKit, "CommandKit");
|
|
5618
5701
|
__publicField(_CommandKit, "createElement", createElement);
|
|
@@ -5633,7 +5716,7 @@ var init_version = __esm({
|
|
|
5633
5716
|
"use strict";
|
|
5634
5717
|
init_cjs_shims();
|
|
5635
5718
|
version = /* @__MACRO__ $version */
|
|
5636
|
-
"0.1.11-dev.
|
|
5719
|
+
"0.1.11-dev.20250331145527";
|
|
5637
5720
|
}
|
|
5638
5721
|
});
|
|
5639
5722
|
|
|
@@ -6234,6 +6317,7 @@ __export(index_exports, {
|
|
|
6234
6317
|
getCommandKit: () => getCommandKit,
|
|
6235
6318
|
getConfig: () => getConfig,
|
|
6236
6319
|
getContext: () => getContext,
|
|
6320
|
+
getCurrentDirectory: () => getCurrentDirectory,
|
|
6237
6321
|
getElement: () => getElement,
|
|
6238
6322
|
invalidate: () => invalidate,
|
|
6239
6323
|
isCachedFunction: () => isCachedFunction,
|
|
@@ -6301,6 +6385,7 @@ init_Logger();
|
|
|
6301
6385
|
init_router();
|
|
6302
6386
|
init_version();
|
|
6303
6387
|
init_plugins();
|
|
6388
|
+
init_utilities();
|
|
6304
6389
|
|
|
6305
6390
|
// src/cli/init.ts
|
|
6306
6391
|
init_cjs_shims();
|
|
@@ -6425,6 +6510,7 @@ var index_default = CommandKit;
|
|
|
6425
6510
|
getCommandKit,
|
|
6426
6511
|
getConfig,
|
|
6427
6512
|
getContext,
|
|
6513
|
+
getCurrentDirectory,
|
|
6428
6514
|
getElement,
|
|
6429
6515
|
invalidate,
|
|
6430
6516
|
isCachedFunction,
|