commandkit 0.1.11-dev.20250331033059 → 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 +31 -3
- package/dist/index.js +112 -28
- 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.
|
|
@@ -1307,7 +1312,7 @@ declare class CommandsRouter {
|
|
|
1307
1312
|
*/
|
|
1308
1313
|
interface EventsRouterOptions {
|
|
1309
1314
|
/** Root directory path where event handlers are located */
|
|
1310
|
-
|
|
1315
|
+
entrypoints: string[];
|
|
1311
1316
|
}
|
|
1312
1317
|
/**
|
|
1313
1318
|
* Represents a parsed event with its handlers
|
|
@@ -1339,6 +1344,11 @@ declare class EventsRouter {
|
|
|
1339
1344
|
* @throws Error if entrypoint is not provided
|
|
1340
1345
|
*/
|
|
1341
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;
|
|
1342
1352
|
/**
|
|
1343
1353
|
* Find a parsed event by its name
|
|
1344
1354
|
* @param event - Name of the event to find
|
|
@@ -1349,7 +1359,7 @@ declare class EventsRouter {
|
|
|
1349
1359
|
* Get the entrypoint directory path
|
|
1350
1360
|
* @returns Entrypoint directory path
|
|
1351
1361
|
*/
|
|
1352
|
-
get
|
|
1362
|
+
get entrypoints(): string[];
|
|
1353
1363
|
/**
|
|
1354
1364
|
* Checks if the entrypoint path is valid
|
|
1355
1365
|
*/
|
|
@@ -1432,12 +1442,18 @@ declare class AppCommandHandler {
|
|
|
1432
1442
|
private onMessageCreate;
|
|
1433
1443
|
private onMessageUpdate;
|
|
1434
1444
|
readonly commandRunner: AppCommandRunner;
|
|
1445
|
+
readonly externalCommandData: Collection<string, Command>;
|
|
1446
|
+
readonly externalMiddlewareData: Collection<string, Middleware>;
|
|
1435
1447
|
constructor(commandkit: CommandKit);
|
|
1436
1448
|
printBanner(): void;
|
|
1437
1449
|
getCommandsArray(): LoadedCommand[];
|
|
1438
1450
|
registerCommandHandler(): void;
|
|
1439
1451
|
prepareCommandRun(source: Interaction | Message$1, cmdName?: string): Promise<PreparedAppCommandExecution | null>;
|
|
1440
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>;
|
|
1441
1457
|
loadCommands(): Promise<void>;
|
|
1442
1458
|
private loadMiddleware;
|
|
1443
1459
|
private loadCommand;
|
|
@@ -1704,6 +1720,16 @@ declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> ex
|
|
|
1704
1720
|
* @param execute The function that executes the command
|
|
1705
1721
|
*/
|
|
1706
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>;
|
|
1707
1733
|
}
|
|
1708
1734
|
declare function isRuntimePlugin(plugin: unknown): plugin is RuntimePlugin;
|
|
1709
1735
|
|
|
@@ -1959,6 +1985,8 @@ declare const Logger: LoggerImpl;
|
|
|
1959
1985
|
*/
|
|
1960
1986
|
declare const version: string;
|
|
1961
1987
|
|
|
1988
|
+
declare function getCurrentDirectory(): string;
|
|
1989
|
+
|
|
1962
1990
|
/**
|
|
1963
1991
|
* Creates a command line interface for CommandKit.
|
|
1964
1992
|
* @param argv The arguments passed to the CLI.
|
|
@@ -1966,4 +1994,4 @@ declare const version: string;
|
|
|
1966
1994
|
*/
|
|
1967
1995
|
declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
|
|
1968
1996
|
|
|
1969
|
-
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
|
@@ -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 {
|
|
@@ -4888,12 +4954,25 @@ var init_EventsRouter = __esm({
|
|
|
4888
4954
|
*/
|
|
4889
4955
|
constructor(options) {
|
|
4890
4956
|
this.options = options;
|
|
4891
|
-
|
|
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)) {
|
|
4892
4962
|
throw new Error("Entrypoint directory must be provided");
|
|
4893
4963
|
}
|
|
4894
4964
|
}
|
|
4895
4965
|
/** Internal storage of parsed events */
|
|
4896
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
|
+
}
|
|
4897
4976
|
/**
|
|
4898
4977
|
* Find a parsed event by its name
|
|
4899
4978
|
* @param event - Name of the event to find
|
|
@@ -4906,14 +4985,14 @@ var init_EventsRouter = __esm({
|
|
|
4906
4985
|
* Get the entrypoint directory path
|
|
4907
4986
|
* @returns Entrypoint directory path
|
|
4908
4987
|
*/
|
|
4909
|
-
get
|
|
4910
|
-
return this.options.
|
|
4988
|
+
get entrypoints() {
|
|
4989
|
+
return this.options.entrypoints;
|
|
4911
4990
|
}
|
|
4912
4991
|
/**
|
|
4913
4992
|
* Checks if the entrypoint path is valid
|
|
4914
4993
|
*/
|
|
4915
4994
|
isValidPath() {
|
|
4916
|
-
return (0, import_node_fs5.existsSync)(
|
|
4995
|
+
return this.entrypoints.every((entrypoint) => (0, import_node_fs5.existsSync)(entrypoint));
|
|
4917
4996
|
}
|
|
4918
4997
|
/**
|
|
4919
4998
|
* Clear all parsed events
|
|
@@ -4934,11 +5013,13 @@ var init_EventsRouter = __esm({
|
|
|
4934
5013
|
* @returns Promise resolving to the events tree
|
|
4935
5014
|
*/
|
|
4936
5015
|
async scan() {
|
|
4937
|
-
const
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
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
|
+
}
|
|
4942
5023
|
}
|
|
4943
5024
|
}
|
|
4944
5025
|
return Object.fromEntries(this.events);
|
|
@@ -5010,6 +5091,9 @@ var init_AppEventsHandler = __esm({
|
|
|
5010
5091
|
await this.loadEvents();
|
|
5011
5092
|
}
|
|
5012
5093
|
async loadEvents() {
|
|
5094
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
5095
|
+
return plugin.onBeforeEventsLoad(ctx);
|
|
5096
|
+
});
|
|
5013
5097
|
const router = this.commandkit.eventsRouter;
|
|
5014
5098
|
const events = await router.scan();
|
|
5015
5099
|
for (const event of Object.values(events)) {
|
|
@@ -5044,6 +5128,9 @@ var init_AppEventsHandler = __esm({
|
|
|
5044
5128
|
);
|
|
5045
5129
|
}
|
|
5046
5130
|
this.registerAllClientEvents();
|
|
5131
|
+
await this.commandkit.plugins.execute((ctx, plugin) => {
|
|
5132
|
+
return plugin.onAfterEventsLoad(ctx);
|
|
5133
|
+
});
|
|
5047
5134
|
}
|
|
5048
5135
|
unregisterAll() {
|
|
5049
5136
|
this.unregisterAllClientListeners();
|
|
@@ -5579,16 +5666,19 @@ var init_CommandKit = __esm({
|
|
|
5579
5666
|
this.commandsRouter = new CommandsRouter({
|
|
5580
5667
|
entrypoint: commandsPath
|
|
5581
5668
|
});
|
|
5669
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
5670
|
+
return plugin.onCommandsRouterInit(ctx);
|
|
5671
|
+
});
|
|
5582
5672
|
this.eventsRouter = new EventsRouter({
|
|
5583
|
-
|
|
5673
|
+
entrypoints: [events]
|
|
5674
|
+
});
|
|
5675
|
+
await this.plugins.execute((ctx, plugin) => {
|
|
5676
|
+
return plugin.onEventsRouterInit(ctx);
|
|
5584
5677
|
});
|
|
5585
5678
|
await __privateMethod(this, _CommandKit_instances, initEvents_fn).call(this);
|
|
5586
5679
|
await __privateMethod(this, _CommandKit_instances, initCommands_fn).call(this);
|
|
5587
5680
|
}, "#init");
|
|
5588
5681
|
initCommands_fn = /* @__PURE__ */ __name(async function() {
|
|
5589
|
-
await this.plugins.execute((ctx, plugin) => {
|
|
5590
|
-
return plugin.onBeforeCommandsLoad(ctx);
|
|
5591
|
-
});
|
|
5592
5682
|
if (this.commandsRouter.isValidPath()) {
|
|
5593
5683
|
const result = await this.commandsRouter.scan();
|
|
5594
5684
|
if (COMMANDKIT_IS_DEV) {
|
|
@@ -5599,22 +5689,13 @@ var init_CommandKit = __esm({
|
|
|
5599
5689
|
}
|
|
5600
5690
|
}
|
|
5601
5691
|
await this.commandHandler.loadCommands();
|
|
5602
|
-
await this.plugins.execute((ctx, plugin) => {
|
|
5603
|
-
return plugin.onAfterCommandsLoad(ctx);
|
|
5604
|
-
});
|
|
5605
5692
|
this.commandHandler.printBanner();
|
|
5606
5693
|
}, "#initCommands");
|
|
5607
5694
|
initEvents_fn = /* @__PURE__ */ __name(async function() {
|
|
5608
|
-
await this.plugins.execute((ctx, plugin) => {
|
|
5609
|
-
return plugin.onBeforeEventsLoad(ctx);
|
|
5610
|
-
});
|
|
5611
5695
|
if (this.eventsRouter.isValidPath()) {
|
|
5612
5696
|
await this.eventsRouter.scan();
|
|
5613
5697
|
}
|
|
5614
5698
|
await this.eventHandler.loadEvents();
|
|
5615
|
-
await this.plugins.execute((ctx, plugin) => {
|
|
5616
|
-
return plugin.onAfterEventsLoad(ctx);
|
|
5617
|
-
});
|
|
5618
5699
|
}, "#initEvents");
|
|
5619
5700
|
__name(_CommandKit, "CommandKit");
|
|
5620
5701
|
__publicField(_CommandKit, "createElement", createElement);
|
|
@@ -5635,7 +5716,7 @@ var init_version = __esm({
|
|
|
5635
5716
|
"use strict";
|
|
5636
5717
|
init_cjs_shims();
|
|
5637
5718
|
version = /* @__MACRO__ $version */
|
|
5638
|
-
"0.1.11-dev.
|
|
5719
|
+
"0.1.11-dev.20250331145527";
|
|
5639
5720
|
}
|
|
5640
5721
|
});
|
|
5641
5722
|
|
|
@@ -6236,6 +6317,7 @@ __export(index_exports, {
|
|
|
6236
6317
|
getCommandKit: () => getCommandKit,
|
|
6237
6318
|
getConfig: () => getConfig,
|
|
6238
6319
|
getContext: () => getContext,
|
|
6320
|
+
getCurrentDirectory: () => getCurrentDirectory,
|
|
6239
6321
|
getElement: () => getElement,
|
|
6240
6322
|
invalidate: () => invalidate,
|
|
6241
6323
|
isCachedFunction: () => isCachedFunction,
|
|
@@ -6303,6 +6385,7 @@ init_Logger();
|
|
|
6303
6385
|
init_router();
|
|
6304
6386
|
init_version();
|
|
6305
6387
|
init_plugins();
|
|
6388
|
+
init_utilities();
|
|
6306
6389
|
|
|
6307
6390
|
// src/cli/init.ts
|
|
6308
6391
|
init_cjs_shims();
|
|
@@ -6427,6 +6510,7 @@ var index_default = CommandKit;
|
|
|
6427
6510
|
getCommandKit,
|
|
6428
6511
|
getConfig,
|
|
6429
6512
|
getContext,
|
|
6513
|
+
getCurrentDirectory,
|
|
6430
6514
|
getElement,
|
|
6431
6515
|
invalidate,
|
|
6432
6516
|
isCachedFunction,
|