@guardbot/framework 1.1.1 → 1.1.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/build/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { Client, PermissionResolvable, InteractionContextType, ApplicationIntegrationType, LocalizationMap, ApplicationCommandOptionData, ChatInputCommandInteraction, AutocompleteInteraction, Message, ContextMenuCommandInteraction, CommandInteraction, PermissionsString, Interaction, Collection, ClientEvents, ModalSubmitInteraction, ClientOptions, MessageCollectorOptions, InteractionCollectorOptions } from 'discord.js';
2
+ import { Client, PermissionResolvable, InteractionContextType, ApplicationIntegrationType, LocalizationMap, ApplicationCommandOptionData, ToAPIApplicationCommandOptions, ChatInputCommandInteraction, AutocompleteInteraction, Message, ContextMenuCommandInteraction, CommandInteraction, PermissionsString, Interaction, Collection, ClientEvents, ModalSubmitInteraction, ClientOptions, MessageCollectorOptions, InteractionCollectorOptions } from 'discord.js';
3
3
  export { SlashCommandAttachmentOption as AttachmentOption, SlashCommandBooleanOption as BooleanOption, SlashCommandChannelOption as ChannelOption, SlashCommandIntegerOption as IntegerOption, SlashCommandMentionableOption as MentionableOption, SlashCommandNumberOption as NumberOption, SlashCommandRoleOption as RoleOption, SlashCommandStringOption as StringOption, SlashCommandSubcommandBuilder as SubcommandBuilder, SlashCommandSubcommandGroupBuilder as SubcommandGroupBuilder, SlashCommandUserOption as UserOption } from 'discord.js';
4
4
  import EventEmitter from 'events';
5
5
 
