calamity-0.11.0.0: A library for writing discord bots in haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Calamity.Commands.Utils

Description

Command handler utilities

Synopsis

Documentation

addCommands :: (BotC r, Typeable c, CommandContext c, Members [ParsePrefix Message, ConstructContext (Message, User, Maybe Member) c IO ()] r) => Sem (DSLState c r) a -> Sem r (Sem r (), CommandHandler c, a) Source #

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

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

Command Resolution

To determine if a command was invoked, and if so which command was invoked, the following happens:

  1. parsePrefix is invoked, if no prefix is found: stop here.
  2. The input is read a word at a time until a matching command is found, fire the "command-not-found" event if not.
  3. A Context is built, and the command invoked.

Custom Events

This will fire the following events:

  1. CtxCommandError

    Fired when a command returns an error.

  2. CommandNotFound

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

  3. CommandInvoked

    Fired when a command is successfully invoked.

useConstantPrefix :: Text -> Sem (ParsePrefix Message ': r) a -> Sem r a Source #

A default interpretation for ParsePrefix that uses a single constant prefix.

data CmdInvokeFailReason c Source #

Constructors

NoContext 
NotFound [Text] 
CommandInvokeError c CommandError 

data CtxCommandError c Source #

Constructors

CtxCommandError 

Fields

  • ctx :: c
     
  • err :: CommandError
     

Instances

Instances details
(k ~ A_Lens, a ~ c1, b ~ c2) => LabelOptic "ctx" k (CtxCommandError c1) (CtxCommandError c2) a b Source # 
Instance details

Defined in Calamity.Commands.Utils

(k ~ A_Lens, a ~ CommandError, b ~ CommandError) => LabelOptic "err" k (CtxCommandError c) (CtxCommandError c) a b Source # 
Instance details

Defined in Calamity.Commands.Utils

Show c => Show (CtxCommandError c) Source # 
Instance details

Defined in Calamity.Commands.Utils

data CommandNotFound Source #

Constructors

CommandNotFound 

Fields

newtype CommandInvoked c Source #

Constructors

CommandInvoked 

Fields

Instances

Instances details
(k ~ An_Iso, a ~ c1, b ~ c2) => LabelOptic "ctx" k (CommandInvoked c1) (CommandInvoked c2) a b Source # 
Instance details

Defined in Calamity.Commands.Utils

Show c => Show (CommandInvoked c) Source # 
Instance details

Defined in Calamity.Commands.Utils