commandkit 0.1.10-dev.20231229085439 → 0.1.10-dev.20240108063947

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.mts CHANGED
@@ -1,50 +1,75 @@
1
- import { Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
1
+ import * as discord_js from 'discord.js';
2
+ import { ChatInputCommandInteraction, ContextMenuCommandInteraction, AutocompleteInteraction, Client, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, CacheType, Interaction, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder, PartialTextBasedChannelFields, TextBasedChannel, Guild, GuildMember, APIInteractionGuildMember, User } from 'discord.js';
3
+ import { AsyncLocalStorage } from 'async_hooks';
2
4
 
3
5
  /**
4
- * Options for instantiating a CommandKit handler.
6
+ * Validation handler options (validationsPath).
5
7
  */
6
- interface CommandKitOptions {
8
+ interface ValidationHandlerOptions {
9
+ validationsPath: string;
10
+ }
11
+
12
+ /**
13
+ * A handler for command validations.
14
+ */
15
+ declare class ValidationHandler {
16
+ #private;
17
+ constructor({ ...options }: ValidationHandlerOptions);
18
+ init(): Promise<void>;
19
+ get validations(): Function[];
20
+ reloadValidations(): Promise<void>;
21
+ }
22
+
23
+ /**
24
+ * Command handler options.
25
+ * Similar to CommandKit options in structure.
26
+ */
27
+ interface CommandHandlerOptions {
7
28
  /**
8
- * The Discord.js client object to use with CommandKit.
29
+ * The client created by the user.
9
30
  */
10
31
  client: Client;
11
32
  /**
12
- * The path to your commands directory.
33
+ * Path to the user's commands.
13
34
  */
14
- commandsPath?: string;
35
+ commandsPath: string;
15
36
  /**
16
- * The path to your events directory.
37
+ * An array of developer guild IDs.
17
38
  */
18
- eventsPath?: string;
39
+ devGuildIds: string[];
19
40
  /**
20
- * The path to the validations directory.
41
+ * An array of developer user IDs.
21
42
  */
22
- validationsPath?: string;
43
+ devUserIds: string[];
23
44
  /**
24
- * List of development guild IDs to restrict devOnly commands to.
45
+ * An array of developer role IDs.
25
46
  */
26
- devGuildIds?: string[];
47
+ devRoleIds: string[];
27
48
  /**
28
- * List of developer user IDs to restrict devOnly commands to.
49
+ * A validation handler instance to run validations before commands.
29
50
  */
30
- devUserIds?: string[];
51
+ validationHandler?: ValidationHandler;
31
52
  /**
32
- * List of developer role IDs to restrict devOnly commands to.
53
+ * A boolean indicating whether to skip CommandKit's built-in validations (permission checking, etc.)
33
54
  */
34
- devRoleIds?: string[];
55
+ skipBuiltInValidations: boolean;
35
56
  /**
36
- * Skip CommandKit's built-in validations (for devOnly commands).
57
+ * The CommandKit handler that instantiated this.
37
58
  */
38
- skipBuiltInValidations?: boolean;
59
+ commandkitInstance: CommandKit;
39
60
  /**
40
- * Bulk register application commands instead of one-by-one.
61
+ * A boolean indicating whether to register all commands in bulk.
41
62
  */
42
- bulkRegister?: boolean;
63
+ bulkRegister: boolean;
64
+ /**
65
+ * Whether to enable hooks context.
66
+ */
67
+ enableHooks: boolean;
43
68
  }
44
69
  /**
45
- * A reload type for commands.
70
+ * Represents a command interaction.
46
71
  */
47
- type ReloadOptions = 'dev' | 'global' | ReloadType;
72
+ type CommandKitInteraction = ChatInputCommandInteraction | ContextMenuCommandInteraction | AutocompleteInteraction;
48
73
 
49
74
  /**
50
75
  * Props for command run functions.
@@ -202,8 +227,110 @@ declare enum ReloadType {
202
227
  Global = "global"
203
228
  }
204
229
 
230
+ interface hCommandContext {
231
+ interaction: CommandKitInteraction;
232
+ command: CommandData;
233
+ }
234
+ /**
235
+ * A handler for client application commands.
236
+ */
237
+ declare class CommandHandler {
238
+ #private;
239
+ context: AsyncLocalStorage<hCommandContext> | null;
240
+ constructor({ ...options }: CommandHandlerOptions);
241
+ init(): Promise<void>;
242
+ handleCommands(): void;
243
+ get commands(): CommandFileObject[];
244
+ reloadCommands(type?: ReloadOptions): Promise<void>;
245
+ }
246
+
247
+ /**
248
+ * Options for instantiating a CommandKit handler.
249
+ */
250
+ interface CommandKitOptions {
251
+ /**
252
+ * The Discord.js client object to use with CommandKit.
253
+ */
254
+ client: Client;
255
+ /**
256
+ * The path to your commands directory.
257
+ */
258
+ commandsPath?: string;
259
+ /**
260
+ * The path to your events directory.
261
+ */
262
+ eventsPath?: string;
263
+ /**
264
+ * The path to the validations directory.
265
+ */
266
+ validationsPath?: string;
267
+ /**
268
+ * List of development guild IDs to restrict devOnly commands to.
269
+ */
270
+ devGuildIds?: string[];
271
+ /**
272
+ * List of developer user IDs to restrict devOnly commands to.
273
+ */
274
+ devUserIds?: string[];
275
+ /**
276
+ * List of developer role IDs to restrict devOnly commands to.
277
+ */
278
+ devRoleIds?: string[];
279
+ /**
280
+ * Skip CommandKit's built-in validations (for devOnly commands).
281
+ */
282
+ skipBuiltInValidations?: boolean;
283
+ /**
284
+ * Bulk register application commands instead of one-by-one.
285
+ */
286
+ bulkRegister?: boolean;
287
+ /**
288
+ * Options for experimental features.
289
+ */
290
+ experimental?: {
291
+ /**
292
+ * Enable hooks. This allows you to utilize hooks such as `useInteraction()` to access the interaction object anywhere inside the command.
293
+ */
294
+ hooks?: boolean;
295
+ };
296
+ }
297
+ /**
298
+ * Represents a command context.
299
+ */
300
+ interface CommandContext<T extends Interaction, Cached extends CacheType> {
301
+ /**
302
+ * The interaction that triggered this command.
303
+ */
304
+ interaction: Interaction<CacheType>;
305
+ /**
306
+ * The client that instantiated this command.
307
+ */
308
+ client: Client;
309
+ /**
310
+ * The command data.
311
+ */
312
+ handler: CommandKit;
313
+ }
314
+ /**
315
+ * Represents a command file.
316
+ */
317
+ interface CommandFileObject {
318
+ data: CommandData;
319
+ options?: CommandOptions;
320
+ run: <Cached extends CacheType = CacheType>(ctx: CommandContext<Interaction, Cached>) => Awaited<void>;
321
+ autocomplete?: <Cached extends CacheType = CacheType>(ctx: CommandContext<Interaction, Cached>) => Awaited<void>;
322
+ filePath: string;
323
+ category: string | null;
324
+ [key: string]: any;
325
+ }
326
+ /**
327
+ * A reload type for commands.
328
+ */
329
+ type ReloadOptions = 'dev' | 'global' | ReloadType;
330
+
205
331
  declare class CommandKit {
206
332
  #private;
333
+ static _instance: CommandKit | null;
207
334
  /**
208
335
  * Create a new command and event handler with CommandKit.
209
336
  *
@@ -211,6 +338,14 @@ declare class CommandKit {
211
338
  * @see {@link https://commandkit.js.org/docs/commandkit-setup}
212
339
  */
213
340
  constructor(options: CommandKitOptions);
341
+ /**
342
+ * Get the client attached to this CommandKit instance.
343
+ */
344
+ get client(): discord_js.Client<boolean>;
345
+ /**
346
+ * Get command handler instance.
347
+ */
348
+ get commandHandler(): CommandHandler | undefined;
214
349
  /**
215
350
  * Updates application commands with the latest from "commandsPath".
216
351
  */
@@ -376,4 +511,24 @@ declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T
376
511
  */
377
512
  declare function createEffect(callback: CommandKitEffectCallback): void;
378
513
 
379
- export { AutocompleteProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitButtonBuilderOnEnd, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationProps, createEffect, createSignal, defineConfig, getConfig };
514
+ declare function useClient(): discord_js.Client<boolean>;
515
+
516
+ declare function useCommandKit(): CommandKit;
517
+
518
+ type ChatInputReplyData = Parameters<ChatInputCommandInteraction['reply']>[0];
519
+ type MessageData = Parameters<PartialTextBasedChannelFields['send']>[0] | ChatInputReplyData;
520
+ declare function response(data: MessageData): Promise<void>;
521
+
522
+ declare function useChannel(): TextBasedChannel | null;
523
+
524
+ declare function useCommandData(): discord_js.RESTPostAPIApplicationCommandsJSONBody;
525
+
526
+ declare function useGuild(): Guild | null;
527
+
528
+ declare function useInteraction<T extends CommandKitInteraction = CommandKitInteraction>(): T;
529
+
530
+ declare function useMember(): GuildMember | APIInteractionGuildMember | null;
531
+
532
+ declare function useUser(): User;
533
+
534
+ export { AutocompleteProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitButtonBuilderOnEnd, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationProps, createEffect, createSignal, defineConfig, getConfig, response, useChannel, useClient, useCommandData, useCommandKit, useGuild, useInteraction, useMember, useUser };
package/dist/index.d.ts CHANGED
@@ -1,50 +1,75 @@
1
- import { Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
1
+ import * as discord_js from 'discord.js';
2
+ import { ChatInputCommandInteraction, ContextMenuCommandInteraction, AutocompleteInteraction, Client, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, CacheType, Interaction, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder, PartialTextBasedChannelFields, TextBasedChannel, Guild, GuildMember, APIInteractionGuildMember, User } from 'discord.js';
3
+ import { AsyncLocalStorage } from 'async_hooks';
2
4
 
3
5
  /**
4
- * Options for instantiating a CommandKit handler.
6
+ * Validation handler options (validationsPath).
5
7
  */
6
- interface CommandKitOptions {
8
+ interface ValidationHandlerOptions {
9
+ validationsPath: string;
10
+ }
11
+
12
+ /**
13
+ * A handler for command validations.
14
+ */
15
+ declare class ValidationHandler {
16
+ #private;
17
+ constructor({ ...options }: ValidationHandlerOptions);
18
+ init(): Promise<void>;
19
+ get validations(): Function[];
20
+ reloadValidations(): Promise<void>;
21
+ }
22
+
23
+ /**
24
+ * Command handler options.
25
+ * Similar to CommandKit options in structure.
26
+ */
27
+ interface CommandHandlerOptions {
7
28
  /**
8
- * The Discord.js client object to use with CommandKit.
29
+ * The client created by the user.
9
30
  */
10
31
  client: Client;
11
32
  /**
12
- * The path to your commands directory.
33
+ * Path to the user's commands.
13
34
  */
14
- commandsPath?: string;
35
+ commandsPath: string;
15
36
  /**
16
- * The path to your events directory.
37
+ * An array of developer guild IDs.
17
38
  */
18
- eventsPath?: string;
39
+ devGuildIds: string[];
19
40
  /**
20
- * The path to the validations directory.
41
+ * An array of developer user IDs.
21
42
  */
22
- validationsPath?: string;
43
+ devUserIds: string[];
23
44
  /**
24
- * List of development guild IDs to restrict devOnly commands to.
45
+ * An array of developer role IDs.
25
46
  */
26
- devGuildIds?: string[];
47
+ devRoleIds: string[];
27
48
  /**
28
- * List of developer user IDs to restrict devOnly commands to.
49
+ * A validation handler instance to run validations before commands.
29
50
  */
30
- devUserIds?: string[];
51
+ validationHandler?: ValidationHandler;
31
52
  /**
32
- * List of developer role IDs to restrict devOnly commands to.
53
+ * A boolean indicating whether to skip CommandKit's built-in validations (permission checking, etc.)
33
54
  */
34
- devRoleIds?: string[];
55
+ skipBuiltInValidations: boolean;
35
56
  /**
36
- * Skip CommandKit's built-in validations (for devOnly commands).
57
+ * The CommandKit handler that instantiated this.
37
58
  */
38
- skipBuiltInValidations?: boolean;
59
+ commandkitInstance: CommandKit;
39
60
  /**
40
- * Bulk register application commands instead of one-by-one.
61
+ * A boolean indicating whether to register all commands in bulk.
41
62
  */
42
- bulkRegister?: boolean;
63
+ bulkRegister: boolean;
64
+ /**
65
+ * Whether to enable hooks context.
66
+ */
67
+ enableHooks: boolean;
43
68
  }
44
69
  /**
45
- * A reload type for commands.
70
+ * Represents a command interaction.
46
71
  */
47
- type ReloadOptions = 'dev' | 'global' | ReloadType;
72
+ type CommandKitInteraction = ChatInputCommandInteraction | ContextMenuCommandInteraction | AutocompleteInteraction;
48
73
 
49
74
  /**
50
75
  * Props for command run functions.
@@ -202,8 +227,110 @@ declare enum ReloadType {
202
227
  Global = "global"
203
228
  }
204
229
 
230
+ interface hCommandContext {
231
+ interaction: CommandKitInteraction;
232
+ command: CommandData;
233
+ }
234
+ /**
235
+ * A handler for client application commands.
236
+ */
237
+ declare class CommandHandler {
238
+ #private;
239
+ context: AsyncLocalStorage<hCommandContext> | null;
240
+ constructor({ ...options }: CommandHandlerOptions);
241
+ init(): Promise<void>;
242
+ handleCommands(): void;
243
+ get commands(): CommandFileObject[];
244
+ reloadCommands(type?: ReloadOptions): Promise<void>;
245
+ }
246
+
247
+ /**
248
+ * Options for instantiating a CommandKit handler.
249
+ */
250
+ interface CommandKitOptions {
251
+ /**
252
+ * The Discord.js client object to use with CommandKit.
253
+ */
254
+ client: Client;
255
+ /**
256
+ * The path to your commands directory.
257
+ */
258
+ commandsPath?: string;
259
+ /**
260
+ * The path to your events directory.
261
+ */
262
+ eventsPath?: string;
263
+ /**
264
+ * The path to the validations directory.
265
+ */
266
+ validationsPath?: string;
267
+ /**
268
+ * List of development guild IDs to restrict devOnly commands to.
269
+ */
270
+ devGuildIds?: string[];
271
+ /**
272
+ * List of developer user IDs to restrict devOnly commands to.
273
+ */
274
+ devUserIds?: string[];
275
+ /**
276
+ * List of developer role IDs to restrict devOnly commands to.
277
+ */
278
+ devRoleIds?: string[];
279
+ /**
280
+ * Skip CommandKit's built-in validations (for devOnly commands).
281
+ */
282
+ skipBuiltInValidations?: boolean;
283
+ /**
284
+ * Bulk register application commands instead of one-by-one.
285
+ */
286
+ bulkRegister?: boolean;
287
+ /**
288
+ * Options for experimental features.
289
+ */
290
+ experimental?: {
291
+ /**
292
+ * Enable hooks. This allows you to utilize hooks such as `useInteraction()` to access the interaction object anywhere inside the command.
293
+ */
294
+ hooks?: boolean;
295
+ };
296
+ }
297
+ /**
298
+ * Represents a command context.
299
+ */
300
+ interface CommandContext<T extends Interaction, Cached extends CacheType> {
301
+ /**
302
+ * The interaction that triggered this command.
303
+ */
304
+ interaction: Interaction<CacheType>;
305
+ /**
306
+ * The client that instantiated this command.
307
+ */
308
+ client: Client;
309
+ /**
310
+ * The command data.
311
+ */
312
+ handler: CommandKit;
313
+ }
314
+ /**
315
+ * Represents a command file.
316
+ */
317
+ interface CommandFileObject {
318
+ data: CommandData;
319
+ options?: CommandOptions;
320
+ run: <Cached extends CacheType = CacheType>(ctx: CommandContext<Interaction, Cached>) => Awaited<void>;
321
+ autocomplete?: <Cached extends CacheType = CacheType>(ctx: CommandContext<Interaction, Cached>) => Awaited<void>;
322
+ filePath: string;
323
+ category: string | null;
324
+ [key: string]: any;
325
+ }
326
+ /**
327
+ * A reload type for commands.
328
+ */
329
+ type ReloadOptions = 'dev' | 'global' | ReloadType;
330
+
205
331
  declare class CommandKit {
206
332
  #private;
333
+ static _instance: CommandKit | null;
207
334
  /**
208
335
  * Create a new command and event handler with CommandKit.
209
336
  *
@@ -211,6 +338,14 @@ declare class CommandKit {
211
338
  * @see {@link https://commandkit.js.org/docs/commandkit-setup}
212
339
  */
213
340
  constructor(options: CommandKitOptions);
341
+ /**
342
+ * Get the client attached to this CommandKit instance.
343
+ */
344
+ get client(): discord_js.Client<boolean>;
345
+ /**
346
+ * Get command handler instance.
347
+ */
348
+ get commandHandler(): CommandHandler | undefined;
214
349
  /**
215
350
  * Updates application commands with the latest from "commandsPath".
216
351
  */
@@ -376,4 +511,24 @@ declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T
376
511
  */
377
512
  declare function createEffect(callback: CommandKitEffectCallback): void;
378
513
 
379
- export { AutocompleteProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitButtonBuilderOnEnd, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationProps, createEffect, createSignal, defineConfig, getConfig };
514
+ declare function useClient(): discord_js.Client<boolean>;
515
+
516
+ declare function useCommandKit(): CommandKit;
517
+
518
+ type ChatInputReplyData = Parameters<ChatInputCommandInteraction['reply']>[0];
519
+ type MessageData = Parameters<PartialTextBasedChannelFields['send']>[0] | ChatInputReplyData;
520
+ declare function response(data: MessageData): Promise<void>;
521
+
522
+ declare function useChannel(): TextBasedChannel | null;
523
+
524
+ declare function useCommandData(): discord_js.RESTPostAPIApplicationCommandsJSONBody;
525
+
526
+ declare function useGuild(): Guild | null;
527
+
528
+ declare function useInteraction<T extends CommandKitInteraction = CommandKitInteraction>(): T;
529
+
530
+ declare function useMember(): GuildMember | APIInteractionGuildMember | null;
531
+
532
+ declare function useUser(): User;
533
+
534
+ export { AutocompleteProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitButtonBuilderOnEnd, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationProps, createEffect, createSignal, defineConfig, getConfig, response, useChannel, useClient, useCommandData, useCommandKit, useGuild, useInteraction, useMember, useUser };