Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
CalamityCommands.Utils
Description
Command handler utilities
Synopsis
- buildCommands :: forall r c m a x. (Monad m, MonadFix m, Member (Final m) r) => Sem (DSLState m c a r) x -> Sem r (CommandHandler m c a, x)
- processCommands :: (Monad m, Members '[ParsePrefix msg, ConstructContext msg c m a, Embed m] r, CommandContext m c a) => CommandHandler m c a -> msg -> Sem r (Maybe (Either (CmdInvokeFailReason c) (c, a)))
- handleCommands :: (Monad m, Members '[ConstructContext msg c m a, Embed m] r, CommandContext m c a) => CommandHandler m c a -> msg -> Text -> Text -> Sem r (Either (CmdInvokeFailReason c) (c, a))
- findCommand :: forall c a m. CommandHandler m c a -> Text -> Either [Text] (Command m c a, Text)
- data CmdInvokeFailReason c
Documentation
buildCommands :: forall r c m a x. (Monad m, MonadFix m, Member (Final m) r) => Sem (DSLState m c a r) x -> Sem r (CommandHandler m c a, x) Source #
Run a command DSL, returning the constructed CommandHandler
Arguments
:: (Monad m, Members '[ParsePrefix msg, ConstructContext msg c m a, Embed m] r, CommandContext m c a) | |
=> CommandHandler m c a | |
-> msg | The message that invoked the command |
-> Sem r (Maybe (Either (CmdInvokeFailReason c) (c, a))) |
Manages parsing messages and handling commands for a CommandHandler.
Returns Nothing if the prefix didn't match.
Returns Right with the context and result if the command succeeded in parsing and running, Left with the reason otherwise.
Arguments
:: (Monad m, Members '[ConstructContext msg c m a, Embed m] r, CommandContext m c a) | |
=> CommandHandler m c a | |
-> msg | The message that invoked the command |
-> Text | The prefix used |
-> Text | The command string, without a prefix |
-> Sem r (Either (CmdInvokeFailReason c) (c, a)) |
Manages finding the invoked command and parsing parameters for a CommandHandler.
Returns Right with the context and result if the command succeeded in parsing and running, Left with the reason otherwise.
findCommand :: forall c a m. CommandHandler m c a -> Text -> Either [Text] (Command m c a, 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.
data CmdInvokeFailReason c Source #
Constructors
NoContext | |
NotFound [Text] | |
CommandInvokeError c CommandError |
Instances
Show c => Show (CmdInvokeFailReason c) Source # | |
Defined in CalamityCommands.Utils Methods showsPrec :: Int -> CmdInvokeFailReason c -> ShowS # show :: CmdInvokeFailReason c -> String # showList :: [CmdInvokeFailReason c] -> ShowS # |