ghastly (master) doxdox documentation

A powerful and flexible library for modularizing Discord.js clients.

# constructor(options, options.prefix)

Constructor.

Parameters

Name Types Description
options ClientOptions - The options for the client.
options.prefix PrefixType - The prefix for the client's dispatcher. If a function is provided, it is given a received Message as an argument and must return a boolean indicating if it passes the filter.

# Ghastly()

# this.commands()

The command registry for the client.

# this.dispatcher()

private method

The client's dispatcher.

# this.services()

The client's service container.

# constructor(filter)

Constructor.

Parameters

Name Types Description
filter Function - The filter.

# DeferredFilter()

Filters out messages based on the return value of a closure.

# test(message)

Tests a message and determines if it passes the filter.

Parameters

Name Types Description
message Message - The message.

# constructor(options, options.client, options.prefix)

Constructor.

Parameters

Name Types Description
options Object - The configuration values for the dispatcher.
options.client Ghastly - The client this dispatcher is attached to.
options.prefix PrefixType - The prefix for this dispatcher.

# createPrefixFilter(prefix)

private method

Generates a prefix filter.

Parameters

Name Types Description
prefix PrefixType - The prefix.

# dispatch(message, newMessage)

Receives message update events and dispatches commands found in the messages.

Parameters

Name Types Description
message Message - A Discord.js Message object.
newMessage Message - A Discord.js Message object. Should be received only when the message event was an update.

# Dispatcher()

# dispatchResponse(channel, response)

private method

Dispatches the given response value.

Parameters

Name Types Description
channel Channel - The channel to send the response to.
response * - The response value.

# resolveResponseType(response)

private method

Resolves a given response value to a type.

Parameters

Name Types Description
response * - The response to resolve.

# RESPONSE_TYPES()

Response type strings.

# shouldFilterEvent(message, newMessage)

private method

Determines if a message event should be filtered from the handler.

Parameters

Name Types Description
message Message - A Discord.js Message object.
newMessage Message - A Discord.js Message object. Should be received only when the message event was an update.

# shouldFilterPrefix(prefix, message)

private method

Determines if a message should be filtered from the handler based on the given prefix.

Parameters

Name Types Description
prefix RegExp - The prefix to test the message against.
message Message - The message contents.

# this.client()

The client this dispatcher is attached to.

# this.prefix()

private method

The raw prefix given as an option.

# this.prefixFilter()

private method

The prefix filter constructed from the raw prefix.

# constructor(filter)

Constructor.

Parameters

Name Types Description
filter * - The filter.

# PrefixFilter()

Filters out messages based on a prefix.

# test(message)

Tests a message and determines if it passes the filter.

Parameters

Name Types Description
message Message - The message.

# this.filter()

The filter.

# constructor(filter)

Constructor.

Parameters

Name Types Description
filter RegExp - The filter.

# RegexFilter()

Filters out messages based on a RegEx.

# test(message)

Tests a message and determines if it passes the filter.

Parameters

Name Types Description
message Message - The message.

# ConstructedService()

# es(aliases, builder)

Constructor.

Parameters

Name Types Description
aliases string[] - Aliases for this entry.
builder Function - The service builder.

# service()

The service.

# es(aliases, instance)

Constructor.

Parameters

Name Types Description
aliases string[] - Aliases for this entry.
instance * - The service instance.

# InstanceService()

# service()

The service.

# constructor(options, options.aliases, options.builder, options.instance)

Constructor.

Parameters

Name Types Description
options Object - Options for the entry.
options.aliases string[] - Aliases for this entry.
options.builder Function - The service builder. Only applicable to constructed and singleton services.
options.instance * - The service instance. Only applicable to singleton and instance services.

# Service()

# ServiceTypes()

Type identifier for services.

# this.aliases()

Aliases for this entry.

# this.builder()

The service builder. Only applicable to constructed and singleton services.

# this.instance()

The service instance. Only applicable to singleton and instance services.

# ...providers(providers)

Binds services to the service container via service providers.

Parameters

Name Types Description
providers ...serviceProvider - The service providers.

# addService(type, identifier, service)

private method

Adds a service to the container.

Parameters

Name Types Description
type string - The type of service being added.
identifier (string string[])
service * - The service being added.

# construct(identifier, builder)

Binds a service to the container which is rebuilt each time it is fetched.

Parameters

Name Types Description
identifier (string string[])
builder Function - The function which will build the service.

# constructor()

