Safe Haskell | None |
---|---|
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
Show c => Show (CtxCommandError c) Source # | |
Defined in Calamity.Commands.Utils showsPrec :: Int -> CtxCommandError c -> ShowS # show :: CtxCommandError c -> String # showList :: [CtxCommandError c] -> ShowS # | |
Generic (CtxCommandError c) Source # | |
Defined in Calamity.Commands.Utils type Rep (CtxCommandError c) :: Type -> Type # from :: CtxCommandError c -> Rep (CtxCommandError c) x # to :: Rep (CtxCommandError c) x -> CtxCommandError c # | |
type Rep (CtxCommandError c) Source # | |
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 #
Instances
newtype CommandInvoked c Source #
CommandInvoked | |
|
Instances
Show c => Show (CommandInvoked c) Source # | |
Defined in Calamity.Commands.Utils showsPrec :: Int -> CommandInvoked c -> ShowS # show :: CommandInvoked c -> String # showList :: [CommandInvoked c] -> ShowS # | |
Generic (CommandInvoked c) Source # | |
Defined in Calamity.Commands.Utils type Rep (CommandInvoked c) :: Type -> Type # from :: CommandInvoked c -> Rep (CommandInvoked c) x # to :: Rep (CommandInvoked c) x -> CommandInvoked c # | |
type Rep (CommandInvoked c) Source # | |
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))) |