Safe Haskell | None |
---|---|
Language | Haskell2010 |
The client
Synopsis
- react :: forall (s :: EventType) r t eh ehIO. (BotC r, ReactConstraints r s eh ehIO t) => EHType s (Sem r) () -> Sem r (Sem r ())
- runBotIO :: forall r a. (Members '[Embed IO, Final IO, CacheEff, MetricEff] r, Typeable (SetupEff r)) => Token -> Sem (SetupEff r) a -> Sem r (Maybe StartupError)
- stopBot :: BotC r => Sem r ()
- sendPresence :: BotC r => StatusUpdateData -> Sem r ()
- events :: BotC r => Sem r (OutChan CalamityEvent)
- fire :: BotC r => CalamityEvent -> Sem r ()
- waitUntil :: forall (s :: EventType) r t eh ehB. (BotC r, WaitUntilConstraints r s eh ehB t) => ehB -> Sem r t
- data CalamityEvent
- customEvt :: forall s a. (Typeable s, Typeable a) => a -> CalamityEvent
Documentation
react :: forall (s :: EventType) r t eh ehIO. (BotC r, ReactConstraints r s eh ehIO t) => EHType s (Sem r) () -> Sem r (Sem r ()) Source #
Register an event handler, returning an action that removes the event handler from the bot.
Refer to EventType
for what events you can register, and EHType
for the
parameters the event handlers they receive.
You'll probably want TypeApplications
and need DataKinds
enabled to
specify the type of s
.
Examples
Reacting to every message:
react
@'MessageCreateEvt
$
msg ->$
"Got message: "<>
show
msg
Reacting to a custom event:
react
('
CustomEvt
"my-event" (Text
,Message
)) $ (s, m) ->void
$tell
Text
m ("Somebody told me to tell you about: "<>
s)
Notes
This function is pretty bad for giving nasty type errors,
since if something doesn't match then EHType
might not get substituted,
which will result in errors about parameter counts mismatching.
runBotIO :: forall r a. (Members '[Embed IO, Final IO, CacheEff, MetricEff] r, Typeable (SetupEff r)) => Token -> Sem (SetupEff r) a -> Sem r (Maybe StartupError) Source #
Create a bot, run your setup action, and then loop until the bot closes.
sendPresence :: BotC r => StatusUpdateData -> Sem r () Source #
Set the bot's presence on all shards.
events :: BotC r => Sem r (OutChan CalamityEvent) Source #
Get a copy of the event stream.
fire :: BotC r => CalamityEvent -> Sem r () Source #
waitUntil :: forall (s :: EventType) r t eh ehB. (BotC r, WaitUntilConstraints r s eh ehB t) => ehB -> Sem r t Source #
Wait until an event satisfying a condition happens, then returns it's parameters
This is what it would look like with s ~ '
:MessageCreateEvt
waitUntil
:: (Message
->Sem
rBool
) ->Sem
rMessage
And for s ~ '
:MessageUpdateEvt
waitUntil
:: (Message
->Message
->Sem
rBool
) ->Sem
r (Message
,Message
)
Examples
Waiting for a message containing the text "hi":
f = do msg <-waitUntil
@'MessageCreateEvt
(m ->pure
$isInfixOf
"hi" $ m ^. #content) print $ msg ^. #content
data CalamityEvent Source #