@hyperneutrino/djs-lite 1.3.0 → 1.4.0

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 (2) hide show
  1. package/index.ts +13 -11
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ ApplicationCommandOptionType,
2
3
  ApplicationCommandType,
3
4
  AutocompleteInteraction,
4
5
  ButtonInteraction,
@@ -56,12 +57,12 @@ abstract class Command<T extends BaseApplicationCommandData, U extends CommandIn
56
57
  }
57
58
  }
58
59
 
59
- export class SlashCommand extends Command<ChatInputApplicationCommandData & { type: ApplicationCommandType.ChatInput }, ChatInputCommandInteraction, true> {}
60
- export class UserCommand extends Command<UserApplicationCommandData, UserContextMenuCommandInteraction> {}
61
- export class MessageCommand extends Command<MessageApplicationCommandData, MessageContextMenuCommandInteraction> {}
60
+ export class SlashCommand extends Command<Omit<ChatInputApplicationCommandData, "type">, ChatInputCommandInteraction, true> {}
61
+ export class UserCommand extends Command<Omit<UserApplicationCommandData, "type">, UserContextMenuCommandInteraction> {}
62
+ export class MessageCommand extends Command<Omit<MessageApplicationCommandData, "type">, MessageContextMenuCommandInteraction> {}
62
63
 
63
64
  export class SlashCommandWithSubcommands {
64
- data: Omit<ChatInputApplicationCommandData, "options"> & { type: ApplicationCommandType.ChatInput };
65
+ data: Omit<ChatInputApplicationCommandData, "options" | "type">;
65
66
 
66
67
  constructor(data: typeof this.data) {
67
68
  this.data = data;
@@ -69,7 +70,7 @@ export class SlashCommandWithSubcommands {
69
70
  }
70
71
 
71
72
  export class SubcommandGroup {
72
- data: Omit<ApplicationCommandSubGroupData, "options">;
73
+ data: Omit<ApplicationCommandSubGroupData, "options" | "type">;
73
74
 
74
75
  constructor(data: typeof this.data) {
75
76
  this.data = data;
@@ -77,7 +78,7 @@ export class SubcommandGroup {
77
78
  }
78
79
 
79
80
  export class Subcommand {
80
- data: ApplicationCommandSubCommandData;
81
+ data: Omit<ApplicationCommandSubCommandData, "type">;
81
82
  handler: Handler<ChatInputCommandInteraction>;
82
83
 
83
84
  constructor({ handler, ...data }: typeof this.data & { handler: Subcommand["handler"] }) {
@@ -143,7 +144,7 @@ export async function loadSubcommands(directory: string): Promise<{
143
144
 
144
145
  await importAll({ directory, recursive: false }, async ({ file, relativePath, item }) => {
145
146
  if (item instanceof Subcommand) {
146
- options.push(item.data);
147
+ options.push({ ...item.data, type: ApplicationCommandOptionType.Subcommand });
147
148
  handlers.set(item.data.name, item.handler);
148
149
  } else throw new Error(`Loading commands failed: export from ${relativePath} (third-level in commands folder) was not an instance of Subcommand.`);
149
150
 
@@ -165,11 +166,11 @@ export async function loadSubcommandsAndGroups(directory: string): Promise<{
165
166
 
166
167
  await importAll({ directory, recursive: false }, async ({ file, relativePath, item }) => {
167
168
  if (item instanceof Subcommand) {
168
- options.push(item.data);
169
+ options.push({ ...item.data, type: ApplicationCommandOptionType.Subcommand });
169
170
  handlers.set(`/${item.data.name}`, item.handler);
170
171
  } else if (item instanceof SubcommandGroup) {
171
172
  const subcommands = await loadSubcommands(relativePath.replace(/\.[^/.]+$/, ""));
172
- options.push({ ...item.data, options: subcommands.options });
173
+ options.push({ ...item.data, type: ApplicationCommandOptionType.SubcommandGroup, options: subcommands.options });
173
174
  subcommands.handlers.entries().forEach(([key, handler]) => handlers.set(`${item.data.name}/${key}`, handler));
174
175
  } else
175
176
  throw new Error(
@@ -207,11 +208,14 @@ export async function loadCommands(client: Client<true>, directory: string, guil
207
208
  const { default: item } = await import(absolutePath);
208
209
 
209
210
  if (item instanceof SlashCommand) {
211
+ commandData.push({ ...item.data, type: ApplicationCommandType.ChatInput });
210
212
  slashCommandHandlers.set(item.data.name, item.handler);
211
213
  if (item.autocomplete) slashCommandAutocompletes.set(item.data.name, item.autocomplete);
212
214
  } else if (item instanceof UserCommand) {
215
+ commandData.push({ ...item.data, type: ApplicationCommandType.User });
213
216
  userCommandHandlers.set(item.data.name, item.handler);
214
217
  } else if (item instanceof MessageCommand) {
218
+ commandData.push({ ...item.data, type: ApplicationCommandType.Message });
215
219
  messageCommandHandlers.set(item.data.name, item.handler);
216
220
  } else if (item instanceof SlashCommandWithSubcommands) {
217
221
  const { options, handler } = await loadSubcommandsAndGroups(relativePath.replace(/\.[^/.]+$/, ""));
@@ -223,8 +227,6 @@ export async function loadCommands(client: Client<true>, directory: string, guil
223
227
 
224
228
  if (item.data.name !== file.name.replace(/.[^/.]+$/, ""))
225
229
  throw new Error(`Code style enforcement: name exported from ${relativePath} does not match the filename`);
226
-
227
- commandData.push(item.data);
228
230
  }),
229
231
  );
230
232
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hyperneutrino/djs-lite",
3
3
  "private": false,
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "module": "index.ts",
6
6
  "type": "module",
7
7
  "devDependencies": {