diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 690d03e..f908dcc 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -57,11 +57,14 @@ class CommandHandler extends Observer { }); const response = await this._parseInteraction(interaction); - if(response.error) { + if (response.error) { + let content = interaction.format(`O_COMMANDHANDLER_TYPE${response.option.type}`, { + option: response.option.name, min: response.option.minimum, max: response.option.maximum + }); + if (response.dependency) content = interaction.format(`O_COMMANDHANDLER_DEPEDENCY`, + { option: response.option.name, dependency: response.dependency }); return interaction.reply({ - content: interaction.format(`O_COMMANDHANDLER_TYPE${response.option.type}`, { - option: response.option.name, min: response.option.minimum, max: response.option.maximum - }), + content, emoji: 'failure', ephemeral: true }); @@ -114,7 +117,7 @@ class CommandHandler extends Observer { const newOption = new CommandOption({ name: matched.name, type: matched.type, minimum: matched.minimum, maximum: matched.maximum, - _rawValue: option.value + _rawValue: option.value, dependsOn: matched.dependsOn }); const parsed = await this._parseOption(interaction, newOption); @@ -130,6 +133,13 @@ class CommandHandler extends Observer { options[matched.name] = newOption; } + // Ensure option dependencies + for (const opt of Object.values(options)) { + for (const dep of opt.dependsOn) if (!options[dep]) { + return { option: opt, error: true, dependency: dep }; + } + } + if(error) return error; return { error: false, diff --git a/src/structure/interfaces/CommandOption.js b/src/structure/interfaces/CommandOption.js index 3e9f5e2..6719fd1 100644 --- a/src/structure/interfaces/CommandOption.js +++ b/src/structure/interfaces/CommandOption.js @@ -38,6 +38,8 @@ class CommandOption { this.choices = options.choices || []; //Used for STRING/INTEGER/NUMBER types. this.options = options.options || []; //Used for SUB_COMMAND/SUB_COMMAND_GROUP types. + this.dependsOn = options.dependsOn || []; // If an option has to be paired with another + this.minimum = typeof options.minimum === 'number' ? options.minimum : undefined; //Used for INTEGER/NUMBER/FLOAT types. this.maximum = typeof options.maximum === 'number' ? options.maximum : undefined; diff --git a/src/structure/interfaces/Setting.js b/src/structure/interfaces/Setting.js index a1f104e..bd8b3ea 100644 --- a/src/structure/interfaces/Setting.js +++ b/src/structure/interfaces/Setting.js @@ -93,9 +93,14 @@ class Setting extends Component { fields.push({ name: `》 ${guild.format(`GENERAL_OPTIONS`)}`, value: this.commandOptions.map( - (opt) => `**${opt.name} [${opt.type}]:** ${opt.description} ${opt.choices.length - ? `\n__${guild.format('GENERAL_CHOICES')}__: ${opt.choices.map((choice) => choice.name).join(', ')}` - : ''}` + (opt) => { + let msg = `**${opt.name} [${opt.type}]:** ${opt.description}`; + if (opt.choices.length) + msg += `\n__${guild.format('GENERAL_CHOICES')}__: ${opt.choices.map((choice) => choice.name).join(', ')}`; + if (opt.dependsOn.length) + msg += `\n${guild.format('GENERAL_DEPENDSON', { dependencies: opt.dependsOn.join('`, `') })}`; + return msg; + } ).join('\n\n') }); } @@ -159,7 +164,7 @@ class Setting extends Component { if (!message.length && !index && !embeds.length) throw new Error('Must declare either message, index or embeds'); const response = await interaction.promptMessage( index ? interaction.format(index, params) : message, - { time: time * 1000, editInteraction: true, embeds } + { time, editInteraction: true, embeds } ); if (!response) return { error: true, message: interaction.format('ERR_TIMEOUT') };