@hyperneutrino/djs-lite 1.4.1 → 1.4.3

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 +24 -20
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -29,8 +29,6 @@ import type { Dirent } from "node:fs";
29
29
  import fs from "node:fs/promises";
30
30
  import path from "node:path";
31
31
 
32
- // TODO: comments (requires some refactoring of types to do right)
33
-
34
32
  process.on("uncaughtException", (err) => console.error(err));
35
33
 
36
34
  type Handler<T extends CommandInteraction | AutocompleteInteraction | MessageComponentInteraction | ModalSubmitInteraction> = (
@@ -133,7 +131,7 @@ async function importAll(
133
131
  );
134
132
  }
135
133
 
136
- export async function loadSubcommands(directory: string): Promise<{
134
+ async function loadSubcommands(directory: string): Promise<{
137
135
  options: ApplicationCommandSubCommandData[];
138
136
  handlers: Map<string, Handler<ChatInputCommandInteraction>>;
139
137
  }> {
@@ -155,7 +153,7 @@ export async function loadSubcommands(directory: string): Promise<{
155
153
  return { options, handlers };
156
154
  }
157
155
 
158
- export async function loadSubcommandsAndGroups(directory: string): Promise<{
156
+ async function loadSubcommandsAndGroups(directory: string): Promise<{
159
157
  options: (ApplicationCommandSubGroupData | ApplicationCommandSubCommandData)[];
160
158
  handler: Handler<ChatInputCommandInteraction>;
161
159
  }> {
@@ -234,27 +232,29 @@ export async function loadCommands(client: Client<true>, directory: string, guil
234
232
  } else {
235
233
  await client.application.commands.set(commandData);
236
234
  }
235
+
236
+ return { commands: commandData, slashCommandHandlers, userCommandHandlers, messageCommandHandlers };
237
237
  }
238
238
 
239
239
  export async function loadInteractions(client: Client, directory: string, argumentSeparator: string = ":") {
240
240
  const modalHandlers = new Map<string, Handler<ModalSubmitInteraction>>();
241
241
  const buttonHandlers = new Map<string, Handler<ButtonInteraction>>();
242
- const stringHandlers = new Map<string, Handler<StringSelectMenuInteraction>>();
243
- const userHandlers = new Map<string, Handler<UserSelectMenuInteraction>>();
244
- const roleHandlers = new Map<string, Handler<RoleSelectMenuInteraction>>();
245
- const mentionHandlers = new Map<string, Handler<MentionableSelectMenuInteraction>>();
246
- const channelHandlers = new Map<string, Handler<ChannelSelectMenuInteraction>>();
242
+ const stringSelectHandlers = new Map<string, Handler<StringSelectMenuInteraction>>();
243
+ const userSelectHandlers = new Map<string, Handler<UserSelectMenuInteraction>>();
244
+ const roleSelectHandlers = new Map<string, Handler<RoleSelectMenuInteraction>>();
245
+ const mentionSelectHandlers = new Map<string, Handler<MentionableSelectMenuInteraction>>();
246
+ const channelSelectHandlers = new Map<string, Handler<ChannelSelectMenuInteraction>>();
247
247
 
248
- await importAll({ directory, recursive: true }, async ({ file, relativePath, item }) => {
248
+ await importAll({ directory, recursive: true }, async ({ relativePath, item }) => {
249
249
  const handlerKey = relativePath.replace(/\.[^/.]+$/, "").replace(/\\/g, "/");
250
250
 
251
251
  if (item instanceof ModalHandler) modalHandlers.set(handlerKey, item.handler);
252
252
  else if (item instanceof ButtonHandler) buttonHandlers.set(handlerKey, item.handler);
253
- else if (item instanceof StringSelectHandler) stringHandlers.set(handlerKey, item.handler);
254
- else if (item instanceof UserSelectHandler) userHandlers.set(handlerKey, item.handler);
255
- else if (item instanceof RoleSelectHandler) roleHandlers.set(handlerKey, item.handler);
256
- else if (item instanceof MentionSelectHandler) mentionHandlers.set(handlerKey, item.handler);
257
- else if (item instanceof ChannelSelectHandler) channelHandlers.set(handlerKey, item.handler);
253
+ else if (item instanceof StringSelectHandler) stringSelectHandlers.set(handlerKey, item.handler);
254
+ else if (item instanceof UserSelectHandler) userSelectHandlers.set(handlerKey, item.handler);
255
+ else if (item instanceof RoleSelectHandler) roleSelectHandlers.set(handlerKey, item.handler);
256
+ else if (item instanceof MentionSelectHandler) mentionSelectHandlers.set(handlerKey, item.handler);
257
+ else if (item instanceof ChannelSelectHandler) channelSelectHandlers.set(handlerKey, item.handler);
258
258
  else throw new Error(`Loading interactions failed: export from ${relativePath} was not an instance of <InteractionType>Handler.`);
259
259
  });
260
260
 
@@ -266,12 +266,14 @@ export async function loadInteractions(client: Client, directory: string, argume
266
266
 
267
267
  if (interaction.isModalSubmit()) modalHandlers.get(path)?.(interaction, ...args);
268
268
  else if (interaction.isButton()) buttonHandlers.get(path)?.(interaction, ...args);
269
- else if (interaction.isStringSelectMenu()) stringHandlers.get(path)?.(interaction, ...args);
270
- else if (interaction.isUserSelectMenu()) userHandlers.get(path)?.(interaction, ...args);
271
- else if (interaction.isRoleSelectMenu()) roleHandlers.get(path)?.(interaction, ...args);
272
- else if (interaction.isMentionableSelectMenu()) mentionHandlers.get(path)?.(interaction, ...args);
273
- else if (interaction.isChannelSelectMenu()) channelHandlers.get(path)?.(interaction, ...args);
269
+ else if (interaction.isStringSelectMenu()) stringSelectHandlers.get(path)?.(interaction, ...args);
270
+ else if (interaction.isUserSelectMenu()) userSelectHandlers.get(path)?.(interaction, ...args);
271
+ else if (interaction.isRoleSelectMenu()) roleSelectHandlers.get(path)?.(interaction, ...args);
272
+ else if (interaction.isMentionableSelectMenu()) mentionSelectHandlers.get(path)?.(interaction, ...args);
273
+ else if (interaction.isChannelSelectMenu()) channelSelectHandlers.get(path)?.(interaction, ...args);
274
274
  });
275
+
276
+ return { modalHandlers, buttonHandlers, stringSelectHandlers, userSelectHandlers, roleSelectHandlers, mentionSelectHandlers, channelSelectHandlers };
275
277
  }
276
278
 
277
279
  export async function loadEvents(client: Client, directory: string, recursive: boolean = false) {
@@ -285,4 +287,6 @@ export async function loadEvents(client: Client, directory: string, recursive: b
285
287
  });
286
288
 
287
289
  Object.entries(handlers).forEach(([key, handlers]) => client.on(key, (...args) => handlers.forEach((handler) => (handler as any)(...args))));
290
+
291
+ return { handlers };
288
292
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hyperneutrino/djs-lite",
3
3
  "private": false,
4
- "version": "1.4.1",
4
+ "version": "1.4.3",
5
5
  "module": "index.ts",
6
6
  "type": "module",
7
7
  "devDependencies": {