Home Manual Reference Source Repository
import CommandDispatcher from 'discord-graf/src/commands/dispatcher.js'
public class | source

CommandDispatcher

Extends:

events~EventEmitter → CommandDispatcher

Handles parsing messages and running commands from them

Static Method Summary

Static Public Methods
public static

Makes a command result object from a command's run result

public static

parseArgs(argString: string, argCount: number, allowSingleQuote: boolean): string[]

Parses an argument string into an array of arguments

Constructor Summary

Public Constructor
public

Member Summary

Public Members
public

bot: Bot

Method Summary

Public Methods
public

handleMessage(message: Message, oldMessage: Message): Promise<null>

Handle a new message or a message update

public

Handle a message result

public

run(command: Command, args: string[], fromPattern: boolean, message: Message): Promise<CommandResult>

Run a command

public

sendMessages(message: Message, contents: string[], type: string): Promise<Message[]>

Sends messages

public

Sends messages for a command result

public

updateMessages(message: Message, oldMessages: Message[], contents: string[], type: string): Promise<Message[]>

Updates messages

public

Updates messages for a command result

Static Public Methods

public static makeResultObject(result: CommandResult | string[] | string): CommandResult source

Makes a command result object from a command's run result

Params:

NameTypeAttributeDescription
result CommandResult | string[] | string

The command's run result

Return:

CommandResult

The result object

public static parseArgs(argString: string, argCount: number, allowSingleQuote: boolean): string[] source

Parses an argument string into an array of arguments

Params:

NameTypeAttributeDescription
argString string

The argument string to parse

argCount number
  • optional

The number of arguments to extract from the string

allowSingleQuote boolean
  • optional
  • default: true

Whether or not single quotes should be allowed to wrap arguments, in addition to double quotes

Return:

string[]

The array of arguments

Public Constructors

public constructor(bot: Bot) source

Params:

NameTypeAttributeDescription
bot Bot

The bot the dispatcher is for

Public Members

public bot: Bot source

Public Methods

public handleMessage(message: Message, oldMessage: Message): Promise<null> source

Handle a new message or a message update

Params:

NameTypeAttributeDescription
message Message

The message to handle

oldMessage Message
  • optional

The old message before the update

Return:

Promise<null>

No value

public handleMessageResult(message: Message, result: CommandResult, oldResult: CommandResult): Promise<null> source

Handle a message result

Params:

NameTypeAttributeDescription
message Message

The message the result is from

result CommandResult
  • nullable: true

The result

oldResult CommandResult
  • optional

The old result

Return:

Promise<null>

No value

public run(command: Command, args: string[], fromPattern: boolean, message: Message): Promise<CommandResult> source

Run a command

Params:

NameTypeAttributeDescription
command Command

The command to run

args string[]

The arguments for the command

fromPattern boolean

Whether or not the arguments are from a pattern match

message Message

The message that triggered the run

Return:

Promise<CommandResult>

The result of running the command

Emit:

*

commandRun When a command is run, with the command, result, message, args, and fromPattern passed

*

commandError When an error occurs while running a command, with the command, message, args, and fromPattern passed

public sendMessages(message: Message, contents: string[], type: string): Promise<Message[]> source

Sends messages

Params:

NameTypeAttributeDescription
message Message

The message the messages are being sent in response to

contents string[]

Contents of the messages to send

type string

One of 'plain', 'reply', or 'direct'

Return:

Promise<Message[]>

The sent messages

public sendMessagesForResult(message: Message, result: CommandResult): Promise<null> source

Sends messages for a command result

Params:

NameTypeAttributeDescription
message Message

The message the result is for

result CommandResult

The command result

Return:

Promise<null>

No value

public updateMessages(message: Message, oldMessages: Message[], contents: string[], type: string): Promise<Message[]> source

Updates messages

Params:

NameTypeAttributeDescription
message Message

The message the old messages are being updated in response to

oldMessages Message[]

The old messages to update

contents string[]

Contents of the messages to send

type string

One of 'plain', 'reply', or 'direct'

Return:

Promise<Message[]>

The updated messages

public updateMessagesForResult(message: Message, result: CommandResult, oldResult: CommandResult): Promise<null> source

Updates messages for a command result

Params:

NameTypeAttributeDescription
message Message

The message the result is for

result CommandResult

The command result

oldResult CommandResult

The old command result

Return:

Promise<null>

No value