forked from Galactic/galactic-bot
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 };
|
if (!component) return { error: true };
|
||||||
return { value: component };
|
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) => {
|
STRING: (string) => {
|
||||||
return { error: false, value: string };
|
return { error: false, value: string };
|
||||||
},
|
},
|
||||||
|
@ -13,6 +13,10 @@ const Constants = {
|
|||||||
TIME: 3, // timestring
|
TIME: 3, // timestring
|
||||||
DATE: 3,
|
DATE: 3,
|
||||||
COMPONENT: 3,
|
COMPONENT: 3,
|
||||||
|
COMPONENTS: 3,
|
||||||
|
COMMAND: 3,
|
||||||
|
COMMANDS: 3,
|
||||||
|
MODULE: 3,
|
||||||
STRING: 3,
|
STRING: 3,
|
||||||
INTEGER: 4,
|
INTEGER: 4,
|
||||||
BOOLEAN: 5,
|
BOOLEAN: 5,
|
||||||
@ -43,10 +47,26 @@ class CommandOption {
|
|||||||
this.required = Boolean(options.required);
|
this.required = Boolean(options.required);
|
||||||
this.choices = options.choices || []; //Used for STRING/INTEGER/NUMBER types.
|
this.choices = options.choices || []; //Used for STRING/INTEGER/NUMBER types.
|
||||||
this.options = [];
|
this.options = [];
|
||||||
if (options.options) for (const opt of options.options) {
|
if (options.options)
|
||||||
if (opt instanceof CommandOption) this.options.push(opt);
|
for (const opt of options.options) {
|
||||||
else this.options.push(new CommandOption(opt));
|
// 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.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.dependsOn = options.dependsOn || []; // If an option has to be paired with another
|
||||||
|
Loading…
Reference in New Issue
Block a user