vimcord 1.0.50 → 1.0.52

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/dist/index.js CHANGED
@@ -222,9 +222,13 @@ var BaseCommandBuilder = class {
222
222
  await config.beforeExecute?.({ cancel: () => cancel = true }, ...args);
223
223
  if (cancel) return;
224
224
  if (config.logExecution !== false) {
225
- const cmdName = this.options.name || this.builder?.name || "Unknown";
225
+ const optionsWithName = this.options;
226
+ const builderWithName = this;
227
+ const cmdName = optionsWithName.name ?? builderWithName.builder?.name ?? "Unknown";
226
228
  const location = ctx.guild ? `${ctx.guild.name} (${ctx.guild.id})` : "Direct Messages";
227
- client.logger.commandExecuted(cmdName, ctx.user.username, location);
229
+ if (client.logger) {
230
+ client.logger.commandExecuted(cmdName, ctx.user.username, location);
231
+ }
228
232
  }
229
233
  const result = await config.execute?.(...args);
230
234
  await config.afterExecute?.(result, ...args);
@@ -452,9 +456,7 @@ var Logger = class {
452
456
  extend(extras) {
453
457
  for (const [key, fn] of Object.entries(extras)) {
454
458
  if (typeof fn === "function") {
455
- this[key] = function(...args) {
456
- return fn.call(this, ...args);
457
- };
459
+ this[key] = (...args) => fn.call(this, ...args);
458
460
  }
459
461
  }
460
462
  return this;
@@ -824,12 +826,14 @@ var contextCommandHandler = new EventBuilder({
824
826
  if (!command) {
825
827
  const content = `**${interaction.commandName}** is not a registered context command.`;
826
828
  if (interaction.replied || interaction.deferred) {
827
- return interaction.followUp({ content, flags: "Ephemeral" });
829
+ await interaction.followUp({ content, flags: "Ephemeral" });
830
+ } else {
831
+ await interaction.reply({ content, flags: "Ephemeral" });
828
832
  }
829
- return interaction.reply({ content, flags: "Ephemeral" });
833
+ return;
830
834
  }
831
835
  try {
832
- return await command.run(client, client, interaction);
836
+ await command.run(client, client, interaction);
833
837
  } catch (err) {
834
838
  await client.error.handleCommandError(err, interaction.guild, interaction);
835
839
  }
@@ -888,12 +892,14 @@ var slashCommandHandler = new EventBuilder({
888
892
  if (!command) {
889
893
  const content = `**/\`${interaction.commandName}\`** is not a registered command.`;
890
894
  if (interaction.replied || interaction.deferred) {
891
- return interaction.followUp({ content, flags: "Ephemeral" });
895
+ await interaction.followUp({ content, flags: "Ephemeral" });
896
+ } else {
897
+ await interaction.reply({ content, flags: "Ephemeral" });
892
898
  }
893
- return interaction.reply({ content, flags: "Ephemeral" });
899
+ return;
894
900
  }
895
901
  try {
896
- return await command.run(client, client, interaction);
902
+ await command.run(client, client, interaction);
897
903
  } catch (err) {
898
904
  await client.error.handleCommandError(err, interaction.guild, interaction);
899
905
  }
@@ -1695,7 +1701,7 @@ var VimcordErrorHandler = class {
1695
1701
  import chalk2 from "chalk";
1696
1702
 
1697
1703
  // package.json
1698
- var version = "1.0.50";
1704
+ var version = "1.0.51";
1699
1705
 
1700
1706
  // src/client/vimcord.logger.ts
1701
1707
  var clientLoggerFactory = (client) => new Logger({ prefixEmoji: "\u26A1", prefix: `vimcord (i${client.clientId})` }).extend({
@@ -1771,9 +1777,11 @@ function getDevMode() {
1771
1777
  }
1772
1778
 
1773
1779
  // src/configs/app.config.ts
1780
+ var packageJson = getPackageJson();
1781
+ var version2 = typeof packageJson.version === "string" ? packageJson.version : "1.0.0";
1774
1782
  var defaultConfig = {
1775
1783
  name: "Discord Bot",
1776
- version: getPackageJson()?.version ?? "1.0.0",
1784
+ version: version2,
1777
1785
  devMode: getDevMode(),
1778
1786
  verbose: false,
1779
1787
  enableCLI: false,
@@ -2097,11 +2105,16 @@ var CommandManager = class {
2097
2105
  slash;
2098
2106
  prefix;
2099
2107
  context;
2108
+ logger;
2100
2109
  constructor(client) {
2101
2110
  this.client = client;
2102
2111
  this.slash = new SlashCommandManager(client);
2103
2112
  this.prefix = new PrefixCommandManager(client);
2104
2113
  this.context = new ContextCommandManager(client);
2114
+ this.logger = new Logger({
2115
+ prefixEmoji: "\u26A1",
2116
+ prefix: `vimcord (i${client.clientId}) [CommandManager]`
2117
+ });
2105
2118
  }
2106
2119
  getAllAppCommands(options = {}) {
2107
2120
  return [...this.slash.getAll(options), ...this.context.getAll(options)];
@@ -2109,23 +2122,21 @@ var CommandManager = class {
2109
2122
  async registerGlobal(options = {}) {
2110
2123
  const client = await Vimcord.getReadyInstance(this.client.clientId);
2111
2124
  if (!client.rest) {
2112
- console.error(`[CommandManager] \u2716 Failed to register app commands globally: REST is not initialized`);
2125
+ this.logger.error("Failed to register app commands globally: REST is not initialized");
2113
2126
  return;
2114
2127
  }
2115
2128
  const commands = this.getAllAppCommands(options).map((cmd) => cmd.builder.toJSON());
2116
2129
  if (!commands.length) {
2117
- console.log("[CommandManager] No commands to register globally");
2130
+ this.logger.info("No commands to register globally");
2118
2131
  return;
2119
2132
  }
2120
- console.log(
2121
- `[CommandManager] Registering (${commands.length}) ${commands.length === 1 ? "command" : "commands"} globally...`
2122
- );
2133
+ this.logger.info(`Registering (${commands.length}) ${commands.length === 1 ? "command" : "commands"} globally...`);
2123
2134
  try {
2124
2135
  await client.rest.put(Routes.applicationCommands(client.user.id), { body: commands });
2125
- console.log(`[CommandManager] \u2714 Registered app ${commands.length === 1 ? "command" : "commands"} globally`);
2136
+ this.logger.success(`Registered app ${commands.length === 1 ? "command" : "commands"} globally`);
2126
2137
  } catch (err) {
2127
- console.error(
2128
- `[CommandManager] \u2716 Failed to register app ${commands.length === 1 ? "command" : "commands"} globally`,
2138
+ this.logger.error(
2139
+ `Failed to register app ${commands.length === 1 ? "command" : "commands"} globally`,
2129
2140
  err
2130
2141
  );
2131
2142
  }
@@ -2133,60 +2144,66 @@ var CommandManager = class {
2133
2144
  async unregisterGlobal() {
2134
2145
  const client = await Vimcord.getReadyInstance(this.client.clientId);
2135
2146
  if (!client.rest) {
2136
- console.error(`[CommandManager] \u2716 Failed to remove app commands globally: REST is not initialized`);
2147
+ this.logger.error("Failed to remove app commands globally: REST is not initialized");
2137
2148
  return;
2138
2149
  }
2139
2150
  try {
2140
2151
  await client.rest.put(Routes.applicationCommands(client.user.id), { body: [] });
2141
- console.log(`[CommandManager] \u2714 Removed app commands globally`);
2152
+ this.logger.success("Removed app commands globally");
2142
2153
  } catch (err) {
2143
- console.error(`[CommandManager] \u2716 Failed to remove app commands globally`, err);
2154
+ this.logger.error("Failed to remove app commands globally", err);
2144
2155
  }
2145
2156
  }
2146
2157
  async registerGuild(options = {}) {
2147
2158
  const client = await Vimcord.getReadyInstance(this.client.clientId);
2148
2159
  if (!client.rest) {
2149
- console.error(`[CommandManager] \u2716 Failed to register app commands by guild: REST is not initialized`);
2160
+ this.logger.error("Failed to register app commands by guild: REST is not initialized");
2150
2161
  return;
2151
2162
  }
2152
2163
  const commands = this.getAllAppCommands(options).map((cmd) => cmd.builder.toJSON());
2153
2164
  if (!commands.length) {
2154
- console.log("[CommandManager] No commands to register by guild");
2165
+ this.logger.info("No commands to register by guild");
2155
2166
  return;
2156
2167
  }
2157
2168
  const guildIds = options.guilds || client.guilds.cache.map((g) => g.id);
2158
- console.log(
2159
- `[CommandManager] Registering (${commands.length}) ${commands.length === 1 ? "command" : "commands"} for ${guildIds.length} guilds...`
2169
+ this.logger.info(
2170
+ `Registering (${commands.length}) ${commands.length === 1 ? "command" : "commands"} for ${guildIds.length} guilds...`
2160
2171
  );
2161
2172
  await Promise.all(
2162
- guildIds.map(
2163
- (guildId) => client.rest.put(Routes.applicationGuildCommands(client.user.id, guildId), { body: commands }).then(() => {
2173
+ guildIds.map(async (guildId) => {
2174
+ try {
2175
+ await client.rest.put(Routes.applicationGuildCommands(client.user.id, guildId), { body: commands });
2164
2176
  const gName = client.guilds.cache.get(guildId)?.name || "n/a";
2165
- console.log(
2166
- `[CommandManager] \u2714 Set app ${commands.length === 1 ? "command" : "commands"} in guild: ${guildId} (${gName})`
2177
+ this.logger.success(
2178
+ `Set app ${commands.length === 1 ? "command" : "commands"} in guild: ${guildId} (${gName})`
2167
2179
  );
2168
- }).catch((err) => {
2180
+ } catch (err) {
2169
2181
  const gName = client.guilds.cache.get(guildId)?.name || "n/a";
2170
- console.log(
2171
- `[CommandManager] \u2716 Failed to set app ${commands.length === 1 ? "command" : "commands"} in guild: ${guildId} (${gName})`,
2182
+ this.logger.error(
2183
+ `Failed to set app ${commands.length === 1 ? "command" : "commands"} in guild: ${guildId} (${gName})`,
2172
2184
  err
2173
2185
  );
2174
- })
2175
- )
2186
+ }
2187
+ })
2176
2188
  );
2177
2189
  }
2178
2190
  async unregisterGuild(options = {}) {
2179
2191
  const client = await Vimcord.getReadyInstance(this.client.clientId);
2180
2192
  if (!client.rest) {
2181
- console.error(`[CommandManager] \u2716 Failed to register app commands by guild: REST is not initialized`);
2193
+ this.logger.error("Failed to unregister app commands by guild: REST is not initialized");
2182
2194
  return;
2183
2195
  }
2184
2196
  const guildIds = options.guilds || client.guilds.cache.map((g) => g.id);
2185
- console.log(`[CommandManager] Unregistering commands from ${guildIds.length} guilds...`);
2197
+ this.logger.info(`Unregistering commands from ${guildIds.length} guilds...`);
2186
2198
  await Promise.all(
2187
- guildIds.map(
2188
- (guildId) => client.rest.put(Routes.applicationGuildCommands(client.user.id, guildId), { body: [] }).then(() => console.log(`[CommandManager] \u2714 Removed app commands in guild: ${guildId}`)).catch((err) => console.log(`[CommandManager] \u2716 Failed to remove app commands in guild: ${guildId}`, err))
2189
- )
2199
+ guildIds.map(async (guildId) => {
2200
+ try {
2201
+ await client.rest.put(Routes.applicationGuildCommands(client.user.id, guildId), { body: [] });
2202
+ this.logger.success(`Removed app commands in guild: ${guildId}`);
2203
+ } catch (err) {
2204
+ this.logger.error(`Failed to remove app commands in guild: ${guildId}`, err);
2205
+ }
2206
+ })
2190
2207
  );
2191
2208
  }
2192
2209
  };
@@ -2694,8 +2711,8 @@ var Vimcord = class _Vimcord extends Client2 {
2694
2711
  return this.config.app.version;
2695
2712
  }
2696
2713
  // prettier-ignore
2697
- set $version(version2) {
2698
- this.config.app.version = version2;
2714
+ set $version(version3) {
2715
+ this.config.app.version = version3;
2699
2716
  }
2700
2717
  /** Current dev mode state */
2701
2718
  // prettier-ignore
@@ -3474,59 +3491,89 @@ var BetterContainer = class {
3474
3491
  // src/tools/BetterModal.ts
3475
3492
  import {
3476
3493
  ChannelSelectMenuBuilder,
3494
+ CheckboxBuilder,
3495
+ CheckboxGroupBuilder,
3477
3496
  FileUploadBuilder,
3478
3497
  LabelBuilder,
3479
3498
  MentionableSelectMenuBuilder,
3480
3499
  ModalBuilder,
3500
+ RadioGroupBuilder,
3481
3501
  RoleSelectMenuBuilder,
3482
3502
  StringSelectMenuBuilder,
3483
3503
  TextInputBuilder,
3484
- TextInputStyle,
3485
3504
  UserSelectMenuBuilder
3486
3505
  } from "discord.js";
3487
- import { $ as $6 } from "qznt";
3488
- var BetterModal = class {
3489
- id;
3490
- options;
3491
- modal;
3506
+ var DEFAULT_CONFIG = {
3507
+ timeout: 6e4
3508
+ };
3509
+ function createRandomId() {
3510
+ return `v-${Math.random().toString(36).split(".")[1]}`;
3511
+ }
3512
+ var BetterModal = class _BetterModal {
3513
+ customId;
3492
3514
  components = /* @__PURE__ */ new Map();
3493
- config;
3494
- constructor(options = {}) {
3495
- this.id = options.id || this.createModalId();
3496
- this.options = options;
3497
- this.modal = new ModalBuilder().setCustomId(this.id);
3498
- this.config = options.config || globalToolsConfig;
3499
- if (options.title) {
3500
- this.setTitle(options.title);
3501
- }
3502
- if (options.components?.length) {
3503
- this.addComponents(...options.components);
3504
- }
3515
+ labelComponents = [];
3516
+ modal;
3517
+ constructor(options) {
3518
+ this.customId = options?.customId ?? createRandomId();
3519
+ this.modal = new ModalBuilder().setCustomId(this.customId);
3520
+ if (options?.title) this.setTitle(options.title);
3521
+ if (options?.components?.length) this.addComponents(...options.components);
3505
3522
  }
3506
- createModalId() {
3507
- return `modal:${$6.rnd.str(10, "alpha", { casing: "mixed" })}-${Date.now()}`;
3523
+ validateComponentLength() {
3524
+ if ((this.components.size ?? 0) >= 25) {
3525
+ throw new Error("[BetterModal] Modal can only have 25 components");
3526
+ }
3508
3527
  }
3509
3528
  createComponentId() {
3510
- return `modal-component:${this.id}-${$6.rnd.str(4, "alpha", { casing: "mixed" })}-${Date.now().toString().slice(-4)}`;
3529
+ return `${this.customId}:${createRandomId()}`;
3511
3530
  }
3512
- validateComponentLength() {
3513
- if (this.components.size >= 5) throw new Error("Modal can only have 5 components");
3514
- }
3515
- toJSON() {
3516
- return this.modal.toJSON();
3531
+ createLabelComponent(data) {
3532
+ const component = new LabelBuilder().setLabel(data.label);
3533
+ if (data.description) component.setDescription(data.description);
3534
+ return component;
3517
3535
  }
3518
3536
  build() {
3519
- this.modal.setLabelComponents(Array.from(this.components.values()));
3537
+ if (!this.modal.data.title) throw new Error("[BetterModal] Modal must have a title");
3538
+ this.modal.setLabelComponents(this.labelComponents);
3520
3539
  return this.modal;
3521
3540
  }
3541
+ clone() {
3542
+ return new _BetterModal({
3543
+ customId: this.customId,
3544
+ title: this.modal.data.title,
3545
+ components: Array.from(this.components.values())
3546
+ });
3547
+ }
3548
+ toJSON() {
3549
+ return this.build().toJSON();
3550
+ }
3551
+ /**
3552
+ * Sets the title of the modal.
3553
+ * @param title The title of the modal.
3554
+ */
3522
3555
  setTitle(title) {
3523
3556
  this.modal.setTitle(title);
3524
3557
  return this;
3525
3558
  }
3559
+ /** Sets components for the modal. */
3560
+ setComponents(...components) {
3561
+ this.components.clear();
3562
+ this.labelComponents = [];
3563
+ this.addComponents(...components);
3564
+ return this;
3565
+ }
3566
+ /** Adds components to the modal. */
3526
3567
  addComponents(...components) {
3527
3568
  for (const component of components) {
3528
3569
  if ("textInput" in component) {
3529
3570
  this.addTextInput(component.textInput);
3571
+ } else if ("checkbox" in component) {
3572
+ this.addCheckbox(component.checkbox);
3573
+ } else if ("checkboxGroup" in component) {
3574
+ this.addCheckboxGroup(component.checkboxGroup);
3575
+ } else if ("radioGroup" in component) {
3576
+ this.addRadioGroup(component.radioGroup);
3530
3577
  } else if ("stringSelect" in component) {
3531
3578
  this.addStringSelect(component.stringSelect);
3532
3579
  } else if ("channelSelect" in component) {
@@ -3543,112 +3590,144 @@ var BetterModal = class {
3543
3590
  }
3544
3591
  return this;
3545
3592
  }
3546
- setComponents(...components) {
3547
- this.modal.spliceLabelComponents(0, this.modal.components.length);
3548
- this.addComponents(...components);
3549
- return this;
3550
- }
3551
3593
  addTextInput(data) {
3552
3594
  this.validateComponentLength();
3553
- let { label, description, custom_id, ...rest } = data;
3554
- custom_id ||= this.createComponentId();
3555
- const textInputComponent = new TextInputBuilder(rest).setCustomId(custom_id);
3556
- if (!rest.style) textInputComponent.setStyle(TextInputStyle.Short);
3557
- const labelComponent = new LabelBuilder().setLabel(label).setTextInputComponent(textInputComponent);
3558
- if (description) labelComponent.setDescription(description);
3559
- this.components.set(custom_id, labelComponent);
3595
+ const customId = data.customId ?? this.createComponentId();
3596
+ const textInput = new TextInputBuilder({ ...data, customId });
3597
+ const label = this.createLabelComponent(data);
3598
+ label.setTextInputComponent(textInput);
3599
+ this.components.set(customId, { textInput: data });
3600
+ this.labelComponents.push(label);
3560
3601
  return this;
3561
3602
  }
3562
3603
  addStringSelect(data) {
3563
3604
  this.validateComponentLength();
3564
- let { label, description, custom_id, ...rest } = data;
3565
- custom_id ||= this.createComponentId();
3566
- const stringSelectComponent = new StringSelectMenuBuilder(rest).setCustomId(custom_id);
3567
- const labelComponent = new LabelBuilder().setLabel(label).setStringSelectMenuComponent(stringSelectComponent);
3568
- if (description) labelComponent.setDescription(description);
3569
- this.components.set(custom_id, labelComponent);
3605
+ const customId = data.customId ?? this.createComponentId();
3606
+ const select = new StringSelectMenuBuilder({ ...data, customId });
3607
+ const label = this.createLabelComponent(data);
3608
+ label.setStringSelectMenuComponent(select);
3609
+ this.components.set(customId, { stringSelect: data });
3610
+ this.labelComponents.push(label);
3611
+ return this;
3612
+ }
3613
+ addCheckbox(data) {
3614
+ this.validateComponentLength();
3615
+ const customId = data.custom_id ?? this.createComponentId();
3616
+ const checkbox = new CheckboxBuilder({ ...data, custom_id: customId });
3617
+ const label = this.createLabelComponent(data);
3618
+ label.setCheckboxComponent(checkbox);
3619
+ this.components.set(customId, { checkbox: data });
3620
+ this.labelComponents.push(label);
3621
+ return this;
3622
+ }
3623
+ addCheckboxGroup(data) {
3624
+ this.validateComponentLength();
3625
+ const customId = data.custom_id ?? this.createComponentId();
3626
+ const checkboxGroup = new CheckboxGroupBuilder({ ...data, custom_id: customId });
3627
+ const label = this.createLabelComponent(data);
3628
+ label.setCheckboxGroupComponent(checkboxGroup);
3629
+ this.components.set(customId, { checkboxGroup: data });
3630
+ this.labelComponents.push(label);
3631
+ return this;
3632
+ }
3633
+ addRadioGroup(data) {
3634
+ this.validateComponentLength();
3635
+ const customId = data.custom_id ?? this.createComponentId();
3636
+ const radioGroup = new RadioGroupBuilder({ ...data, custom_id: customId });
3637
+ const label = this.createLabelComponent(data);
3638
+ label.setRadioGroupComponent(radioGroup);
3639
+ this.components.set(customId, { radioGroup: data });
3640
+ this.labelComponents.push(label);
3570
3641
  return this;
3571
3642
  }
3572
3643
  addChannelSelect(data) {
3573
3644
  this.validateComponentLength();
3574
- let { label, description, custom_id, ...rest } = data;
3575
- custom_id ||= this.createComponentId();
3576
- const channelSelectComponent = new ChannelSelectMenuBuilder(rest).setCustomId(custom_id);
3577
- const labelComponent = new LabelBuilder().setLabel(label).setChannelSelectMenuComponent(channelSelectComponent);
3578
- if (description) labelComponent.setDescription(description);
3579
- this.components.set(custom_id, labelComponent);
3645
+ const customId = data.customId ?? this.createComponentId();
3646
+ const channelSelect = new ChannelSelectMenuBuilder({ ...data, customId });
3647
+ const label = this.createLabelComponent(data);
3648
+ label.setChannelSelectMenuComponent(channelSelect);
3649
+ this.components.set(customId, { channelSelect: data });
3650
+ this.labelComponents.push(label);
3580
3651
  return this;
3581
3652
  }
3582
3653
  addUserSelect(data) {
3583
3654
  this.validateComponentLength();
3584
- let { label, description, custom_id, ...rest } = data;
3585
- custom_id ||= this.createComponentId();
3586
- const userSelectComponent = new UserSelectMenuBuilder(rest).setCustomId(custom_id);
3587
- const labelComponent = new LabelBuilder().setLabel(label).setUserSelectMenuComponent(userSelectComponent);
3588
- if (description) labelComponent.setDescription(description);
3589
- this.components.set(custom_id, labelComponent);
3655
+ const customId = data.customId ?? this.createComponentId();
3656
+ const userSelect = new UserSelectMenuBuilder({ ...data, customId });
3657
+ const label = this.createLabelComponent(data);
3658
+ label.setUserSelectMenuComponent(userSelect);
3659
+ this.components.set(customId, { userSelect: data });
3660
+ this.labelComponents.push(label);
3590
3661
  return this;
3591
3662
  }
3592
3663
  addRoleSelect(data) {
3593
3664
  this.validateComponentLength();
3594
- let { label, description, custom_id, ...rest } = data;
3595
- custom_id ||= this.createComponentId();
3596
- const roleSelectComponent = new RoleSelectMenuBuilder(rest).setCustomId(custom_id);
3597
- const labelComponent = new LabelBuilder().setLabel(label).setRoleSelectMenuComponent(roleSelectComponent);
3598
- if (description) labelComponent.setDescription(description);
3599
- this.components.set(custom_id, labelComponent);
3665
+ const customId = data.customId ?? this.createComponentId();
3666
+ const roleSelect = new RoleSelectMenuBuilder({ ...data, customId });
3667
+ const label = this.createLabelComponent(data);
3668
+ label.setRoleSelectMenuComponent(roleSelect);
3669
+ this.components.set(customId, { roleSelect: data });
3670
+ this.labelComponents.push(label);
3600
3671
  return this;
3601
3672
  }
3602
3673
  addMentionableSelect(data) {
3603
3674
  this.validateComponentLength();
3604
- let { label, description, custom_id, ...rest } = data;
3605
- custom_id ||= this.createComponentId();
3606
- const mentionableSelectComponent = new MentionableSelectMenuBuilder(rest).setCustomId(custom_id);
3607
- const labelComponent = new LabelBuilder().setLabel(label).setMentionableSelectMenuComponent(mentionableSelectComponent);
3608
- if (description) labelComponent.setDescription(description);
3609
- this.components.set(custom_id, labelComponent);
3675
+ const customId = data.customId ?? this.createComponentId();
3676
+ const mentionableSelect = new MentionableSelectMenuBuilder({ ...data, customId });
3677
+ const label = this.createLabelComponent(data);
3678
+ label.setMentionableSelectMenuComponent(mentionableSelect);
3679
+ this.components.set(customId, { mentionableSelect: data });
3680
+ this.labelComponents.push(label);
3610
3681
  return this;
3611
3682
  }
3612
3683
  addFileUpload(data) {
3613
3684
  this.validateComponentLength();
3614
- let { label, description, custom_id, ...rest } = data;
3615
- custom_id ||= this.createComponentId();
3616
- const fileUploadComponent = new FileUploadBuilder(rest).setCustomId(custom_id);
3617
- const labelComponent = new LabelBuilder().setLabel(label).setFileUploadComponent(fileUploadComponent);
3618
- if (description) labelComponent.setDescription(description);
3619
- this.components.set(custom_id, labelComponent);
3685
+ const customId = data.custom_id ?? this.createComponentId();
3686
+ const fileUpload = new FileUploadBuilder({ ...data, custom_id: customId });
3687
+ const label = this.createLabelComponent(data);
3688
+ label.setFileUploadComponent(fileUpload);
3689
+ this.components.set(customId, { fileUpload: data });
3690
+ this.labelComponents.push(label);
3620
3691
  return this;
3621
3692
  }
3622
3693
  /**
3623
- * Shows the modal via interaction.
3624
- * @param interaction The interaction used to show the modal
3694
+ * Shows the modal to the user via interaction.
3695
+ * @param interaction The command interaction to show the modal with.
3696
+ * @param options Modal options.
3625
3697
  */
3626
- async show(interaction) {
3627
- if (!("showModal" in interaction)) throw new Error("Interaction does not support showing modals");
3628
- if (!this.modal.data.title) throw new Error("Modal must have a title");
3629
- this.build();
3630
- await interaction.showModal(this.modal).catch((err) => {
3631
- console.error("Modal failed to send", err);
3632
- });
3698
+ async show(interaction, options) {
3699
+ if (!interaction) throw new Error("[BetterModal] Interaction is null or undefined");
3700
+ const modal = this.build();
3701
+ await interaction.showModal(modal, options);
3702
+ }
3703
+ /**
3704
+ * Shows the modal and waits for it to be submitted.
3705
+ * @param interaction The interaction to show the modal with.
3706
+ * @param options Modal submission options.
3707
+ */
3708
+ async showAndAwait(interaction, options) {
3709
+ await this.show(interaction);
3710
+ return this.awaitSubmit(interaction, options);
3633
3711
  }
3634
3712
  /**
3635
- * Waits for the modal to be submitted and returns the component data.
3636
- * @param interaction The interaction used to show the modal
3637
- * @param options Options */
3713
+ * Waits for this modal to be submitted, returning a helper utility object.
3714
+ * @param interaction The interaction to show the modal with.
3715
+ * @param options Modal submission options.
3716
+ */
3638
3717
  async awaitSubmit(interaction, options) {
3639
- if (!("showModal" in interaction)) throw new Error("Interaction does not support showing modals");
3718
+ if (!interaction) throw new Error("[BetterModal] Interaction is null or undefined");
3719
+ const timeout = options?.timeout ?? DEFAULT_CONFIG.timeout;
3640
3720
  try {
3641
3721
  const modalSubmit = await interaction.awaitModalSubmit({
3642
- filter: (i) => i.customId === this.id,
3643
- time: options?.timeout ?? this.config.timeouts.modalSubmit,
3644
- ...options
3722
+ filter: (i) => i.customId === this.customId,
3723
+ time: timeout
3645
3724
  });
3646
- if (options?.autoDefer) {
3725
+ if (options?.deferUpdate) {
3647
3726
  await modalSubmit.deferUpdate();
3648
3727
  }
3649
3728
  const fields = /* @__PURE__ */ new Map();
3650
3729
  const values = [];
3651
- for (const [customId] of this.components) {
3730
+ for (const customId of this.components.keys()) {
3652
3731
  let value = null;
3653
3732
  try {
3654
3733
  value = modalSubmit.fields.getTextInputValue(customId);
@@ -3665,31 +3744,17 @@ var BetterModal = class {
3665
3744
  values.push(value);
3666
3745
  }
3667
3746
  return {
3668
- getField(customId, required) {
3669
- const value = fields.get(customId);
3670
- if (required && value === void 0) {
3671
- throw new Error(`ModalSubmitResult: Field ${customId} is required but was not found`);
3672
- }
3673
- return value;
3674
- },
3675
3747
  values,
3676
3748
  interaction: modalSubmit,
3749
+ getField: (customId) => fields.get(customId),
3677
3750
  reply: (options2) => dynaSend(modalSubmit, options2),
3678
- deferUpdate: async (options2) => await modalSubmit.deferUpdate(options2),
3679
- followUp: async (options2) => await modalSubmit.followUp(options2)
3751
+ followUp: async (options2) => dynaSend(modalSubmit, options2),
3752
+ deferUpdate: () => modalSubmit.deferUpdate()
3680
3753
  };
3681
- } catch (error) {
3754
+ } catch {
3682
3755
  return null;
3683
3756
  }
3684
3757
  }
3685
- /**
3686
- * Shows the modal and waits for the modal to be submitted, returning the component data.
3687
- * @param interaction The interaction used to show the modal
3688
- * @param options Options */
3689
- async showAndAwait(interaction, options) {
3690
- await this.show(interaction);
3691
- return this.awaitSubmit(interaction, options);
3692
- }
3693
3758
  };
3694
3759
 
3695
3760
  // src/tools/Paginator.ts
@@ -3923,7 +3988,7 @@ var Paginator = class {
3923
3988
  if (disabledNavRow.components.length > 0) {
3924
3989
  newComponents.push(disabledNavRow);
3925
3990
  }
3926
- await this.data.message.edit({ components: newComponents }).catch(Boolean);
3991
+ await this.data.message.edit({ components: newComponents });
3927
3992
  if (this.options.useReactions) {
3928
3993
  await this.nav_removeFromMessage();
3929
3994
  }
@@ -3934,7 +3999,7 @@ var Paginator = class {
3934
3999
  }
3935
4000
  break;
3936
4001
  case 2 /* DeleteMessage */:
3937
- await this.data.message.delete().catch(Boolean);
4002
+ await this.data.message.delete();
3938
4003
  break;
3939
4004
  case 3 /* DoNothing */:
3940
4005
  break;
@@ -3944,16 +4009,16 @@ var Paginator = class {
3944
4009
  async nav_removeFromMessage() {
3945
4010
  if (!this.data.message?.editable) return;
3946
4011
  if (this.options.useReactions) {
3947
- await this.data.message.reactions.removeAll().catch(Boolean);
4012
+ await this.data.message.reactions.removeAll();
3948
4013
  } else {
3949
4014
  const newComponents = this.data.message.components.filter((c) => c.type !== ComponentType2.Container);
3950
- await this.data.message.edit({ components: newComponents }).catch(Boolean);
4015
+ await this.data.message.edit({ components: newComponents });
3951
4016
  }
3952
4017
  }
3953
4018
  async nav_addReactions() {
3954
4019
  if (!this.data.message || !this.options.useReactions || !this.data.navigation.reactions.length) return;
3955
4020
  for (const r of this.data.navigation.reactions) {
3956
- await this.data.message.react(r.id).catch(Boolean);
4021
+ await this.data.message.react(r.id);
3957
4022
  }
3958
4023
  }
3959
4024
  async collect_components() {
@@ -3988,7 +4053,7 @@ var Paginator = class {
3988
4053
  }
3989
4054
  switch (i.customId) {
3990
4055
  case "ssm_chapterSelect":
3991
- await i.deferUpdate().catch(Boolean);
4056
+ await i.deferUpdate();
3992
4057
  const chapterIndex = this.chapters.findIndex(
3993
4058
  (c) => c.id === i.values[0]
3994
4059
  );
@@ -3996,25 +4061,25 @@ var Paginator = class {
3996
4061
  await this.refresh();
3997
4062
  break;
3998
4063
  case "btn_first":
3999
- await i.deferUpdate().catch(Boolean);
4064
+ await i.deferUpdate();
4000
4065
  this.callEventStack("first", this.data.page.current, this.data.page.index);
4001
4066
  await this.setPage(this.data.page.index.chapter, 0);
4002
4067
  await this.refresh();
4003
4068
  break;
4004
4069
  case "btn_back":
4005
- await i.deferUpdate().catch(Boolean);
4070
+ await i.deferUpdate();
4006
4071
  this.callEventStack("back", this.data.page.current, this.data.page.index);
4007
4072
  await this.setPage(this.data.page.index.chapter, this.data.page.index.nested - 1);
4008
4073
  await this.refresh();
4009
4074
  break;
4010
4075
  case "btn_next":
4011
- await i.deferUpdate().catch(Boolean);
4076
+ await i.deferUpdate();
4012
4077
  this.callEventStack("next", this.data.page.current, this.data.page.index);
4013
4078
  await this.setPage(this.data.page.index.chapter, this.data.page.index.nested + 1);
4014
4079
  await this.refresh();
4015
4080
  break;
4016
4081
  case "btn_last":
4017
- await i.deferUpdate().catch(Boolean);
4082
+ await i.deferUpdate();
4018
4083
  this.callEventStack("last", this.data.page.current, this.data.page.index);
4019
4084
  await this.setPage(
4020
4085
  this.data.page.index.chapter,