new command option resolve types
This commit is contained in:
parent
f5111c993d
commit
6ceb1bbe77
@ -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 };
|
||||
},
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user