improve result for early return
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4c7af5c5dd
commit
662ff50bea
@ -17,7 +17,8 @@ type ParseResult = {
|
|||||||
args: ArgsResult,
|
args: ArgsResult,
|
||||||
command: ICommand,
|
command: ICommand,
|
||||||
subcommand: string | null,
|
subcommand: string | null,
|
||||||
subcommandGroup: string | null
|
subcommandGroup: string | null,
|
||||||
|
aborted?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParserOptions = {
|
type ParserOptions = {
|
||||||
@ -90,7 +91,9 @@ class Parser extends EventEmitter
|
|||||||
{
|
{
|
||||||
if (!message.startsWith(prefix) || !message.length)
|
if (!message.startsWith(prefix) || !message.length)
|
||||||
return null;
|
return null;
|
||||||
|
this.debug(`Given text: "${message}"`);
|
||||||
let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length);
|
let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length);
|
||||||
|
this.debug(`Split params: "${params.join('", "')}"`);
|
||||||
const commandName = params.shift();
|
const commandName = params.shift();
|
||||||
if (!commandName)
|
if (!commandName)
|
||||||
return null;
|
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))
|
if (typeof commandFound === 'function' && await commandFound(command))
|
||||||
return null;
|
{
|
||||||
|
parseResult.aborted = true;
|
||||||
|
return parseResult;
|
||||||
|
}
|
||||||
|
|
||||||
const { subcommands, subcommandGroups } = command;
|
const { subcommands, subcommandGroups } = command;
|
||||||
const args: ArgsResult = {};
|
|
||||||
const parseResult: ParseResult = { args, command, subcommand: null, subcommandGroup: null };
|
|
||||||
let group = null,
|
let group = null,
|
||||||
subcommand = null;
|
subcommand = null;
|
||||||
|
|
||||||
@ -151,6 +157,7 @@ class Parser extends EventEmitter
|
|||||||
}
|
}
|
||||||
|
|
||||||
const activeCommand = subcommand || command;
|
const activeCommand = subcommand || command;
|
||||||
|
this.debug(params.join(', '));
|
||||||
params = Util.parseQuotes(params.join(' ')).map(([ str ]: (string | boolean)[]): string => str.toString());
|
params = Util.parseQuotes(params.join(' ')).map(([ str ]: (string | boolean)[]): string => str.toString());
|
||||||
this.debug(`Given params: "${params.join('", "')}"`);
|
this.debug(`Given params: "${params.join('", "')}"`);
|
||||||
parseResult.args = await this.parseOptions(params, activeCommand.options, guild);
|
parseResult.args = await this.parseOptions(params, activeCommand.options, guild);
|
||||||
|
Loading…
Reference in New Issue
Block a user