From 6686aa1fc1a2e9fb0c993918696857bc7e07e4dd Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 29 Jul 2022 21:15:42 +0300 Subject: [PATCH] better func definition --- package.json | 2 +- src/Parser.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3a8655a..490bae7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commandparser", - "version": "1.0.18", + "version": "1.0.19", "description": "Parser meant to parse commands and their options for discord bots", "main": "build/index.js", "author": "Navy.gif", diff --git a/src/Parser.ts b/src/Parser.ts index 52e66d9..b0e2502 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -67,12 +67,13 @@ class Parser extends EventEmitter { * @param {string} message The text to parse command from * @param {string} [prefix=this.prefix] Optional prefix to look for in front of the message * @param {unknown} [guild] The guild to pass to the parser if the command options require values that expect guild based structures, e.g. a guild member. - * @param {Function} [commandFilter] Function for filtering out commands, useful if you want to stop the parser on a command level before argument parsin, probably saves some processing time. + * @param {Function} [commandFilter] Function for filtering out commands, useful if you want to stop the parser on a command level before argument parsin, probably saves some processing time. If the function evaluates to true the parsing stops * @return {Promise} {(Promise)} * @memberof Parser */ // eslint-disable-next-line @typescript-eslint/ban-types - async parseMessage(message: string, prefix = this.prefix, guild?: unknown, commandFilter?: Function): Promise { + async parseMessage(message: string, prefix = this.prefix, + guild?: unknown, commandFilter?: (command: ICommand) => boolean): Promise { if (!message.startsWith(prefix) || !message.length) return null; let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length); @@ -81,7 +82,7 @@ class Parser extends EventEmitter { const command = this.matchCommand(commandName); if (!command) return null; - if (commandFilter && typeof commandFilter === 'function' && commandFilter(command)) return null; + if (commandFilter && typeof commandFilter === 'function' && await commandFilter(command)) return null; this.debug(`Matched command ${command.name}`); const { subcommands, subcommandGroups } = command;