CommandHandler(data)

The module that handles incoming commands

new CommandHandler(data)

Create a CommandHandler

Parameters:
Name Type Description
data Object

The command handler data

Properties:
Name Type Attributes Default Description
data.agent Agent <optional>

The agent managing the bot

data.client Eris.Client

The Eris client

data.commands Array<Command> | Command <optional>
[]

Array of commands to load initially

data.replacers Array<Replacer> | Replacer <optional>
[]

Array of the message content replacers to load initially

data.options Object <optional>
{}

Additional options for the command handler

Properties
Name Type Attributes Default Description
prefix String <optional>
'!'

The prefix of commands

replacerBraces Object <optional>
{}

The braces that invoke a replacer

Properties
Name Type Attributes Default Description
open String <optional>
'|'

The opening brace

close String <optional>
'|'

The closing brace

guildPrefixes PrefixList <optional>

Server-specific prefixes

_app Object <optional>

The Discord bot app info (If not supplied, the app is gotten automatically)

Members

private _aliases : Map<String, String>

Map of the command aliases

private _awaits : Map<String, AwaitData>

An object containing message data used to wait for a user's response

private _commands : Map<String, Command>

Map of the commands

private _options : Object

This options for the command handler

Properties:
Name Type Description
prefix String

The prefix to execute commands

replacerBraces Object

The braces that invoke a replacer

Properties
Name Type Description
open String

The opening brace

close String

The closing brace

guildPrefixes PrefixList

Server-specific prefixes

private _regexes : Object

Various regular expressions used internally

Properties:
Name Type Description
escapables RegExp

Characters that must be escaped in Regex

dynamics Object

Regular expressions used for dynamic arguments

Properties
Name Type Description
user RegExp

Parse the ID out of a user mention

channel RegExp

Parse the ID out of a channel mention

private _replacers : Map<String, Replacer>

Map of the message content replacers

Methods

private _commandCleanup(command)

Tidy up after a command has finished executing

Parameters:
Name Type Description
command Command

The command object

private _getAwait(msg, normalized) → {Await|undefined}

Get an awaited message

Parameters:
Name Type Description
msg Eris.Message

The message

normalized Normalized

The normalized message content

Returns:
Await | undefined -

The await

async, private _implementResponse(data, options, response) → {Promise<Eris.Message>}

Finish environment setup for responses from a command

Parameters:
Name Type Description
data Object

Situational data

options Object

The options for the response

response Eris.Message | Error

The response that was sent to Discord

Returns:
Promise<Eris.Message> -

The response that was utilized

Properties:
Name Type Description
data.msg Eris.Message

The message that executed the command

options.channel String

The ID of the channel the response was sent to

options.awaits Array<Await> | Await

An action or list of actions that are awaited after the results are processed

options.reactInterface ReactInterface

A react interface that is bound to the resulting message

options.deleteAfter Number

How long until the response is deleted

private _loadCommand(command)

Load a command

Parameters:
Name Type Description
command Command

The command to load

private _loadReplacer(replacer)

Load a replacer

Parameters:
Name Type Description
replacer Replacer

The replacer to load

private _normalize(msg) → {Normalized}

Normalize a message's content

Parameters:
Name Type Description
msg String

The subject message

Returns:
Normalized -

The processed content

private _parseArgs(guild, command, chars) → {Array<(String|Number|Eris.Channel|Eris.User)>|undefined}

Parse the arguments from a message

Parameters:
Name Type Description
guild Eris.Guild

The guild the command was initiated in

command String

The command

chars String

The argument content provided

Returns:
Array<(String|Number|Eris.Channel|Eris.User)> | undefined -

The parsed arguments or undefined if the type requirements aren't matched

private _parseDynArg(guild, arg, type)

Parse a dynamic arg (Either a mention or name)

Parameters:
Name Type Description
guild Eris.Guild

The guild the target is in

arg String

The argument

type String

The type of arg (user, channel)

private _runReplacers(guild, content) → {String}

Check message content for stuff to replace

Parameters:
Name Type Description
guild Eris.Guild

The guild the message was sent in

content String

The message content to run the replacers against

Returns:
String -

The message content after replacement

addAwaits(awaits, options : opt) → {Array<Await>}

Set an await

Parameters:
Name Type Attributes Default Description
awaits Array<Await> | Await

The command or a list of commands to await

options Object <optional>
{}

The data for the awaits

Returns:
Array<Await> -

The submitted awaits

Properties:
Name Type Attributes Description
options._fallBackChannel String <optional>

The channel ID to listen for the message on if its not defined in the Await object

options._fallBackUser String <optional>

The user ID to listen for if its not defined in the Await object

options._triggerResponse Eris.Message <optional>

The response to the command that created the awaits

getCommand(name) → {Command|undefined}

Get a command

Parameters:
Name Type Description
name String

The name or an alias of the command

Returns:
Command | undefined -

The found command

getReplacer(name) → {Command|undefined}

Get a replacer

Parameters:
Name Type Description
name String

The name of the replacer

Returns:
Command | undefined -

The found replacer

async handle(msg) → {Promise<CommandHandlerResultList>}

Handle an incoming Discord messages

Parameters:
Name Type Description
msg Eris.Message

The Discord message

Returns:
Promise<CommandHandlerResultList> -

The results of the command

loadCommands(commands : opt)

Load commands

Parameters:
Name Type Attributes Default Description
commands Array<Command> | Command <optional>
[]

The command(s) to load

loadReplacers(replacers : opt)

Load replacers

Parameters:
Name Type Attributes Default Description
replacers Array<Replacer> | Replacer <optional>
[]

The replacer(s) to load

setGuildPrefix(guild, prefix)

Set a server's custom prefix

Parameters:
Name Type Description
guild String

The ID of the guild

prefix String

The custom prefix