commandkit 0.1.11-dev.20240202064607 → 0.1.11-dev.20241214134338

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.
Files changed (186) hide show
  1. package/bin/build.mjs +126 -0
  2. package/bin/common.mjs +125 -0
  3. package/bin/development.mjs +180 -0
  4. package/bin/index.mjs +53 -0
  5. package/bin/parse-env.mjs +65 -0
  6. package/bin/production.mjs +86 -0
  7. package/dist/CommandKit-Co5QNlps.d.ts +451 -0
  8. package/dist/CommandKit-D84HlsL0.d.mts +451 -0
  9. package/dist/CommandKit.d.mts +5 -0
  10. package/dist/CommandKit.d.ts +5 -0
  11. package/dist/CommandKit.js +11 -0
  12. package/dist/CommandKit.js.map +1 -0
  13. package/dist/CommandKit.mjs +2 -0
  14. package/dist/CommandKit.mjs.map +1 -0
  15. package/dist/chunk-6B4TPFI4.mjs +7 -0
  16. package/dist/chunk-6B4TPFI4.mjs.map +1 -0
  17. package/dist/chunk-6J4XVVL4.mjs +2 -0
  18. package/dist/chunk-6J4XVVL4.mjs.map +1 -0
  19. package/dist/chunk-6TIBWNPX.mjs +2 -0
  20. package/dist/chunk-6TIBWNPX.mjs.map +1 -0
  21. package/dist/chunk-7YWJADOI.mjs +2 -0
  22. package/dist/chunk-7YWJADOI.mjs.map +1 -0
  23. package/dist/chunk-CATZUF3K.mjs +2 -0
  24. package/dist/chunk-CATZUF3K.mjs.map +1 -0
  25. package/dist/chunk-EQ62HPWY.mjs +2 -0
  26. package/dist/chunk-EQ62HPWY.mjs.map +1 -0
  27. package/dist/chunk-FBYSGXIA.mjs +2 -0
  28. package/dist/chunk-FBYSGXIA.mjs.map +1 -0
  29. package/dist/chunk-IHDVSF4H.mjs +2 -0
  30. package/dist/chunk-IHDVSF4H.mjs.map +1 -0
  31. package/dist/chunk-JWT7PUZJ.mjs +4 -0
  32. package/dist/chunk-JWT7PUZJ.mjs.map +1 -0
  33. package/dist/chunk-KR3OAQKX.mjs +2 -0
  34. package/dist/chunk-KR3OAQKX.mjs.map +1 -0
  35. package/dist/chunk-M5FMJETI.mjs +1 -0
  36. package/dist/chunk-M5FMJETI.mjs.map +1 -0
  37. package/dist/chunk-MTG5LNGD.mjs +2 -0
  38. package/dist/chunk-MTG5LNGD.mjs.map +1 -0
  39. package/dist/chunk-PFU3PH6M.mjs +1 -0
  40. package/dist/chunk-PFU3PH6M.mjs.map +1 -0
  41. package/dist/chunk-PXNT5WYC.mjs +2 -0
  42. package/dist/chunk-PXNT5WYC.mjs.map +1 -0
  43. package/dist/chunk-Q7JC46G6.mjs +2 -0
  44. package/dist/chunk-Q7JC46G6.mjs.map +1 -0
  45. package/dist/chunk-VHU3SDTR.mjs +2 -0
  46. package/dist/chunk-VHU3SDTR.mjs.map +1 -0
  47. package/dist/chunk-VURGPMLB.mjs +2 -0
  48. package/dist/chunk-VURGPMLB.mjs.map +1 -0
  49. package/dist/chunk-XVIYQWRZ.mjs +2 -0
  50. package/dist/chunk-XVIYQWRZ.mjs.map +1 -0
  51. package/dist/chunk-Y7QBWZVQ.mjs +4 -0
  52. package/dist/chunk-Y7QBWZVQ.mjs.map +1 -0
  53. package/dist/components/ButtonKit.d.mts +55 -0
  54. package/dist/components/ButtonKit.d.ts +55 -0
  55. package/dist/components/ButtonKit.js +2 -0
  56. package/dist/components/ButtonKit.js.map +1 -0
  57. package/dist/components/ButtonKit.mjs +2 -0
  58. package/dist/components/ButtonKit.mjs.map +1 -0
  59. package/dist/components/index.d.mts +2 -0
  60. package/dist/components/index.d.ts +2 -0
  61. package/dist/components/index.js +2 -0
  62. package/dist/components/index.js.map +1 -0
  63. package/dist/components/index.mjs +2 -0
  64. package/dist/components/index.mjs.map +1 -0
  65. package/dist/config.d.mts +53 -0
  66. package/dist/config.d.ts +53 -0
  67. package/dist/config.js +2 -0
  68. package/dist/config.js.map +1 -0
  69. package/dist/config.mjs +2 -0
  70. package/dist/config.mjs.map +1 -0
  71. package/dist/handlers/command-handler/CommandHandler.d.mts +5 -0
  72. package/dist/handlers/command-handler/CommandHandler.d.ts +5 -0
  73. package/dist/handlers/command-handler/CommandHandler.js +11 -0
  74. package/dist/handlers/command-handler/CommandHandler.js.map +1 -0
  75. package/dist/handlers/command-handler/CommandHandler.mjs +2 -0
  76. package/dist/handlers/command-handler/CommandHandler.mjs.map +1 -0
  77. package/dist/handlers/command-handler/functions/loadCommandsWithRest.d.mts +35 -0
  78. package/dist/handlers/command-handler/functions/loadCommandsWithRest.d.ts +35 -0
  79. package/dist/handlers/command-handler/functions/loadCommandsWithRest.js +4 -0
  80. package/dist/handlers/command-handler/functions/loadCommandsWithRest.js.map +1 -0
  81. package/dist/handlers/command-handler/functions/loadCommandsWithRest.mjs +2 -0
  82. package/dist/handlers/command-handler/functions/loadCommandsWithRest.mjs.map +1 -0
  83. package/dist/handlers/command-handler/functions/registerCommands.d.mts +20 -0
  84. package/dist/handlers/command-handler/functions/registerCommands.d.ts +20 -0
  85. package/dist/handlers/command-handler/functions/registerCommands.js +7 -0
  86. package/dist/handlers/command-handler/functions/registerCommands.js.map +1 -0
  87. package/dist/handlers/command-handler/functions/registerCommands.mjs +2 -0
  88. package/dist/handlers/command-handler/functions/registerCommands.mjs.map +1 -0
  89. package/dist/handlers/command-handler/typings.d.mts +5 -0
  90. package/dist/handlers/command-handler/typings.d.ts +5 -0
  91. package/dist/handlers/command-handler/typings.js +2 -0
  92. package/dist/handlers/command-handler/typings.js.map +1 -0
  93. package/dist/handlers/command-handler/typings.mjs +1 -0
  94. package/dist/handlers/command-handler/typings.mjs.map +1 -0
  95. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.d.mts +9 -0
  96. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.d.ts +9 -0
  97. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.js +2 -0
  98. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.js.map +1 -0
  99. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.mjs +2 -0
  100. package/dist/handlers/command-handler/utils/areSlashCommandsDifferent.mjs.map +1 -0
  101. package/dist/handlers/command-handler/validations/devOnly.d.mts +9 -0
  102. package/dist/handlers/command-handler/validations/devOnly.d.ts +9 -0
  103. package/dist/handlers/command-handler/validations/devOnly.js +2 -0
  104. package/dist/handlers/command-handler/validations/devOnly.js.map +1 -0
  105. package/dist/handlers/command-handler/validations/devOnly.mjs +2 -0
  106. package/dist/handlers/command-handler/validations/devOnly.mjs.map +1 -0
  107. package/dist/handlers/command-handler/validations/index.d.mts +10 -0
  108. package/dist/handlers/command-handler/validations/index.d.ts +10 -0
  109. package/dist/handlers/command-handler/validations/index.js +4 -0
  110. package/dist/handlers/command-handler/validations/index.js.map +1 -0
  111. package/dist/handlers/command-handler/validations/index.mjs +2 -0
  112. package/dist/handlers/command-handler/validations/index.mjs.map +1 -0
  113. package/dist/handlers/command-handler/validations/permissions.d.mts +9 -0
  114. package/dist/handlers/command-handler/validations/permissions.d.ts +9 -0
  115. package/dist/handlers/command-handler/validations/permissions.js +4 -0
  116. package/dist/handlers/command-handler/validations/permissions.js.map +1 -0
  117. package/dist/handlers/command-handler/validations/permissions.mjs +2 -0
  118. package/dist/handlers/command-handler/validations/permissions.mjs.map +1 -0
  119. package/dist/handlers/event-handler/EventHandler.d.mts +5 -0
  120. package/dist/handlers/event-handler/EventHandler.d.ts +5 -0
  121. package/dist/handlers/event-handler/EventHandler.js +2 -0
  122. package/dist/handlers/event-handler/EventHandler.js.map +1 -0
  123. package/dist/handlers/event-handler/EventHandler.mjs +2 -0
  124. package/dist/handlers/event-handler/EventHandler.mjs.map +1 -0
  125. package/dist/handlers/event-handler/typings.d.mts +5 -0
  126. package/dist/handlers/event-handler/typings.d.ts +5 -0
  127. package/dist/handlers/event-handler/typings.js +2 -0
  128. package/dist/handlers/event-handler/typings.js.map +1 -0
  129. package/dist/handlers/event-handler/typings.mjs +1 -0
  130. package/dist/handlers/event-handler/typings.mjs.map +1 -0
  131. package/dist/handlers/index.d.mts +5 -0
  132. package/dist/handlers/index.d.ts +5 -0
  133. package/dist/handlers/index.js +11 -0
  134. package/dist/handlers/index.js.map +1 -0
  135. package/dist/handlers/index.mjs +2 -0
  136. package/dist/handlers/index.mjs.map +1 -0
  137. package/dist/handlers/validation-handler/ValidationHandler.d.mts +14 -0
  138. package/dist/handlers/validation-handler/ValidationHandler.d.ts +14 -0
  139. package/dist/handlers/validation-handler/ValidationHandler.js +2 -0
  140. package/dist/handlers/validation-handler/ValidationHandler.js.map +1 -0
  141. package/dist/handlers/validation-handler/ValidationHandler.mjs +2 -0
  142. package/dist/handlers/validation-handler/ValidationHandler.mjs.map +1 -0
  143. package/dist/handlers/validation-handler/typings.d.mts +14 -0
  144. package/dist/handlers/validation-handler/typings.d.ts +14 -0
  145. package/dist/handlers/validation-handler/typings.js +2 -0
  146. package/dist/handlers/validation-handler/typings.js.map +1 -0
  147. package/dist/handlers/validation-handler/typings.mjs +1 -0
  148. package/dist/handlers/validation-handler/typings.mjs.map +1 -0
  149. package/dist/index.d.mts +14 -0
  150. package/dist/index.d.ts +14 -0
  151. package/dist/index.js +11 -0
  152. package/dist/index.js.map +1 -0
  153. package/dist/index.mjs +2 -0
  154. package/dist/index.mjs.map +1 -0
  155. package/dist/types.d.mts +5 -0
  156. package/dist/types.d.ts +5 -0
  157. package/dist/types.js +2 -0
  158. package/dist/types.js.map +1 -0
  159. package/dist/types.mjs +2 -0
  160. package/dist/types.mjs.map +1 -0
  161. package/dist/utils/clone.d.mts +3 -0
  162. package/dist/utils/clone.d.ts +3 -0
  163. package/dist/utils/clone.js +2 -0
  164. package/dist/utils/clone.js.map +1 -0
  165. package/dist/utils/clone.mjs +2 -0
  166. package/dist/utils/clone.mjs.map +1 -0
  167. package/dist/utils/colors.d.mts +27 -0
  168. package/dist/utils/colors.d.ts +27 -0
  169. package/dist/utils/colors.js +2 -0
  170. package/dist/utils/colors.js.map +1 -0
  171. package/dist/utils/colors.mjs +2 -0
  172. package/dist/utils/colors.mjs.map +1 -0
  173. package/dist/utils/get-paths.d.mts +4 -0
  174. package/dist/utils/get-paths.d.ts +4 -0
  175. package/dist/utils/get-paths.js +2 -0
  176. package/dist/utils/get-paths.js.map +1 -0
  177. package/dist/utils/get-paths.mjs +2 -0
  178. package/dist/utils/get-paths.mjs.map +1 -0
  179. package/dist/utils/resolve-file-url.d.mts +8 -0
  180. package/dist/utils/resolve-file-url.d.ts +8 -0
  181. package/dist/utils/resolve-file-url.js +2 -0
  182. package/dist/utils/resolve-file-url.js.map +1 -0
  183. package/dist/utils/resolve-file-url.mjs +2 -0
  184. package/dist/utils/resolve-file-url.mjs.map +1 -0
  185. package/package.json +8 -9
  186. package/bin/index.cjs +0 -3
