Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Command handler utilities
Synopsis
- 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)
- useConstantPrefix :: Text -> Sem (ParsePrefix Message ': r) a -> Sem r a
- data CmdInvokeFailReason c
- = NoContext
- | NotFound [Text]
- | CommandInvokeError c CommandError
- data CtxCommandError c = CtxCommandError {}
- data CommandNotFound = CommandNotFound {}
- newtype CommandInvoked c = CommandInvoked {
- ctx :: c
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:
parsePrefix
is invoked, if no prefix is found: stop here.- The input is read a word at a time until a matching command is found, fire the "command-not-found" event if not.
- A
Context
is built, and the command invoked.
Custom Events
This will fire the following events:
Fired when a command returns an error.
Fired when a valid prefix is used, but the command is not found.
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 #
NoContext | |
NotFound [Text] | |
CommandInvokeError c CommandError |
data CtxCommandError c Source #
Instances
(k ~ A_Lens, a ~ c1, b ~ c2) => LabelOptic "ctx" k (CtxCommandError c1) (CtxCommandError c2) a b Source # | |
Defined in Calamity.Commands.Utils labelOptic :: Optic k NoIx (CtxCommandError c1) (CtxCommandError c2) a b # | |
(k ~ A_Lens, a ~ CommandError, b ~ CommandError) => LabelOptic "err" k (CtxCommandError c) (CtxCommandError c) a b Source # | |
Defined in Calamity.Commands.Utils labelOptic :: Optic k NoIx (CtxCommandError c) (CtxCommandError c) a b # | |
Show c => Show (CtxCommandError c) Source # | |
Defined in Calamity.Commands.Utils showsPrec :: Int -> CtxCommandError c -> ShowS # show :: CtxCommandError c -> String # showList :: [CtxCommandError c] -> ShowS # |
data CommandNotFound Source #
Instances
newtype CommandInvoked c Source #
CommandInvoked | |
|
Instances
(k ~ An_Iso, a ~ c1, b ~ c2) => LabelOptic "ctx" k (CommandInvoked c1) (CommandInvoked c2) a b Source # | |
Defined in Calamity.Commands.Utils labelOptic :: Optic k NoIx (CommandInvoked c1) (CommandInvoked c2) a b # | |
Show c => Show (CommandInvoked c) Source # | |
Defined in Calamity.Commands.Utils showsPrec :: Int -> CommandInvoked c -> ShowS # show :: CommandInvoked c -> String # showList :: [CommandInvoked c] -> ShowS # |