calamity-0.1.14.9: A library for writing discord bots in haskell
Safe HaskellNone
LanguageHaskell2010

Calamity.Commands.Utils

Description

Command handler utilities

Synopsis

Documentation

addCommands :: (BotC r, Member ParsePrefix r) => Sem (DSLState r) a -> Sem r (Sem r (), CommandHandler, a) Source #

Construct commands and groups from a command DSL, then registers an event handler on the bot that manages running those commands.

This registers the following event handler for: "invoke-command" (Message, Text) that takes a message and the command string to invoke (without a prefix)

Returns an action to remove the event handler, and the CommandHandler that was constructed

buildCommands :: forall r a. Member (Final IO) r => Sem (DSLState r) a -> Sem r (CommandHandler, a) Source #

Run a command DSL, returning the constructed CommandHandler

buildContext :: BotC r => Message -> Text -> Command -> Text -> Sem r (Maybe Context) Source #

Attempt to build the context for a command

handleCommands Source #

Arguments

:: (BotC r, Member ParsePrefix r) 
=> CommandHandler 
-> Message

The message that invoked the command

-> Text

The prefix used

-> Text

The command string, without a prefix

-> Sem r () 

Manages parsing messages and handling commands for a CommandHandler.

Custom Events

This will fire the following events:

  1. "command-error" (Context, CommandError)

    Fired when a command returns an error.

  2. "command-not-found" [Text]

    Fired when a valid prefix is used, but the command is not found.

  3. "command-invoked" Context

    Fired when a command is successfully invoked.

findCommand :: CommandHandler -> Text -> Either [Text] (Command, Text) Source #

Attempt to find what command was used.

On error: returns the path of existing groups that were found, so "group0 group1 group2 notacommand" will error with Left ["group0", "group1", "group2"]

On success: returns the command that was invoked, and the remaining text after it.

This function isn't greedy, if you have a group and a command at the same level, this will find the command first and ignore the group.