@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.
- package/index.ts +24 -20
- 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
|
-
|
|
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
|
-
|
|
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
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
const
|
|
246
|
-
const
|
|
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 ({
|
|
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)
|
|
254
|
-
else if (item instanceof UserSelectHandler)
|
|
255
|
-
else if (item instanceof RoleSelectHandler)
|
|
256
|
-
else if (item instanceof MentionSelectHandler)
|
|
257
|
-
else if (item instanceof ChannelSelectHandler)
|
|
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())
|
|
270
|
-
else if (interaction.isUserSelectMenu())
|
|
271
|
-
else if (interaction.isRoleSelectMenu())
|
|
272
|
-
else if (interaction.isMentionableSelectMenu())
|
|
273
|
-
else if (interaction.isChannelSelectMenu())
|
|
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
|
}
|