Constructor.

# get(identifier)

Fetches a service from the container, constructing it if necessary.

Parameters

Name Types Description
identifier string - The identifier of the service to fetch.

# getMainBinding(alias)

private method

Returns the main bound identifier for an alias. If the alias is already a main bound identifier, that identifier is returned directly.

Parameters

Name Types Description
alias string - The alias.

# has(identifier)

Determines if an identifier has been bound in the container.

Parameters

Name Types Description
identifier string - The identifier.

# instance(identifier, value)

Binds a service to the container which is returned as a value each time it is fetched.

Parameters

Name Types Description
identifier (string string[])
value * - The value to store as an instance.

# mainBindings()

Returns an iterator containing the main service bindings that have been registered.

# ServiceContainer()

# singleton(identifier, builder)

Binds a service to the container which is built once and cached for subsequent fetches.

Parameters

Name Types Description
identifier (string string[])
builder Function - The function which will build the service.

# this.aliases()

private method

The identifier aliases in this container.

# this.services()

private method

The services stored in this container.

# unbind(identifier)

Removes a binding from the container, along with its aliases.

Parameters

Name Types Description
identifier string - The identifier or an alias for the service.

# es(aliases, builder)

Constructor.

Parameters

Name Types Description
aliases string[] - Aliases for this entry.
builder Function - The service builder.

# service()

The service.

# SingletonService()

# this.instance()

# ...layers(layers)

Adds the given middleware to the current group middleware layers.

Parameters

Name Types Description
layers ...middlewareLayer - The layers to apply.

# add(command)

Adds a command to the group.

Parameters

Name Types Description
command CommandObject - The command.

# CommandGroup()

# constructor(name)

Constructor.

Parameters

Name Types Description
name string - The name of the group.

# this.commands()

private method

The commands that are a part of the group.

# this.middleware()

private method

The middleware applied to the group.

# this.name()

The name of the group.

# CommandObject()

# constructor(configuration)

Constructor.

Parameters

Name Types Description
configuration CommandConfiguration - The command configuration.

# generateHandler(handler, middleware)

private method

Applies middleware to a command handler and returns the resulting handler function.

Parameters

Name Types Description
handler Function - The command handler.
middleware middlewareLayer[] - The middleware to apply.

# handle(context)

Executes the command handler.

Parameters

Name Types Description
context Object - The command context.

# linkGroup(commandGroup)

Subscribes to updates from a command group.

Parameters

Name Types Description
commandGroup CommandGroup - The command group.

# this.aliases()

An array of aliases for the command.

# this.dependencies()

A mapping between service names and the context names they should be injected under for the command handler.

# this.description()

The description for the command.

# this.group()

The name of the group this command is part of, if any.

# this.handler()

private method

The command handler function with middleware applied to it.

# this.middleware()

private method

The middleware applied to the handler function.

# this.name()

The main trigger of the command, also acting as its name.

# this.originalHandler()

private method

The original command handler function.

# this.parameters()

An array of parameter definitions for the command.

# ...configurators(configurators)

Adds the given commands to the registry.

Parameters

Name Types Description
configurators ...commandConfigurator - The command configurators.

# addCommand(command)

private method

Adds a command to the registry.

Parameters

Name Types Description
command CommandObject - The command to register.

# applyGroupMiddleware(group, middleware)

Applies middleware to a command group.

Parameters

Name Types Description
group string - The command group to apply middleware to.
middleware middlewareLayer[] - The middleware to apply.

# CommandRegistry()

# constructor()

Constructor.

# es(name, aliases)

private method

Adds command aliases to the registry.

Parameters

Name Types Description
name string - The name of the command to add aliases to.
aliases string[] - The command aliases.

# get(identifier)

Gets a command from the registry.

Parameters

Name Types Description
identifier string - The identifier of the command in the registry, or an alias of a command.

# getMainName(identifier)

private method

Returns the main name associated with an identifier.

Parameters

Name Types Description
identifier string - The identifier.

# this.aliases()

private method

The command aliases stored in this registry.

# this.commands()

private method

The commands stored in this registry.

# this.groups()

private method

The command groups stored in the registry.

# ArgumentParser()

# normalizeArgumentType(type, argument)

Converts an argument to the given type, ignoring string arguments.

Parameters

Name Types Description
type string - The type the argument should be converted to.
argument string - The argument to convertType.

# parse(rules, args)

Parses an array of arguments for a command call.

Parameters

