Crux v2020-03-17 17:55:51Z Crux.Extensions.Command.Handler behaviour View Source
Handler module serving as entry point for command pipelines.
Example
defmodule MyBot.Handler do
use Crux.Extensions.Command.Handler
def commands() do
[
MyBot.Command.Ping,
MyBot.Command.Dog
]
end
def producers(), do: MyBot.Producers.fetch()
def rest(), do: MyBot.Rest
def prefixes(), do: ["!"]
end
Link to this section Summary
Callbacks
Gets all available commands.
Removes the prefix from content.
Gets all commands matching the given content.
Called when an error occured.
Gets the current prefixes.
Gets the current producers.
Called after the command is done to send the response.
Gets the module handling rest.
Link to this section Callbacks
commands()
View Source
commands() :: [Crux.Extensions.Command.command()]
commands() :: [Crux.Extensions.Command.command()]
Gets all available commands.
handle_prefixes(message)
View Source
(optional)
handle_prefixes(message :: Crux.Structs.Message.t()) :: [
{:ok, String.t()} | :error
]
handle_prefixes(message :: Crux.Structs.Message.t()) :: [ {:ok, String.t()} | :error ]
Removes the prefix from content.
Returns a list of:
{:ok, content}
if a prefix matched:error
if a prefix did not
match_commands(content, message, shard_id)
View Source
(optional)
match_commands(
content :: String.t(),
message :: Crux.Structs.Message.t(),
shard_id :: non_neg_integer()
) :: [{Crux.Extensions.Command.command_info(), Crux.Extensions.Command.t()}]
match_commands( content :: String.t(), message :: Crux.Structs.Message.t(), shard_id :: non_neg_integer() ) :: [{Crux.Extensions.Command.command_info(), Crux.Extensions.Command.t()}]
Gets all commands matching the given content.
on_error(arg1, todo)
View Source
on_error(Crux.Extensions.Command.t(), todo :: any()) :: any()
on_error(Crux.Extensions.Command.t(), todo :: any()) :: any()
Called when an error occured.
> Not implementing this function causes any errors to terminate the handling process.
prefixes()
View Source
prefixes() :: [String.t() | nil]
prefixes() :: [String.t() | nil]
Gets the current prefixes.
> nil
is used for "no prefix"
producers()
View Source
producers() :: [pid()]
producers() :: [pid()]
Gets the current producers.
respond(arg1)
View Source
(optional)
respond(Crux.Extensions.Command.t()) :: any()
respond(Crux.Extensions.Command.t()) :: any()
Called after the command is done to send the response.
rest()
View Source
rest() :: module()
rest() :: module()
Gets the module handling rest.
> See Crux.Rest