commandkit 0.1.11-dev.20250403165359 → 0.1.11-dev.20250405091951
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 +80 -28
- package/dist/index.js +115 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -731,6 +731,36 @@ declare function rethrow(error: unknown): void;
|
|
|
731
731
|
*/
|
|
732
732
|
declare function redirect(): never;
|
|
733
733
|
|
|
734
|
+
interface PreRegisterCommandsEvent {
|
|
735
|
+
preventDefault(): void;
|
|
736
|
+
commands: CommandData[];
|
|
737
|
+
}
|
|
738
|
+
declare class CommandRegistrar {
|
|
739
|
+
readonly commandkit: CommandKit;
|
|
740
|
+
private api;
|
|
741
|
+
/**
|
|
742
|
+
* Creates an instance of CommandRegistrar.
|
|
743
|
+
* @param commandkit The commandkit instance.
|
|
744
|
+
*/
|
|
745
|
+
constructor(commandkit: CommandKit);
|
|
746
|
+
/**
|
|
747
|
+
* Gets the commands data.
|
|
748
|
+
*/
|
|
749
|
+
getCommandsData(): CommandData[];
|
|
750
|
+
/**
|
|
751
|
+
* Registers loaded commands.
|
|
752
|
+
*/
|
|
753
|
+
register(): Promise<void>;
|
|
754
|
+
/**
|
|
755
|
+
* Updates the global commands.
|
|
756
|
+
*/
|
|
757
|
+
updateGlobalCommands(commands: CommandData[]): Promise<void>;
|
|
758
|
+
/**
|
|
759
|
+
* Updates the guild commands.
|
|
760
|
+
*/
|
|
761
|
+
updateGuildCommands(commands: CommandData[]): Promise<void>;
|
|
762
|
+
}
|
|
763
|
+
|
|
734
764
|
type CommandSource = Interaction | Message$1;
|
|
735
765
|
declare function isMessageSource(source: CommandSource): source is Message$1;
|
|
736
766
|
declare function isInteractionSource(source: CommandSource): source is Interaction;
|
|
@@ -1035,32 +1065,6 @@ declare class MiddlewareContext<T extends CommandExecutionMode = CommandExecutio
|
|
|
1035
1065
|
setCommandRunner(fn: RunCommand): void;
|
|
1036
1066
|
}
|
|
1037
1067
|
|
|
1038
|
-
declare class CommandRegistrar {
|
|
1039
|
-
readonly commandkit: CommandKit;
|
|
1040
|
-
private api;
|
|
1041
|
-
/**
|
|
1042
|
-
* Creates an instance of CommandRegistrar.
|
|
1043
|
-
* @param commandkit The commandkit instance.
|
|
1044
|
-
*/
|
|
1045
|
-
constructor(commandkit: CommandKit);
|
|
1046
|
-
/**
|
|
1047
|
-
* Gets the commands data.
|
|
1048
|
-
*/
|
|
1049
|
-
getCommandsData(): CommandData[];
|
|
1050
|
-
/**
|
|
1051
|
-
* Registers loaded commands.
|
|
1052
|
-
*/
|
|
1053
|
-
register(): Promise<void>;
|
|
1054
|
-
/**
|
|
1055
|
-
* Updates the global commands.
|
|
1056
|
-
*/
|
|
1057
|
-
updateGlobalCommands(commands: CommandData[]): Promise<void>;
|
|
1058
|
-
/**
|
|
1059
|
-
* Updates the guild commands.
|
|
1060
|
-
*/
|
|
1061
|
-
updateGuildCommands(commands: CommandData[]): Promise<void>;
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
1068
|
declare class MemoryCache extends CacheProvider {
|
|
1065
1069
|
#private;
|
|
1066
1070
|
get<T>(key: string): Promise<CacheEntry<T> | undefined>;
|
|
@@ -1196,6 +1200,7 @@ interface Middleware {
|
|
|
1196
1200
|
relativePath: string;
|
|
1197
1201
|
parentPath: string;
|
|
1198
1202
|
global: boolean;
|
|
1203
|
+
command: string | null;
|
|
1199
1204
|
}
|
|
1200
1205
|
interface ParsedCommandData {
|
|
1201
1206
|
commands: Record<string, Command>;
|
|
@@ -1663,6 +1668,33 @@ declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> ex
|
|
|
1663
1668
|
* @param commands The command that is being loaded. This is a CommandBuilderLike object which represents Discord's command
|
|
1664
1669
|
*/
|
|
1665
1670
|
prepareCommand(ctx: CommandKitPluginRuntime, commands: CommandBuilderLike): Promise<CommandBuilderLike | null>;
|
|
1671
|
+
/**
|
|
1672
|
+
* Called before command is registered to discord. This method can cancel the registration of the command and handle it manually.
|
|
1673
|
+
* @param ctx The context
|
|
1674
|
+
* @param data The command registration data
|
|
1675
|
+
*/
|
|
1676
|
+
onBeforeRegisterCommands(ctx: CommandKitPluginRuntime, event: PreRegisterCommandsEvent): Promise<void>;
|
|
1677
|
+
/**
|
|
1678
|
+
* Called before global commands registration. This method can cancel the registration of the command and handle it manually.
|
|
1679
|
+
* This method is called after `onBeforeRegisterCommands` if that stage was not handled.
|
|
1680
|
+
* @param ctx The context
|
|
1681
|
+
* @param event The command registration data
|
|
1682
|
+
*/
|
|
1683
|
+
onBeforeRegisterGlobalCommands(ctx: CommandKitPluginRuntime, event: PreRegisterCommandsEvent): Promise<void>;
|
|
1684
|
+
/**
|
|
1685
|
+
* Called before guild commands registration. This method can cancel the registration of the command and handle it manually.
|
|
1686
|
+
* This method is called before guilds of the command are resolved. It is called after `onBeforeRegisterCommands` if that stage was not handled.
|
|
1687
|
+
* @param ctx The context
|
|
1688
|
+
* @param event The command registration data
|
|
1689
|
+
*/
|
|
1690
|
+
onBeforePrepareGuildCommandsRegistration(ctx: CommandKitPluginRuntime, event: PreRegisterCommandsEvent): Promise<void>;
|
|
1691
|
+
/**
|
|
1692
|
+
* Called before guild commands registration. This method can cancel the registration of the command and handle it manually.
|
|
1693
|
+
* This method is called after guilds of the command are resolved. It is called after `onBeforePrepareGuildCommandsRegistration` if that stage was not handled.
|
|
1694
|
+
* @param ctx The context
|
|
1695
|
+
* @param event The command registration data
|
|
1696
|
+
*/
|
|
1697
|
+
onBeforeRegisterGuildCommands(ctx: CommandKitPluginRuntime, event: PreRegisterCommandsEvent): Promise<void>;
|
|
1666
1698
|
}
|
|
1667
1699
|
declare function isRuntimePlugin(plugin: unknown): plugin is RuntimePlugin;
|
|
1668
1700
|
|
|
@@ -1771,7 +1803,7 @@ interface CommandKitConfig {
|
|
|
1771
1803
|
/**
|
|
1772
1804
|
* The plugins to use with CommandKit.
|
|
1773
1805
|
*/
|
|
1774
|
-
plugins?: CommandKitPlugin[]
|
|
1806
|
+
plugins?: MaybeArray<CommandKitPlugin[]>;
|
|
1775
1807
|
/**
|
|
1776
1808
|
* The esbuild plugins to use with CommandKit.
|
|
1777
1809
|
*/
|
|
@@ -1909,6 +1941,26 @@ declare const version: string;
|
|
|
1909
1941
|
|
|
1910
1942
|
declare function getCurrentDirectory(): string;
|
|
1911
1943
|
declare function getSourceDirectories(): string[];
|
|
1944
|
+
/**
|
|
1945
|
+
* Debounces a function.
|
|
1946
|
+
* @param fn The function to debounce.
|
|
1947
|
+
* @param ms The debounce time in milliseconds.
|
|
1948
|
+
* @returns The debounced function.
|
|
1949
|
+
*/
|
|
1950
|
+
declare function debounce<R, F extends (...args: any[]) => R>(fn: F, ms: number): F;
|
|
1951
|
+
/**
|
|
1952
|
+
* Creates a function from the given function that runs only in development mode.
|
|
1953
|
+
* @param fn The function to run in development mode.
|
|
1954
|
+
* @returns The function that runs only in development mode.
|
|
1955
|
+
* @example
|
|
1956
|
+
* ```ts
|
|
1957
|
+
* const devOnlyFn = devOnly(() => {
|
|
1958
|
+
* console.log('This function runs only in development mode');
|
|
1959
|
+
* });
|
|
1960
|
+
* devOnlyFn(); // This will log the message only in development mode
|
|
1961
|
+
* ```
|
|
1962
|
+
*/
|
|
1963
|
+
declare function devOnly<T extends (...args: any[]) => any>(fn: T): T;
|
|
1912
1964
|
|
|
1913
1965
|
/**
|
|
1914
1966
|
* Creates a command line interface for CommandKit.
|
|
@@ -1917,4 +1969,4 @@ declare function getSourceDirectories(): string[];
|
|
|
1917
1969
|
*/
|
|
1918
1970
|
declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
|
|
1919
1971
|
|
|
1920
|
-
export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, ChannelSelectMenu, ChannelSelectMenuKit, type ChannelSelectMenuKitPredicate, type ChannelSelectMenuProps, type Command, type CommandBuilderLike, 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 CommandKitHMREvent, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandKitPlugin, CommandKitPluginRuntime, type CommandKitSelectMenuBuilderInteractionCollectorDispatch, type CommandKitSelectMenuBuilderInteractionCollectorDispatchContextData, type CommandKitSelectMenuBuilderOnEnd, type CommandSource, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonBuilderKit, type CommonPluginRuntime, type CommonSelectMenuProps, CompilerPlugin, CompilerPluginRuntime, Context, type ContextParameters, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, HMREventType, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, type Loader, 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 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, getSourceDirectories, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isInteractionSource, isMessageSource, isRuntimePlugin, makeContextAwareFunction, provideContext, redirect, rethrow, revalidate, useEnvironment, version, zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired };
|
|
1972
|
+
export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, COMMANDKIT_CACHE_TAG, COMMANDKIT_IS_DEV, COMMANDKIT_IS_TEST, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, ChannelSelectMenu, ChannelSelectMenuKit, type ChannelSelectMenuKitPredicate, type ChannelSelectMenuProps, type Command, type CommandBuilderLike, 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 CommandKitHMREvent, type CommandKitLoggerOptions, type CommandKitModalBuilderInteractionCollectorDispatch, type CommandKitModalBuilderInteractionCollectorDispatchContextData, type CommandKitModalBuilderOnEnd, type CommandKitOptions, type CommandKitPlugin, CommandKitPluginRuntime, type CommandKitSelectMenuBuilderInteractionCollectorDispatch, type CommandKitSelectMenuBuilderInteractionCollectorDispatchContextData, type CommandKitSelectMenuBuilderOnEnd, CommandRegistrar, type CommandSource, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonBuilderKit, type CommonPluginRuntime, type CommonSelectMenuProps, CompilerPlugin, CompilerPluginRuntime, Context, type ContextParameters, DefaultLogger, ElementType, EventInterceptor, type EventInterceptorContextData, type EventInterceptorErrorHandler, EventsRouter, type EventsRouterOptions, type EventsTree, Fragment, type FragmentElementProps, type GenericFunction, HMREventType, type ILogger, type InteractionCommandContext, type InteractionCommandMiddlewareContext, type LoadedCommand, type Loader, 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 PreRegisterCommandsEvent, 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 UserContextMenuCommand, type UserContextMenuCommandContext, type UserContextMenuCommandMiddlewareContext, UserSelectMenu, UserSelectMenuKit, type UserSelectMenuKitPredicate, type UserSelectMenuProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, commandkit, createElement, createLogger, debounce, CommandKit as default, defineConfig, devOnly, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getCurrentDirectory, getElement, getSourceDirectories, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isInteractionSource, isMessageSource, isRuntimePlugin, makeContextAwareFunction, provideContext, redirect, rethrow, revalidate, useEnvironment, version, zzz_commandkit_secret_internal_use_cache_wrapper_do_not_use_or_you_will_be_fired };
|
package/dist/index.js
CHANGED
|
@@ -2053,6 +2053,37 @@ var init_RuntimePlugin = __esm({
|
|
|
2053
2053
|
async prepareCommand(ctx, commands) {
|
|
2054
2054
|
return null;
|
|
2055
2055
|
}
|
|
2056
|
+
/**
|
|
2057
|
+
* Called before command is registered to discord. This method can cancel the registration of the command and handle it manually.
|
|
2058
|
+
* @param ctx The context
|
|
2059
|
+
* @param data The command registration data
|
|
2060
|
+
*/
|
|
2061
|
+
async onBeforeRegisterCommands(ctx, event) {
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* Called before global commands registration. This method can cancel the registration of the command and handle it manually.
|
|
2065
|
+
* This method is called after `onBeforeRegisterCommands` if that stage was not handled.
|
|
2066
|
+
* @param ctx The context
|
|
2067
|
+
* @param event The command registration data
|
|
2068
|
+
*/
|
|
2069
|
+
async onBeforeRegisterGlobalCommands(ctx, event) {
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Called before guild commands registration. This method can cancel the registration of the command and handle it manually.
|
|
2073
|
+
* This method is called before guilds of the command are resolved. It is called after `onBeforeRegisterCommands` if that stage was not handled.
|
|
2074
|
+
* @param ctx The context
|
|
2075
|
+
* @param event The command registration data
|
|
2076
|
+
*/
|
|
2077
|
+
async onBeforePrepareGuildCommandsRegistration(ctx, event) {
|
|
2078
|
+
}
|
|
2079
|
+
/**
|
|
2080
|
+
* Called before guild commands registration. This method can cancel the registration of the command and handle it manually.
|
|
2081
|
+
* This method is called after guilds of the command are resolved. It is called after `onBeforePrepareGuildCommandsRegistration` if that stage was not handled.
|
|
2082
|
+
* @param ctx The context
|
|
2083
|
+
* @param event The command registration data
|
|
2084
|
+
*/
|
|
2085
|
+
async onBeforeRegisterGuildCommands(ctx, event) {
|
|
2086
|
+
}
|
|
2056
2087
|
};
|
|
2057
2088
|
__name(_RuntimePlugin, "RuntimePlugin");
|
|
2058
2089
|
RuntimePlugin = _RuntimePlugin;
|
|
@@ -2810,7 +2841,10 @@ function defineConfig(config = {}) {
|
|
|
2810
2841
|
...config.esbuildPlugins ?? [],
|
|
2811
2842
|
...defaultConfig.esbuildPlugins ?? []
|
|
2812
2843
|
],
|
|
2813
|
-
plugins: [
|
|
2844
|
+
plugins: [
|
|
2845
|
+
...config.plugins ?? [],
|
|
2846
|
+
...defaultConfig.plugins ?? []
|
|
2847
|
+
],
|
|
2814
2848
|
sourceMap: {
|
|
2815
2849
|
...defaultConfig.sourceMap,
|
|
2816
2850
|
...config.sourceMap
|
|
@@ -2891,6 +2925,14 @@ function debounce(fn, ms2) {
|
|
|
2891
2925
|
});
|
|
2892
2926
|
};
|
|
2893
2927
|
}
|
|
2928
|
+
function devOnly(fn) {
|
|
2929
|
+
const f = /* @__PURE__ */ __name((...args) => {
|
|
2930
|
+
if (COMMANDKIT_IS_DEV) {
|
|
2931
|
+
return fn(...args);
|
|
2932
|
+
}
|
|
2933
|
+
}, "f");
|
|
2934
|
+
return f;
|
|
2935
|
+
}
|
|
2894
2936
|
var import_node_fs, import_node_path, appDir, currentDir;
|
|
2895
2937
|
var init_utilities = __esm({
|
|
2896
2938
|
"src/utils/utilities.ts"() {
|
|
@@ -2906,6 +2948,7 @@ var init_utilities = __esm({
|
|
|
2906
2948
|
__name(getSourceDirectories, "getSourceDirectories");
|
|
2907
2949
|
__name(findAppDirectory, "findAppDirectory");
|
|
2908
2950
|
__name(debounce, "debounce");
|
|
2951
|
+
__name(devOnly, "devOnly");
|
|
2909
2952
|
}
|
|
2910
2953
|
});
|
|
2911
2954
|
|
|
@@ -3192,10 +3235,22 @@ var init_CommandRegistrar = __esm({
|
|
|
3192
3235
|
* Registers loaded commands.
|
|
3193
3236
|
*/
|
|
3194
3237
|
async register() {
|
|
3238
|
+
const commands = this.getCommandsData();
|
|
3239
|
+
let preRegistrationPrevented = false;
|
|
3240
|
+
const preRegisterEvent = {
|
|
3241
|
+
preventDefault() {
|
|
3242
|
+
preRegistrationPrevented = true;
|
|
3243
|
+
},
|
|
3244
|
+
commands
|
|
3245
|
+
};
|
|
3246
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
3247
|
+
if (preRegistrationPrevented) return;
|
|
3248
|
+
return plugin.onBeforeRegisterCommands(ctx, preRegisterEvent);
|
|
3249
|
+
});
|
|
3250
|
+
if (preRegistrationPrevented) return;
|
|
3195
3251
|
if (!this.commandkit.client.isReady()) {
|
|
3196
3252
|
throw new Error("Cannot register commands before the client is ready");
|
|
3197
3253
|
}
|
|
3198
|
-
const commands = this.getCommandsData();
|
|
3199
3254
|
const guildCommands = commands.filter((command) => {
|
|
3200
3255
|
var _a;
|
|
3201
3256
|
return (_a = command.guilds) == null ? void 0 : _a.filter(Boolean).length;
|
|
@@ -3220,6 +3275,17 @@ var init_CommandRegistrar = __esm({
|
|
|
3220
3275
|
*/
|
|
3221
3276
|
async updateGlobalCommands(commands) {
|
|
3222
3277
|
if (!commands.length) return;
|
|
3278
|
+
let prevented = false;
|
|
3279
|
+
const preRegisterEvent = {
|
|
3280
|
+
preventDefault() {
|
|
3281
|
+
prevented = true;
|
|
3282
|
+
},
|
|
3283
|
+
commands
|
|
3284
|
+
};
|
|
3285
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
3286
|
+
if (prevented) return;
|
|
3287
|
+
return plugin.onBeforeRegisterGlobalCommands(ctx, preRegisterEvent);
|
|
3288
|
+
});
|
|
3223
3289
|
try {
|
|
3224
3290
|
const data = await this.api.put(
|
|
3225
3291
|
import_discord14.Routes.applicationCommands(this.commandkit.client.user.id),
|
|
@@ -3241,6 +3307,22 @@ var init_CommandRegistrar = __esm({
|
|
|
3241
3307
|
* Updates the guild commands.
|
|
3242
3308
|
*/
|
|
3243
3309
|
async updateGuildCommands(commands) {
|
|
3310
|
+
if (!commands.length) return;
|
|
3311
|
+
let prevented = false;
|
|
3312
|
+
const preRegisterEvent = {
|
|
3313
|
+
preventDefault() {
|
|
3314
|
+
prevented = true;
|
|
3315
|
+
},
|
|
3316
|
+
commands
|
|
3317
|
+
};
|
|
3318
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
3319
|
+
if (prevented) return;
|
|
3320
|
+
return plugin.onBeforePrepareGuildCommandsRegistration(
|
|
3321
|
+
ctx,
|
|
3322
|
+
preRegisterEvent
|
|
3323
|
+
);
|
|
3324
|
+
});
|
|
3325
|
+
if (prevented) return;
|
|
3244
3326
|
try {
|
|
3245
3327
|
const guildCommandsMap = /* @__PURE__ */ new Map();
|
|
3246
3328
|
commands.forEach((command) => {
|
|
@@ -3256,6 +3338,18 @@ var init_CommandRegistrar = __esm({
|
|
|
3256
3338
|
if (!guildCommandsMap.size) return;
|
|
3257
3339
|
let count = 0;
|
|
3258
3340
|
for (const [guild, guildCommands] of guildCommandsMap) {
|
|
3341
|
+
let prevented2 = false;
|
|
3342
|
+
const preRegisterEvent2 = {
|
|
3343
|
+
preventDefault() {
|
|
3344
|
+
prevented2 = true;
|
|
3345
|
+
},
|
|
3346
|
+
commands: guildCommands
|
|
3347
|
+
};
|
|
3348
|
+
await this.commandkit.plugins.execute(async (ctx, plugin) => {
|
|
3349
|
+
if (prevented2) return;
|
|
3350
|
+
return plugin.onBeforeRegisterGuildCommands(ctx, preRegisterEvent2);
|
|
3351
|
+
});
|
|
3352
|
+
if (prevented2) continue;
|
|
3259
3353
|
const data = await this.api.put(
|
|
3260
3354
|
import_discord14.Routes.applicationGuildCommands(
|
|
3261
3355
|
this.commandkit.client.user.id,
|
|
@@ -4553,7 +4647,7 @@ var init_AppCommandHandler = __esm({
|
|
|
4553
4647
|
});
|
|
4554
4648
|
|
|
4555
4649
|
// src/app/router/CommandsRouter.ts
|
|
4556
|
-
var import_discord17, import_node_fs3, import_promises3, import_node_path3, MIDDLEWARE_PATTERN, GLOBAL_MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
4650
|
+
var import_discord17, import_node_fs3, import_promises3, import_node_path3, MIDDLEWARE_PATTERN, COMMAND_MIDDLEWARE_PATTERN, GLOBAL_MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
|
|
4557
4651
|
var init_CommandsRouter = __esm({
|
|
4558
4652
|
"src/app/router/CommandsRouter.ts"() {
|
|
4559
4653
|
"use strict";
|
|
@@ -4563,6 +4657,7 @@ var init_CommandsRouter = __esm({
|
|
|
4563
4657
|
import_promises3 = require("fs/promises");
|
|
4564
4658
|
import_node_path3 = require("path");
|
|
4565
4659
|
MIDDLEWARE_PATTERN = /^\+middleware\.(m|c)?(j|t)sx?$/;
|
|
4660
|
+
COMMAND_MIDDLEWARE_PATTERN = /^\+([^+().][^().]*)\.middleware\.(m|c)?(j|t)sx?$/;
|
|
4566
4661
|
GLOBAL_MIDDLEWARE_PATTERN = /^\+global-middleware\.(m|c)?(j|t)sx?$/;
|
|
4567
4662
|
COMMAND_PATTERN = /^([^+().][^().]*)\.(m|c)?(j|t)sx?$/;
|
|
4568
4663
|
CATEGORY_PATTERN = /^\(.+\)$/;
|
|
@@ -4587,7 +4682,7 @@ var init_CommandsRouter = __esm({
|
|
|
4587
4682
|
return COMMAND_PATTERN.test(name);
|
|
4588
4683
|
}
|
|
4589
4684
|
isMiddleware(name) {
|
|
4590
|
-
return MIDDLEWARE_PATTERN.test(name) || GLOBAL_MIDDLEWARE_PATTERN.test(name);
|
|
4685
|
+
return MIDDLEWARE_PATTERN.test(name) || GLOBAL_MIDDLEWARE_PATTERN.test(name) || COMMAND_MIDDLEWARE_PATTERN.test(name);
|
|
4591
4686
|
}
|
|
4592
4687
|
isCategory(name) {
|
|
4593
4688
|
return CATEGORY_PATTERN.test(name);
|
|
@@ -4659,7 +4754,8 @@ var init_CommandsRouter = __esm({
|
|
|
4659
4754
|
path: path3,
|
|
4660
4755
|
relativePath: this.replaceEntrypoint(path3),
|
|
4661
4756
|
parentPath: entry.parentPath,
|
|
4662
|
-
global: GLOBAL_MIDDLEWARE_PATTERN.test(name)
|
|
4757
|
+
global: GLOBAL_MIDDLEWARE_PATTERN.test(name),
|
|
4758
|
+
command: COMMAND_MIDDLEWARE_PATTERN.test(name) ? name.split(".")[0] || null : null
|
|
4663
4759
|
};
|
|
4664
4760
|
this.middlewares.set(middleware.id, middleware);
|
|
4665
4761
|
}
|
|
@@ -4668,7 +4764,9 @@ var init_CommandsRouter = __esm({
|
|
|
4668
4764
|
this.commands.forEach((command) => {
|
|
4669
4765
|
const commandPath = command.parentPath;
|
|
4670
4766
|
const samePathMiddlewares = Array.from(this.middlewares.values()).filter((middleware) => {
|
|
4671
|
-
|
|
4767
|
+
if (middleware.global) return true;
|
|
4768
|
+
if (middleware.command) return middleware.command === command.name;
|
|
4769
|
+
return middleware.parentPath === commandPath;
|
|
4672
4770
|
}).map((middleware) => middleware.id);
|
|
4673
4771
|
command.middlewares = Array.from(
|
|
4674
4772
|
/* @__PURE__ */ new Set([...command.middlewares, ...samePathMiddlewares])
|
|
@@ -5317,7 +5415,7 @@ var init_CommandKit = __esm({
|
|
|
5317
5415
|
return (_a = plugin.onBeforeClientLogin) == null ? void 0 : _a.call(plugin, ctx);
|
|
5318
5416
|
});
|
|
5319
5417
|
await this.options.client.login(
|
|
5320
|
-
token ?? process.env.TOKEN ?? process.env.DISCORD_TOKEN
|
|
5418
|
+
token ?? this.options.client.token ?? process.env.TOKEN ?? process.env.DISCORD_TOKEN
|
|
5321
5419
|
);
|
|
5322
5420
|
await this.plugins.execute((ctx, plugin) => {
|
|
5323
5421
|
var _a;
|
|
@@ -5333,7 +5431,7 @@ var init_CommandKit = __esm({
|
|
|
5333
5431
|
*/
|
|
5334
5432
|
async loadPlugins() {
|
|
5335
5433
|
const config = await loadConfigFile();
|
|
5336
|
-
const plugins = config.plugins.filter((p) => isRuntimePlugin(p));
|
|
5434
|
+
const plugins = config.plugins.flat(2).filter((p) => isRuntimePlugin(p));
|
|
5337
5435
|
if (!plugins.length) return;
|
|
5338
5436
|
for (const plugin of plugins) {
|
|
5339
5437
|
await this.plugins.softRegisterPlugin(plugin);
|
|
@@ -5497,7 +5595,7 @@ var init_version = __esm({
|
|
|
5497
5595
|
"use strict";
|
|
5498
5596
|
init_cjs_shims();
|
|
5499
5597
|
version = /* @__MACRO__ $version */
|
|
5500
|
-
"0.1.11-dev.
|
|
5598
|
+
"0.1.11-dev.20250405091951";
|
|
5501
5599
|
}
|
|
5502
5600
|
});
|
|
5503
5601
|
|
|
@@ -5848,7 +5946,7 @@ async function buildAndStart(configPath, skipStart = false) {
|
|
|
5848
5946
|
await buildApplication({
|
|
5849
5947
|
configPath,
|
|
5850
5948
|
isDev: true,
|
|
5851
|
-
plugins: config.plugins.filter((p) => isCompilerPlugin(p)),
|
|
5949
|
+
plugins: config.plugins.flat(2).filter((p) => isCompilerPlugin(p)),
|
|
5852
5950
|
esbuildPlugins: config.esbuildPlugins
|
|
5853
5951
|
});
|
|
5854
5952
|
if (skipStart) return null;
|
|
@@ -6376,6 +6474,7 @@ __export(index_exports, {
|
|
|
6376
6474
|
CommandKitEnvironment: () => CommandKitEnvironment,
|
|
6377
6475
|
CommandKitEnvironmentType: () => CommandKitEnvironmentType,
|
|
6378
6476
|
CommandKitPluginRuntime: () => CommandKitPluginRuntime,
|
|
6477
|
+
CommandRegistrar: () => CommandRegistrar,
|
|
6379
6478
|
CommandsRouter: () => CommandsRouter,
|
|
6380
6479
|
CompilerPlugin: () => CompilerPlugin,
|
|
6381
6480
|
CompilerPluginRuntime: () => CompilerPluginRuntime,
|
|
@@ -6415,8 +6514,10 @@ __export(index_exports, {
|
|
|
6415
6514
|
commandkit: () => commandkit,
|
|
6416
6515
|
createElement: () => createElement,
|
|
6417
6516
|
createLogger: () => createLogger,
|
|
6517
|
+
debounce: () => debounce,
|
|
6418
6518
|
default: () => index_default,
|
|
6419
6519
|
defineConfig: () => defineConfig,
|
|
6520
|
+
devOnly: () => devOnly,
|
|
6420
6521
|
exitContext: () => exitContext,
|
|
6421
6522
|
exitMiddleware: () => exitMiddleware,
|
|
6422
6523
|
fromEsbuildPlugin: () => fromEsbuildPlugin,
|
|
@@ -6458,6 +6559,7 @@ init_AppCommandHandler();
|
|
|
6458
6559
|
init_Context();
|
|
6459
6560
|
init_MessageCommandParser();
|
|
6460
6561
|
init_signals();
|
|
6562
|
+
init_CommandRegistrar();
|
|
6461
6563
|
|
|
6462
6564
|
// src/app/commands/helpers.ts
|
|
6463
6565
|
init_cjs_shims();
|
|
@@ -6559,6 +6661,7 @@ var index_default = CommandKit;
|
|
|
6559
6661
|
CommandKitEnvironment,
|
|
6560
6662
|
CommandKitEnvironmentType,
|
|
6561
6663
|
CommandKitPluginRuntime,
|
|
6664
|
+
CommandRegistrar,
|
|
6562
6665
|
CommandsRouter,
|
|
6563
6666
|
CompilerPlugin,
|
|
6564
6667
|
CompilerPluginRuntime,
|
|
@@ -6598,7 +6701,9 @@ var index_default = CommandKit;
|
|
|
6598
6701
|
commandkit,
|
|
6599
6702
|
createElement,
|
|
6600
6703
|
createLogger,
|
|
6704
|
+
debounce,
|
|
6601
6705
|
defineConfig,
|
|
6706
|
+
devOnly,
|
|
6602
6707
|
exitContext,
|
|
6603
6708
|
exitMiddleware,
|
|
6604
6709
|
fromEsbuildPlugin,
|