Name Types Description
rules ParsedParameter[] - An array of rules for the command being evaluated whose order matches that of the arguments.
args string - A string containing the arguments for this command.

# CommandParser()

# parse(message, prefix)

Parses the given message for a command.

Parameters

Name Types Description
message Message - The Discord.js Message object.
prefix RegExp - The prefix to remove from the message.

# ...parameters(parameters)

Validates a set of parameters.

Parameters

Name Types Description
parameters ...(ParameterDefinition string)

# ...parameters(parameters)

Parses a set of parameters into ParsedParameter objects.

Parameters

Name Types Description
parameters ...(ParameterDefinition string)

# ParameterParser()

# parseDefinition(definition)

Parses the definition portion of a parameter string.

Parameters

Name Types Description
definition string - The definition portion of a parameter string.

# parseParameter(parameter)

Parses the given command parameter definition and returns an object containing data on it.

Parameters

Name Types Description
parameter String - The command parameter definition.

# constructor(values, values.raw, values.trimmed, values.identifier, values.args, values.rawArgs)

Constructor.

Parameters

Name Types Description
values Object - The parsed data.
values.raw string - The raw message content.
values.trimmed string - The raw message content with any command prefix trimmed from the start.
values.identifier string - The name of the command being invoked.
values.args string[] - A space-delimited array of arguments that were given as part of the command.
values.rawArgs string - The delimited arguments joined together as a string.

# ParsedCommand()

# this.args()

A space-delimited array of arguments that were given as part of the command.

# this.identifier()

The name of the command being invoked.

# this.raw()

The raw message content.

# this.rawArgs()

The delimited arguments joined together as a string.

# this.trimmed()

The raw message content with any command prefix trimmed from the start.

# constructor(values)

Constructor.

Parameters

Name Types Description
values ParameterDefinition - The parsed data.

# ParsedParameter()

# this.defaultValue()

The default value of the parameter. This is non-null only if the parameter is optional. The default value for a repeatable parameter will be an array of values while non-repeatable parameters store a single primitive as a default value. The types of these values are determined by the parameters's type declaration defaulting to strings.

# this.description()

A description of the parameter.

# this.literal()

Whether or no the parameter is a literal string, i.e. takes the value of the input as given. Can only be applied to string parameters.

# this.name()

The name of the parameter.

# this.optional()

Whether or not the parameter is optional.

# this.repeatable()

Whether or not the parameter accepts a variable number of input arguments.

# this.type()

The expected type of the parameter.

# BOOL()

Alias for Boolean type.

# BOOLEAN()

Boolean type.

# convertType(value, type)

Converts a string value to a given type.

Parameters

Name Types Description
value string - The string.
type string - The type to convertType to.

# INT()

Alias for Integer type.

# INTEGER()

Integer type.

# isType(value, expectedType)

Determines if a string value is of the expected type.

Parameters

Name Types Description
value string - The string.
expectedType string - The expected type.

# NUM()

Alias for Number type.

# NUMBER()

Number type.

# resolveType(value)

Resolves a string value to a type string.

Parameters

Name Types Description
value string - The string.

# STR()

Alias for String type.

# STRING()

String type.

# ArbitraryVoiceResponse()

# constructor(context, input, options)

Constructor.

Parameters

Name Types Description
context Object - The handler context.
input string - The arbitrary input.
options StreamOptions - The options for playing the stream.

# BroadcastVoiceResponse()

# t(context, broadcast, options)

Constructor.

Parameters

Name Types Description
context Object - The handler context.
broadcast VoiceBroadcast - The broadcast.
options StreamOptions - The options for playing the stream.

# constructor(context, stream, options)

Constructor.

Parameters

Name Types Description
context Object - The handler context.
stream ReadableStream - The stream.
options StreamOptions - The options for playing the stream.

# ConvertedVoiceResponse()

# constructor(context, file, options)

Constructor.

Parameters

Name Types Description
context Object - The handler context.
file string - The absolute path to the file.
options StreamOptions - The options for playing the stream.

# FileVoiceResponse()

# constructor(context, stream, options)

Constructor.

Parameters

Name Types Description
context Object - The handler context.
stream ReadableStream - The Opus stream.
options StreamOptions - The options for playing the stream.

# OpusVoiceResponse()

# constructor(executor)

Constructor.

Parameters

Name Types Description
executor Function - The function which will handle the message response.

# respond()

Executes the message response handler.

# Response()

# this.executor()

