commandkit 0.1.11-dev.20250328085113 → 0.1.11-dev.20250330063035

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { RESTPostAPIApplicationCommandsJSONBody, Client, Interaction, CacheType, PermissionsString, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, ClientEvents, Awaitable, ButtonBuilder, ButtonInteraction, Events, ModalBuilder, ModalSubmitInteraction, ActionRowBuilder, TextInputBuilder, ButtonStyle, ComponentEmojiResolvable, TextInputStyle, LocalizationMap, Locale, Message as Message$1, ApplicationCommandOptionType, GuildMember, Attachment, User, Role, CommandInteractionOption, SlashCommandBuilder, ContextMenuCommandBuilder, PartialMessage } from 'discord.js';
2
+ import { RESTPostAPIApplicationCommandsJSONBody, Client, Interaction, CacheType, ClientEvents, Awaitable, ButtonBuilder, ButtonInteraction, Events, ModalBuilder, ModalSubmitInteraction, ActionRowBuilder, TextInputBuilder, ButtonStyle, ComponentEmojiResolvable, TextInputStyle, LocalizationMap, Locale, Message as Message$1, ApplicationCommandOptionType, GuildMember, Attachment, User, Role, CommandInteractionOption, ChatInputCommandInteraction, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, AutocompleteInteraction, Collection, SlashCommandBuilder, ContextMenuCommandBuilder, PartialMessage } from 'discord.js';
3
3
  import EventEmitter from 'node:events';
4
4
  import { Channel } from 'diagnostics_channel';
5
5
  import * as commander from 'commander';
@@ -25,42 +25,6 @@ interface CommandKitOptions {
25
25
  * The Discord.js client object to use with CommandKit.
26
26
  */
27
27
  client: Client;
28
- /**
29
- * The path to your commands directory.
30
- */
31
- commandsPath?: string;
32
- /**
33
- * The path to your events directory.
34
- */
35
- eventsPath?: string;
36
- /**
37
- * The path to the validations directory.
38
- */
39
- validationsPath?: string;
40
- /**
41
- * List of development guild IDs to restrict devOnly commands to.
42
- */
43
- devGuildIds?: string[];
44
- /**
45
- * List of developer user IDs to restrict devOnly commands to.
46
- */
47
- devUserIds?: string[];
48
- /**
49
- * List of developer role IDs to restrict devOnly commands to.
50
- */
51
- devRoleIds?: string[];
52
- /**
53
- * Skip CommandKit's built-in validations (for devOnly commands).
54
- */
55
- skipBuiltInValidations?: boolean;
56
- /**
57
- * Bulk register application commands instead of one-by-one.
58
- */
59
- bulkRegister?: boolean;
60
- /**
61
- * Whether or not to debug the command handler.
62
- */
63
- debugCommands?: boolean;
64
28
  /**
65
29
  * The cache provider to use with CommandKit. Defaults to MemoryCache provider.
66
30
  * Set this to `null` to not use any cache provider.
@@ -84,179 +48,9 @@ interface CommandContext<T extends Interaction, Cached extends CacheType> {
84
48
  */
85
49
  handler: CommandKit;
86
50
  }
