diff --git a/src/Parser.ts b/src/Parser.ts index 7430e88..3b34fbe 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -9,6 +9,7 @@ import Util from "./util/Util"; type ParseResult = { args: object, + command: ICommand, subcommand: string | null, subcommandGroup: string | null } @@ -52,11 +53,11 @@ class Parser extends EventEmitter { return command || null; } - async parseMessage(message: string, prefix = this.prefix, guild?: unknown) { + async parseMessage(message: string, prefix = this.prefix, guild?: unknown): Promise { if (!message.startsWith(prefix) || !message.length) return null; let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length); - const [commandName] = params.shift() || []; + const commandName = params.shift(); if (!commandName) return null; const command = this.matchCommand(commandName); @@ -65,7 +66,7 @@ class Parser extends EventEmitter { this.debug(`Matched command ${command.name}`); const { subcommands, subcommandGroups } = command; const args: {[key: string]: CommandOption} = {}; - const parseResult: ParseResult = { args, subcommand: null, subcommandGroup: null }; + const parseResult: ParseResult = { args, command, subcommand: null, subcommandGroup: null }; let group = null, subcommand = null; @@ -240,7 +241,7 @@ class Parser extends EventEmitter { if (strings.length) throw new Error(`Unrecognised option(s): "${strings.join('", "')}"`);//return { error: true, index: 'O_COMMANDHANDLER_UNRECOGNISED_OPTIONS', params: { opts: strings.join('`, `') } }; - return { options: args, verbose: true }; + return parseResult; }