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
|
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 prefixString The prefix to execute commands
replacerBracesObject The braces that invoke a replacer
Properties
Name Type Description openString The opening brace
closeString The closing brace
guildPrefixesPrefixList Server-specific prefixes
-
private _regexes : Object
-
Various regular expressions used internally
Properties:
Name Type Description escapablesRegExp Characters that must be escaped in Regex
dynamicsObject Regular expressions used for dynamic arguments
Properties
Name Type Description userRegExp Parse the ID out of a user mention
channelRegExp 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 commandCommand The command object
-
private _getAwait(msg, normalized) → {Await|undefined}
-
Get an awaited message
Parameters:
Name Type Description msgEris.Message The message
normalizedNormalized The normalized message content
-
async, private _implementResponse(data, options, response) → {Promise<Eris.Message>}
-
Finish environment setup for responses from a command
Parameters:
Name Type Description dataObject Situational data
optionsObject The options for the response
responseEris.Message | Error The response that was sent to Discord
Returns:
Promise<Eris.Message> -The response that was utilized
Properties:
Name Type Description data.msgEris.Message The message that executed the command
options.channelString The ID of the channel the response was sent to
options.awaitsArray<Await> | Await An action or list of actions that are awaited after the results are processed
options.reactInterfaceReactInterface A react interface that is bound to the resulting message
options.deleteAfterNumber How long until the response is deleted
-
private _loadCommand(command)
-
Load a command
Parameters:
Name Type Description commandCommand The command to load
-
private _loadReplacer(replacer)
-
Load a replacer
Parameters:
Name Type Description replacerReplacer The replacer to load
-
private _normalize(msg) → {Normalized}
-
Normalize a message's content
Parameters:
Name Type Description msgString The subject message
-
private _parseArgs(guild, command, chars) → {Array<(String|Number|Eris.Channel|Eris.User)>|undefined}
-
Parse the arguments from a message
Parameters:
Name Type Description guildEris.Guild The guild the command was initiated in
commandString The command
charsString 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 guildEris.Guild The guild the target is in
argString The argument
typeString The type of arg (user, channel)
-
private _runReplacers(guild, content) → {String}
-
Check message content for stuff to replace
Parameters:
Name Type Description guildEris.Guild The guild the message was sent in
contentString 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 awaitsArray<Await> | Await The command or a list of commands to await
optionsObject <optional>
{} The data for the awaits
Properties:
Name Type Attributes Description options._fallBackChannelString <optional>
The channel ID to listen for the message on if its not defined in the Await object
options._fallBackUserString <optional>
The user ID to listen for if its not defined in the Await object
options._triggerResponseEris.Message <optional>
The response to the command that created the awaits
-
getCommand(name) → {Command|undefined}
-
Get a command
Parameters:
Name Type Description nameString The name or an alias of the command
-
getReplacer(name) → {Command|undefined}
-
Get a replacer
Parameters:
Name Type Description nameString The name of the replacer
-
async handle(msg) → {Promise<CommandHandlerResultList>}
-
Handle an incoming Discord messages
Parameters:
Name Type Description msgEris.Message The Discord message
-
loadCommands(commands : opt)
-
Load commands
Parameters:
Name Type Attributes Default Description commandsArray<Command> | Command <optional>
[] The command(s) to load
-
loadReplacers(replacers : opt)
-
Load replacers
Parameters:
Name Type Attributes Default Description replacersArray<Replacer> | Replacer <optional>
[] The replacer(s) to load
-
setGuildPrefix(guild, prefix)
-
Set a server's custom prefix
Parameters:
Name Type Description guildString The ID of the guild
prefixString The custom prefix