private method

The function handling the message response.

# constructor(context, stream, options)

Constructor.

Parameters

Name Types Description
context Object - The handler context.
stream ReadableStream - The audio stream.
options StreamOptions - The options for playing the stream.

# StreamVoiceResponse()

# constructor(context, inputMethod, payload, options)

Constructor.

Parameters

Name Types Description
context Object - The handler context.
inputMethod VoiceInputMethod - The method of voice input to use.
payload * - The source of the voice input.
options StreamOptions - The options for playing the stream.

# VoiceInputMethods()

Valid voice input methods.

# VoiceResponse()

# apply(middleware)

Takes a set of middleware functions and returns a function which consumes a single command handler function and produces a new handler function with the given middleware applied to it.

Parameters

Name Types Description
middleware ...middlewareLayer - The set of middleware to apply to the input handler.

# compose(functions)

Composes a set of functions into a chain of middleware. The last function acts as the innermost part of the middleware chain. For instance, compose(f, g) returns a function with contract (...args) => f(g, ...args).

Parameters

Name Types Description
functions ...Function - The set of functions to compose.

# configure(configuration)

Provides a bridge to provide configuration data for command configurators. Consumes a config object containing the configuration data and produces a function. This function consumes a configurator and returns another configurator with the given configuration applied to it. Several configure() calls can be made successively on the returned configurator, with the outer config objects overwriting the keys in the innermost configs.

Parameters

Name Types Description
configuration Object - An object containing the configuration data to pass to the command configurator.

# DEFAULT_PROPERTIES()

Properties which are automatically handled when using object configurations.

# ArgumentParserError()

# CommandError()

# CommandParserError()

# ParameterParserError()

# expectDM()

Middleware which filters out messages not received in a DM context.

# expectGroupDM()

Middleware which filters out messages not received in a group DM context.

# expectGuild()

Middleware which filters out messages not received in a guild context.

# expectPermissions(permissions)

Middleware which filters out messages based on user permissions. Members must possess all of the given permissions to pass the filter. Only filters out messages if in a guild context.

Parameters

Name Types Description
permissions ...PermissionResolvable - The permissions required to pass the filter.

# expectRole(identifiers)

Middleware which filters out messages based on user role IDs or names. Only filters out messages if in a guild context.

Parameters

Name Types Description
identifiers ...string - The role IDs or names which are allowed to pass the filter.

# expectUser(identifiers)

Middleware which filters out messages based on user IDs or usernames and discriminators.

Parameters

Name Types Description
identifiers ...string - The user IDs or username/discriminator values that are allowed to pass the filter.

# expectChannelType(type)

Middleware which filters out messages based on the channel type.

Parameters

Name Types Description
type string - The channel type required to pass the filter.

# BaseResolver()

# constructor()

Constructor.

# resolve(options)

Validates the given options object and returns a promise.

Parameters

Name Types Description
options Object - Options object to resolve.

# this.resolver()

The resolver.

# CommandObjectResolver()

# constructor()

Constructor.

# constructor()

Constructor.

# ParameterResolver()

# createResolver()

Custom version of krachot/options-resolver that supports synchronous resolution.

# bold(text)

Formats a string as bold text.

Parameters

Name Types Description
text string - The text to format.

# code(text)

Formats a string as inline code.

Parameters

Name Types Description
text string - The text to format. Single backticks in the text do not need to be escaped.

# codeBlock(text, syntax)

Formats a string as multi-line code.

Parameters

Name Types Description
text string - The text to format.
syntax string - The syntax highlighting to use.

# italic(text)

Formats a string as italic text.

Parameters

Name Types Description
text string - The text to format.

# MarkdownFormatter()

# strikeout(text)

Formats a string as strikeout text.

Parameters

Name Types Description
text string - The text to format.

# underline(text)

Formats a string as underlined text.

Parameters

Name Types Description
text string - The text to format.

# constructor(iterable)

Constructor.

Parameters

Name Types Description
iterable * - The iterable to use to construct the map.

# delete(key)

Removes a key from the map.

Parameters

Name Types Description
key string - The key to remove.

# get(key)

Returns a value from the map.

Parameters

Name Types Description
key string - The key of the value to get.

# has(key)

Checks if a key exists in the map.

Parameters

Name Types Description
key string - The key to check.

# set(key, value)

Sets a value in the map.

Parameters

Name Types Description
key string - The key of the value to add.
value * - The value to add.

# StringMap()