Crux vdev 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

Gets all available commands.

Link to this callback

handle_prefixes(message) View Source (optional)
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
Link to this callback

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()}]

Gets all commands matching the given content.

Link to this callback

on_error(arg1, todo) View Source
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.

Link to this callback

prefixes() View Source
prefixes() :: [String.t() | nil]

Gets the current prefixes.

> nil is used for "no prefix"

Link to this callback

producers() View Source
producers() :: [pid()]

Gets the current producers.

Called after the command is done to send the response.

Gets the module handling rest.

> See Crux.Rest