calamity-0.1.11.1: A library for writing discord bots
Safe HaskellNone
LanguageHaskell2010

Calamity.Commands

Contents

Description

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

Synopsis

Documentation

data Context Source #

Invokation context for commands

Instances

Instances details
Show Context Source # 
Instance details

Defined in Calamity.Commands.Context

Generic Context Source # 
Instance details

Defined in Calamity.Commands.Context

Associated Types

type Rep Context :: Type -> Type #

Methods

from :: Context -> Rep Context x #

to :: Rep Context x -> Context #

TextShow Context Source # 
Instance details

Defined in Calamity.Commands.Context

Tellable Context Source # 
Instance details

Defined in Calamity.Commands.Context

Methods

getChannel :: forall (r :: [(Type -> Type) -> Type -> Type]). (BotC r, Member (Error RestError) r) => Context -> Sem r (Snowflake Channel) Source #

type Rep Context Source # 
Instance details

Defined in Calamity.Commands.Context

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 Dsl for constructing commands declaratively.

You can implement Parser for your own types to allow them to be used in the parameter list of commands.

A default help command is provided in Help which can be added just by using helpCommand inside the command declaration DSL.

Custom Events

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

  1. "command-error" (Context, CommandError)

    Fired when a command returns an error.

  2. "command-not-found" [Text]

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

  3. "command-invoked" Context

    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: " <> showtl u
  group "admin" $ do
    command @'[] "bye" $ ctx -> do
      void $ tell ctx "bye!"
      stopBot