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

Calamity.Commands.Dsl

Description

A DSL for generating commands and groups

Synopsis

Documentation

command' :: Member (Final IO) r => Text -> [Text] -> (Context -> Sem r (Either CommandError a)) -> ((Context, a) -> Sem (Fail ': r) ()) -> Sem (DSLState r) Command Source #

Given the command name and parameter names, parser and callback for a command in the Sem monad, build a command by transforming the Polysemy actions into IO actions. Then register the command.

The parent group, checks, and command help are drawn from the reader context.

command :: forall ps r. (Member (Final IO) r, TypedCommandC ps r) => Text -> (Context -> CommandForParsers ps r) -> Sem (DSLState r) Command Source #

Given the name of a command and a callback, and a type level list of the parameters, build and register a command.

Examples

Building a command that bans a user by id.

command @'[Named "user" (Snowflake User),
               Named "reason" (KleeneConcat Text)]
   "ban" $ ctx uid r -> case (ctx ^. #guild) of
     Just guild -> do
       void . invoke . reason r $ CreateGuildBan guild uid
       void $ tell ctx ("Banned user `" <> showt uid <> "` with reason: " <> r)
     Nothing -> void $ tell @Text ctx "Can only ban users from guilds."

help :: Member (Reader (Context -> Text)) r => (Context -> Text) -> Sem r a -> Sem r a Source #

Set the help for any groups or commands registered inside the given action.

requires :: [Check] -> Sem (DSLState r) a -> Sem (DSLState r) a Source #

Add to the list of checks for any commands registered inside the given action.

requires' :: Member (Final IO) r => Text -> (Context -> Sem r (Maybe Text)) -> Sem (DSLState r) a -> Sem (DSLState r) a Source #

Construct a check and add it to the list of checks for any commands registered inside the given action.

requiresPure :: [(Text, Context -> Maybe Text)] -> Sem (DSLState r) a -> Sem (DSLState r) a Source #

Construct some pure checks and add them to the list of checks for any commands registered inside the given action.

group :: Member (Final IO) r => Text -> Sem (DSLState r) a -> Sem (DSLState r) a Source #

Construct a group and place any commands registered in the given action into the new group.

This also resets the help function back to it's original value, use group' if you don't want that (i.e. your help function is context aware).

group' :: Member (Final IO) r => Text -> Sem (DSLState r) a -> Sem (DSLState r) a Source #

Construct a group and place any commands registered in the given action into the new group.

Unlike help this doesn't reset the help function back to it's original value.

type DSLState r = LocalWriter (HashMap Text Command) ': (LocalWriter (HashMap Text Group) ': (Reader (Maybe Group) ': (Reader (Context -> Text) ': (Tagged "original-help" (Reader (Context -> Text)) ': (Reader [Check] ': (Reader CommandHandler ': (Fixpoint ': r))))))) Source #

raiseDSL :: Sem r a -> Sem (DSLState r) a Source #