| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Calamity.Client.Client
Description
The client
Synopsis
- react :: forall (s :: EventType) r t eh ehIO. (BotC r, InsertEventHandler s, RemoveEventHandler s, eh ~ EHType s (Sem r) (), ehIO ~ EHType s IO (), Uncurry eh, Uncurried eh ~ (t -> Sem r ()), Curry (t -> IO ()), ehIO ~ Curried (t -> IO ())) => eh -> 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, InsertEventHandler s, RemoveEventHandler s, Uncurry eh, eh ~ EHType s (Sem r) (), eh ~ Curried (t -> Sem r ()), Uncurry ehB, Uncurried ehB ~ (t -> Sem r Bool), Curry (t -> IO ()), Curried (t -> IO ()) ~ EHType s IO ()) => 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, InsertEventHandler s, RemoveEventHandler s, eh ~ EHType s (Sem r) (), ehIO ~ EHType s IO (), Uncurry eh, Uncurried eh ~ (t -> Sem r ()), Curry (t -> IO ()), ehIO ~ Curried (t -> IO ())) => eh -> 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: "<>showmsg
Reacting to a custom event:
react('CustomEvt"my-event" (Text,Message)) $ (s, m) ->void$tellTextm ("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, InsertEventHandler s, RemoveEventHandler s, Uncurry eh, eh ~ EHType s (Sem r) (), eh ~ Curried (t -> Sem r ()), Uncurry ehB, Uncurried ehB ~ (t -> Sem r Bool), Curry (t -> IO ()), Curried (t -> IO ()) ~ EHType s IO ()) => ehB -> Sem r t Source #
Wait until an event satisfying a condition happens, then returns it's parameters
Sorry about this horrendous type sig, this is what it would look like with s
~ ':MessageCreateEvt
waitUntil:: (Message->SemrBool) ->SemrMessage
And for s ~ ':MessageUpdateEvt
waitUntil:: (Message->Message->SemrBool) ->Semr (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 #
Constructors
| Dispatch DispatchData | |
| ShutDown |