@@ -72,7 +72,7 @@ interface MessageCommandOptions$1 extends BaseCommandOptions {
72
72
  interface SlashCommandOptions$1 extends BaseAppCommandOptions {
73
73
  commandType: 'Slash';
74
74
  /** The Application Command Options of this Command */
75
- options?: ApplicationCommandOptionData[];
75
+ options?: (ApplicationCommandOptionData | ToAPIApplicationCommandOptions)[];
76
76
  execute: (client: FrameworkClient<true>, interaction: ChatInputCommandInteraction) => Promise<unknown>;
77
77
  autocomplete?: (client: FrameworkClient<true>, interaction: AutocompleteInteraction) => Promise<unknown>;
78
78
  }
@@ -113,7 +113,7 @@ declare class AutocompleteModule extends EventEmitter {
113
113
  constructor(client: FrameworkClient);
114
114
  load(filepath: string, reload?: boolean): Promise<boolean>;
115
115
  loadAll(): Promise<void>;
116
- reload(id: string): void;
116
+ reload(id: string): Promise<void>;
117
117
  private unload;
118
118
  private _handleInteraction;
119
119
  }
@@ -123,7 +123,7 @@ declare class ListenerModule {
123
123
  constructor(client: FrameworkClient);
124
124
  load(filepath: string, reload?: boolean): Promise<boolean>;
125
125
  loadAll(): Promise<void>;
126
- reload(id: string): void;
126
+ reload(id: string): Promise<void>;
127
127
  private unload;
128
128
  }
129
129
 
@@ -143,7 +143,7 @@ declare class CommandsModule extends EventEmitter {
143
143
  setInteractionInterceptor(callback: (interaction: Interaction) => Promise<boolean>): (interaction: Interaction) => Promise<boolean>;
144
144
  load(filepath: string, reload?: boolean): Promise<boolean>;
145
145
  loadAll(): Promise<void>;
146
- reload(id: string): void;
146
+ reload(id: string): Promise<void>;
147
147
  private unload;
148
148
  registerOnStart(guildIds: string[], commands?: Collection<string, FrameworkCommand>): Promise<void>;
149
149
  publishGlobal(commands?: Collection<string, FrameworkCommand>): Promise<false | Collection<string, discord_js.ApplicationCommand<{
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as discord_js from 'discord.js';
2
- import { Client, PermissionResolvable, InteractionContextType, ApplicationIntegrationType, LocalizationMap, ApplicationCommandOptionData, ChatInputCommandInteraction, AutocompleteInteraction, Message, ContextMenuCommandInteraction, CommandInteraction, PermissionsString, Interaction, Collection, ClientEvents, ModalSubmitInteraction, ClientOptions, MessageCollectorOptions, InteractionCollectorOptions } from 'discord.js';
2
+ import { Client, PermissionResolvable, InteractionContextType, ApplicationIntegrationType, LocalizationMap, ApplicationCommandOptionData, ToAPIApplicationCommandOptions, ChatInputCommandInteraction, AutocompleteInteraction, Message, ContextMenuCommandInteraction, CommandInteraction, PermissionsString, Interaction, Collection, ClientEvents, ModalSubmitInteraction, ClientOptions, MessageCollectorOptions, InteractionCollectorOptions } from 'discord.js';
3
3
  export { SlashCommandAttachmentOption as AttachmentOption, SlashCommandBooleanOption as BooleanOption, SlashCommandChannelOption as ChannelOption, SlashCommandIntegerOption as IntegerOption, SlashCommandMentionableOption as MentionableOption, SlashCommandNumberOption as NumberOption, SlashCommandRoleOption as RoleOption, SlashCommandStringOption as StringOption, SlashCommandSubcommandBuilder as SubcommandBuilder, SlashCommandSubcommandGroupBuilder as SubcommandGroupBuilder, SlashCommandUserOption as UserOption } from 'discord.js';
4
4
  import EventEmitter from 'events';
5
5
 
@@ -72,7 +72,7 @@ interface MessageCommandOptions$1 extends BaseCommandOptions {
72
72
  interface SlashCommandOptions$1 extends BaseAppCommandOptions {
73
73
  commandType: 'Slash';
74
74
  /** The Application Command Options of this Command */
75
- options?: ApplicationCommandOptionData[];
75
+ options?: (ApplicationCommandOptionData | ToAPIApplicationCommandOptions)[];
76
76
  execute: (client: FrameworkClient<true>, interaction: ChatInputCommandInteraction) => Promise<unknown>;
77
77
  autocomplete?: (client: FrameworkClient<true>, interaction: AutocompleteInteraction) => Promise<unknown>;
78
78
  }
@@ -113,7 +113,7 @@ declare class AutocompleteModule extends EventEmitter {
113
113
  constructor(client: FrameworkClient);
114
114
  load(filepath: string, reload?: boolean): Promise<boolean>;
115
115
  loadAll(): Promise<void>;
116
- reload(id: string): void;
116
+ reload(id: string): Promise<void>;
117
117
  private unload;
118
118
  private _handleInteraction;
119
119
  }
@@ -123,7 +123,7 @@ declare class ListenerModule {
123
123
  constructor(client: FrameworkClient);
124
124
  load(filepath: string, reload?: boolean): Promise<boolean>;
125
125
  loadAll(): Promise<void>;
126
- reload(id: string): void;
126
+ reload(id: string): Promise<void>;
127
127
  private unload;
128
128
  }
129
129
 
@@ -143,7 +143,7 @@ declare class CommandsModule extends EventEmitter {
143
143
  setInteractionInterceptor(callback: (interaction: Interaction) => Promise<boolean>): (interaction: Interaction) => Promise<boolean>;
144
144
  load(filepath: string, reload?: boolean): Promise<boolean>;
145
145
  loadAll(): Promise<void>;
146
- reload(id: string): void;
146
+ reload(id: string): Promise<void>;
147
147
  private unload;
148
148
  registerOnStart(guildIds: string[], commands?: Collection<string, FrameworkCommand>): Promise<void>;
149
149
  publishGlobal(commands?: Collection<string, FrameworkCommand>): Promise<false | Collection<string, discord_js.ApplicationCommand<{
package/build/index.js CHANGED
@@ -262,7 +262,7 @@ var AutocompleteModule = class extends import_events.default {
262
262
  this.client.on("interactionCreate", (interaction) => this._handleInteraction(interaction));
263
263
  }
264
264
  async load(filepath, reload = false) {
265
- const completerModule = await import((0, import_node_url.pathToFileURL)(filepath).href);
265
+ const completerModule = reload ? require(filepath) : await import((0, import_node_url.pathToFileURL)(filepath).href);
266
266
  const completer = completerModule.autocomplete ?? completerModule.default?.default ?? completerModule.default ?? completerModule;
267
267
  if (typeof completer !== "object" || !completer.name || completer.disabled) return false;
268
268
  if (!reload && this.client.autocomplete.has(completer.id)) throw new FrameworkError("ComponentAlreadyLoaded", "autocomplete", completer.id);
@@ -281,16 +281,16 @@ var AutocompleteModule = class extends import_events.default {
281
281
  }
282
282
  }
283
283
  }
284
- reload(id) {
284
+ async reload(id) {
285
285
  const completer = this.client.autocomplete.get(id);
286
286
  if (!completer) throw new FrameworkError("UnknownComponent", "autocomplete", id);
287
287
  this.unload(id, true);
288
- this.load(completer.filepath, true);
288
+ await this.load(completer.filepath, true);
289
289
  }
290
290
  unload(id, reload = false) {
291
291
  if (!this.client.autocomplete.has(id)) throw new FrameworkError("UnknownComponent", "autocomplete", id);
292
292
  const completer = this.client.autocomplete.get(id);
293
- delete require.cache[completer.filepath];
293
+ delete require.cache[require.resolve(completer.filepath)];
294
294
  if (!reload) this.client.autocomplete.delete(id);
295
295
  }
296
296
  async _handleInteraction(interaction) {
@@ -333,7 +333,7 @@ var ListenerModule = class {
333
333
  this.client = client;
334
334
  }
335
335
  async load(filepath, reload = false) {
336
- const listenerModule = await import((0, import_node_url2.pathToFileURL)(filepath).href);
336
+ const listenerModule = reload ? require(filepath) : await import((0, import_node_url2.pathToFileURL)(filepath).href);
337
337
  const listener = listenerModule.listener ?? listenerModule.default?.default ?? listenerModule.default ?? listenerModule;
338
338
  if (typeof listener !== "object" || !listener.name || listener.disabled) return false;
339
339
  if (!reload && this.client.events.has(listener.id)) throw new FrameworkError("ComponentAlreadyLoaded", "listener", listener.id);
@@ -354,17 +354,17 @@ var ListenerModule = class {
354
354
  }
355
355
  }
356
356
  }
357
- reload(id) {
357
+ async reload(id) {
358
358
  if (!this.client.events.has(id)) throw new FrameworkError("UnknownComponent", "listener", id);
359
359
  const listener = this.client.events.get(id);
360
360
  this.unload(id, true);
361
- this.load(listener.filepath, true);
361
+ await this.load(listener.filepath, true);
362
362
  }
363
363
  unload(id, reload = false) {
364
364
  if (!this.client.events.has(id)) throw new FrameworkError("UnknownComponent", "listener", id);
365
365
  const listener = this.client.events.get(id);
366
366
  if (listener._execute) this.client.off(listener.name, listener._execute);
367
- delete require.cache[listener.filepath];
367
+ delete require.cache[require.resolve(listener.filepath)];
368
368
  if (!reload) this.client.events.delete(id);
369
369
  }
370
370
  };
@@ -393,7 +393,7 @@ var CommandsModule = class extends import_events2.default {
393
393
  return this.handler.InteractionCommandInterceptor = callback;
394
394
  }
395
395
  async load(filepath, reload = false) {
396
- const commandModule = await import((0, import_node_url3.pathToFileURL)(filepath).href);
396
+ const commandModule = reload ? require(filepath) : await import((0, import_node_url3.pathToFileURL)(filepath).href);
397
397
  const command = commandModule?.command ?? commandModule?.default?.default ?? commandModule?.default ?? commandModule;
398
398
  if (typeof command !== "object" || !command.name || command.disabled) return false;
399
399
  if (!reload && this.client.commands.has(command.id)) throw new FrameworkError("ComponentAlreadyLoaded", "command", command.id);
@@ -415,16 +415,16 @@ var CommandsModule = class extends import_events2.default {
415
415
  }
416
416
  }
417
417
  }
418
- reload(id) {
418
+ async reload(id) {
419
419
  if (!this.client.commands.has(id)) throw new FrameworkError("UnknownComponent", "commands", id);
420
420
  const command = this.client.commands.get(id);
421
421
  this.unload(id, true);
422
- this.load(command.filepath, true);
422
+ await this.load(command.filepath, true);
423
423
  }
424
424
  unload(id, reload = false) {
425
425
  if (!this.client.commands.has(id)) throw new FrameworkError("UnknownComponent", "commands", id);
426
426
  const command = this.client.commands.get(id);
427
- delete require.cache[command.filepath];
427
+ delete require.cache[require.resolve(command.filepath)];
428
428
  if (!reload) this.client.commands.delete(id);
429
429
  }
430
430
  async registerOnStart(guildIds, commands) {
@@ -460,7 +460,7 @@ var CommandsModule = class extends import_events2.default {
460
460
  const commandName = args.shift()?.toLowerCase();
461
461
  if (!commandName) return;
462
462
  const commandId = `Message:${commandName}`;
463
- const command = this.client.commands.get(commandId) || this.client.commands.get(this.client.aliases.get(commandId) || "");
463
+ const command = this.client.commands.get(commandId) || this.client.commands.get(this.client.aliases.get(commandName) || "");
464
464
  if (!command || command.commandType !== "Message" || command.disabled || command.devOnly && !this.client.developers.includes(message.author.id)) return;
465
465
  if (!message.inGuild() && !command.contexts.includes("BotDM") || message.inGuild() && !command.contexts.includes("Guild")) return;
466
466
  if (message.inGuild() && command.memberPermissions) {
@@ -570,7 +570,9 @@ var CommandsModule = class extends import_events2.default {
570
570
  integrationTypes: resolveIntegrationTypes(command.integrationTypes),
571
571
  nameLocalizations: command.nameLocalizations,
572
572
  descriptionLocalizations: command.descriptionLocalizations,
573
- ...command.commandType === "Slash" ? { options: command.options ?? [] } : {}
573
+ ...command.commandType === "Slash" ? {
574
+ options: command.options ? command.options.map((op) => typeof op.toJSON === "function" ? op.toJSON() : op) : []
575
+ } : {}
574
576
  };
575
577
  }
576
578
  };
package/build/index.mjs CHANGED
@@ -217,7 +217,7 @@ var AutocompleteModule = class extends EventEmitter {
217
217
  this.client.on("interactionCreate", (interaction) => this._handleInteraction(interaction));
218
218
  }
219
219
  async load(filepath, reload = false) {
220
- const completerModule = await import(pathToFileURL(filepath).href);
220
+ const completerModule = reload ? __require(filepath) : await import(pathToFileURL(filepath).href);
221
221
  const completer = completerModule.autocomplete ?? completerModule.default?.default ?? completerModule.default ?? completerModule;
222
222
  if (typeof completer !== "object" || !completer.name || completer.disabled) return false;
223
223
  if (!reload && this.client.autocomplete.has(completer.id)) throw new FrameworkError("ComponentAlreadyLoaded", "autocomplete", completer.id);
@@ -236,16 +236,16 @@ var AutocompleteModule = class extends EventEmitter {
236
236
  }
237
237
  }
238
238
  }
239
- reload(id) {
239
+ async reload(id) {
240
240
  const completer = this.client.autocomplete.get(id);
241
241
  if (!completer) throw new FrameworkError("UnknownComponent", "autocomplete", id);
242
242
  this.unload(id, true);
243
- this.load(completer.filepath, true);
243
+ await this.load(completer.filepath, true);
244
244
  }
245
245
  unload(id, reload = false) {
246
246
  if (!this.client.autocomplete.has(id)) throw new FrameworkError("UnknownComponent", "autocomplete", id);
247
247
  const completer = this.client.autocomplete.get(id);
248
- delete __require.cache[completer.filepath];
248
+ delete __require.cache[__require.resolve(completer.filepath)];
249
249
  if (!reload) this.client.autocomplete.delete(id);
250
250
  }
251
251
  async _handleInteraction(interaction) {
@@ -288,7 +288,7 @@ var ListenerModule = class {
288
288
  this.client = client;
289
289
  }
290
290
  async load(filepath, reload = false) {
291
- const listenerModule = await import(pathToFileURL2(filepath).href);
291
+ const listenerModule = reload ? __require(filepath) : await import(pathToFileURL2(filepath).href);
292
292
  const listener = listenerModule.listener ?? listenerModule.default?.default ?? listenerModule.default ?? listenerModule;
293
293
  if (typeof listener !== "object" || !listener.name || listener.disabled) return false;
294
294
  if (!reload && this.client.events.has(listener.id)) throw new FrameworkError("ComponentAlreadyLoaded", "listener", listener.id);
@@ -309,17 +309,17 @@ var ListenerModule = class {
309
309
  }
310
310
  }
311
311
  }
312
- reload(id) {
312
+ async reload(id) {
313
313
  if (!this.client.events.has(id)) throw new FrameworkError("UnknownComponent", "listener", id);
314
314
  const listener = this.client.events.get(id);
315
315
  this.unload(id, true);
316
- this.load(listener.filepath, true);
316
+ await this.load(listener.filepath, true);
317
317
  }
318
318
  unload(id, reload = false) {
319
319
  if (!this.client.events.has(id)) throw new FrameworkError("UnknownComponent", "listener", id);
320
320
  const listener = this.client.events.get(id);
321
321
  if (listener._execute) this.client.off(listener.name, listener._execute);
322
- delete __require.cache[listener.filepath];
322
+ delete __require.cache[__require.resolve(listener.filepath)];
323
323
  if (!reload) this.client.events.delete(id);
324
324
  }
325
325
  };
@@ -348,7 +348,7 @@ var CommandsModule = class extends EventEmitter2 {
348
348
  return this.handler.InteractionCommandInterceptor = callback;
349
349
  }
350
350
  async load(filepath, reload = false) {
351
- const commandModule = await import(pathToFileURL3(filepath).href);
351
+ const commandModule = reload ? __require(filepath) : await import(pathToFileURL3(filepath).href);
352
352
  const command = commandModule?.command ?? commandModule?.default?.default ?? commandModule?.default ?? commandModule;
353
353
  if (typeof command !== "object" || !command.name || command.disabled) return false;
354
354
  if (!reload && this.client.commands.has(command.id)) throw new FrameworkError("ComponentAlreadyLoaded", "command", command.id);
@@ -370,16 +370,16 @@ var CommandsModule = class extends EventEmitter2 {
370
370
  }
371
371
  }
372
372
  }
373
- reload(id) {
373
+ async reload(id) {
374
374
  if (!this.client.commands.has(id)) throw new FrameworkError("UnknownComponent", "commands", id);
375
375
  const command = this.client.commands.get(id);
376
376
  this.unload(id, true);
377
- this.load(command.filepath, true);
377
+ await this.load(command.filepath, true);
378
378
  }
379
379
  unload(id, reload = false) {
380
380
  if (!this.client.commands.has(id)) throw new FrameworkError("UnknownComponent", "commands", id);
381
381
  const command = this.client.commands.get(id);
382
- delete __require.cache[command.filepath];
382
+ delete __require.cache[__require.resolve(command.filepath)];
383
383
  if (!reload) this.client.commands.delete(id);
384
384
  }
385
385
  async registerOnStart(guildIds, commands) {
@@ -415,7 +415,7 @@ var CommandsModule = class extends EventEmitter2 {
415
415
  const commandName = args.shift()?.toLowerCase();
416
416
  if (!commandName) return;
417
417
  const commandId = `Message:${commandName}`;
418
- const command = this.client.commands.get(commandId) || this.client.commands.get(this.client.aliases.get(commandId) || "");
418
+ const command = this.client.commands.get(commandId) || this.client.commands.get(this.client.aliases.get(commandName) || "");
419
419
  if (!command || command.commandType !== "Message" || command.disabled || command.devOnly && !this.client.developers.includes(message.author.id)) return;
420
420
  if (!message.inGuild() && !command.contexts.includes("BotDM") || message.inGuild() && !command.contexts.includes("Guild")) return;
421
421
  if (message.inGuild() && command.memberPermissions) {
@@ -525,7 +525,9 @@ var CommandsModule = class extends EventEmitter2 {
525
525
  integrationTypes: resolveIntegrationTypes(command.integrationTypes),
526
526
  nameLocalizations: command.nameLocalizations,
527
527
  descriptionLocalizations: command.descriptionLocalizations,
528
- ...command.commandType === "Slash" ? { options: command.options ?? [] } : {}
528
+ ...command.commandType === "Slash" ? {
529
+ options: command.options ? command.options.map((op) => typeof op.toJSON === "function" ? op.toJSON() : op) : []
530
+ } : {}
529
531
  };
530
532
  }
531
533
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardbot/framework",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "A simple framework made for building discord bots with discord.js.",
5
5
  "main": "./build/index.js",
6
6
  "module": "./build/index.mjs",