better func definition
This commit is contained in:
parent
7d00001504
commit
6686aa1fc1
@ -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",
|
||||
|
@ -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<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> {
|
||||
async parseMessage(message: string, prefix = this.prefix,
|
||||
guild?: unknown, commandFilter?: (command: ICommand) => boolean): Promise<ParseResult | null> {
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user