commandkit 0.0.10 → 0.1.1

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 CHANGED
@@ -1,3 +1,8 @@
1
+ <h1 align="center">
2
+ <img src="https://raw.githubusercontent.com/underctrl-io/commandkit/master/apps/docs/public/ckit_logo.png" width="50%">
3
+ <br>
4
+ </h1>
5
+
1
6
  # CommandKit
2
7
 
3
8
  CommandKit is a library that makes it easy to handle commands (+ validations), and events in your Discord.js projects.
@@ -29,12 +34,26 @@ For npm:
29
34
  npm install commandkit
30
35
  ```
31
36
 
32
- For yarn:
37
+ Yarn:
33
38
 
34
39
  ```bash
35
40
  yarn add commandkit
36
41
  ```
37
42
 
43
+ pnpm:
44
+
45
+ ```bash
46
+ pnpm add commandkit
47
+ ```
48
+
49
+ ### Install development version
50
+
51
+ To install the development version of CommandKit, run the following command:
52
+
53
+ ```bash
54
+ npm install underctrl-io/commandkit#dev-build
55
+ ```
56
+
38
57
  # Usage
39
58
 
40
59
  This is a simple overview of how to set up this library with all the options. You can read more in the [full documentation](https://commandkit.underctrl.io)
package/dist/index.d.mts CHANGED
@@ -1,6 +1,4 @@
1
- import * as discord_js from 'discord.js';
2
- import { Client } from 'discord.js';
3
- import * as _discordjs_builders from '@discordjs/builders';
1
+ import { Client, Interaction, CommandInteraction, ChatInputCommandInteraction, ContextMenuCommandInteraction, PermissionResolvable, APIApplicationCommandOption } from 'discord.js';
4
2
 
5
3
  interface CommandKitOptions {
6
4
  client: Client;
@@ -13,39 +11,69 @@ interface CommandKitOptions {
13
11
  skipBuiltInValidations?: boolean;
14
12
  }
15
13
 
14
+ interface CommandFileObject {
15
+ data: CommandData;
16
+ options?: CommandOptions;
17
+ run: ({}: { interaction: Interaction; client: Client; handler: CommandKit }) => void;
18
+ }
19
+
20
+ interface CommandProps {
21
+ interaction: CommandInteraction;
22
+ client: Client<true>;
23
+ handler: CommandKit;
24
+ }
25
+ interface SlashCommandProps {
26
+ interaction: ChatInputCommandInteraction;
27
+ client: Client<true>;
28
+ handler: CommandKit;
29
+ }
30
+ interface ContextMenuCommandProps {
31
+ interaction: ContextMenuCommandInteraction;
32
+ client: Client<true>;
33
+ handler: CommandKit;
34
+ }
35
+ interface ValidationFunctionProps {
36
+ interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction;
37
+ client: Client<true>;
38
+ commandObj: CommandObject;
39
+ handler: CommandKit;
40
+ }
41
+ interface CommandOptions {
42
+ guildOnly?: boolean;
43
+ devOnly?: boolean;
44
+ deleted?: boolean;
45
+ userPermissions?: PermissionResolvable;
46
+ botPermissions?: PermissionResolvable;
47
+ [key: string]: any;
48
+ }
49
+ declare enum CommandType {
50
+ 'ChatInput' = 1,
51
+ 'Message' = 3,
52
+ 'User' = 2
53
+ }
54
+ 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';
55
+ type CommandData = {
56
+ name: string;
57
+ description: string;
58
+ type?: CommandType;
59
+ name_localizations?: Partial<Record<LocaleString, string | null>>;
60
+ description_localizations?: Partial<Record<LocaleString, string | null>>;
61
+ dm_permission?: boolean;
62
+ default_member_permissions?: string;
63
+ nsfw?: boolean;
64
+ options?: Array<APIApplicationCommandOption>;
65
+ };
66
+ type CommandObject = Omit<CommandFileObject, 'run'>;
67
+
16
68
  declare class CommandKit {
17
69
  #private;
18
70
  constructor({ ...options }: CommandKitOptions);
19
- get commands(): ({
20
- data: _discordjs_builders.SlashCommandBuilder | {
21
- name: string;
22
- name_localizations?: any;
23
- description: string;
24
- dm_permission?: boolean | undefined;
25
- options?: discord_js.APIApplicationCommandOption[] | undefined;
26
- };
27
- options?: {
28
- guildOnly?: boolean | undefined;
29
- devOnly?: boolean | undefined;
30
- deleted?: boolean | undefined;
31
- userPermissions?: discord_js.PermissionResolvable[] | undefined;
32
- botPermissions?: discord_js.PermissionResolvable[] | undefined;
33
- } | undefined;
34
- } | {
35
- data: _discordjs_builders.ContextMenuCommandBuilder | {
36
- name: string;
37
- name_localizations?: any;
38
- type: _discordjs_builders.ContextMenuCommandType;
39
- dm_permission?: boolean | undefined;
40
- };
41
- options?: {
42
- guildOnly?: boolean | undefined;
43
- devOnly?: boolean | undefined;
44
- deleted?: boolean | undefined;
45
- userPermissions?: discord_js.PermissionResolvable[] | undefined;
46
- botPermissions?: discord_js.PermissionResolvable[] | undefined;
47
- } | undefined;
48
- })[];
71
+ /**
72
+ * Returns all the commands that CommandKit is handling.
73
+ *
74
+ * @returns An array of command objects
75
+ */
76
+ get commands(): CommandObject[];
49
77
  }
50
78
 
51
- export { CommandKit };
79
+ export { CommandData, CommandKit, CommandObject, CommandOptions, CommandProps, CommandType, ContextMenuCommandProps, SlashCommandProps, ValidationFunctionProps };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import * as discord_js from 'discord.js';
2
- import { Client } from 'discord.js';
3
- import * as _discordjs_builders from '@discordjs/builders';
1
+ import { Client, Interaction, CommandInteraction, ChatInputCommandInteraction, ContextMenuCommandInteraction, PermissionResolvable, APIApplicationCommandOption } from 'discord.js';
4
2
 
5
3
  interface CommandKitOptions {
6
4
  client: Client;
@@ -13,39 +11,69 @@ interface CommandKitOptions {
13
11
  skipBuiltInValidations?: boolean;
14
12
  }
15
13
 
14
+ interface CommandFileObject {
15
+ data: CommandData;
16
+ options?: CommandOptions;
17
+ run: ({}: { interaction: Interaction; client: Client; handler: CommandKit }) => void;
18
+ }
19
+
20
+ interface CommandProps {
21
+ interaction: CommandInteraction;
22
+ client: Client<true>;
23
+ handler: CommandKit;
24
+ }
25
+ interface SlashCommandProps {
26
+ interaction: ChatInputCommandInteraction;
27
+ client: Client<true>;
28
+ handler: CommandKit;
29
+ }
30
+ interface ContextMenuCommandProps {
31
+ interaction: ContextMenuCommandInteraction;
32
+ client: Client<true>;
33
+ handler: CommandKit;
34
+ }
35
+ interface ValidationFunctionProps {
36
+ interaction: ChatInputCommandInteraction | ContextMenuCommandInteraction;
37
+ client: Client<true>;
38
+ commandObj: CommandObject;
39
+ handler: CommandKit;
40
+ }
41
+ interface CommandOptions {
42
+ guildOnly?: boolean;
43
+ devOnly?: boolean;
44
+ deleted?: boolean;
45
+ userPermissions?: PermissionResolvable;
46
+ botPermissions?: PermissionResolvable;
47
+ [key: string]: any;
48
+ }
49
+ declare enum CommandType {
50
+ 'ChatInput' = 1,
51
+ 'Message' = 3,
52
+ 'User' = 2
53
+ }
54
+ 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';
55
+ type CommandData = {
56
+ name: string;
57
+ description: string;
58
+ type?: CommandType;
59
+ name_localizations?: Partial<Record<LocaleString, string | null>>;
60
+ description_localizations?: Partial<Record<LocaleString, string | null>>;
61
+ dm_permission?: boolean;
62
+ default_member_permissions?: string;
63
+ nsfw?: boolean;
64
+ options?: Array<APIApplicationCommandOption>;
65
+ };
66
+ type CommandObject = Omit<CommandFileObject, 'run'>;
67
+
16
68
  declare class CommandKit {
17
69
  #private;
18
70
  constructor({ ...options }: CommandKitOptions);
19
- get commands(): ({
20
- data: _discordjs_builders.SlashCommandBuilder | {
21
- name: string;
22
- name_localizations?: any;
23
- description: string;
24
- dm_permission?: boolean | undefined;
25
- options?: discord_js.APIApplicationCommandOption[] | undefined;
26
- };
27
- options?: {
28
- guildOnly?: boolean | undefined;
29
- devOnly?: boolean | undefined;
30
- deleted?: boolean | undefined;
31
- userPermissions?: discord_js.PermissionResolvable[] | undefined;
32
- botPermissions?: discord_js.PermissionResolvable[] | undefined;
33
- } | undefined;
34
- } | {
35
- data: _discordjs_builders.ContextMenuCommandBuilder | {
36
- name: string;
37
- name_localizations?: any;
38
- type: _discordjs_builders.ContextMenuCommandType;
39
- dm_permission?: boolean | undefined;
40
- };
41
- options?: {
42
- guildOnly?: boolean | undefined;
43
- devOnly?: boolean | undefined;
44
- deleted?: boolean | undefined;
45
- userPermissions?: discord_js.PermissionResolvable[] | undefined;
46
- botPermissions?: discord_js.PermissionResolvable[] | undefined;
47
- } | undefined;
48
- })[];
71
+ /**
72
+ * Returns all the commands that CommandKit is handling.
73
+ *
74
+ * @returns An array of command objects
75
+ */
76
+ get commands(): CommandObject[];
49
77
  }
50
78
 
51
- export { CommandKit };
79
+ export { CommandData, CommandKit, CommandObject, CommandOptions, CommandProps, CommandType, ContextMenuCommandProps, SlashCommandProps, ValidationFunctionProps };
package/dist/index.js CHANGED
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- CommandKit: () => CommandKit
33
+ CommandKit: () => CommandKit,
34
+ CommandType: () => CommandType
34
35
  });
35
36
  module.exports = __toCommonJS(src_exports);
36
37
 
@@ -78,31 +79,34 @@ function toFileURL(filePath) {
78
79
  }
79
80
 
80
81
  // src/handlers/command-handler/validations/botPermissions.ts
81
- function botPermissions_default({
82
- interaction,
83
- targetCommand
84
- }) {
82
+ function botPermissions_default({ interaction, targetCommand }) {
85
83
  const botMember = interaction.guild?.members.me;
86
- if (targetCommand.options?.botPermissions && botMember) {
87
- for (const permission of targetCommand.options.botPermissions) {
88
- const hasPermission = botMember.permissions.has(permission);
89
- if (!hasPermission) {
90
- interaction.reply({
91
- content: `\u274C I do not have enough permission to execute this command. Required permission: \`${permission}\``,
92
- ephemeral: true
93
- });
94
- return true;
95
- }
84
+ let commandPermissions = targetCommand.options?.botPermissions;
85
+ if (!botMember || !commandPermissions)
86
+ return;
87
+ if (!Array.isArray(commandPermissions)) {
88
+ commandPermissions = [commandPermissions];
89
+ }
90
+ const missingPermissions = [];
91
+ for (const permission of commandPermissions) {
92
+ const hasPermission = botMember.permissions.has(permission);
93
+ if (!hasPermission) {
94
+ missingPermissions.push(`\`${permission.toString()}\``);
96
95
  }
97
96
  }
