From 6ceb1bbe775cef673f18774fc12594b43c4cabae Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 9 May 2022 16:18:15 +0300 Subject: [PATCH] new command option resolve types --- .../components/observers/CommandHandler.js | 30 +++++++++++++++++++ src/structure/interfaces/CommandOption.js | 28 ++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index c1d87e6..5bc13f5 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -308,6 +308,36 @@ class CommandHandler extends Observer { if (!component) return { error: true }; return { value: component }; }, + COMPONENTS: (string) => { + const strings = string.split(' '); + const components = []; + for (const str of strings) { + const [component] = this.client.resolver.components(str, 'any'); + if (component && !components.includes(component)) components.push(component); + } + if (!components.length) return { error: true }; + return { value: components }; + }, + COMMAND: (string) => { + const [command] = this.client.resolver.components(string, 'command'); + if (!command) return { error: true }; + return { value: command }; + }, + COMMANDS: (string) => { + const strings = string.split(' '); + const commands = []; + for (const str of strings) { + const [command] = this.client.resolver.components(str, 'command'); + if(command && !commands.includes(command)) commands.push(command); + } + if(!commands.length) return { error: true }; + return { value: commands }; + }, + MODULE: (string) => { + const [module] = this.client.resolver.components(string, 'module'); + if (!module) return { error: true }; + return { value: module }; + }, STRING: (string) => { return { error: false, value: string }; }, diff --git a/src/structure/interfaces/CommandOption.js b/src/structure/interfaces/CommandOption.js index 841ef14..53b35bc 100644 --- a/src/structure/interfaces/CommandOption.js +++ b/src/structure/interfaces/CommandOption.js @@ -13,6 +13,10 @@ const Constants = { TIME: 3, // timestring DATE: 3, COMPONENT: 3, + COMPONENTS: 3, + COMMAND: 3, + COMMANDS: 3, + MODULE: 3, STRING: 3, INTEGER: 4, BOOLEAN: 5, @@ -43,10 +47,26 @@ class CommandOption { this.required = Boolean(options.required); this.choices = options.choices || []; //Used for STRING/INTEGER/NUMBER types. this.options = []; - if (options.options) for (const opt of options.options) { - if (opt instanceof CommandOption) this.options.push(opt); - else this.options.push(new CommandOption(opt)); - } + if (options.options) + for (const opt of options.options) { + // console.log(opt); + if (opt instanceof CommandOption) this.options.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.options.push(new CommandOption({ name, type: _type, description: desc, ...opts })); + } + } else this.options.push(new CommandOption(opt)); + } // 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