From 662ff50bea8af8c922b750d5d17304680fa10097 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 22 Dec 2023 17:18:22 +0200 Subject: [PATCH] improve result for early return --- src/Parser.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Parser.ts b/src/Parser.ts index 43175f9..244e174 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -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);