87
- /**
88
- * Represents a command file.
89
- */
90
- interface CommandFileObject {
91
- data: CommandData;
92
- options?: CommandOptions;
93
- run: <Cached extends CacheType = CacheType>(ctx: CommandContext<Interaction, Cached>) => Awaited<void>;
94
- autocomplete?: <Cached extends CacheType = CacheType>(ctx: CommandContext<Interaction, Cached>) => Awaited<void>;
95
- filePath: string;
96
- category: string | null;
97
- [key: string]: any;
98
- }
99
- /**
100
- * A reload type for commands.
101
- */
102
- type ReloadOptions = 'dev' | 'global' | ReloadType;
103
- /**
104
- * Props for command run functions.
105
- */
106
- interface CommandProps {
107
- /**
108
- * The current command interaction object.
109
- */
110
- interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | UserContextMenuCommandInteraction | MessageContextMenuCommandInteraction | AutocompleteInteraction;
111
- /**
112
- * The Discord.js client object that CommandKit is handling.
113
- */
114
- client: Client<true>;
115
- /**
116
- * The current CommandKit handler instance.
117
- */
118
- handler: CommandKit;
119
- }
120
- /**
121
- * Props for autocomplete command run functions.
122
- */
123
- interface AutocompleteProps extends CommandProps {
124
- /**
125
- * The current autocomplete command interaction object.
126
- */
127
- interaction: AutocompleteInteraction;
128
- }
129
- /**
130
- * Props for slash (chat input) command run functions.
131
- */
132
- interface SlashCommandProps extends CommandProps {
133
- /**
134
- * The current slash (chat input) command interaction object.
135
- */
136
- interaction: ChatInputCommandInteraction;
137
- }
138
- /**
139
- * Props for context menu command run functions.
140
- */
141
- interface ContextMenuCommandProps extends CommandProps {
142
- /**
143
- * The current context menu command interaction object.
144
- */
145
- interaction: ContextMenuCommandInteraction;
146
- }
147
- /**
148
- * Props for user context menu command run functions.
149
- */
150
- interface UserContextMenuCommandProps extends CommandProps {
151
- interaction: UserContextMenuCommandInteraction;
152
- }
153
- /**
154
- * Props for message context menu command run functions.
155
- */
156
- interface MessageContextMenuCommandProps extends CommandProps {
157
- interaction: MessageContextMenuCommandInteraction;
158
- }
159
- /**
160
- * Props for command validation functions.
161
- */
162
- interface ValidationProps {
163
- /**
164
- * The current command interaction object.
165
- */
166
- interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | AutocompleteInteraction;
167
- /**
168
- * The Discord.js client object that CommandKit is handling.
169
- */
170
- client: Client<true>;
171
- /**
172
- * The current (local) target command object.
173
- */
174
- commandObj: CommandObject;
175
- /**
176
- * The current CommandKit handler instance.
177
- */
178
- handler: CommandKit;
179
- }
180
- /**
181
- * Additional command configuration options.
182
- */
183
- interface CommandOptions {
184
- /**
185
- * A boolean indicating whether the command is guild-only.
186
- * Used for built-in validation.
187
- *
188
- * @deprecated Use `dm_permission` in the command's `data` object instead.
189
- */
190
- guildOnly?: boolean;
191
- /**
192
- * A boolean indicating whether the command is developer-only.
193
- * Used for registration and built-in validation.
194
- */
195
- devOnly?: boolean;
196
- /**
197
- * A boolean indicating whether the command is deleted/ignored on restart/reload.
198
- */
199
- deleted?: boolean;
200
- /**
201
- * A string or array of permissions that a user needs for the current command to be executed.
202
- * Used for built-in validation.
203
- *
204
- * @example
205
- * userPermissions: 'BanMembers'
206
- * or
207
- * userPermissions: ['BanMembers', 'KickMembers']
208
- */
209
- userPermissions?: PermissionsString | PermissionsString[];
210
- /**
211
- * A string or array of permissions that the bot needs to execute the current command.
212
- * Used for built-in validation.
213
- *
214
- * @example
215
- * botPermissions: 'BanMembers'
216
- * or
217
- * botPermissions: ['BanMembers', 'KickMembers']
218
- */
219
- botPermissions?: PermissionsString | PermissionsString[];
220
- [key: string]: any;
221
- }
222
51
  type CommandData = RESTPostAPIApplicationCommandsJSONBody & {
223
52
  guilds?: string[];
224
53
  };
225
- type CommandObject = {
226
- /**
227
- * An object which defines the structure of the application command.
228
- */
229
- data: CommandData;
230
- /**
231
- * Additional command configuration options.
232
- */
233
- options?: CommandOptions;
234
- /**
235
- * The path to the command file.
236
- */
237
- filePath: string;
238
- /**
239
- * The command's category. Determined based on the command folder.
240
- *
241
- * @example
242
- * ```txt
243
- * "/src/commands/ping.js" -> null
244
- * "/src/commands/Misc/ping.js" -> "Misc"
245
- * ```
246
- */
247
- category: string | null;
248
- [key: string]: any;
249
- };
250
- declare enum ReloadType {
251
- /**
252
- * Reload developer/guild commands.
253
- */
254
- Developer = "dev",
255
- /**
256
- * Reload global commands.
257
- */
258
- Global = "global"
259
- }
260
54
 
