commandkit 0.1.6 → 0.1.7-dev.20231212150647
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/README.md +12 -9
- package/bin/build.mjs +86 -0
- package/bin/common.mjs +102 -0
- package/bin/development.mjs +163 -0
- package/bin/index.mjs +39 -0
- package/bin/parse-env.mjs +61 -0
- package/bin/production.mjs +83 -0
- package/dist/index.d.mts +288 -67
- package/dist/index.d.ts +288 -67
- package/dist/index.js +290 -128
- package/dist/index.mjs +289 -126
- package/package.json +56 -47
package/dist/index.d.ts
CHANGED
|
@@ -1,70 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface CommandProps {
|
|
4
|
-
interaction: CommandInteraction;
|
|
5
|
-
client: Client<true>;
|
|
6
|
-
handler: CommandKit;
|
|
7
|
-
}
|
|
8
|
-
interface SlashCommandProps {
|
|
9
|
-
interaction: ChatInputCommandInteraction;
|
|
10
|
-
client: Client<true>;
|
|
11
|
-
handler: CommandKit;
|
|
12
|
-
}
|
|
13
|
-
interface ContextMenuCommandProps {
|
|
14
|
-
interaction: ContextMenuCommandInteraction;
|
|
15
|
-
client: Client<true>;
|
|
16
|
-
handler: CommandKit;
|
|
17
|
-
}
|
|
18
|
-
interface ValidationFunctionProps {
|
|
19
|
-
interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction;
|
|
20
|
-
client: Client<true>;
|
|
21
|
-
commandObj: CommandObject;
|
|
22
|
-
handler: CommandKit;
|
|
23
|
-
}
|
|
24
|
-
interface CommandOptions {
|
|
25
|
-
guildOnly?: boolean;
|
|
26
|
-
devOnly?: boolean;
|
|
27
|
-
deleted?: boolean;
|
|
28
|
-
userPermissions?: PermissionResolvable;
|
|
29
|
-
botPermissions?: PermissionResolvable;
|
|
30
|
-
[key: string]: any;
|
|
31
|
-
}
|
|
32
|
-
declare enum CommandType {
|
|
33
|
-
'ChatInput' = 1,
|
|
34
|
-
'Message' = 3,
|
|
35
|
-
'User' = 2
|
|
36
|
-
}
|
|
37
|
-
type LocaleString = 'id' | 'en-US' | 'en-GB' | 'bg' | 'zh-CN' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'nl' | 'fi' | 'fr' | 'de' | 'el' | 'hi' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'no' | 'pl' | 'pt-BR' | 'ro' | 'ru' | 'es-ES' | 'sv-SE' | 'th' | 'tr' | 'uk' | 'vi';
|
|
38
|
-
type BaseCommandData = {
|
|
39
|
-
name: string;
|
|
40
|
-
type?: CommandType;
|
|
41
|
-
name_localizations?: Partial<Record<LocaleString, string | null>>;
|
|
42
|
-
dm_permission?: boolean;
|
|
43
|
-
default_member_permissions?: string;
|
|
44
|
-
nsfw?: boolean;
|
|
45
|
-
};
|
|
46
|
-
type ChatInputCommandData = BaseCommandData & {
|
|
47
|
-
type?: CommandType.ChatInput;
|
|
48
|
-
description: string;
|
|
49
|
-
description_localizations?: Partial<Record<LocaleString, string | null>>;
|
|
50
|
-
options?: Array<APIApplicationCommandOption>;
|
|
51
|
-
};
|
|
52
|
-
type UserOrMessageCommandData = BaseCommandData & {
|
|
53
|
-
type: CommandType.User | CommandType.Message;
|
|
54
|
-
};
|
|
55
|
-
type CommandData = ChatInputCommandData | UserOrMessageCommandData;
|
|
56
|
-
type CommandObject = {
|
|
57
|
-
data: CommandData;
|
|
58
|
-
options?: CommandOptions;
|
|
59
|
-
filePath: string;
|
|
60
|
-
category: string | null;
|
|
61
|
-
[key: string]: any;
|
|
62
|
-
};
|
|
63
|
-
declare enum ReloadType {
|
|
64
|
-
'Developer' = "dev",
|
|
65
|
-
'Global' = "global"
|
|
66
|
-
}
|
|
1
|
+
import { Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, AutocompleteInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody, ButtonInteraction, Awaitable, Message, InteractionCollectorOptions, ButtonBuilder } from 'discord.js';
|
|
67
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Options for instantiating a CommandKit handler.
|
|
5
|
+
*/
|
|
68
6
|
interface CommandKitOptions {
|
|
69
7
|
/**
|
|
70
8
|
* The Discord.js client object to use with CommandKit.
|
|
@@ -103,10 +41,175 @@ interface CommandKitOptions {
|
|
|
103
41
|
*/
|
|
104
42
|
bulkRegister?: boolean;
|
|
105
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* A reload type for commands.
|
|
46
|
+
*/
|
|
106
47
|
type ReloadOptions = 'dev' | 'global' | ReloadType;
|
|
107
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Props for command run functions.
|
|
51
|
+
*/
|
|
52
|
+
interface CommandProps {
|
|
53
|
+
/**
|
|
54
|
+
* The current command interaction object.
|
|
55
|
+
*/
|
|
56
|
+
interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | UserContextMenuCommandInteraction | MessageContextMenuCommandInteraction | AutocompleteInteraction;
|
|
57
|
+
/**
|
|
58
|
+
* The Discord.js client object that CommandKit is handling.
|
|
59
|
+
*/
|
|
60
|
+
client: Client<true>;
|
|
61
|
+
/**
|
|
62
|
+
* The current CommandKit handler instance.
|
|
63
|
+
*/
|
|
64
|
+
handler: CommandKit;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Props for autocomplete command run functions.
|
|
68
|
+
*/
|
|
69
|
+
interface AutocompleteCommandProps extends CommandProps {
|
|
70
|
+
/**
|
|
71
|
+
* The current autocomplete command interaction object.
|
|
72
|
+
*/
|
|
73
|
+
interaction: AutocompleteInteraction;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Props for slash (chat input) command run functions.
|
|
77
|
+
*/
|
|
78
|
+
interface SlashCommandProps extends CommandProps {
|
|
79
|
+
/**
|
|
80
|
+
* The current slash (chat input) command interaction object.
|
|
81
|
+
*/
|
|
82
|
+
interaction: ChatInputCommandInteraction;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Props for context menu command run functions.
|
|
86
|
+
*/
|
|
87
|
+
interface ContextMenuCommandProps extends CommandProps {
|
|
88
|
+
/**
|
|
89
|
+
* The current context menu command interaction object.
|
|
90
|
+
*/
|
|
91
|
+
interaction: ContextMenuCommandInteraction;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Props for user context menu command run functions.
|
|
95
|
+
*/
|
|
96
|
+
interface UserContextMenuCommandProps extends CommandProps {
|
|
97
|
+
interaction: UserContextMenuCommandInteraction;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Props for message context menu command run functions.
|
|
101
|
+
*/
|
|
102
|
+
interface MessageContextMenuCommandProps extends CommandProps {
|
|
103
|
+
interaction: MessageContextMenuCommandInteraction;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Props for command validation functions.
|
|
107
|
+
*/
|
|
108
|
+
interface ValidationFunctionProps {
|
|
109
|
+
/**
|
|
110
|
+
* The current command interaction object.
|
|
111
|
+
*/
|
|
112
|
+
interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction;
|
|
113
|
+
/**
|
|
114
|
+
* The Discord.js client object that CommandKit is handling.
|
|
115
|
+
*/
|
|
116
|
+
client: Client<true>;
|
|
117
|
+
/**
|
|
118
|
+
* The current (local) target command object.
|
|
119
|
+
*/
|
|
120
|
+
commandObj: CommandObject;
|
|
121
|
+
/**
|
|
122
|
+
* The current CommandKit handler instance.
|
|
123
|
+
*/
|
|
124
|
+
handler: CommandKit;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Additional command configuration options.
|
|
128
|
+
*/
|
|
129
|
+
interface CommandOptions {
|
|
130
|
+
/**
|
|
131
|
+
* A boolean indicating whether the command is guild-only.
|
|
132
|
+
* Used for built-in validation.
|
|
133
|
+
*
|
|
134
|
+
* @deprecated Use `dm_permission` in the command's `data` object instead.
|
|
135
|
+
*/
|
|
136
|
+
guildOnly?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* A boolean indicating whether the command is developer-only.
|
|
139
|
+
* Used for registration and built-in validation.
|
|
140
|
+
*/
|
|
141
|
+
devOnly?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* A boolean indicating whether the command is deleted/ignored on restart/reload.
|
|
144
|
+
*/
|
|
145
|
+
deleted?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* A string or array of permissions that a user needs for the current command to be executed.
|
|
148
|
+
* Used for built-in validation.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* userPermissions: 'BanMembers'
|
|
152
|
+
* or
|
|
153
|
+
* userPermissions: ['BanMembers', 'KickMembers']
|
|
154
|
+
*/
|
|
155
|
+
userPermissions?: PermissionsString | PermissionsString[];
|
|
156
|
+
/**
|
|
157
|
+
* A string or array of permissions that the bot needs to execute the current command.
|
|
158
|
+
* Used for built-in validation.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* botPermissions: 'BanMembers'
|
|
162
|
+
* or
|
|
163
|
+
* botPermissions: ['BanMembers', 'KickMembers']
|
|
164
|
+
*/
|
|
165
|
+
botPermissions?: PermissionsString | PermissionsString[];
|
|
166
|
+
[key: string]: any;
|
|
167
|
+
}
|
|
168
|
+
type CommandData = RESTPostAPIApplicationCommandsJSONBody;
|
|
169
|
+
type CommandObject = {
|
|
170
|
+
/**
|
|
171
|
+
* An object which defines the structure of the application command.
|
|
172
|
+
*/
|
|
173
|
+
data: CommandData;
|
|
174
|
+
/**
|
|
175
|
+
* Additional command configuration options.
|
|
176
|
+
*/
|
|
177
|
+
options?: CommandOptions;
|
|
178
|
+
/**
|
|
179
|
+
* The path to the command file.
|
|
180
|
+
*/
|
|
181
|
+
filePath: string;
|
|
182
|
+
/**
|
|
183
|
+
* The command's category. Determined based on the command folder.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```txt
|
|
187
|
+
* "/src/commands/ping.js" -> null
|
|
188
|
+
* "/src/commands/Misc/ping.js" -> "Misc"
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
191
|
+
category: string | null;
|
|
192
|
+
[key: string]: any;
|
|
193
|
+
};
|
|
194
|
+
declare enum ReloadType {
|
|
195
|
+
/**
|
|
196
|
+
* Reload developer/guild commands.
|
|
197
|
+
*/
|
|
198
|
+
Developer = "dev",
|
|
199
|
+
/**
|
|
200
|
+
* Reload global commands.
|
|
201
|
+
*/
|
|
202
|
+
Global = "global"
|
|
203
|
+
}
|
|
204
|
+
|
|
108
205
|
declare class CommandKit {
|
|
109
206
|
#private;
|
|
207
|
+
/**
|
|
208
|
+
* Create a new command and event handler with CommandKit.
|
|
209
|
+
*
|
|
210
|
+
* @param options - The default CommandKit configuration.
|
|
211
|
+
* @see {@link https://commandkit.js.org/docs/commandkit-setup}
|
|
212
|
+
*/
|
|
110
213
|
constructor(options: CommandKitOptions);
|
|
111
214
|
/**
|
|
112
215
|
* Updates application commands with the latest from "commandsPath".
|
|
@@ -150,4 +253,122 @@ declare class CommandKit {
|
|
|
150
253
|
get devRoleIds(): string[];
|
|
151
254
|
}
|
|
152
255
|
|
|
153
|
-
|
|
256
|
+
/**
|
|
257
|
+
* The handler to run when a button is clicked. This handler is called with the interaction as the first argument.
|
|
258
|
+
* If the first argument is null, it means that the interaction collector has been destroyed.
|
|
259
|
+
*/
|
|
260
|
+
type CommandKitButtonBuilderInteractionCollectorDispatch = (interaction: ButtonInteraction | null) => Awaitable<void>;
|
|
261
|
+
type CommandKitButtonBuilderInteractionCollectorDispatchContextData = {
|
|
262
|
+
/**
|
|
263
|
+
* The message to listen for button interactions on.
|
|
264
|
+
*/
|
|
265
|
+
message: Message;
|
|
266
|
+
/**
|
|
267
|
+
* The duration (in ms) that the collector should run for.
|
|
268
|
+
*/
|
|
269
|
+
time?: number;
|
|
270
|
+
/**
|
|
271
|
+
* If the collector should automatically reset the timer when a button is clicked.
|
|
272
|
+
*/
|
|
273
|
+
autoReset?: boolean;
|
|
274
|
+
} & Omit<InteractionCollectorOptions<ButtonInteraction>, 'filter' | 'componentType'>;
|
|
275
|
+
declare class ButtonKit extends ButtonBuilder {
|
|
276
|
+
#private;
|
|
277
|
+
/**
|
|
278
|
+
* Sets up an inline interaction collector for this button. This collector by default allows as many interactions as possible if it is actively used.
|
|
279
|
+
* If unused, this expires after 24 hours or custom time if specified.
|
|
280
|
+
* @param handler The handler to run when the button is clicked
|
|
281
|
+
* @param data The context data to use for the interaction collector
|
|
282
|
+
* @returns This button
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* const button = new ButtonKit()
|
|
286
|
+
* .setLabel('Click me')
|
|
287
|
+
* .setStyle(ButtonStyle.Primary)
|
|
288
|
+
* .setCustomId('click_me');
|
|
289
|
+
*
|
|
290
|
+
* const row = new ActionRowBuilder().addComponents(button);
|
|
291
|
+
*
|
|
292
|
+
* const message = await channel.send({ content: 'Click the button', components: [row] });
|
|
293
|
+
*
|
|
294
|
+
* button.onClick(async (interaction) => {
|
|
295
|
+
* await interaction.reply('You clicked me!');
|
|
296
|
+
* }, { message });
|
|
297
|
+
*
|
|
298
|
+
* // Remove onClick handler and destroy the interaction collector
|
|
299
|
+
* button.onClick(null);
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
onClick(handler: null): this;
|
|
303
|
+
onClick(handler: CommandKitButtonBuilderInteractionCollectorDispatch, data: CommandKitButtonBuilderInteractionCollectorDispatchContextData): this;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
interface CommandKitConfig {
|
|
307
|
+
/**
|
|
308
|
+
* The source directory of the project.
|
|
309
|
+
*/
|
|
310
|
+
src: string;
|
|
311
|
+
/**
|
|
312
|
+
* The main "javascript" file of the project.
|
|
313
|
+
*/
|
|
314
|
+
main: string;
|
|
315
|
+
/**
|
|
316
|
+
* Whether or not to use the watch mode. Defaults to `true`.
|
|
317
|
+
*/
|
|
318
|
+
watch: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* The output directory of the project. Defaults to `dist`.
|
|
321
|
+
*/
|
|
322
|
+
outDir: string;
|
|
323
|
+
/**
|
|
324
|
+
* Whether or not to include extra env utilities. Defaults to `true`.
|
|
325
|
+
*/
|
|
326
|
+
envExtra: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* Node.js cli options.
|
|
329
|
+
*/
|
|
330
|
+
nodeOptions: string[];
|
|
331
|
+
/**
|
|
332
|
+
* Whether or not to clear default restart logs. Defaults to `true`.
|
|
333
|
+
*/
|
|
334
|
+
clearRestartLogs: boolean;
|
|
335
|
+
/**
|
|
336
|
+
* Whether or not to minify the output. Defaults to `false`.
|
|
337
|
+
*/
|
|
338
|
+
minify: boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Whether or not to include sourcemaps in production build. Defaults to `false`.
|
|
341
|
+
*/
|
|
342
|
+
sourcemap: boolean | 'inline';
|
|
343
|
+
/**
|
|
344
|
+
* Whether or not to include anti-crash handler in production. Defaults to `true`.
|
|
345
|
+
*/
|
|
346
|
+
antiCrash: boolean;
|
|
347
|
+
}
|
|
348
|
+
declare function getConfig(): CommandKitConfig;
|
|
349
|
+
declare const requiredProps: readonly ["src", "main"];
|
|
350
|
+
type R = (typeof requiredProps)[number];
|
|
351
|
+
type PartialConfig<T extends CommandKitConfig> = Partial<Omit<T, R>> & Pick<T, R>;
|
|
352
|
+
declare function defineConfig(config: PartialConfig<CommandKitConfig>): Partial<CommandKitConfig>;
|
|
353
|
+
|
|
354
|
+
type CommandKitEffectCallback = () => void;
|
|
355
|
+
type CommandKitSignalInitializer<T> = T | (() => T);
|
|
356
|
+
type CommandKitSignalUpdater<T> = T | ((prev: T) => T);
|
|
357
|
+
type CommandKitSignal<T> = readonly [
|
|
358
|
+
() => T,
|
|
359
|
+
(value: CommandKitSignalUpdater<T>) => void,
|
|
360
|
+
() => void
|
|
361
|
+
];
|
|
362
|
+
/**
|
|
363
|
+
* Creates a new signal.
|
|
364
|
+
* @param value - The initial value to use.
|
|
365
|
+
* @returns An array of functions: a getter, a setter, and a disposer.
|
|
366
|
+
*/
|
|
367
|
+
declare function createSignal<T = unknown>(value?: CommandKitSignalInitializer<T>): CommandKitSignal<T>;
|
|
368
|
+
/**
|
|
369
|
+
* Creates a new effect.
|
|
370
|
+
* @param callback - The callback function to execute.
|
|
371
|
+
*/
|
|
372
|
+
declare function createEffect(callback: CommandKitEffectCallback): void;
|
|
373
|
+
|
|
374
|
+
export { AutocompleteCommandProps, ButtonKit, CommandData, CommandKit, CommandKitButtonBuilderInteractionCollectorDispatch, CommandKitButtonBuilderInteractionCollectorDispatchContextData, CommandKitConfig, CommandKitEffectCallback, CommandKitSignal, CommandKitSignalInitializer, CommandKitSignalUpdater, CommandObject, CommandOptions, CommandProps, ContextMenuCommandProps, MessageContextMenuCommandProps, ReloadType, SlashCommandProps, UserContextMenuCommandProps, ValidationFunctionProps, createEffect, createSignal, defineConfig, getConfig };
|