improve result for early return
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Erik 2023-12-22 17:18:22 +02:00
parent 4c7af5c5dd
commit 662ff50bea

View File

@ -17,7 +17,8 @@ type ParseResult = {
args: ArgsResult,
command: ICommand,
subcommand: string | null,
subcommandGroup: string | null
subcommandGroup: string | null,
aborted?: boolean
}
type ParserOptions = {
@ -90,7 +91,9 @@ class Parser extends EventEmitter
{
if (!message.startsWith(prefix) || !message.length)
return null;
this.debug(`Given text: "${message}"`);
let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length);
this.debug(`Split params: "${params.join('", "')}"`);
const commandName = params.shift();
if (!commandName)
return null;
@ -110,12 +113,15 @@ class Parser extends EventEmitter
}
}
const args: ArgsResult = {};
const parseResult: ParseResult = { args, command, subcommand: null, subcommandGroup: null, aborted: false };
if (typeof commandFound === 'function' && await commandFound(command))
return null;
{
parseResult.aborted = true;
return parseResult;
}
const { subcommands, subcommandGroups } = command;
const args: ArgsResult = {};
const parseResult: ParseResult = { args, command, subcommand: null, subcommandGroup: null };
let group = null,
subcommand = null;
@ -151,6 +157,7 @@ class Parser extends EventEmitter
}
const activeCommand = subcommand || command;
this.debug(params.join(', '));
params = Util.parseQuotes(params.join(' ')).map(([ str ]: (string | boolean)[]): string => str.toString());
this.debug(`Given params: "${params.join('", "')}"`);
parseResult.args = await this.parseOptions(params, activeCommand.options, guild);