diff --git a/src/localization/en_gb/commands/en_gb_moderation.lang b/src/localization/en_gb/commands/en_gb_moderation.lang index c617f79..896a212 100644 --- a/src/localization/en_gb/commands/en_gb_moderation.lang +++ b/src/localization/en_gb/commands/en_gb_moderation.lang @@ -350,7 +350,7 @@ Attached the JSON-formatted moderation file in the file below. You may want to format this file for easier viewing. [COMMAND_HISTORY_FAILEXPORT] -Unable to upload JSON file, the file is too large to upload here. **\`[amount/max]\`** +Unable to upload JSON file, the file is too large to upload here. **`[{amount}/{max}]`** If you absolutely need this, contact a bot developer in our support server. //Case Command diff --git a/src/structure/components/commands/moderation/History.js b/src/structure/components/commands/moderation/History.js index 9a3346d..4c20cfb 100644 --- a/src/structure/components/commands/moderation/History.js +++ b/src/structure/components/commands/moderation/History.js @@ -72,7 +72,7 @@ class HistoryCommand extends SlashCommand { const { guild } = invoker; const { user, moderator, channel, before, after, verbose, oldest, export: exp, private: priv, type: infType, pagesize, page } = opts; - if (exp?.value) return this._exportLogs(invoker, priv?.value); + if (exp?.value) return this._exportLogs(invoker, user?.value, priv?.value); const query = { guild: invoker.guild.id, @@ -215,11 +215,13 @@ class HistoryCommand extends SlashCommand { } - async _exportLogs(invoker, priv = false) { + async _exportLogs(invoker, user = null, priv = false) { const member = await invoker.memberWrapper().catch(() => null); if(!member || !member.isAdmin()) return { emoji: 'failure', index: 'COMMAND_HISTORY_NO_EXPORT_PERMS' }; - const logs = await this.client.storageManager.mongodb.infractions.find({ guild: invoker.guild.id }, { projection: { _id: 0 } }); + const logs = await this.client.storageManager.mongodb.infractions.find({ + guild: invoker.guild.id, target: user?.id + }, { projection: { _id: 0 } }); const string = JSON.stringify(logs); const attachment = new AttachmentBuilder(Buffer.from(string), { name: `${invoker.guild.id}-moderation.json` }); diff --git a/src/structure/interfaces/CommandOption.js b/src/structure/interfaces/CommandOption.js index e8c4a1e..d6b8ae0 100644 --- a/src/structure/interfaces/CommandOption.js +++ b/src/structure/interfaces/CommandOption.js @@ -99,6 +99,7 @@ class CommandOption { this.slashOption = options.slashOption || false; this.flag = options.flag ?? false; // used with message based command options this.valueOptional = options.valueOptional ?? false; + if (this.valueOptional && options.defaultValue === undefined) throw new Error(`${this.name} Optional values are only valid if passed with a default value`); this.defaultValue = options.defaultValue ?? null; this.valueAsAlias = options.choices?.length && (options.valueAsAlias ?? false); // this.words = options.words ?? null; // Used when parsing strings if the command has multiple string types that aren't flags @@ -173,10 +174,15 @@ class CommandOption { // console.log('-------PARSE BEGIN---------'); // console.log('1', this.name, this._rawValue, this.valueOptional); const { removed, value, error } = await this.types[this.type](); + if (this.valueOptional && error) { + this.value = this.defaultValue; + } else { + if(error) return { error }; + this.value = value; + } + // console.log('2', removed, value, error); // console.log('--------PARSE END----------'); - if(error) return { error }; - this.value = value; return removed || []; } diff --git a/src/structure/interfaces/commands/ModerationCommand.js b/src/structure/interfaces/commands/ModerationCommand.js index ade1577..a104ea5 100644 --- a/src/structure/interfaces/commands/ModerationCommand.js +++ b/src/structure/interfaces/commands/ModerationCommand.js @@ -29,7 +29,7 @@ class ModerationCommand extends SlashCommand { description: 'How many messages to prune', minimum: 2, maximum: 100, - flag + flag, valueOptional: true, defaultValue: 100 }, { name: 'force', type: 'BOOLEAN', diff --git a/src/structure/interfaces/commands/SettingsCommand.js b/src/structure/interfaces/commands/SettingsCommand.js index dfa3866..46832d4 100644 --- a/src/structure/interfaces/commands/SettingsCommand.js +++ b/src/structure/interfaces/commands/SettingsCommand.js @@ -36,16 +36,20 @@ class SettingsCommand extends SlashCommand { // const modules = new Set(allSettings.map((set) => set.module.name)); for (const setting of settings.values()) { - const subCommand = new CommandOption({ - name: setting.name, - description: setting.description, - type: setting.commandType, //'SUB_COMMAND', - options: setting.commandOptions, - client: this.client - }); - this.options.push(subCommand); - // Overwrite the setting options with the built CommandOption structures - setting.commandOptions = subCommand.options; + try { + const subCommand = new CommandOption({ + name: setting.name, + description: setting.description, + type: setting.commandType, //'SUB_COMMAND', + options: setting.commandOptions, + client: this.client + }); + this.options.push(subCommand); + // Overwrite the setting options with the built CommandOption structures + setting.commandOptions = subCommand.options; + } catch (err) { + this.client.logger.error(`Setting ${setting.name} errored during options build:\n${err.stack}`); + } } // for (const module of modules) {