@hyperneutrino/djs-lite 1.4.6 → 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 +15 -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,9 +248,9 @@ 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 ({
|
|
251
|
+
await importAll({ directory, recursive: true }, async ({ absolutePath, item }) => {
|
|
252
252
|
const handlerKey = path
|
|
253
|
-
.relative(directory,
|
|
253
|
+
.relative(path.resolve(directory), absolutePath)
|
|
254
254
|
.replace(/\.[^/.]+$/, "")
|
|
255
255
|
.replace(/\\/g, "/");
|
|
256
256
|
|
|
@@ -261,7 +261,7 @@ export async function loadInteractions(client: Client, directory: string, argume
|
|
|
261
261
|
else if (item instanceof RoleSelectHandler) roleSelectHandlers.set(handlerKey, item.handler);
|
|
262
262
|
else if (item instanceof MentionSelectHandler) mentionSelectHandlers.set(handlerKey, item.handler);
|
|
263
263
|
else if (item instanceof ChannelSelectHandler) channelSelectHandlers.set(handlerKey, item.handler);
|
|
264
|
-
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.`);
|
|
265
265
|
});
|
|
266
266
|
|
|
267
267
|
client.on(Events.InteractionCreate, (interaction) => {
|
|
@@ -286,12 +286,12 @@ export async function loadEvents(client: Client, directory: string, recursive: b
|
|
|
286
286
|
const handlers: Partial<{ [K in keyof ClientEvents]: ((...args: ClientEvents[K]) => unknown)[] }> = {};
|
|
287
287
|
const filenames: Partial<{ [K in keyof ClientEvents]: string[] }> = {};
|
|
288
288
|
|
|
289
|
-
await importAll({ directory, recursive }, async ({
|
|
289
|
+
await importAll({ directory, recursive }, async ({ absolutePath, item }) => {
|
|
290
290
|
if (item instanceof EventHandler) {
|
|
291
291
|
(handlers[item.event as keyof ClientEvents] ??= []).push(item.handler);
|
|
292
|
-
(filenames[item.event as keyof ClientEvents] ??= []).push(path.relative(directory,
|
|
292
|
+
(filenames[item.event as keyof ClientEvents] ??= []).push(path.relative(path.resolve(directory), absolutePath));
|
|
293
293
|
} else {
|
|
294
|
-
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>.`);
|
|
295
295
|
}
|
|
296
296
|
});
|
|
297
297
|
|