LemonGateway. Command behaviour
(lemon_gateway v0.1.0)
View Source
Behaviour for slash command plugins.
Commands are invoked when a user sends a message starting with /command_name.
They execute synchronously and can return an immediate reply or perform
background actions.
Usage
defmodule MyCommand do
use LemonGateway.Command
@impl true
def name, do: "mycommand"
@impl true
def description, do: "Does something useful"
@impl true
def handle(scope, args, context) do
{:reply, "You said: #{args}"}
end
end
Summary
Callbacks
Returns a short description of the command for help text.
Handles the command invocation.
Returns the command name (without the leading slash).
Types
Callbacks
@callback description() :: String.t()
Returns a short description of the command for help text.
@callback handle( scope :: LemonCore.ChatScope.t(), args :: String.t(), context :: context() ) :: result()
Handles the command invocation.
scope- The chat scope where the command was issuedargs- The arguments string after the command name (may be empty)context- Additional context including the original message
Returns:
:ok- Command executed, no reply needed{:reply, text}- Send text as a reply{:error, reason}- Command failed with error message
@callback name() :: String.t()
Returns the command name (without the leading slash).
Must be a lowercase string matching ^[a-z][a-z0-9_]*$.