allow paassing of an optional filter when parsing

This commit is contained in:
Erik 2022-07-29 21:12:56 +03:00
parent 9b95d4ec2b
commit 7d00001504
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
2 changed files with 15 additions and 2 deletions

View File

@ -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",

View File

@ -60,7 +60,19 @@ class Parser extends EventEmitter {
return command || null;
}
async parseMessage(message: string, prefix = this.prefix, guild?: unknown): Promise<ParseResult | null> {
/**
*
*
* @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<ParseResult | null>} {(Promise<ParseResult | null>)}
* @memberof Parser
*/
// eslint-disable-next-line @typescript-eslint/ban-types
async parseMessage(message: string, prefix = this.prefix, guild?: unknown, commandFilter?: Function): Promise<ParseResult | null> {
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;