calamity-0.3.0.0: A library for writing discord bots in haskell
Safe HaskellNone
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
Show c => Show (CtxCommandError c) Source # 
Instance details

Defined in Calamity.Commands.Utils

Generic (CtxCommandError c) Source # 
Instance details

Defined in Calamity.Commands.Utils

Associated Types

type Rep (CtxCommandError c) :: Type -> Type #

type Rep (CtxCommandError c) Source # 
Instance details

Defined in Calamity.Commands.Utils

type Rep (CtxCommandError c) = D1 ('MetaData "CtxCommandError" "Calamity.Commands.Utils" "calamity-0.3.0.0-inplace" 'False) (C1 ('MetaCons "CtxCommandError" 'PrefixI 'True) (S1 ('MetaSel ('Just "ctx") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 c) :*: S1 ('MetaSel ('Just "err") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedStrict) (Rec0 CommandError)))

data CommandNotFound Source #

Constructors

CommandNotFound 

Fields

Instances

Instances details
Show CommandNotFound Source # 
Instance details

Defined in Calamity.Commands.Utils

Generic CommandNotFound Source # 
Instance details

Defined in Calamity.Commands.Utils

Associated Types

type Rep CommandNotFound :: Type -> Type #

type Rep CommandNotFound Source # 
Instance details

Defined in Calamity.Commands.Utils

newtype CommandInvoked c Source #

Constructors

CommandInvoked 

Fields

Instances

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

Defined in Calamity.Commands.Utils

Generic (CommandInvoked c) Source # 
Instance details

Defined in Calamity.Commands.Utils

Associated Types

type Rep (CommandInvoked c) :: Type -> Type #

type Rep (CommandInvoked c) Source # 
Instance details

Defined in Calamity.Commands.Utils

type Rep (CommandInvoked c) = D1 ('MetaData "CommandInvoked" "Calamity.Commands.Utils" "calamity-0.3.0.0-inplace" 'True) (C1 ('MetaCons "CommandInvoked" 'PrefixI 'True) (S1 ('MetaSel ('Just "ctx") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 c)))