Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Calamity commands This module exports the DSL and core types for using commands
Synopsis
- module Calamity.Commands.Dsl
- module Calamity.Commands.Help
- module Calamity.Commands.Utils
- module Calamity.Commands.Types
Documentation
module Calamity.Commands.Dsl
module Calamity.Commands.Help
module Calamity.Commands.Utils
module Calamity.Commands.Types
Commands
This module provides abstractions for writing declarative commands, that support grouping, pre-invokation checks, and automatic argument parsing by using a type level list of parameter types.
A DSL is provided in Calamity.Commands.Dsl for constructing commands declaratively.
You can implement ParameterParser
for your own types to allow them to be used
in the parameter list of commands.
A default help command is provided in Calamity.Commands.Help which can be
added just by using helpCommand
inside the command declaration DSL.
This module is pretty much a wrapper/re-export of the package CalamityCommands, look there for more documentation.
To decide which context type you want to use, and how the command prefix should be parsed, you need to handle the following effects:
Handles parsing prefixes, the
useConstantPrefix
function handles constant prefixes.Handles constructing the context and also decides which context is going to be used, calamity offers
useFullContext
which makes the contextFullContext
, anduseLightContext
which makes the contextLightContext
.
Custom Events
The event handler registered by addCommands
will fire the following custom 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.
Registered Metrics
Counter:
"commands_invoked" [name]
Incremented on each command invokation, the parameter
name
is the path/name of the invoked command.
Examples
An example of using commands:
addCommands
$ dohelpCommand
command
@'[User
] "utest" $ \ctx u -> dovoid
$tell
ctx $ "got user: "<>
showt
ugroup
"admin" $ docommand
@'[] "bye" $ \ctx -> dovoid
$tell
ctx "bye!"stopBot