Safe Haskell | None |
---|---|
Language | Haskell2010 |
Command utilities
Synopsis
- type TypedCommandC ps r = (ApplyTupRes (ParserResult (ListToTup ps)) (CommandSemType r) ~ CommandForParsers ps r, Parser (ListToTup ps) r, ApplyTup (ParserResult (ListToTup ps)) (CommandSemType r), ParamNamesForParsers ps r)
- type family CommandForParsers (ps :: [Type]) r where ...
- buildCommand :: forall ps r. (Member (Final IO) r, TypedCommandC ps r) => Text -> Maybe Group -> [Check] -> (Context -> Text) -> (Context -> CommandForParsers ps r) -> Sem r Command
- buildCommand' :: Member (Final IO) r => Text -> Maybe Group -> [Check] -> [Text] -> (Context -> Text) -> (Context -> Sem r (Either CommandError a)) -> ((Context, a) -> Sem (Fail ': r) ()) -> Sem r Command
- buildParser :: Member (Final IO) r => Text -> (Context -> Sem r (Either CommandError a)) -> Sem r (Context -> IO (Either CommandError a))
- buildCallback :: Member (Final IO) r => ((Context, a) -> Sem (Fail ': r) ()) -> Sem r ((Context, a) -> IO (Maybe Text))
- runCommand :: Member (Embed IO) r => Context -> Command -> Sem r (Either CommandError ())
- invokeCommand :: Member (Embed IO) r => Context -> Command -> Sem r (Either CommandError ())
- groupPath :: Group -> [Text]
- commandPath :: Command -> [Text]
- commandParams :: Command -> Text
Documentation
type TypedCommandC ps r = (ApplyTupRes (ParserResult (ListToTup ps)) (CommandSemType r) ~ CommandForParsers ps r, Parser (ListToTup ps) r, ApplyTup (ParserResult (ListToTup ps)) (CommandSemType r), ParamNamesForParsers ps r) Source #
Some constraints used for making parameter typed commands work
type family CommandForParsers (ps :: [Type]) r where ... Source #
Transform a type level list of types implementing the parser typeclass into the type a command callback matching those parameters should be.
CommandForParsers '[] r = Sem (Fail ': r) () | |
CommandForParsers (x ': xs) r = ParserResult x -> CommandForParsers xs r |
buildCommand :: forall ps r. (Member (Final IO) r, TypedCommandC ps r) => Text -> Maybe Group -> [Check] -> (Context -> Text) -> (Context -> CommandForParsers ps r) -> Sem r Command Source #
Given the properties of a Command
, a callback, and a type level list of
the parameters, build a command by constructing a parser and wiring it up to
the callback.
Examples
Building a command that bans a user by id.
buildCommand
'[
Named
"user" (Snowflake
User
),Named
"reason" (KleeneStarConcat
Text
)] "ban"Nothing
[] (const
"Ban a user") $ ctx uid r -> case (ctx^.
#guild) ofJust
guild -> dovoid
.invoke
.reason
r $CreateGuildBan
guild uidvoid
$tell
ctx ("Banned user `"<>
showt
uid<>
"` with reason: "<>
r)Nothing
->void
$tell
Text
ctx "Can only ban users from guilds."
buildCommand' :: Member (Final IO) r => Text -> Maybe Group -> [Check] -> [Text] -> (Context -> Text) -> (Context -> Sem r (Either CommandError a)) -> ((Context, a) -> Sem (Fail ': r) ()) -> Sem r Command Source #
Given the properties of a Command
with the parser
and callback
in the
Sem
monad, build a command by transforming the Polysemy actions into IO
actions.
buildParser :: Member (Final IO) r => Text -> (Context -> Sem r (Either CommandError a)) -> Sem r (Context -> IO (Either CommandError a)) Source #
Given the name of the command the parser is for and a parser function in
the Sem
monad, build a parser by transforming the Polysemy action into an
IO action.
buildCallback :: Member (Final IO) r => ((Context, a) -> Sem (Fail ': r) ()) -> Sem r ((Context, a) -> IO (Maybe Text)) Source #
Given a callback for a command in the Sem
monad, build a command callback by
transforming the Polysemy action into an IO action.
runCommand :: Member (Embed IO) r => Context -> Command -> Sem r (Either CommandError ()) Source #
Given an invokation Context
, run a command. This does not perform the command's checks.
invokeCommand :: Member (Embed IO) r => Context -> Command -> Sem r (Either CommandError ()) Source #
Given an invokation Context
, first run all of the command's checks, then
run the command if they all pass.
commandPath :: Command -> [Text] Source #
commandParams :: Command -> Text Source #