261
55
  interface EventInterceptorContextData<E extends keyof ClientEvents> {
262
56
  /**
@@ -707,6 +501,7 @@ declare class MessageCommandOptions {
707
501
 
708
502
  type GenericFunction<A extends any[] = any[]> = (...args: A) => any;
709
503
  declare function exitContext<T>(fn: () => T): T;
504
+ declare function provideContext<R>(value: CommandKitEnvironment, receiver: () => R): R;
710
505
  /**
711
506
  * Returns a context-aware version of the given function.
712
507
  * @param env - The commandkit environment data.
@@ -732,14 +527,6 @@ declare function getContext(): CommandKitEnvironment | undefined;
732
527
  * Use current commandkit context. Throws an error if no context is found.
733
528
  */
734
529
  declare function useEnvironment(): CommandKitEnvironment;
735
- /**
736
- * Ensures the command is only available in guilds.
737
- */
738
- declare function guildOnly(): void;
739
- /**
740
- * Ensures the command is only available in DMs.
741
- */
742
- declare function dmOnly(): void;
743
530
 
744
531
  interface CommandKitEnvironmentInternalData {
745
532
  executionError: Error | null;
@@ -1228,8 +1015,8 @@ declare class CommandsRouter {
1228
1015
  };
1229
1016
  }>;
1230
1017
  getData(): {
1231
- commands: Map<string, Command>;
1232
- middlewares: Map<string, Middleware>;
1018
+ commands: Collection<string, Command>;
1019
+ middlewares: Collection<string, Middleware>;
1233
1020
  };
1234
1021
  toJSON(): {
1235
1022
  commands: {
@@ -1267,7 +1054,7 @@ interface ParsedEvent {
1267
1054
  /** Namespace of the event */
1268
1055
  namespace: string | null;
1269
1056
  }
1270
- /** Map of event names to their parsed metadata */
1057
+ /** Collection of event names to their parsed metadata */
1271
1058
  type EventsTree = Record<string, ParsedEvent>;
1272
1059
  /**
1273
1060
  * Router for discovering and managing event handler files in a directory structure.
@@ -1313,7 +1100,7 @@ declare class EventsRouter {
1313
1100
  */
1314
1101
  scan(): Promise<EventsTree>;
1315
1102
  /**
1316
- * Convert the internal events map to a plain object
1103
+ * Convert the internal events Collection to a plain object
1317
1104
  * @returns Events tree as a plain object
1318
1105
  */
1319
1106
  toJSON(): EventsTree;
@@ -1379,7 +1166,7 @@ declare class AppCommandHandler {
1379
1166
  constructor(commandkit: CommandKit);
1380
1167
  getCommandsArray(): LoadedCommand[];
1381
1168
  registerCommandHandler(): void;
1382
- prepareCommandRun(source: Interaction | Message$1): Promise<PreparedAppCommandExecution | null>;
1169
+ prepareCommandRun(source: Interaction | Message$1, cmdName?: string): Promise<PreparedAppCommandExecution | null>;
1383
1170
  reloadCommands(): Promise<void>;
1384
1171
  loadCommands(): Promise<void>;
1385
1172
  private loadMiddleware;
@@ -1596,6 +1383,10 @@ declare function rethrow(error: unknown): void;
1596
1383
  */
1597
1384
  declare function redirect(): never;
1598
1385
 
1386
+ type CommandSource = Interaction | Message$1;
1387
+ declare function isMessageSource(source: CommandSource): source is Message$1;
1388
+ declare function isInteractionSource(source: CommandSource): source is Interaction;
1389
+
1599
1390
  declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> extends PluginCommon<T, CommandKitPluginRuntime> {
1600
1391
  /**
1601
1392
  * Called before commands are loaded
@@ -1626,11 +1417,6 @@ declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> ex
1626
1417
  * @param interaction The interaction
1627
1418
  */
1628
1419
  onBeforeInteraction(ctx: CommandKitPluginRuntime, interaction: Interaction): Promise<void>;
1629
- /**
1630
- * Called after interaction is handled
1631
- * @param interaction The interaction that was handled
1632
- */
1633
- onAfterInteraction(ctx: CommandKitPluginRuntime, interaction: Interaction): Promise<void>;
1634
1420
  /**
1635
1421
  * Called before message command is processed
1636
1422
  * @param message The message
@@ -1647,14 +1433,13 @@ declare abstract class RuntimePlugin<T extends PluginOptions = PluginOptions> ex
1647
1433
  * @param command The command
1648
1434
  * @param execute The function that executes the command
1649
1435
  */
1650
- executeCommand(ctx: CommandKitPluginRuntime, source: Interaction | Message$1, command: PreparedAppCommandExecution, execute: () => Promise<any>): Promise<boolean>;
1436
+ executeCommand(ctx: CommandKitPluginRuntime, env: CommandKitEnvironment, source: Interaction | Message$1, command: PreparedAppCommandExecution, execute: () => Promise<any>): Promise<boolean>;
1651
1437
  }
1652
1438
  declare function isRuntimePlugin(plugin: unknown): plugin is RuntimePlugin;
1653
1439
 
1654
- declare class CommandKitPluginRuntime extends EventTarget {
1440
+ declare class CommandKitPluginRuntime {
1655
1441
  readonly commandkit: CommandKit;
1656
1442
  private plugins;
1657
- private onClientLogin;
1658
1443
  constructor(commandkit: CommandKit);
1659
1444
  getPlugin(pluginName: string): RuntimePlugin | null;
1660
1445
  softRegisterPlugin(plugin: RuntimePlugin): Promise<void>;
@@ -1724,10 +1509,6 @@ declare class CommandKit extends EventEmitter {
1724
1509
  * Resolves the current cache provider.
1725
1510
  */
1726
1511
  getCacheProvider(): CacheProvider | null;
1727
- /**
1728
- * Whether or not to debug the command handler.
1729
- */
1730
- isDebuggingCommands(): boolean;
1731
1512
  /**
1732
1513
  * Get the client attached to this CommandKit instance.
1733
1514
  */
@@ -1740,30 +1521,6 @@ declare class CommandKit extends EventEmitter {
1740
1521
  * Updates application events with the latest from "eventsPath".
1741
1522
  */
1742
1523
  reloadEvents(): Promise<void>;
1743
- /**
1744
- * @returns The path to the commands folder which was set when instantiating CommandKit.
1745
- */
1746
- get commandsPath(): string | undefined;
1747
- /**
1748
- * @returns The path to the events folder which was set when instantiating CommandKit.
1749
- */
1750
- get eventsPath(): string | undefined;
1751
- /**
1752
- * @returns The path to the validations folder which was set when instantiating CommandKit.
1753
- */
1754
- get validationsPath(): string | undefined;
1755
- /**
1756
- * @returns An array of all the developer user IDs which was set when instantiating CommandKit.
1757
- */
1758
- get devUserIds(): string[];
1759
- /**
1760
- * @returns An array of all the developer guild IDs which was set when instantiating CommandKit.
1761
- */
1762
- get devGuildIds(): string[];
1763
- /**
1764
- * @returns An array of all the developer role IDs which was set when instantiating CommandKit.
1765
- */
1766
- get devRoleIds(): string[];
1767
1524
  /**
1768
1525
  * Increment the client listeners count.
1769
1526
  */
@@ -1934,4 +1691,4 @@ declare const version: string;
1934
1691
  */
1935
1692
  declare function bootstrapCommandkitCLI(argv: string[], options?: commander.ParseOptions | undefined): Promise<void>;
1936
1693
 
1937
- export { ActionRow, type ActionRowProps, type AnyCommandExecute, type AnyCommandKitElement, type ApiTranslatableCommandOptions, AppCommandHandler, type AsyncFunction, type AutocompleteCommand, type AutocompleteCommandContext, type AutocompleteCommandMiddlewareContext, type AutocompleteProps, Button, type ButtonChildrenLike, ButtonKit, type ButtonKitPredicate, type ButtonProps, type CacheContext, type CacheEntry, type CacheMetadata, CacheProvider, type Command, type CommandContext, type CommandContextOptions, type CommandData, CommandExecutionMode, type CommandFileObject, 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 CommandLocalizationTypeData, type CommandObject, type CommandOptions, type CommandProps, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonPluginRuntime, CompilerPlugin, CompilerPluginRuntime, Context, type ContextMenuCommandProps, 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, type Message, type MessageCommand, type MessageCommandContext, type MessageCommandMiddlewareContext, MessageCommandOptions, type MessageCommandOptionsSchema, MessageCommandParser, type MessageContextMenuCommand, type MessageContextMenuCommandContext, type MessageContextMenuCommandMiddlewareContext, type MessageContextMenuCommandProps, type Middleware, MiddlewareContext, type MiddlewareContextArgs, Modal, ModalKit, type ModalKitPredicate, type ModalProps, type OnButtonKitClick, type OnButtonKitEnd, type OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreparedAppCommandExecution, type ReloadOptions, ReloadType, type ResolvableCommand, type ResolveKind, type ResolveResult, type RunCommand, RuntimePlugin, type Setup, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, type SlashCommandProps, 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, type UserContextMenuCommandProps, type ValidationProps, afterCommand, bootstrapCommandkitCLI, cache, cacheLife, cacheTag, cancelAfterCommand, commandkit, createElement, createLogger, CommandKit as default, defineConfig, dmOnly, exitContext, exitMiddleware, fromEsbuildPlugin, getCommandKit, getConfig, getContext, getElement, guildOnly, invalidate, isCachedFunction, isCommandKitElement, isCompilerPlugin, isRuntimePlugin, makeContextAwareFunction, 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 };
1694
+ 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, 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 CommandLocalizationTypeData, type CommandSource, type CommandTypeData, CommandsRouter, type CommandsRouterOptions, type CommonPluginRuntime, 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, 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 OnLoadArgs, type OnLoadOptions, type OnLoadResult, type OnModalKitEnd, type OnModalKitSubmit, type OnResolveArgs, type OnResolveOptions, type OnResolveResult, ParagraphInput, type ParsedCommandData, type ParsedEvent, type ParsedMessageCommand, type PluginTransformParameters, type PreparedAppCommandExecution, type ResolvableCommand, type ResolveKind, type ResolveResult, type RunCommand, RuntimePlugin, type Setup, ShortInput, type SlashCommand, type SlashCommandContext, type SlashCommandMiddlewareContext, 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, 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 };