diff --git a/package.json b/package.json index 6a73baa..3a8655a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "commandparser", - "version": "1.0.17", + "version": "1.0.18", "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 106fcec..52e66d9 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -60,7 +60,19 @@ class Parser extends EventEmitter { return command || null; } - async parseMessage(message: string, prefix = this.prefix, guild?: unknown): Promise { + + /** + * + * + * @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. + * @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 { if (!message.startsWith(prefix) || !message.length) return null; let params: string[] = message.replace(prefix, '').split(' ').filter((str) => str.length); @@ -69,6 +81,7 @@ class Parser extends EventEmitter { const command = this.matchCommand(commandName); if (!command) return null; + if (commandFilter && typeof commandFilter === 'function' && commandFilter(command)) return null; this.debug(`Matched command ${command.name}`); const { subcommands, subcommandGroups } = command;