calamity-0.8.0.0: A library for writing discord bots in haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Calamity.Commands

Contents

Description

Calamity commands This module exports the DSL and core types for using commands

Synopsis

Documentation

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:

  1. ParsePrefix

    Handles parsing prefixes, the useConstantPrefix function handles constant prefixes.

  2. ConstructContext

    Handles constructing the context and also decides which context is going to be used, calamity offers useFullContext which makes the context FullContext, and useLightContext which makes the context LightContext.

Custom Events

The event handler registered by addCommands will fire the following custom events:

  1. CtxCommandError

    Fired when a command returns an error.

  2. CommandNotFound

    Fired when a valid prefix is used, but the command is not found.

  3. CommandInvoked

    Fired when a command is successfully invoked.

Registered Metrics

  1. 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 $ do
  helpCommand
  command @'[User] "utest" $ \ctx u -> do
    void $ tell ctx $ "got user: " <> showt u
  group "admin" $ do
    command @'[] "bye" $ \ctx -> do
      void $ tell ctx "bye!"
      stopBot