@hyperneutrino/djs-lite 1.4.5 → 1.4.7
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 +18 -15
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -140,14 +140,14 @@ async function loadSubcommands(directory: string): Promise<{
|
|
|
140
140
|
const options: ApplicationCommandSubCommandData[] = [];
|
|
141
141
|
const handlers = new Map<string, Handler<ChatInputCommandInteraction>>();
|
|
142
142
|
|
|
143
|
-
await importAll({ directory, recursive: false }, async ({ file,
|
|
143
|
+
await importAll({ directory, recursive: false }, async ({ file, absolutePath, item }) => {
|
|
144
144
|
if (item instanceof Subcommand) {
|
|
145
145
|
options.push({ ...item.data, type: ApplicationCommandOptionType.Subcommand });
|
|
146
146
|
handlers.set(item.data.name, item.handler);
|
|
147
|
-
} else throw new Error(`Loading commands failed: export from ${
|
|
147
|
+
} else throw new Error(`Loading commands failed: export from ${absolutePath} (third-level in commands folder) was not an instance of Subcommand.`);
|
|
148
148
|
|
|
149
149
|
if (item.data.name !== file.name.replace(/.[^/.]+$/, ""))
|
|
150
|
-
throw new Error(`Code style enforcement: name exported from ${
|
|
150
|
+
throw new Error(`Code style enforcement: name exported from ${absolutePath} does not match the filename`);
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
return { options, handlers };
|
|
@@ -162,7 +162,7 @@ async function loadSubcommandsAndGroups(directory: string): Promise<{
|
|
|
162
162
|
const options: (ApplicationCommandSubGroupData | ApplicationCommandSubCommandData)[] = [];
|
|
163
163
|
const handlers = new Map<string, Handler<ChatInputCommandInteraction>>();
|
|
164
164
|
|
|
165
|
-
await importAll({ directory, recursive: false }, async ({ file, relativePath, item }) => {
|
|
165
|
+
await importAll({ directory, recursive: false }, async ({ file, absolutePath, relativePath, item }) => {
|
|
166
166
|
if (item instanceof Subcommand) {
|
|
167
167
|
options.push({ ...item.data, type: ApplicationCommandOptionType.Subcommand });
|
|
168
168
|
handlers.set(`/${item.data.name}`, item.handler);
|
|
@@ -172,11 +172,11 @@ async function loadSubcommandsAndGroups(directory: string): Promise<{
|
|
|
172
172
|
subcommands.handlers.entries().forEach(([key, handler]) => handlers.set(`${item.data.name}/${key}`, handler));
|
|
173
173
|
} else
|
|
174
174
|
throw new Error(
|
|
175
|
-
`Loading commands failed: export from ${
|
|
175
|
+
`Loading commands failed: export from ${absolutePath} (second-level in commands folder) was not an instance of SubcommandGroup or Subcommand.`,
|
|
176
176
|
);
|
|
177
177
|
|
|
178
178
|
if (item.data.name !== file.name.replace(/.[^/.]+$/, ""))
|
|
179
|
-
throw new Error(`Code style enforcement: name exported from ${
|
|
179
|
+
throw new Error(`Code style enforcement: name exported from ${absolutePath} does not match the filename`);
|
|
180
180
|
});
|
|
181
181
|
|
|
182
182
|
return {
|
|
@@ -194,7 +194,7 @@ export async function loadCommands(client: Client<true>, directory: string, opti
|
|
|
194
194
|
|
|
195
195
|
const slashCommandAutocompletes = new Map<string, Handler<AutocompleteInteraction>>();
|
|
196
196
|
|
|
197
|
-
await importAll({ directory, recursive: false }, async ({ file, relativePath, item }) => {
|
|
197
|
+
await importAll({ directory, recursive: false }, async ({ file, absolutePath, relativePath, item }) => {
|
|
198
198
|
if (item instanceof SlashCommand) {
|
|
199
199
|
commandData.push({ ...item.data, type: ApplicationCommandType.ChatInput });
|
|
200
200
|
slashCommandHandlers.set(item.data.name, item.handler);
|
|
@@ -210,11 +210,11 @@ export async function loadCommands(client: Client<true>, directory: string, opti
|
|
|
210
210
|
commandData.push({ ...item.data, options });
|
|
211
211
|
slashCommandHandlers.set(item.data.name, handler);
|
|
212
212
|
} else {
|
|
213
|
-
throw new Error(`Loading commands failed: export from ${
|
|
213
|
+
throw new Error(`Loading commands failed: export from ${absolutePath} was not an instance of <Type>Command.`);
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
if (item.data.name !== file.name.replace(/.[^/.]+$/, ""))
|
|
217
|
-
throw new Error(`Code style enforcement: name exported from ${
|
|
217
|
+
throw new Error(`Code style enforcement: name exported from ${absolutePath} does not match the filename`);
|
|
218
218
|
});
|
|
219
219
|
|
|
220
220
|
client.on(Events.InteractionCreate, (interaction) => {
|
|
@@ -248,8 +248,11 @@ export async function loadInteractions(client: Client, directory: string, argume
|
|
|
248
248
|
const mentionSelectHandlers = new Map<string, Handler<MentionableSelectMenuInteraction>>();
|
|
249
249
|
const channelSelectHandlers = new Map<string, Handler<ChannelSelectMenuInteraction>>();
|
|
250
250
|
|
|
251
|
-
await importAll({ directory, recursive: true }, async ({
|
|
252
|
-
const handlerKey =
|
|
251
|
+
await importAll({ directory, recursive: true }, async ({ absolutePath, item }) => {
|
|
252
|
+
const handlerKey = path
|
|
253
|
+
.relative(path.resolve(directory), absolutePath)
|
|
254
|
+
.replace(/\.[^/.]+$/, "")
|
|
255
|
+
.replace(/\\/g, "/");
|
|
253
256
|
|
|
254
257
|
if (item instanceof ModalHandler) modalHandlers.set(handlerKey, item.handler);
|
|
255
258
|
else if (item instanceof ButtonHandler) buttonHandlers.set(handlerKey, item.handler);
|
|
@@ -258,7 +261,7 @@ export async function loadInteractions(client: Client, directory: string, argume
|
|
|
258
261
|
else if (item instanceof RoleSelectHandler) roleSelectHandlers.set(handlerKey, item.handler);
|
|
259
262
|
else if (item instanceof MentionSelectHandler) mentionSelectHandlers.set(handlerKey, item.handler);
|
|
260
263
|
else if (item instanceof ChannelSelectHandler) channelSelectHandlers.set(handlerKey, item.handler);
|
|
261
|
-
else throw new Error(`Loading interactions failed: export from ${
|
|
264
|
+
else throw new Error(`Loading interactions failed: export from ${absolutePath} was not an instance of <InteractionType>Handler.`);
|
|
262
265
|
});
|
|
263
266
|
|
|
264
267
|
client.on(Events.InteractionCreate, (interaction) => {
|
|
@@ -283,12 +286,12 @@ export async function loadEvents(client: Client, directory: string, recursive: b
|
|
|
283
286
|
const handlers: Partial<{ [K in keyof ClientEvents]: ((...args: ClientEvents[K]) => unknown)[] }> = {};
|
|
284
287
|
const filenames: Partial<{ [K in keyof ClientEvents]: string[] }> = {};
|
|
285
288
|
|
|
286
|
-
await importAll({ directory, recursive }, async ({
|
|
289
|
+
await importAll({ directory, recursive }, async ({ absolutePath, item }) => {
|
|
287
290
|
if (item instanceof EventHandler) {
|
|
288
291
|
(handlers[item.event as keyof ClientEvents] ??= []).push(item.handler);
|
|
289
|
-
(filenames[item.event as keyof ClientEvents] ??= []).push(path.relative(directory,
|
|
292
|
+
(filenames[item.event as keyof ClientEvents] ??= []).push(path.relative(path.resolve(directory), absolutePath));
|
|
290
293
|
} else {
|
|
291
|
-
throw new Error(`Loading events failed: export from ${
|
|
294
|
+
throw new Error(`Loading events failed: export from ${absolutePath} was not an instance of EventHandler<T>.`);
|
|
292
295
|
}
|
|
293
296
|
});
|
|
294
297
|
|