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 = {
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<ParseResult | null> {
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;
}