Safe Haskell | None |
---|---|
Language | Haskell2010 |
Command handler utilities
Synopsis
- addCommands :: (BotC r, Member ParsePrefix r) => Sem (DSLState r) a -> Sem r (Sem r (), CommandHandler, a)
- buildCommands :: forall r a. Member (Final IO) r => Sem (DSLState r) a -> Sem r (CommandHandler, a)
- buildContext :: BotC r => Message -> Text -> Command -> Text -> Sem r (Maybe Context)
- handleCommands :: (BotC r, Member ParsePrefix r) => CommandHandler -> Message -> Text -> Text -> Sem r (Either CmdInvokeFailReason Context)
- findCommand :: CommandHandler -> Text -> Either [Text] (Command, Text)
- data CmdInvokeFailReason
Documentation
addCommands :: (BotC r, Member ParsePrefix r) => Sem (DSLState r) a -> Sem r (Sem r (), CommandHandler, 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.
Custom Events
This will fire the following events:
"command-error" (
Context
,CommandError
)Fired when a command returns an error.
"command-not-found" (
Message
, [Text
])Fired when a valid prefix is used, but the command is not found.
"command-invoked"
Context
Fired when a command is successfully invoked.
buildCommands :: forall r a. Member (Final IO) r => Sem (DSLState r) a -> Sem r (CommandHandler, a) Source #
Run a command DSL, returning the constructed CommandHandler
buildContext :: BotC r => Message -> Text -> Command -> Text -> Sem r (Maybe Context) Source #
Attempt to build the context for a command
:: (BotC r, Member ParsePrefix r) | |
=> CommandHandler | |
-> Message | The message that invoked the command |
-> Text | The prefix used |
-> Text | The command string, without a prefix |
-> Sem r (Either CmdInvokeFailReason Context) |
Manages parsing messages and handling commands for a CommandHandler.
Returns Right if the command succeeded in parsing and running, Left with the reason otherwise.
findCommand :: CommandHandler -> Text -> Either [Text] (Command, 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.