@@ -0,0 +1,451 @@
1
+ import { ValidationHandler } from './handlers/validation-handler/ValidationHandler.mjs';
2
+ import * as discord_js from 'discord.js';
3
+ import { Client, ChatInputCommandInteraction, ContextMenuCommandInteraction, AutocompleteInteraction, Interaction, CacheType, UserContextMenuCommandInteraction, MessageContextMenuCommandInteraction, PermissionsString, RESTPostAPIApplicationCommandsJSONBody } from 'discord.js';
4
+ import { AsyncLocalStorage } from 'async_hooks';
5
+
6
+ /**
7
+ * Command handler options.
8
+ * Similar to CommandKit options in structure.
9
+ */
10
+ interface CommandHandlerOptions {
11
+ /**
12
+ * The client created by the user.
13
+ */
14
+ client: Client;
15
+ /**
16
+ * Path to the user's commands.
17
+ */
18
+ commandsPath: string;
19
+ /**
20
+ * An array of developer guild IDs.
21
+ */
22
+ devGuildIds: string[];
23
+ /**
24
+ * An array of developer user IDs.
25
+ */
26
+ devUserIds: string[];
27
+ /**
28
+ * An array of developer role IDs.
29
+ */
30
+ devRoleIds: string[];
31
+ /**
32
+ * A validation handler instance to run validations before commands.
33
+ */
34
+ validationHandler?: ValidationHandler;
35
+ /**
36
+ * A boolean indicating whether to skip CommandKit's built-in validations (permission checking, etc.)
37
+ */
38
+ skipBuiltInValidations: boolean;
39
+ /**
40
+ * The CommandKit handler that instantiated this.
41
+ */
42
+ commandkitInstance: CommandKit;
43
+ /**
44
+ * A boolean indicating whether to register all commands in bulk.
45
+ */
46
+ bulkRegister: boolean;
47
+ /**
48
+ * Whether to enable hooks context.
49
+ */
50
+ enableHooks: boolean;
51
+ }
52
+ /**
53
+ * Private command handler data.
54
+ */
55
+ interface CommandHandlerData extends CommandHandlerOptions {
56
+ /**
57
+ * An array of command file objects.
58
+ */
59
+ commands: CommandFileObject[];
60
+ /**
61
+ * An array of built-in validations.
62
+ */
63
+ builtInValidations: BuiltInValidation[];
64
+ /**
65
+ * A validation handler instance to run validations before commands.
66
+ */
67
+ validationHandler?: ValidationHandler;
68
+ }
69
+ /**
70
+ * Parameters for CommandKit's built-in validations.
71
+ */
72
+ interface BuiltInValidationParams {
73
+ /**
74
+ * The target command to validate.
75
+ */
76
+ targetCommand: CommandFileObject;
77
+ /**
78
+ * The interaction of the target command.
79
+ */
80
+ interaction: CommandKitInteraction;
81
+ /**
82
+ * The command handler's data.
83
+ */
84
+ handlerData: CommandHandlerData;
85
+ }
86
+ /**
87
+ * Represents a command interaction.
88
+ */
89
+ type CommandKitInteraction = ChatInputCommandInteraction | ContextMenuCommandInteraction | AutocompleteInteraction;
90
+ /**
91
+ * A built in validation. Returns a boolean or void.
92
+ */
93
+ type BuiltInValidation = ({}: BuiltInValidationParams) => boolean | void;
94
+
95
+ interface hCommandContext {
96
+ interaction: CommandKitInteraction;
97
+ command: CommandData;
98
+ }
99
+ /**
100
+ * A handler for client application commands.
101
+ */
102
+ declare class CommandHandler {
103
+ #private;
104
+ context: AsyncLocalStorage<hCommandContext> | null;
105
+ constructor({ ...options }: CommandHandlerOptions);
106
+ init(): Promise<void>;
107
+ handleCommands(): void;
108
+ get commands(): CommandFileObject[];
109
+ reloadCommands(type?: ReloadOptions): Promise<void>;
110
+ }
111
+
112
+ /**
113
+ * Event handler options.
114
+ */
115
+ interface EventHandlerOptions {
116
+ client: Client;
117
+ eventsPath: string;
118
+ commandKitInstance: CommandKit;
119
+ }
120
+ /**
121
+ * Private event handler data.
122
+ */
123
+ interface EventHandlerData extends EventHandlerOptions {
124
+ events: {
125
+ name: string;
126
+ functions: Function[];
127
+ }[];
128
+ }
129
+
130
+ /**
131
+ * A handler for client events.
132
+ */
133
+ declare class EventHandler {
134
+ #private;
135
+ constructor({ ...options }: EventHandlerOptions);
136
+ init(): Promise<void>;
137
+ get events(): {
138
+ name: string;
139
+ functions: Function[];
140
+ }[];
141
+ reloadEvents(commandHandler?: CommandHandler): Promise<void>;
142
+ }
143
+
144
+ /**
145
+ * Options for instantiating a CommandKit handler.
146
+ */
147
+ interface CommandKitOptions {
148
+ /**
149
+ * The Discord.js client object to use with CommandKit.
150
+ */
151
+ client: Client;
152
+ /**
153
+ * The path to your commands directory.
154
+ */
155
+ commandsPath?: string;
156
+ /**
157
+ * The path to your events directory.
158
+ */
159
+ eventsPath?: string;
160
+ /**
161
+ * The path to the validations directory.
162
+ */
163
+ validationsPath?: string;
164
+ /**
165
+ * List of development guild IDs to restrict devOnly commands to.
166
+ */
167
+ devGuildIds?: string[];
168
+ /**
169
+ * List of developer user IDs to restrict devOnly commands to.
170
+ */
171
+ devUserIds?: string[];
172
+ /**
173
+ * List of developer role IDs to restrict devOnly commands to.
174
+ */
175
+ devRoleIds?: string[];
176
+ /**
177
+ * Skip CommandKit's built-in validations (for devOnly commands).
178
+ */
179
+ skipBuiltInValidations?: boolean;
180
+ /**
181
+ * Bulk register application commands instead of one-by-one.
182
+ */
183
+ bulkRegister?: boolean;
184
+ /**
185
+ * Options for experimental features.
186
+ */
187
+ experimental?: {
188
+ /**
189
+ * Enable hooks. This allows you to utilize hooks such as `useInteraction()` to access the interaction object anywhere inside the command.
190
+ */
191
+ hooks?: boolean;
192
+ };
193
+ }
194
+ /**
195
+ * Private data for the CommandKit class.
196
+ */
197
+ interface CommandKitData extends CommandKitOptions {
198
+ commandHandler?: CommandHandler;
199
+ eventHandler?: EventHandler;
200
+ validationHandler?: ValidationHandler;
201
+ }
202
+ /**
203
+ * Represents a command context.
204
+ */
205
+ interface CommandContext<T extends Interaction, Cached extends CacheType> {
206
+ /**
207
+ * The interaction that triggered this command.
208
+ */
209
+ interaction: Interaction<CacheType>;
210
+ /**
211
+ * The client that instantiated this command.
212
+ */
213
+ client: Client;
214
+ /**
215
+ * The command data.
216
+ */
217
+ handler: CommandKit;
218
+ }
219
+ /**
220
+ * Represents a command file.
221
+ */
222
+ interface CommandFileObject {
223
+ data: CommandData;
224
+ options?: CommandOptions;
225
+ run: <Cached extends CacheType = CacheType>(ctx: CommandContext<Interaction, Cached>) => Awaited<void>;
226
+ autocomplete?: <Cached extends CacheType = CacheType>(ctx: CommandContext<Interaction, Cached>) => Awaited<void>;
227
+ filePath: string;
228
+ category: string | null;
229
+ [key: string]: any;
230
+ }
231
+ /**
232
+ * A reload type for commands.
233
+ */
234
+ type ReloadOptions = 'dev' | 'global' | ReloadType;
235
+ /**
236
+ * Props for command run functions.
237
+ */
238
+ interface CommandProps {
239
+ /**
240
+ * The current command interaction object.
241
+ */
242
+ interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | UserContextMenuCommandInteraction | MessageContextMenuCommandInteraction | AutocompleteInteraction;
243
+ /**
244
+ * The Discord.js client object that CommandKit is handling.
245
+ */
246
+ client: Client<true>;
247
+ /**
248
+ * The current CommandKit handler instance.
249
+ */
250
+ handler: CommandKit;
251
+ }
252
+ /**
253
+ * Props for autocomplete command run functions.
254
+ */
255
+ interface AutocompleteProps extends CommandProps {
256
+ /**
257
+ * The current autocomplete command interaction object.
258
+ */
259
+ interaction: AutocompleteInteraction;
260
+ }
261
+ /**
262
+ * Props for slash (chat input) command run functions.
263
+ */
264
+ interface SlashCommandProps extends CommandProps {
265
+ /**
266
+ * The current slash (chat input) command interaction object.
267
+ */
268
+ interaction: ChatInputCommandInteraction;
269
+ }
270
+ /**
271
+ * Props for context menu command run functions.
272
+ */
273
+ interface ContextMenuCommandProps extends CommandProps {
274
+ /**
275
+ * The current context menu command interaction object.
276
+ */
277
+ interaction: ContextMenuCommandInteraction;
278
+ }
279
+ /**
280
+ * Props for user context menu command run functions.
281
+ */
282
+ interface UserContextMenuCommandProps extends CommandProps {
283
+ interaction: UserContextMenuCommandInteraction;
284
+ }
285
+ /**
286
+ * Props for message context menu command run functions.
287
+ */
288
+ interface MessageContextMenuCommandProps extends CommandProps {
289
+ interaction: MessageContextMenuCommandInteraction;
290
+ }
291
+ /**
292
+ * Props for command validation functions.
293
+ */
294
+ interface ValidationProps {
295
+ /**
296
+ * The current command interaction object.
297
+ */
298
+ interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction | AutocompleteInteraction;
299
+ /**
300
+ * The Discord.js client object that CommandKit is handling.
301
+ */
302
+ client: Client<true>;
303
+ /**
304
+ * The current (local) target command object.
305
+ */
306
+ commandObj: CommandObject;
307
+ /**
308
+ * The current CommandKit handler instance.
309
+ */
310
+ handler: CommandKit;
311
+ }
312
+ /**
313
+ * Additional command configuration options.
314
+ */
315
+ interface CommandOptions {
316
+ /**
317
+ * A boolean indicating whether the command is guild-only.
318
+ * Used for built-in validation.
319
+ *
320
+ * @deprecated Use `dm_permission` in the command's `data` object instead.
321
+ */
322
+ guildOnly?: boolean;
323
+ /**
324
+ * A boolean indicating whether the command is developer-only.
325
+ * Used for registration and built-in validation.
326
+ */
327
+ devOnly?: boolean;
328
+ /**
329
+ * A boolean indicating whether the command is deleted/ignored on restart/reload.
330
+ */
331
+ deleted?: boolean;
332
+ /**
333
+ * A string or array of permissions that a user needs for the current command to be executed.
334
+ * Used for built-in validation.
335
+ *
336
+ * @example
337
+ * userPermissions: 'BanMembers'
338
+ * or
339
+ * userPermissions: ['BanMembers', 'KickMembers']
340
+ */
341
+ userPermissions?: PermissionsString | PermissionsString[];
342
+ /**
343
+ * A string or array of permissions that the bot needs to execute the current command.
344
+ * Used for built-in validation.
345
+ *
346
+ * @example
347
+ * botPermissions: 'BanMembers'
348
+ * or
349
+ * botPermissions: ['BanMembers', 'KickMembers']
350
+ */
351
+ botPermissions?: PermissionsString | PermissionsString[];
352
+ [key: string]: any;
353
+ }
354
+ type CommandData = RESTPostAPIApplicationCommandsJSONBody;
355
+ type CommandObject = {
356
+ /**
357
+ * An object which defines the structure of the application command.
358
+ */
359
+ data: CommandData;
360
+ /**
361
+ * Additional command configuration options.
362
+ */
363
+ options?: CommandOptions;
364
+ /**
365
+ * The path to the command file.
366
+ */
367
+ filePath: string;
368
+ /**
369
+ * The command's category. Determined based on the command folder.
370
+ *
371
+ * @example
372
+ * ```txt
373
+ * "/src/commands/ping.js" -> null
374
+ * "/src/commands/Misc/ping.js" -> "Misc"
375
+ * ```
376
+ */
377
+ category: string | null;
378
+ [key: string]: any;
379
+ };
380
+ declare enum ReloadType {
381
+ /**
382
+ * Reload developer/guild commands.
383
+ */
384
+ Developer = "dev",
385
+ /**
386
+ * Reload global commands.
387
+ */
388
+ Global = "global"
389
+ }
390
+
391
+ declare class CommandKit {
392
+ #private;
393
+ static _instance: CommandKit | null;
394
+ /**
395
+ * Create a new command and event handler with CommandKit.
396
+ *
397
+ * @param options - The default CommandKit configuration.
398
+ * @see {@link https://commandkit.js.org/guide/commandkit-setup}
399
+ */
400
+ constructor(options: CommandKitOptions);
401
+ /**
402
+ * Get the client attached to this CommandKit instance.
403
+ */
404
+ get client(): discord_js.Client<boolean>;
405
+ /**
406
+ * Get command handler instance.
407
+ */
408
+ get commandHandler(): CommandHandler | undefined;
409
+ /**
410
+ * Updates application commands with the latest from "commandsPath".
411
+ */
412
+ reloadCommands(type?: ReloadOptions): Promise<void>;
413
+ /**
414
+ * Updates application events with the latest from "eventsPath".
415
+ */
416
+ reloadEvents(): Promise<void>;
417
+ /**
418
+ * Updates application command validations with the latest from "validationsPath".
419
+ */
420
+ reloadValidations(): Promise<void>;
421
+ /**
422
+ * @returns An array of objects of all the commands that CommandKit is handling.
423
+ */
424
+ get commands(): CommandObject[];
425
+ /**
426
+ * @returns The path to the commands folder which was set when instantiating CommandKit.
427
+ */
428
+ get commandsPath(): string | undefined;
429
+ /**
430
+ * @returns The path to the events folder which was set when instantiating CommandKit.
431
+ */
432
+ get eventsPath(): string | undefined;
433
+ /**
434
+ * @returns The path to the validations folder which was set when instantiating CommandKit.
435
+ */
436
+ get validationsPath(): string | undefined;
437
+ /**
438
+ * @returns An array of all the developer user IDs which was set when instantiating CommandKit.
439
+ */
440
+ get devUserIds(): string[];
441
+ /**
442
+ * @returns An array of all the developer guild IDs which was set when instantiating CommandKit.
443
+ */
444
+ get devGuildIds(): string[];
445
+ /**
446
+ * @returns An array of all the developer role IDs which was set when instantiating CommandKit.
447
+ */
448
+ get devRoleIds(): string[];
449
+ }
450
+
451
+ export { type AutocompleteProps as A, type BuiltInValidationParams as B, CommandKit as C, type EventHandlerOptions as E, type MessageContextMenuCommandProps as M, type ReloadOptions as R, type SlashCommandProps as S, type UserContextMenuCommandProps as U, type ValidationProps as V, type CommandKitOptions as a, type CommandKitData as b, type CommandContext as c, type CommandFileObject as d, type CommandProps as e, type ContextMenuCommandProps as f, type CommandOptions as g, type CommandData as h, type CommandObject as i, ReloadType as j, type CommandHandlerOptions as k, type CommandHandlerData as l, type CommandKitInteraction as m, type BuiltInValidation as n, type hCommandContext as o, CommandHandler as p, type EventHandlerData as q, EventHandler as r };
@@ -0,0 +1,5 @@
1
+ import 'discord.js';
2
+ export { C as CommandKit } from './CommandKit-D84HlsL0.mjs';
3
+ import './handlers/validation-handler/ValidationHandler.mjs';
4
+ import './handlers/validation-handler/typings.mjs';
5
+ import 'async_hooks';
@@ -0,0 +1,5 @@
1
+ import 'discord.js';
2
+ export { C as CommandKit } from './CommandKit-Co5QNlps.js';
3
+ import './handlers/validation-handler/ValidationHandler.js';
4
+ import './handlers/validation-handler/typings.js';
5
+ import 'async_hooks';
@@ -0,0 +1,11 @@
1
+ "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var CommandKit_exports={};__export(CommandKit_exports,{CommandKit:()=>CommandKit});module.exports=__toCommonJS(CommandKit_exports);var import_path=__toESM(require("path"));function toFileURL(filePath){return"file://"+import_path.default.resolve(filePath).replace(/\\\\|\\/g,"/")}__name(toFileURL,"toFileURL");var import_path2=__toESM(require("path")),import_promises=__toESM(require("fs/promises"));async function getFilePaths(directory,nesting){let filePaths=[];if(!directory)return filePaths;let files=await import_promises.default.readdir(directory,{withFileTypes:!0});for(let file of files){let filePath=import_path2.default.join(directory,file.name);file.isFile()&&filePaths.push(filePath),nesting&&file.isDirectory()&&(filePaths=[...filePaths,...await getFilePaths(filePath,!0)])}return filePaths}__name(getFilePaths,"getFilePaths");async function getFolderPaths(directory,nesting){let folderPaths=[];if(!directory)return folderPaths;let folders=await import_promises.default.readdir(directory,{withFileTypes:!0});for(let folder of folders){let folderPath=import_path2.default.join(directory,folder.name);folder.isDirectory()&&(folderPaths.push(folderPath),nesting&&(folderPaths=[...folderPaths,...await getFolderPaths(folderPath,!0)]))}return folderPaths}__name(getFolderPaths,"getFolderPaths");var import_rfdc=__toESM(require("rfdc")),clone=(0,import_rfdc.default)();var resetColor="\x1B[0m",colors_default={reset:__name(text=>`${text}${resetColor}`,"reset"),bright:__name(text=>`\x1B[1m${text}${resetColor}`,"bright"),dim:__name(text=>`\x1B[2m${text}${resetColor}`,"dim"),underscore:__name(text=>`\x1B[4m${text}${resetColor}`,"underscore"),blink:__name(text=>`\x1B[5m${text}${resetColor}`,"blink"),reverse:__name(text=>`\x1B[7m${text}${resetColor}`,"reverse"),hidden:__name(text=>`\x1B[8m${text}${resetColor}`,"hidden"),black:__name(text=>`\x1B[30m${text}${resetColor}`,"black"),red:__name(text=>`\x1B[31m${text}${resetColor}`,"red"),green:__name(text=>`\x1B[32m${text}${resetColor}`,"green"),yellow:__name(text=>`\x1B[33m${text}${resetColor}`,"yellow"),blue:__name(text=>`\x1B[34m${text}${resetColor}`,"blue"),magenta:__name(text=>`\x1B[35m${text}${resetColor}`,"magenta"),cyan:__name(text=>`\x1B[36m${text}${resetColor}`,"cyan"),white:__name(text=>`\x1B[37m${text}${resetColor}`,"white"),bgBlack:__name(text=>`\x1B[40m${text}${resetColor}`,"bgBlack"),bgRed:__name(text=>`\x1B[41m${text}${resetColor}`,"bgRed"),bgGreen:__name(text=>`\x1B[42m${text}${resetColor}`,"bgGreen"),bgYellow:__name(text=>`\x1B[43m${text}${resetColor}`,"bgYellow"),bgBlue:__name(text=>`\x1B[44m${text}${resetColor}`,"bgBlue"),bgMagenta:__name(text=>`\x1B[45m${text}${resetColor}`,"bgMagenta"),bgCyan:__name(text=>`\x1B[46m${text}${resetColor}`,"bgCyan"),bgWhite:__name(text=>`\x1B[47m${text}${resetColor}`,"bgWhite")};async function loadCommandsWithRest(props){if(props.reloading)if(props.client.isReady())await handleLoading(props.client,props.commands,props.devGuildIds,props.reloading,props.type);else throw new Error(colors_default.red("Cannot reload commands when client is not ready."));else props.client.once("ready",async c=>{await handleLoading(c,props.commands,props.devGuildIds,props.reloading,props.type)})}__name(loadCommandsWithRest,"loadCommandsWithRest");async function handleLoading(client,commands,devGuildIds,reloading,type){commands=commands.filter(cmd=>!cmd.options?.deleted);let devOnlyCommands=commands.filter(cmd=>cmd.options?.devOnly),globalCommands=commands.filter(cmd=>!cmd.options?.devOnly);type==="dev"?await loadDevCommands(client,devOnlyCommands,devGuildIds,reloading):type==="global"?await loadGlobalCommands(client,globalCommands,reloading):(await loadDevCommands(client,devOnlyCommands,devGuildIds,reloading),await loadGlobalCommands(client,globalCommands,reloading))}__name(handleLoading,"handleLoading");async function loadGlobalCommands(client,commands,reloading){let requestBody=commands.map(cmd=>cmd.data);await client.application.commands.set(requestBody).catch(error=>{throw new Error(colors_default.red(`Error ${reloading?"reloading":"loading"} global application commands.
2
+ `),error)}),console.log(colors_default.green(`${reloading?"Reloaded":"Loaded"} ${requestBody.length} global commands.`))}__name(loadGlobalCommands,"loadGlobalCommands");async function loadDevCommands(client,commands,guildIds,reloading){let requestBody=commands.map(cmd=>cmd.data);for(let guildId of guildIds){let targetGuild=client.guilds.cache.get(guildId)||await client.guilds.fetch(guildId);if(!targetGuild){process.emitWarning(`Cannot ${reloading?"reload":"load"} commands in guild "${guildId}" - guild doesn't exist or client isn't part of the guild.`);continue}await targetGuild.commands.set(requestBody).catch(error=>{throw new Error(colors_default.red(`Error ${reloading?"reloading":"loading"} developer application commands in guild "${targetGuild?.name||guildId}".
3
+ `),error)}),console.log(colors_default.green(`${reloading?"Reloaded":"Loaded"} ${requestBody.length} developer commands in guild "${targetGuild.name}".`))}}__name(loadDevCommands,"loadDevCommands");function areSlashCommandsDifferent(appCommand,localCommand){if(appCommand.options||(appCommand.options=[]),localCommand.options||(localCommand.options=[]),appCommand.description||(appCommand.description=""),localCommand.description||(localCommand.description=""),localCommand.description!==appCommand.description||localCommand.options.length!==appCommand.options.length)return!0}__name(areSlashCommandsDifferent,"areSlashCommandsDifferent");async function registerCommands(props){if(props.reloading)if(props.client.isReady())await handleRegistration(props.client,props.commands,props.devGuildIds,props.type);else throw new Error(colors_default.red("Cannot reload commands when client is not ready."));else props.client.once("ready",async c=>{await handleRegistration(c,props.commands,props.devGuildIds,props.type)})}__name(registerCommands,"registerCommands");async function handleRegistration(client,commands,devGuildIds,type){let devOnlyCommands=commands.filter(cmd=>cmd.options?.devOnly),globalCommands=commands.filter(cmd=>!cmd.options?.devOnly);type==="dev"?await registerDevCommands(client,devOnlyCommands,devGuildIds):type==="global"?await registerGlobalCommands(client,globalCommands):(await registerDevCommands(client,devOnlyCommands,devGuildIds),await registerGlobalCommands(client,globalCommands))}__name(handleRegistration,"handleRegistration");async function registerGlobalCommands(client,commands){let appCommandsManager=client.application.commands;await appCommandsManager.fetch();for(let command of commands){let targetCommand=appCommandsManager.cache.find(cmd=>cmd.name===command.data.name);if(command.options?.deleted){targetCommand?(await targetCommand.delete().catch(error=>{throw new Error(colors_default.red(`Failed to delete command "${command.data.name}" globally.
4
+ `),error)}),console.log(colors_default.green(`Deleted command "${command.data.name}" globally.`))):process.emitWarning(colors_default.yellow(`Ignoring: Command "${command.data.name}" is globally marked as deleted.`));continue}if(targetCommand&&areSlashCommandsDifferent(targetCommand,command.data)){await targetCommand.edit(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to edit command "${command.data.name}" globally.
5
+ `),error)}),console.log(colors_default.green(`Edited command "${command.data.name}" globally.`));continue}targetCommand||(await appCommandsManager.create(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to register command "${command.data.name}" globally.
6
+ `),error)}),console.log(colors_default.green(`Registered command "${command.data.name}" globally.`)))}}__name(registerGlobalCommands,"registerGlobalCommands");async function registerDevCommands(client,commands,guildIds){let devGuilds=[];for(let guildId of guildIds){let guild=client.guilds.cache.get(guildId)||await client.guilds.fetch(guildId);if(!guild){process.emitWarning(colors_default.yellow(`Ignoring: Guild ${guildId} doesn't exist or client isn't part of the guild.`));continue}devGuilds.push(guild)}let guildCommandsManagers=[];for(let guild of devGuilds){let guildCommandsManager=guild.commands;await guildCommandsManager.fetch(),guildCommandsManagers.push(guildCommandsManager)}for(let command of commands)for(let guildCommands of guildCommandsManagers){let targetCommand=guildCommands.cache.find(cmd=>cmd.name===command.data.name);if(command.options?.deleted){targetCommand?(await targetCommand.delete().catch(error=>{throw new Error(colors_default.red(`Failed to delete command "${command.data.name}" in ${guildCommands.guild.name}.`),error)}),console.log(colors_default.green(`Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`))):process.emitWarning(colors_default.yellow(`Ignoring: Command "${command.data.name}" is marked as deleted in ${guildCommands.guild.name}.`));continue}if(targetCommand&&areSlashCommandsDifferent(targetCommand,command.data)){await targetCommand.edit(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to edit command "${command.data.name}" in ${guildCommands.guild.name}.
7
+ `),error)}),console.log(colors_default.green(`Edited command "${command.data.name}" in ${guildCommands.guild.name}.`));continue}targetCommand||(await guildCommands.create(command.data).catch(error=>{throw new Error(colors_default.red(`Failed to register command "${command.data.name}" in ${guildCommands.guild.name}.
8
+ `),error)}),console.log(colors_default.green(`Registered command "${command.data.name}" in ${guildCommands.guild.name}.`)))}}__name(registerDevCommands,"registerDevCommands");function devOnly_default({interaction,targetCommand,handlerData}){if(!interaction.isAutocomplete()&&targetCommand.options?.devOnly){if(interaction.inGuild()&&!handlerData.devGuildIds.includes(interaction.guildId))return interaction.reply({content:"\u274C This command can only be used inside development servers.",ephemeral:!0}),!0;let memberRoles=interaction.guild?.members.cache.get(interaction.user.id)?.roles.cache,hasDevRole=!1;if(memberRoles?.forEach(role=>{handlerData.devRoleIds.includes(role.id)&&(hasDevRole=!0)}),!(handlerData.devUserIds.includes(interaction.user.id)||hasDevRole))return interaction.reply({content:"\u274C This command can only be used by developers.",ephemeral:!0}),!0}}__name(devOnly_default,"default");var import_discord=require("discord.js");function permissions_default({interaction,targetCommand}){if(interaction.isAutocomplete())return;let userPermissions=interaction.memberPermissions,userPermissionsRequired=targetCommand.options?.userPermissions,missingUserPermissions=[];typeof userPermissionsRequired=="string"&&(userPermissionsRequired=[userPermissionsRequired]);let botPermissions=interaction.guild?.members.me?.permissions,botPermissionsRequired=targetCommand.options?.botPermissions,missingBotPermissions=[];if(typeof botPermissionsRequired=="string"&&(botPermissionsRequired=[botPermissionsRequired]),!userPermissionsRequired?.length&&!botPermissionsRequired?.length)return;if(userPermissions&&userPermissionsRequired)for(let permission of userPermissionsRequired)userPermissions.has(permission)||missingUserPermissions.push(permission);if(botPermissions&&botPermissionsRequired)for(let permission of botPermissionsRequired)botPermissions.has(permission)||missingBotPermissions.push(permission);if(!missingUserPermissions.length&&!missingBotPermissions.length)return;let pattern=/([a-z])([A-Z])|([A-Z]+)([A-Z][a-z])/g;missingUserPermissions=missingUserPermissions.map(str=>str.replace(pattern,"$1$3 $2$4")),missingBotPermissions=missingBotPermissions.map(str=>str.replace(pattern,"$1$3 $2$4"));let embedDescription="",formatter=new Intl.ListFormat("en",{style:"long",type:"conjunction"}),getPermissionWord=__name(permissions=>permissions.length===1?"permission":"permissions","getPermissionWord");if(missingUserPermissions.length){let formattedPermissions=missingUserPermissions.map(p=>`\`${p}\``),permissionsString=formatter.format(formattedPermissions);embedDescription+=`- You must have the ${permissionsString} ${getPermissionWord(missingUserPermissions)} to be able to run this command.
9
+ `}if(missingBotPermissions.length){let formattedPermissions=missingBotPermissions.map(p=>`\`${p}\``),permissionsString=formatter.format(formattedPermissions);embedDescription+=`- I must have the ${permissionsString} ${getPermissionWord(missingBotPermissions)} to be able to execute this command.
10
+ `}let embed=new import_discord.EmbedBuilder().setTitle(":x: Missing permissions!").setDescription(embedDescription).setColor("Red");return interaction.reply({embeds:[embed],ephemeral:!0}),!0}__name(permissions_default,"default");var validations_default=[devOnly_default,permissions_default];var import_async_hooks=require("async_hooks");var CommandHandler=class{static{__name(this,"CommandHandler")}#data;context=null;constructor({...options}){this.#data={...options,builtInValidations:[],commands:[]}}async init(){this.#data.enableHooks&&!this.context&&(this.context=new import_async_hooks.AsyncLocalStorage),await this.#buildCommands(),this.#buildBuiltInValidations();let devOnlyCommands=this.#data.commands.filter(cmd=>cmd.options?.devOnly);devOnlyCommands.length&&!this.#data.devGuildIds.length&&process.emitWarning(colors_default.yellow('You have commands marked as "devOnly", but "devGuildIds" have not been set.')),devOnlyCommands.length&&!this.#data.devUserIds.length&&!this.#data.devRoleIds.length&&process.emitWarning(colors_default.yellow('You have commands marked as "devOnly", but "devUserIds" or "devRoleIds" have not been set.')),this.#data.bulkRegister?await loadCommandsWithRest({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands}):await registerCommands({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands}),this.handleCommands()}async#buildCommands(){let allowedExtensions=/\.(js|mjs|cjs|ts)$/i,commandFilePaths=(await getFilePaths(this.#data.commandsPath,!0)).filter(path3=>allowedExtensions.test(path3));for(let commandFilePath of commandFilePaths){let importedObj=await import(`${toFileURL(commandFilePath)}?t=${Date.now()}`),commandObj=clone(importedObj);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(commandFilePath)];let compactFilePath=commandFilePath.split(process.cwd())[1]||commandFilePath;if(commandObj.default&&(commandObj=commandObj.default),importedObj.default?commandObj.data=importedObj.default.data:commandObj.data=importedObj.data,!commandObj.data){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${compactFilePath} does not export "data".`));continue}if(!commandObj.data.name){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${compactFilePath} does not export "data.name".`));continue}if(!commandObj.run){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${commandObj.data.name} does not export "run".`));continue}if(typeof commandObj.run!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Command file ${commandObj.data.name} does not export "run" as a function.`));continue}commandObj.filePath=commandFilePath;let commandCategory=commandFilePath.split(this.#data.commandsPath)[1]?.replace(/\\\\|\\/g,"/").split("/")[1]||null;commandCategory&&allowedExtensions.test(commandCategory)?commandObj.category=null:commandObj.category=commandCategory,this.#data.commands.push(commandObj)}}#buildBuiltInValidations(){for(let builtInValidationFunction of validations_default)this.#data.builtInValidations.push(builtInValidationFunction)}handleCommands(){let areHooksEnabled=this.#data.enableHooks;this.#data.client.on("interactionCreate",async interaction=>{if(!interaction.isChatInputCommand()&&!interaction.isContextMenuCommand()&&!interaction.isAutocomplete())return;let isAutocomplete=interaction.isAutocomplete(),targetCommand=this.#data.commands.find(cmd=>cmd.data.name===interaction.commandName);if(!targetCommand)return;let{data,options,run,autocomplete,...rest}=targetCommand;if(isAutocomplete&&!autocomplete)return;let executor=__name(async()=>{let commandObj={data:targetCommand.data,options:targetCommand.options,...rest};if(this.#data.validationHandler){let canRun2=!0;for(let validationFunction of this.#data.validationHandler.validations)if(await validationFunction({interaction,commandObj,client:this.#data.client,handler:this.#data.commandkitInstance})){canRun2=!1;break}if(!canRun2)return}let canRun=!0;if(!this.#data.skipBuiltInValidations){for(let validation of this.#data.builtInValidations)if(validation({targetCommand,interaction,handlerData:this.#data})){canRun=!1;break}}if(!canRun)return;let command=targetCommand[isAutocomplete?"autocomplete":"run"];if(!areHooksEnabled){let context={interaction,client:this.#data.client,handler:this.#data.commandkitInstance};return await command(context)}return command()},"executor");return this.context?this.context.run({command:targetCommand.data,interaction},executor):executor()})}get commands(){return this.#data.commands}async reloadCommands(type){if(!this.#data.commandsPath)throw new Error(colors_default.red('Cannot reload commands as "commandsPath" was not provided when instantiating CommandKit.'));this.#data.commands=[],await this.#buildCommands(),this.#data.bulkRegister?await loadCommandsWithRest({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands,reloading:!0,type}):await registerCommands({client:this.#data.client,devGuildIds:this.#data.devGuildIds,commands:this.#data.commands,reloading:!0,type})}};var EventHandler=class{static{__name(this,"EventHandler")}#data;constructor({...options}){this.#data={...options,events:[]}}async init(){await this.#buildEvents(),this.#registerEvents()}async#buildEvents(){let eventFolderPaths=await getFolderPaths(this.#data.eventsPath);for(let eventFolderPath of eventFolderPaths){let eventName=eventFolderPath.replace(/\\\\|\\/g,"/").split("/").pop(),allowedExtensions=/\.(js|mjs|cjs|ts)$/i,eventFilePaths=(await getFilePaths(eventFolderPath,!0)).filter(path3=>allowedExtensions.test(path3)),eventObj={name:eventName,functions:[]};this.#data.events.push(eventObj);for(let eventFilePath of eventFilePaths){let importedFunction=(await import(`${toFileURL(eventFilePath)}?t=${Date.now()}`)).default,eventFunction=clone(importedFunction);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(eventFilePath)],eventFunction?.default&&(eventFunction=eventFunction.default);let compactFilePath=eventFilePath.split(process.cwd())[1]||eventFilePath;if(typeof eventFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Event file ${compactFilePath} does not export a function.`));continue}eventObj.functions.push(eventFunction)}}}#registerEvents(){let client=this.#data.client,handler=this.#data.commandKitInstance;for(let eventObj of this.#data.events)client.on(eventObj.name,async(...params)=>{for(let eventFunction of eventObj.functions)if(await eventFunction(...params,client,handler))break})}get events(){return this.#data.events}async reloadEvents(commandHandler){if(!this.#data.eventsPath)throw new Error(colors_default.red('Cannot reload events as "eventsPath" was not provided when instantiating CommandKit.'));this.#data.events=[],await this.#buildEvents(),this.#data.client.removeAllListeners(),this.#registerEvents(),commandHandler?.handleCommands()}};var ValidationHandler=class{static{__name(this,"ValidationHandler")}#data;constructor({...options}){this.#data={...options,validations:[]}}async init(){this.#data.validations=await this.#buildValidations()}async#buildValidations(){let allowedExtensions=/\.(js|mjs|cjs|ts)$/i,validationFilePaths=(await getFilePaths(this.#data.validationsPath,!0)).filter(path3=>allowedExtensions.test(path3)),validationFunctions=[];for(let validationFilePath of validationFilePaths){let importedFunction=(await import(`${toFileURL(validationFilePath)}?t=${Date.now()}`)).default,validationFunction=clone(importedFunction);typeof module<"u"&&typeof require<"u"&&delete require.cache[require.resolve(validationFilePath)],validationFunction?.default&&(validationFunction=validationFunction.default);let compactFilePath=validationFilePath.split(process.cwd())[1]||validationFilePath;if(typeof validationFunction!="function"){process.emitWarning(colors_default.yellow(`Ignoring: Validation file ${compactFilePath} does not export a function.`));continue}validationFunctions.push(validationFunction)}return validationFunctions}get validations(){return this.#data.validations}async reloadValidations(){if(!this.#data.validationsPath)throw new Error(colors_default.red('Cannot reload validations as "validationsPath" was not provided when instantiating CommandKit.'));let newValidations=await this.#buildValidations();this.#data.validations=newValidations}};var CommandKit=class _CommandKit{static{__name(this,"CommandKit")}#data;static _instance=null;constructor(options){if(!options.client)throw new Error(colors_default.red('"client" is required when instantiating CommandKit.'));if(options.validationsPath&&!options.commandsPath)throw new Error(colors_default.red('"commandsPath" is required when "validationsPath" is set.'));this.#data=options,_CommandKit._instance=this,this.#init()}get client(){return this.#data.client}get commandHandler(){return this.#data.commandHandler}async#init(){if(this.#data.eventsPath){let eventHandler=new EventHandler({client:this.#data.client,eventsPath:this.#data.eventsPath,commandKitInstance:this});await eventHandler.init(),this.#data.eventHandler=eventHandler}if(this.#data.validationsPath){let validationHandler=new ValidationHandler({validationsPath:this.#data.validationsPath});await validationHandler.init(),this.#data.validationHandler=validationHandler}if(this.#data.commandsPath){let commandHandler=new CommandHandler({client:this.#data.client,commandsPath:this.#data.commandsPath,devGuildIds:this.#data.devGuildIds||[],devUserIds:this.#data.devUserIds||[],devRoleIds:this.#data.devRoleIds||[],validationHandler:this.#data.validationHandler,skipBuiltInValidations:this.#data.skipBuiltInValidations||!1,commandkitInstance:this,bulkRegister:this.#data.bulkRegister||!1,enableHooks:this.#data.experimental?.hooks??!1});await commandHandler.init(),this.#data.commandHandler=commandHandler}}async reloadCommands(type){this.#data.commandHandler&&await this.#data.commandHandler.reloadCommands(type)}async reloadEvents(){this.#data.eventHandler&&await this.#data.eventHandler.reloadEvents(this.#data.commandHandler)}async reloadValidations(){this.#data.validationHandler&&await this.#data.validationHandler.reloadValidations()}get commands(){return this.#data.commandHandler?this.#data.commandHandler.commands.map(cmd=>{let{run,autocomplete,...command}=cmd;return command}):[]}get commandsPath(){return this.#data.commandsPath}get eventsPath(){return this.#data.eventsPath}get validationsPath(){return this.#data.validationsPath}get devUserIds(){return this.#data.devUserIds||[]}get devGuildIds(){return this.#data.devGuildIds||[]}get devRoleIds(){return this.#data.devRoleIds||[]}};0&&(module.exports={CommandKit});
11
+ //# sourceMappingURL=CommandKit.js.map