mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 14:04:38 +02:00
Fix
This commit is contained in:
@@ -32,15 +32,15 @@ module.exports = class CommandDispatcher {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
const content = msg.content.replace(this.commandPattern, '').trim();
|
const content = msg.content.replace(this.commandPattern, '').trim();
|
||||||
const firstResult = (content.match(argRegex) || []).map(m => m.replace(argRegex, '$1$2'));
|
const result = (content.match(argRegex) || []).map(m => m.replace(argRegex, '$1$2'));
|
||||||
const parsed = minimist(firstResult);
|
const parsed = minimist(result);
|
||||||
const result = { flags: [...parsed] };
|
const finalResult = { flags: parsed };
|
||||||
for (let i = 0; i < command.args.length; i++) {
|
for (let i = 0; i < command.args.length; i++) {
|
||||||
const arg = command.args[i];
|
const arg = command.args[i];
|
||||||
const parsedArg = result._[i];
|
const parsedArg = result._[i];
|
||||||
if (arg.isEmpty(parsedArg, msg, arg)) {
|
if (arg.isEmpty(parsedArg, msg, arg)) {
|
||||||
if (arg.default) {
|
if (arg.default) {
|
||||||
result[arg.name] = typeof arg.default === 'function' ? arg.default(msg) : arg.default;
|
finalResult[arg.name] = typeof arg.default === 'function' ? arg.default(msg) : arg.default;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
return `The "${arg.label || arg.name}" argument is required.`;
|
return `The "${arg.label || arg.name}" argument is required.`;
|
||||||
@@ -48,9 +48,9 @@ module.exports = class CommandDispatcher {
|
|||||||
}
|
}
|
||||||
const valid = await arg.validate(parsedArg, msg, arg);
|
const valid = await arg.validate(parsedArg, msg, arg);
|
||||||
if (!valid) return `An invalid value was provided for the "${arg.label || arg.name}" argument.`;
|
if (!valid) return `An invalid value was provided for the "${arg.label || arg.name}" argument.`;
|
||||||
result[arg.name] = await arg.parse(parsedArg, msg, arg);
|
finalResult[arg.name] = await arg.parse(parsedArg, msg, arg);
|
||||||
}
|
}
|
||||||
return { command, args: result };
|
return { command, args: finalResult };
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveCommand(command) {
|
resolveCommand(command) {
|
||||||
|
|||||||
Reference in New Issue
Block a user