97
+ if (missingPermissions.length) {
98
+ interaction.reply({
99
+ content: `\u274C I do not have enough permissions to execute this command. Missing: ${missingPermissions.join(
100
+ ", "
101
+ )}`,
102
+ ephemeral: true
103
+ });
104
+ return true;
105
+ }
98
106
  }
99
107
 
100
108
  // src/handlers/command-handler/validations/devOnly.ts
101
- function devOnly_default({
102
- interaction,
103
- targetCommand,
104
- handlerData
105
- }) {
109
+ function devOnly_default({ interaction, targetCommand, handlerData }) {
106
110
  if (targetCommand.options?.devOnly) {
107
111
  if (interaction.inGuild() && !handlerData.devGuildIds.includes(interaction.guildId)) {
108
112
  interaction.reply({
@@ -111,9 +115,7 @@ function devOnly_default({
111
115
  });
112
116
  return true;
113
117
  }
114
- const guildMember = interaction.guild?.members.cache.get(
115
- interaction.user.id
116
- );
118
+ const guildMember = interaction.guild?.members.cache.get(interaction.user.id);
117
119
  const memberRoles = guildMember?.roles.cache;
118
120
  let hasDevRole = false;
119
121
  memberRoles?.forEach((role) => {
@@ -133,10 +135,7 @@ function devOnly_default({
133
135
  }
134
136
 
135
137
  // src/handlers/command-handler/validations/guildOnly.ts
136
- function guildOnly_default({
137
- interaction,
138
- targetCommand
139
- }) {
138
+ function guildOnly_default({ interaction, targetCommand }) {
140
139
  if (targetCommand.options?.guildOnly && !interaction.inGuild()) {
141
140
  interaction.reply({
142
141
  content: "\u274C This command can only be used inside a server.",
@@ -147,23 +146,30 @@ function guildOnly_default({
147
146
  }
148
147
 
149
148
  // src/handlers/command-handler/validations/userPermissions.ts
150
- function userPermissions_default({
151
- interaction,
152
- targetCommand
153
- }) {
149
+ function userPermissions_default({ interaction, targetCommand }) {
154
150
  const memberPermissions = interaction.memberPermissions;
155
- if (targetCommand.options?.userPermissions && memberPermissions) {
156
- for (const permission of targetCommand.options.userPermissions) {
157
- const hasPermission = memberPermissions.has(permission);
158
- if (!hasPermission) {
159
- interaction.reply({
160
- content: `\u274C You do not have enough permission to run this command. Required permission: \`${permission}\``,
161
- ephemeral: true
162
- });
163
- return true;
164
- }
151
+ let commandPermissions = targetCommand.options?.userPermissions;
152
+ if (!memberPermissions || !commandPermissions)
153
+ return;
154
+ if (!Array.isArray(commandPermissions)) {
155
+ commandPermissions = [commandPermissions];
156
+ }
157
+ const missingPermissions = [];
158
+ for (const permission of commandPermissions) {
159
+ const hasPermission = memberPermissions.has(permission);
160
+ if (!hasPermission) {
161
+ missingPermissions.push(`\`${permission.toString()}\``);
165
162
  }
166
163
  }
164
+ if (missingPermissions.length) {
165
+ interaction.reply({
166
+ content: `\u274C You do not have enough permissions to run this command. Missing: ${missingPermissions.join(
167
+ ", "
168
+ )}`,
169
+ ephemeral: true
170
+ });
171
+ return true;
172
+ }
167
173
  }
168
174
 
169
175
  // src/handlers/command-handler/validations/index.ts
@@ -185,7 +191,7 @@ function areSlashCommandsDifferent(appCommand, localCommand) {
185
191
  }
186
192
 
187
193
  // src/handlers/command-handler/functions/registerCommands.ts
188
- var import_colors = require("colors");
194
+ var import_safe = __toESM(require("colors/safe"));
189
195
  async function registerCommands(commandHandler) {
190
196
  const client = commandHandler._data.client;
191
197
  const devGuildIds = commandHandler._data.devGuildIds;
@@ -195,7 +201,11 @@ async function registerCommands(commandHandler) {
195
201
  for (const devGuildId of devGuildIds) {
196
202
  const guild = client.guilds.cache.get(devGuildId);
197
203
  if (!guild) {
198
- console.log(`\u23E9 Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`.yellow);
204
+ console.log(
205
+ import_safe.default.yellow(
206
+ `\u23E9 Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`
207
+ )
208
+ );
199
209
  continue;
200
210
  }
201
211
  devGuilds.push(guild);
@@ -209,58 +219,92 @@ async function registerCommands(commandHandler) {
209
219
  devGuildCommands.push(guildCommands);
210
220
  }
211
221
  for (const command of commands) {
222
+ let commandData = command.data;
212
223
  if (command.options?.deleted) {
213
- const targetCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
224
+ const targetCommand = appCommands?.cache.find(
225
+ (cmd) => cmd.name === commandData.name
226
+ );
214
227
  if (!targetCommand) {
215
- console.log(`\u23E9 Ignoring: Command "${command.data.name}" is globally marked as deleted.`.yellow);
228
+ console.log(
229
+ import_safe.default.yellow(
230
+ `\u23E9 Ignoring: Command "${commandData.name}" is globally marked as deleted.`
231
+ )
232
+ );
216
233
  } else {
217
234
  targetCommand.delete().then(() => {
218
- console.log(`\u{1F6AE} Deleted command "${command.data.name}" globally.`.green);
235
+ console.log(
236
+ import_safe.default.green(`\u{1F6AE} Deleted command "${commandData.name}" globally.`)
237
+ );
219
238
  });
220
239
  }
221
240
  for (const guildCommands of devGuildCommands) {
222
- const targetCommand2 = guildCommands.cache.find((cmd) => cmd.name === command.data.name);
241
+ const targetCommand2 = guildCommands.cache.find(
242
+ (cmd) => cmd.name === commandData.name
243
+ );
223
244
  if (!targetCommand2) {
224
245
  console.log(
225
- `\u23E9 Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`.yellow
246
+ import_safe.default.yellow(
247
+ `\u23E9 Ignoring: Command "${commandData.name}" is marked as deleted for ${guildCommands.guild.name}.`
248
+ )
226
249
  );
227
250
  } else {
228
251
  targetCommand2.delete().then(() => {
229
252
  console.log(
230
- `\u{1F6AE} Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`.green
253
+ import_safe.default.green(
254
+ `\u{1F6AE} Deleted command "${commandData.name}" in ${guildCommands.guild.name}.`
255
+ )
231
256
  );
232
257
  });
233
258
  }
234
259
  }
235
260
  continue;
236
261
  }
237
- let commandData = command.data;
238
262
  let editedCommand = false;
239
- const appGlobalCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
263
+ const appGlobalCommand = appCommands?.cache.find(
264
+ (cmd) => cmd.name === commandData.name
265
+ );
240
266
  if (appGlobalCommand) {
241
- const commandsAreDifferent = areSlashCommandsDifferent(appGlobalCommand, commandData);
267
+ const commandsAreDifferent = areSlashCommandsDifferent(
268
+ appGlobalCommand,
269
+ commandData
270
+ );
242
271
  if (commandsAreDifferent) {
243
272
  appGlobalCommand.edit(commandData).then(() => {
244
- console.log(`\u2705 Edited command "${commandData.name}" globally.`.green);
273
+ console.log(
274
+ import_safe.default.green(`\u2705 Edited command "${commandData.name}" globally.`)
275
+ );
245
276
  }).catch((error) => {
246
- console.log(`\u274C Failed to edit command "${commandData.name}" globally.`.red);
277
+ console.log(
278
+ import_safe.default.red(
279
+ `\u274C Failed to edit command "${commandData.name}" globally.`
280
+ )
281
+ );
247
282
  console.error(error);
248
283
  });
249
284
  editedCommand = true;
250
285
  }
251
286
  }
252
287
  for (const guildCommands of devGuildCommands) {
253
- const appGuildCommand = guildCommands.cache.find((cmd) => cmd.name === commandData.name);
288
+ const appGuildCommand = guildCommands.cache.find(
289
+ (cmd) => cmd.name === commandData.name
290
+ );
254
291
  if (appGuildCommand) {
255
- const commandsAreDifferent = areSlashCommandsDifferent(appGuildCommand, commandData);
292
+ const commandsAreDifferent = areSlashCommandsDifferent(
293
+ appGuildCommand,
294
+ commandData
295
+ );
256
296
  if (commandsAreDifferent) {
257
297
  appGuildCommand.edit(commandData).then(() => {
258
298
  console.log(
259
- `\u2705 Edited command "${commandData.name}" in ${guildCommands.guild.name}.`.green
299
+ import_safe.default.green(
300
+ `\u2705 Edited command "${commandData.name}" in ${guildCommands.guild.name}.`
301
+ )
260
302
  );
261
303
  }).catch((error) => {
262
304
  console.log(
263
- `\u274C Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`.red
305
+ import_safe.default.red(
306
+ `\u274C Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`
307
+ )
264
308
  );
265
309
  console.error(error);
266
310
  });
@@ -273,29 +317,47 @@ async function registerCommands(commandHandler) {
273
317
  if (command.options?.devOnly) {
274
318
  if (!devGuilds.length) {
275
319
  console.log(
276
- `\u23E9 Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`.yellow
320
+ import_safe.default.yellow(
321
+ `\u23E9 Ignoring: Cannot register command "${commandData.name}" as no valid "devGuildIds" were provided.`
322
+ )
277
323
  );
278
324
  continue;
279
325
  }
280
326
  for (const guild of devGuilds) {
281
- const cmdExists = guild.commands.cache.some((cmd) => cmd.name === command.data.name);
327
+ const cmdExists = guild.commands.cache.some(
328
+ (cmd) => cmd.name === commandData.name
329
+ );
282
330
  if (cmdExists)
283
331
  continue;
284
- guild?.commands.create(command.data).then(() => {
285
- console.log(`\u2705 Registered command "${command.data.name}" in ${guild.name}.`.green);
332
+ guild?.commands.create(commandData).then(() => {
333
+ console.log(
334
+ import_safe.default.green(
335
+ `\u2705 Registered command "${commandData.name}" in ${guild.name}.`
336
+ )
337
+ );
286
338
  }).catch((error) => {
287
- console.log(`\u274C Failed to register command "${command.data.name}" in ${guild.name}.`.red);
339
+ console.log(
340
+ import_safe.default.red(
341
+ `\u274C Failed to register command "${commandData.name}" in ${guild.name}.`
342
+ )
343
+ );
288
344
  console.error(error);
289
345
  });
290
346
  }
291
347
  } else {
292
- const cmdExists = appCommands?.cache.some((cmd) => cmd.name === command.data.name);
348
+ const cmdExists = appCommands?.cache.some((cmd) => cmd.name === commandData.name);
293
349
  if (cmdExists)
294
350
  continue;
295
- appCommands?.create(command.data).then(() => {
296
- console.log(`\u2705 Registered command "${command.data.name}" globally.`.green);
351
+ appCommands?.create(commandData).then(() => {
352
+ console.log(
353
+ import_safe.default.green(`\u2705 Registered command "${commandData.name}" globally.`)
354
+ );
297
355
  }).catch((error) => {
298
- console.log(`\u274C Failed to register command "${command.data.name}" globally.`.red);
356
+ console.log(
357
+ import_safe.default.red(
358
+ `\u274C Failed to register command "${commandData.name}" globally.`
359
+ )
360
+ );
299
361
  console.error(error);
300
362
  });
301
363
  }
@@ -306,10 +368,13 @@ async function registerCommands(commandHandler) {
306
368
  // src/handlers/command-handler/functions/handleCommands.ts
307
369
  function handleCommands(commandHandler) {
308
370
  const client = commandHandler._data.client;
371
+ const handler = commandHandler._data.commandKitInstance;
309
372
  client.on("interactionCreate", async (interaction) => {
310
373
  if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
311
374
  return;
312
- const targetCommand = commandHandler._data.commands.find((cmd) => cmd.data.name === interaction.commandName);
375
+ const targetCommand = commandHandler._data.commands.find(
376
+ (cmd) => cmd.data.name === interaction.commandName
377
+ );
313
378
  if (!targetCommand)
314
379
  return;
315
380
  const { data, options, run, ...rest } = targetCommand;
@@ -323,7 +388,8 @@ function handleCommands(commandHandler) {
323
388
  const stopValidationLoop = await validationFunction({
324
389
  interaction,
325
390
  client,
326
- commandObj
391
+ commandObj,
392
+ handler
327
393
  });
328
394
  if (stopValidationLoop) {
329
395
  canRun = false;
@@ -347,12 +413,12 @@ function handleCommands(commandHandler) {
347
413
  }
348
414
  if (!canRun)
349
415
  return;
350
- targetCommand.run({ interaction, client });
416
+ targetCommand.run({ interaction, client, handler });
351
417
  });
352
418
  }
353
419
 
354
420
  // src/handlers/command-handler/CommandHandler.ts
355
- var import_colors2 = require("colors");
421
+ var import_safe2 = __toESM(require("colors/safe"));
356
422
  var CommandHandler = class {
357
423
  _data;
358
424
  constructor({ ...options }) {
@@ -379,11 +445,17 @@ var CommandHandler = class {
379
445
  if (commandObj.default)
380
446
  commandObj = commandObj.default;
381
447
  if (!commandObj.data) {
382
- console.log(`\u23E9 Ignoring: Command ${compactFilePath} does not export "data".`.yellow);
448
+ console.log(
449
+ import_safe2.default.yellow(
450
+ `\u23E9 Ignoring: Command ${compactFilePath} does not export "data".`
451
+ )
452
+ );
383
453
  continue;
384
454
  }
385
455
  if (!commandObj.run) {
386
- console.log(`\u23E9 Ignoring: Command ${compactFilePath} does not export "run".`.yellow);
456
+ console.log(
457
+ import_safe2.default.yellow(`\u23E9 Ignoring: Command ${compactFilePath} does not export "run".`)
458
+ );
387
459
  continue;
388
460
  }
389
461
  this._data.commands.push(commandObj);
@@ -406,7 +478,7 @@ var CommandHandler = class {
406
478
  };
407
479
 
408
480
  // src/handlers/event-handler/EventHandler.ts
409
- var import_colors3 = require("colors");
481
+ var import_safe3 = __toESM(require("colors/safe"));
410
482
  var EventHandler = class {
411
483
  #data;
412
484
  constructor({ ...options }) {
@@ -434,9 +506,16 @@ var EventHandler = class {
434
506
  for (const eventFilePath of eventFilePaths) {
435
507
  const modulePath = toFileURL(eventFilePath);
436
508
  let eventFunction = (await import(modulePath)).default;
509
+ if (eventFunction?.default) {
510
+ eventFunction = eventFunction.default;
511
+ }
437
512
  const compactFilePath = eventFilePath.split(process.cwd())[1] || eventFilePath;
438
513
  if (typeof eventFunction !== "function") {
439
- console.log(`\u23E9 Ignoring: Event ${compactFilePath} does not export a function.`.yellow);
514
+ console.log(
515
+ import_safe3.default.yellow(
516
+ `\u23E9 Ignoring: Event ${compactFilePath} does not export a function.`
517
+ )
518
+ );
440
519
  continue;
441
520
  }
442
521
  eventObj.functions.push(eventFunction);
@@ -445,10 +524,11 @@ var EventHandler = class {
445
524
  }
446
525
  #registerEvents() {
447
526
  const client = this.#data.client;
527
+ const handler = this.#data.commandKitInstance;
448
528
  for (const eventObj of this.#data.events) {
449
529
  client.on(eventObj.name, async (...params) => {
450
530
  for (const eventFunction of eventObj.functions) {
451
- const stopEventLoop = await eventFunction(...params, client);
531
+ const stopEventLoop = await eventFunction(...params, client, handler);
452
532
  if (stopEventLoop) {
453
533
  break;
454
534
  }
@@ -462,7 +542,7 @@ var EventHandler = class {
462
542
  };
463
543
 
464
544
  // src/handlers/validation-handler/ValidationHandler.ts
465
- var import_colors4 = require("colors");
545
+ var import_safe4 = __toESM(require("colors/safe"));
466
546
  var ValidationHandler = class {
467
547
  #data;
468
548
  constructor({ ...options }) {
@@ -481,9 +561,16 @@ var ValidationHandler = class {
481
561
  for (const validationFilePath of validationFilePaths) {
482
562
  const modulePath = toFileURL(validationFilePath);
483
563
  let validationFunction = (await import(modulePath)).default;
564
+ if (validationFunction?.default) {
565
+ validationFunction = validationFunction.default;
566
+ }
484
567
  const compactFilePath = validationFilePath.split(process.cwd())[1] || validationFilePath;
485
568
  if (typeof validationFunction !== "function") {
486
- console.log(`\u23E9 Ignoring: Validation ${compactFilePath} does not export a function.`.yellow);
569
+ console.log(
570
+ import_safe4.default.yellow(
571
+ `\u23E9 Ignoring: Validation ${compactFilePath} does not export a function.`
572
+ )
573
+ );
487
574
  continue;
488
575
  }
489
576
  this.#data.validations.push(validationFunction);
@@ -495,15 +582,17 @@ var ValidationHandler = class {
495
582
  };
496
583
 
497
584
  // src/CommandKit.ts
498
- var import_colors5 = require("colors");
585
+ var import_safe5 = __toESM(require("colors/safe"));
499
586
  var CommandKit = class {
500
587
  #data;
501
588
  constructor({ ...options }) {
502
589
  if (!options.client) {
503
- throw new Error('"client" is required when instantiating CommandKit.'.red);
590
+ throw new Error(import_safe5.default.red('"client" is required when instantiating CommandKit.'));
504
591
  }
505
592
  if (options.validationsPath && !options.commandsPath) {
506
- throw new Error('"commandsPath" is required when "validationsPath" is set.'.red);
593
+ throw new Error(
594
+ import_safe5.default.red('"commandsPath" is required when "validationsPath" is set.')
595
+ );
507
596
  }
508
597
  this.#data = {
509
598
  ...options,
@@ -515,7 +604,8 @@ var CommandKit = class {
515
604
  if (this.#data.eventsPath) {
516
605
  const eventHandler = new EventHandler({
517
606
  client: this.#data.client,
518
- eventsPath: this.#data.eventsPath
607
+ eventsPath: this.#data.eventsPath,
608
+ commandKitInstance: this
519
609
  });
520
610
  await eventHandler.init();
521
611
  }
@@ -535,20 +625,36 @@ var CommandKit = class {
535
625
  devUserIds: this.#data.devUserIds || [],
536
626
  devRoleIds: this.#data.devRoleIds || [],
537
627
  customValidations: validationFunctions,
538
- skipBuiltInValidations: this.#data.skipBuiltInValidations || false
628
+ skipBuiltInValidations: this.#data.skipBuiltInValidations || false,
629
+ commandKitInstance: this
539
630
  });
540
631
  await commandHandler.init();
541
632
  this.#data.commands = commandHandler.commands;
542
633
  }
543
634
  }
635
+ /**
636
+ * Returns all the commands that CommandKit is handling.
637
+ *
638
+ * @returns An array of command objects
639
+ */
544
640
  get commands() {
545
- return this.#data.commands.map((cmd) => {
641
+ const commands = this.#data.commands.map((cmd) => {
546
642
  const { run, ...command } = cmd;
547
643
  return command;
548
644
  });
645
+ return commands;
549
646
  }
550
647
  };
648
+
649
+ // src/types/index.ts
650
+ var CommandType = /* @__PURE__ */ ((CommandType2) => {
651
+ CommandType2[CommandType2["ChatInput"] = 1] = "ChatInput";
652
+ CommandType2[CommandType2["Message"] = 3] = "Message";
653
+ CommandType2[CommandType2["User"] = 2] = "User";
654
+ return CommandType2;
655
+ })(CommandType || {});
551
656
  // Annotate the CommonJS export names for ESM import in node:
552
657
  0 && (module.exports = {
553
- CommandKit
658
+ CommandKit,
659
+ CommandType
554
660
  });
package/dist/index.mjs CHANGED
@@ -42,31 +42,34 @@ function toFileURL(filePath) {
42
42
  }
43
43
 
44
44
  // src/handlers/command-handler/validations/botPermissions.ts
45
- function botPermissions_default({
46
- interaction,
47
- targetCommand
48
- }) {
45
+ function botPermissions_default({ interaction, targetCommand }) {
49
46
  const botMember = interaction.guild?.members.me;
50
- if (targetCommand.options?.botPermissions && botMember) {
51
- for (const permission of targetCommand.options.botPermissions) {
52
- const hasPermission = botMember.permissions.has(permission);
53
- if (!hasPermission) {
54
- interaction.reply({
55
- content: `\u274C I do not have enough permission to execute this command. Required permission: \`${permission}\``,
56
- ephemeral: true
57
- });
58
- return true;
59
- }
47
+ let commandPermissions = targetCommand.options?.botPermissions;
48
+ if (!botMember || !commandPermissions)
49
+ return;
50
+ if (!Array.isArray(commandPermissions)) {
51
+ commandPermissions = [commandPermissions];
52
+ }
53
+ const missingPermissions = [];
54
+ for (const permission of commandPermissions) {
55
+ const hasPermission = botMember.permissions.has(permission);
56
+ if (!hasPermission) {
57
+ missingPermissions.push(`\`${permission.toString()}\``);
60
58
  }
61
59
  }
60
+ if (missingPermissions.length) {
61
+ interaction.reply({
62
+ content: `\u274C I do not have enough permissions to execute this command. Missing: ${missingPermissions.join(
63
+ ", "
64
+ )}`,
65
+ ephemeral: true
66
+ });
67
+ return true;
68
+ }
62
69
  }
63
70
 
64
71
  // src/handlers/command-handler/validations/devOnly.ts
65
- function devOnly_default({
66
- interaction,
67
- targetCommand,
68
- handlerData
69
- }) {
72
+ function devOnly_default({ interaction, targetCommand, handlerData }) {
70
73
  if (targetCommand.options?.devOnly) {
71
74
  if (interaction.inGuild() && !handlerData.devGuildIds.includes(interaction.guildId)) {
72
75
  interaction.reply({
@@ -75,9 +78,7 @@ function devOnly_default({
75
78
  });
76
79
  return true;
77
80
  }
78
- const guildMember = interaction.guild?.members.cache.get(
79
- interaction.user.id
80
- );
81
+ const guildMember = interaction.guild?.members.cache.get(interaction.user.id);
81
82
  const memberRoles = guildMember?.roles.cache;
82
83
  let hasDevRole = false;
83
84
  memberRoles?.forEach((role) => {
@@ -97,10 +98,7 @@ function devOnly_default({
97
98
  }
98
99
 
99
100
  // src/handlers/command-handler/validations/guildOnly.ts
100
- function guildOnly_default({
101
- interaction,
102
- targetCommand
103
- }) {
101
+ function guildOnly_default({ interaction, targetCommand }) {
104
102
  if (targetCommand.options?.guildOnly && !interaction.inGuild()) {
105
103
  interaction.reply({
106
104
  content: "\u274C This command can only be used inside a server.",
@@ -111,23 +109,30 @@ function guildOnly_default({
111
109
  }
112
110
 
113
111
  // src/handlers/command-handler/validations/userPermissions.ts
114
- function userPermissions_default({
115
- interaction,
116
- targetCommand
117
- }) {
112
+ function userPermissions_default({ interaction, targetCommand }) {
118
113
  const memberPermissions = interaction.memberPermissions;
119
- if (targetCommand.options?.userPermissions && memberPermissions) {
120
- for (const permission of targetCommand.options.userPermissions) {
121
- const hasPermission = memberPermissions.has(permission);
122
- if (!hasPermission) {
123
- interaction.reply({
124
- content: `\u274C You do not have enough permission to run this command. Required permission: \`${permission}\``,
125
- ephemeral: true
126
- });
127
- return true;
128
- }
114
+ let commandPermissions = targetCommand.options?.userPermissions;
115
+ if (!memberPermissions || !commandPermissions)
116
+ return;
117
+ if (!Array.isArray(commandPermissions)) {
118
+ commandPermissions = [commandPermissions];
119
+ }
120
+ const missingPermissions = [];
121
+ for (const permission of commandPermissions) {
122
+ const hasPermission = memberPermissions.has(permission);
123
+ if (!hasPermission) {
124
+ missingPermissions.push(`\`${permission.toString()}\``);
129
125
  }
130
126
  }
127
+ if (missingPermissions.length) {
128
+ interaction.reply({
129
+ content: `\u274C You do not have enough permissions to run this command. Missing: ${missingPermissions.join(
130
+ ", "
131
+ )}`,
132
+ ephemeral: true
133
+ });
134
+ return true;
135
+ }
131
136
  }
132
137
 
133
138
  // src/handlers/command-handler/validations/index.ts
@@ -149,7 +154,7 @@ function areSlashCommandsDifferent(appCommand, localCommand) {
149
154
  }
150
155
 
151
156
  // src/handlers/command-handler/functions/registerCommands.ts
152
- import "colors";
157
+ import colors from "colors/safe";
153
158
  async function registerCommands(commandHandler) {
154
159
  const client = commandHandler._data.client;
155
160
  const devGuildIds = commandHandler._data.devGuildIds;
@@ -159,7 +164,11 @@ async function registerCommands(commandHandler) {
159
164
  for (const devGuildId of devGuildIds) {
160
165
  const guild = client.guilds.cache.get(devGuildId);
161
166
  if (!guild) {
162
- console.log(`\u23E9 Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`.yellow);
167
+ console.log(
168
+ colors.yellow(
169
+ `\u23E9 Ignoring: Guild ${devGuildId} does not exist or client isn't in this guild.`
170
+ )
171
+ );
163
172
  continue;
164
173
  }
165
174
  devGuilds.push(guild);
@@ -173,58 +182,92 @@ async function registerCommands(commandHandler) {
173
182
  devGuildCommands.push(guildCommands);
174
183
  }
175
184
  for (const command of commands) {
185
+ let commandData = command.data;
176
186
  if (command.options?.deleted) {
177
- const targetCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
187
+ const targetCommand = appCommands?.cache.find(
188
+ (cmd) => cmd.name === commandData.name
189
+ );
178
190
  if (!targetCommand) {
179
- console.log(`\u23E9 Ignoring: Command "${command.data.name}" is globally marked as deleted.`.yellow);
191
+ console.log(
192
+ colors.yellow(
193
+ `\u23E9 Ignoring: Command "${commandData.name}" is globally marked as deleted.`
194
+ )
195
+ );
180
196
  } else {
181
197
  targetCommand.delete().then(() => {
182
- console.log(`\u{1F6AE} Deleted command "${command.data.name}" globally.`.green);
198
+ console.log(
199
+ colors.green(`\u{1F6AE} Deleted command "${commandData.name}" globally.`)
200
+ );
183
201
  });
184
202
  }
185
203
  for (const guildCommands of devGuildCommands) {
186
- const targetCommand2 = guildCommands.cache.find((cmd) => cmd.name === command.data.name);
204
+ const targetCommand2 = guildCommands.cache.find(
205
+ (cmd) => cmd.name === commandData.name
206
+ );
187
207
  if (!targetCommand2) {
188
208
  console.log(
189
- `\u23E9 Ignoring: Command "${command.data.name}" is marked as deleted for ${guildCommands.guild.name}.`.yellow
209
+ colors.yellow(
210
+ `\u23E9 Ignoring: Command "${commandData.name}" is marked as deleted for ${guildCommands.guild.name}.`
211
+ )
190
212
  );
191
213
  } else {
192
214
  targetCommand2.delete().then(() => {
193
215
  console.log(
194
- `\u{1F6AE} Deleted command "${command.data.name}" in ${guildCommands.guild.name}.`.green
216
+ colors.green(
217
+ `\u{1F6AE} Deleted command "${commandData.name}" in ${guildCommands.guild.name}.`
218
+ )
195
219
  );
196
220
  });
197
221
  }
198
222
  }
199
223
  continue;
200
224
  }
201
- let commandData = command.data;
202
225
  let editedCommand = false;
203
- const appGlobalCommand = appCommands?.cache.find((cmd) => cmd.name === command.data.name);
226
+ const appGlobalCommand = appCommands?.cache.find(
227
+ (cmd) => cmd.name === commandData.name
228
+ );
204
229
  if (appGlobalCommand) {
205
- const commandsAreDifferent = areSlashCommandsDifferent(appGlobalCommand, commandData);
230
+ const commandsAreDifferent = areSlashCommandsDifferent(
231
+ appGlobalCommand,
232
+ commandData
233
+ );
206
234
  if (commandsAreDifferent) {
207
235
  appGlobalCommand.edit(commandData).then(() => {
208
- console.log(`\u2705 Edited command "${commandData.name}" globally.`.green);
236
+ console.log(
237
+ colors.green(`\u2705 Edited command "${commandData.name}" globally.`)
238
+ );
209
239
  }).catch((error) => {
210
- console.log(`\u274C Failed to edit command "${commandData.name}" globally.`.red);
240
+ console.log(
241
+ colors.red(
242
+ `\u274C Failed to edit command "${commandData.name}" globally.`
243
+ )
244
+ );
211
245
  console.error(error);
212
246
  });
213
247
  editedCommand = true;
214
248
  }
215
249
  }
216
250
  for (const guildCommands of devGuildCommands) {
217
- const appGuildCommand = guildCommands.cache.find((cmd) => cmd.name === commandData.name);
251
+ const appGuildCommand = guildCommands.cache.find(
252
+ (cmd) => cmd.name === commandData.name
253
+ );
218
254
  if (appGuildCommand) {
219
- const commandsAreDifferent = areSlashCommandsDifferent(appGuildCommand, commandData);
255
+ const commandsAreDifferent = areSlashCommandsDifferent(
256
+ appGuildCommand,
257
+ commandData
258
+ );
220
259
  if (commandsAreDifferent) {
221
260
  appGuildCommand.edit(commandData).then(() => {
222
261
  console.log(
223
- `\u2705 Edited command "${commandData.name}" in ${guildCommands.guild.name}.`.green
262
+ colors.green(
263
+ `\u2705 Edited command "${commandData.name}" in ${guildCommands.guild.name}.`
264
+ )
224
265
  );
225
266
  }).catch((error) => {
226
267
  console.log(
227
- `\u274C Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`.red
268
+ colors.red(
269
+ `\u274C Failed to edit command "${commandData.name}" in ${guildCommands.guild.name}.`
270
+ )
228
271
  );
229
272
  console.error(error);
230
273
  });
@@ -237,29 +280,47 @@ async function registerCommands(commandHandler) {
237
280
  if (command.options?.devOnly) {
238
281
  if (!devGuilds.length) {
239
282
  console.log(
240
- `\u23E9 Ignoring: Cannot register command "${command.data.name}" as no valid "devGuildIds" were provided.`.yellow
283
+ colors.yellow(
284
+ `\u23E9 Ignoring: Cannot register command "${commandData.name}" as no valid "devGuildIds" were provided.`
285
+ )
241
286
  );
242
287
  continue;
243
288
  }
244
289
  for (const guild of devGuilds) {
245
- const cmdExists = guild.commands.cache.some((cmd) => cmd.name === command.data.name);
290
+ const cmdExists = guild.commands.cache.some(
291
+ (cmd) => cmd.name === commandData.name
292
+ );
246
293
  if (cmdExists)
247
294
  continue;
248
- guild?.commands.create(command.data).then(() => {
249
- console.log(`\u2705 Registered command "${command.data.name}" in ${guild.name}.`.green);
295
+ guild?.commands.create(commandData).then(() => {
296
+ console.log(
297
+ colors.green(
298
+ `\u2705 Registered command "${commandData.name}" in ${guild.name}.`
299
+ )
300
+ );
250
301
  }).catch((error) => {
251
- console.log(`\u274C Failed to register command "${command.data.name}" in ${guild.name}.`.red);
302
+ console.log(
303
+ colors.red(
304
+ `\u274C Failed to register command "${commandData.name}" in ${guild.name}.`
305
+ )
306
+ );
252
307
  console.error(error);
253
308
  });
254
309
  }
255
310
  } else {
256
- const cmdExists = appCommands?.cache.some((cmd) => cmd.name === command.data.name);
311
+ const cmdExists = appCommands?.cache.some((cmd) => cmd.name === commandData.name);
257
312
  if (cmdExists)
258
313
  continue;
259
- appCommands?.create(command.data).then(() => {
260
- console.log(`\u2705 Registered command "${command.data.name}" globally.`.green);
314
+ appCommands?.create(commandData).then(() => {
315
+ console.log(
316
+ colors.green(`\u2705 Registered command "${commandData.name}" globally.`)
317
+ );
261
318
  }).catch((error) => {
262
- console.log(`\u274C Failed to register command "${command.data.name}" globally.`.red);
319
+ console.log(
320
+ colors.red(
321
+ `\u274C Failed to register command "${commandData.name}" globally.`
322
+ )
323
+ );
263
324
  console.error(error);
264
325
  });
265
326
  }
@@ -270,10 +331,13 @@ async function registerCommands(commandHandler) {
270
331
  // src/handlers/command-handler/functions/handleCommands.ts
271
332
  function handleCommands(commandHandler) {
272
333
  const client = commandHandler._data.client;
334
+ const handler = commandHandler._data.commandKitInstance;
273
335
  client.on("interactionCreate", async (interaction) => {
274
336
  if (!interaction.isChatInputCommand() && !interaction.isContextMenuCommand())
275
337
  return;
276
- const targetCommand = commandHandler._data.commands.find((cmd) => cmd.data.name === interaction.commandName);
338
+ const targetCommand = commandHandler._data.commands.find(
339
+ (cmd) => cmd.data.name === interaction.commandName
340
+ );
277
341
  if (!targetCommand)
278
342
  return;
279
343
  const { data, options, run, ...rest } = targetCommand;
@@ -287,7 +351,8 @@ function handleCommands(commandHandler) {
287
351
  const stopValidationLoop = await validationFunction({
288
352
  interaction,
289
353
  client,
290
- commandObj
354
+ commandObj,
355
+ handler
291
356
  });
292
357
  if (stopValidationLoop) {
293
358
  canRun = false;
@@ -311,12 +376,12 @@ function handleCommands(commandHandler) {
311
376
  }
312
377
  if (!canRun)
313
378
  return;
314
- targetCommand.run({ interaction, client });
379
+ targetCommand.run({ interaction, client, handler });
315
380
  });
316
381
  }
317
382
 
318
383
  // src/handlers/command-handler/CommandHandler.ts
319
- import "colors";
384
+ import colors2 from "colors/safe";
320
385
  var CommandHandler = class {
321
386
  _data;
322
387
  constructor({ ...options }) {
@@ -343,11 +408,17 @@ var CommandHandler = class {
343
408
  if (commandObj.default)
344
409
  commandObj = commandObj.default;
345
410
  if (!commandObj.data) {
346
- console.log(`\u23E9 Ignoring: Command ${compactFilePath} does not export "data".`.yellow);
411
+ console.log(
412
+ colors2.yellow(
413
+ `\u23E9 Ignoring: Command ${compactFilePath} does not export "data".`
414
+ )
415
+ );
347
416
  continue;
348
417
  }
349
418
  if (!commandObj.run) {
350
- console.log(`\u23E9 Ignoring: Command ${compactFilePath} does not export "run".`.yellow);
419
+ console.log(
420
+ colors2.yellow(`\u23E9 Ignoring: Command ${compactFilePath} does not export "run".`)
421
+ );
351
422
  continue;
352
423
  }
353
424
  this._data.commands.push(commandObj);
@@ -370,7 +441,7 @@ var CommandHandler = class {
370
441
  };
371
442
 
372
443
  // src/handlers/event-handler/EventHandler.ts
373
- import "colors";
444
+ import colors3 from "colors/safe";
374
445
  var EventHandler = class {
375
446
  #data;
376
447
  constructor({ ...options }) {
@@ -398,9 +469,16 @@ var EventHandler = class {
398
469
  for (const eventFilePath of eventFilePaths) {
399
470
  const modulePath = toFileURL(eventFilePath);
400
471
  let eventFunction = (await import(modulePath)).default;
472
+ if (eventFunction?.default) {
473
+ eventFunction = eventFunction.default;
474
+ }
401
475
  const compactFilePath = eventFilePath.split(process.cwd())[1] || eventFilePath;
402
476
  if (typeof eventFunction !== "function") {
403
- console.log(`\u23E9 Ignoring: Event ${compactFilePath} does not export a function.`.yellow);
477
+ console.log(
478
+ colors3.yellow(
479
+ `\u23E9 Ignoring: Event ${compactFilePath} does not export a function.`
480
+ )
481
+ );
404
482
  continue;
405
483
  }
406
484
  eventObj.functions.push(eventFunction);
@@ -409,10 +487,11 @@ var EventHandler = class {
409
487
  }
410
488
  #registerEvents() {
411
489
  const client = this.#data.client;
490
+ const handler = this.#data.commandKitInstance;
412
491
  for (const eventObj of this.#data.events) {
413
492
  client.on(eventObj.name, async (...params) => {
414
493
  for (const eventFunction of eventObj.functions) {
415
- const stopEventLoop = await eventFunction(...params, client);
494
+ const stopEventLoop = await eventFunction(...params, client, handler);
416
495
  if (stopEventLoop) {
417
496
  break;
418
497
  }
@@ -426,7 +505,7 @@ var EventHandler = class {
426
505
  };
427
506
 
428
507
  // src/handlers/validation-handler/ValidationHandler.ts
429
- import "colors";
508
+ import colors4 from "colors/safe";
430
509
  var ValidationHandler = class {
431
510
  #data;
432
511
  constructor({ ...options }) {
@@ -445,9 +524,16 @@ var ValidationHandler = class {
445
524
  for (const validationFilePath of validationFilePaths) {
446
525
  const modulePath = toFileURL(validationFilePath);
447
526
  let validationFunction = (await import(modulePath)).default;
527
+ if (validationFunction?.default) {
528
+ validationFunction = validationFunction.default;
529
+ }
448
530
  const compactFilePath = validationFilePath.split(process.cwd())[1] || validationFilePath;
449
531
  if (typeof validationFunction !== "function") {
450
- console.log(`\u23E9 Ignoring: Validation ${compactFilePath} does not export a function.`.yellow);
532
+ console.log(
533
+ colors4.yellow(
534
+ `\u23E9 Ignoring: Validation ${compactFilePath} does not export a function.`
535
+ )
536
+ );
451
537
  continue;
452
538
  }
453
539
  this.#data.validations.push(validationFunction);
@@ -459,15 +545,17 @@ var ValidationHandler = class {
459
545
  };
460
546
 
461
547
  // src/CommandKit.ts
462
- import "colors";
548
+ import colors5 from "colors/safe";
463
549
  var CommandKit = class {
464
550
  #data;
465
551
  constructor({ ...options }) {
466
552
  if (!options.client) {
467
- throw new Error('"client" is required when instantiating CommandKit.'.red);
553
+ throw new Error(colors5.red('"client" is required when instantiating CommandKit.'));
468
554
  }
469
555
  if (options.validationsPath && !options.commandsPath) {
470
- throw new Error('"commandsPath" is required when "validationsPath" is set.'.red);
556
+ throw new Error(
557
+ colors5.red('"commandsPath" is required when "validationsPath" is set.')
558
+ );
471
559
  }
472
560
  this.#data = {
473
561
  ...options,
@@ -479,7 +567,8 @@ var CommandKit = class {
479
567
  if (this.#data.eventsPath) {
480
568
  const eventHandler = new EventHandler({
481
569
  client: this.#data.client,
482
- eventsPath: this.#data.eventsPath
570
+ eventsPath: this.#data.eventsPath,
571
+ commandKitInstance: this
483
572
  });
484
573
  await eventHandler.init();
485
574
  }
@@ -499,19 +588,35 @@ var CommandKit = class {
499
588
  devUserIds: this.#data.devUserIds || [],
500
589
  devRoleIds: this.#data.devRoleIds || [],
501
590
  customValidations: validationFunctions,
502
- skipBuiltInValidations: this.#data.skipBuiltInValidations || false
591
+ skipBuiltInValidations: this.#data.skipBuiltInValidations || false,
592
+ commandKitInstance: this
503
593
  });
504
594
  await commandHandler.init();
505
595
  this.#data.commands = commandHandler.commands;
506
596
  }
507
597
  }
598
+ /**
599
+ * Returns all the commands that CommandKit is handling.
600
+ *
601
+ * @returns An array of command objects
602
+ */
508
603
  get commands() {
509
- return this.#data.commands.map((cmd) => {
604
+ const commands = this.#data.commands.map((cmd) => {
510
605
  const { run, ...command } = cmd;
511
606
  return command;
512
607
  });
608
+ return commands;
513
609
  }
514
610
  };
611
+
612
+ // src/types/index.ts
613
+ var CommandType = /* @__PURE__ */ ((CommandType2) => {
614
+ CommandType2[CommandType2["ChatInput"] = 1] = "ChatInput";
615
+ CommandType2[CommandType2["Message"] = 3] = "Message";
616
+ CommandType2[CommandType2["User"] = 2] = "User";
617
+ return CommandType2;
618
+ })(CommandType || {});
515
619
  export {
516
- CommandKit
620
+ CommandKit,
621
+ CommandType
517
622
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commandkit",
3
- "version": "0.0.10",
3
+ "version": "0.1.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -14,7 +14,10 @@
14
14
  },
15
15
  "scripts": {
16
16
  "lint": "tsc",
17
- "build": "yarn lint && tsup"
17
+ "dev": "tsup --watch",
18
+ "build": "tsup",
19
+ "deploy": "npm publish",
20
+ "test": "tsx tests/index.ts"
18
21
  },
19
22
  "repository": {
20
23
  "type": "git",
@@ -31,8 +34,12 @@
31
34
  "colors": "^1.4.0"
32
35
  },
33
36
  "devDependencies": {
34
- "discord.js": "^14.12.1",
37
+ "@types/node": "^20.5.9",
38
+ "discord.js": "^14.13.0",
39
+ "dotenv": "^16.3.1",
40
+ "tsconfig": "workspace:*",
35
41
  "tsup": "^7.2.0",
42
+ "tsx": "^3.12.8",
36
43
  "typescript": "^5.1.6"
37
44
  },
38
45
  "peerDependencies": {