From 71fed41529bd910b4abcdaa5d80ee962e63dc951 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 9 May 2022 16:18:22 +0300 Subject: [PATCH] improvements --- src/structure/interfaces/Setting.js | 35 +++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/structure/interfaces/Setting.js b/src/structure/interfaces/Setting.js index 2ebc7df..4c9ad7b 100644 --- a/src/structure/interfaces/Setting.js +++ b/src/structure/interfaces/Setting.js @@ -7,6 +7,7 @@ const Component = require("./Component.js"); // Imports to enable JSDocs typing // eslint-disable-next-line no-unused-vars const InteractionWrapper = require("../client/wrappers/InteractionWrapper.js"); +const CommandOption = require('./CommandOption.js'); // eslint-disable-next-line no-unused-vars // const { DiscordClient } = require("../DiscordClient.js"); @@ -69,7 +70,28 @@ class Setting extends Component { this.default = { [this.name]: options.default || {} }; this.definitions = options.definitions || {}; // Used for the API for field definitions - this.commandOptions = options.commandOptions || []; + this.commandOptions = []; + this.commandType = options.commandType || 'SUB_COMMAND'; + + if (options.commandOptions) + for (const opt of options.commandOptions) { + if (opt instanceof CommandOption) this.commandOptions.push(opt); + else if (opt.name instanceof Array) { + const { name: names, description, type, ...opts } = opt; + for (const name of names) { + // console.log(name); + const index = names.indexOf(name); + let desc = description, + _type = type; + if (description instanceof Array) desc = description[index] || 'Missing description'; + if (type instanceof Array) { + _type = type[index]; + if (!_type) throw new Error(`Missing type for option ${name} in command ${this.name}`); + } + this.commandOptions.push(new CommandOption({ name, type: _type, description: desc, ...opts })); + } + } else this.commandOptions.push(new CommandOption(opt)); + } this.clientPermissions = options.clientPermissions || []; this.memberPermissions = options.memberPermissions || []; // Idk if we'll end up using this but it's here anyway @@ -91,14 +113,19 @@ class Setting extends Component { } // , verbose = false -- unsure if this is a necessary argument anymore - usageEmbed(guild) { + // eslint-disable-next-line no-unused-vars + usageEmbed(guild, verbose = false, subcommand = null) { const fields = []; + let options = this.commandOptions; + // eslint-disable-next-line prefer-destructuring + if (subcommand) options = subcommand.options; + + if (options.length) { - if (this.commandOptions.length) { fields.push({ name: `》 ${guild.format(`GENERAL_OPTIONS`)}`, - value: this.commandOptions.map( + value: options.map( (opt) => { let msg = `**${opt.name} [${opt.type}]:** ${opt.description}`; if (opt.choices.length)