This commit is contained in:
Erik 2022-07-29 19:49:50 +03:00
parent 60a67a6522
commit 455aafa1f7
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -9,6 +9,7 @@ import Util from "./util/Util";
type ParseResult = { type ParseResult = {
args: object, args: object,
command: ICommand,
subcommand: string | null, subcommand: string | null,
subcommandGroup: string | null subcommandGroup: string | null
} }
@ -52,11 +53,11 @@ class Parser extends EventEmitter {
return command || null; return command || null;
} }
async parseMessage(message: string, prefix = this.prefix, guild?: unknown) { async parseMessage(message: string, prefix = this.prefix, guild?: unknown): Promise<ParseResult | null> {
if (!message.startsWith(prefix) || !message.length) return null; if (!message.startsWith(prefix) || !message.length) return null;
let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length); let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length);
const [commandName] = params.shift() || []; const commandName = params.shift();
if (!commandName) return null; if (!commandName) return null;
const command = this.matchCommand(commandName); const command = this.matchCommand(commandName);
@ -65,7 +66,7 @@ class Parser extends EventEmitter {
this.debug(`Matched command ${command.name}`); this.debug(`Matched command ${command.name}`);
const { subcommands, subcommandGroups } = command; const { subcommands, subcommandGroups } = command;
const args: {[key: string]: CommandOption} = {}; 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, let group = null,
subcommand = 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('`, `') } }; 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;
} }