Safe Haskell | None |
---|---|
Language | Haskell2010 |
The client
Synopsis
- react :: forall (s :: EventType) r. (BotC r, ReactConstraints s) => (EHType s -> Sem r ()) -> Sem r (Sem r ())
- runBotIO :: forall r a. Members '[Embed IO, Final IO, CacheEff, MetricEff, LogEff] r => Token -> Intents -> Sem (SetupEff r) a -> Sem r (Maybe StartupError)
- runBotIO' :: forall r a. Members '[Embed IO, Final IO, CacheEff, MetricEff, LogEff] r => Token -> Intents -> Maybe StatusUpdateData -> Sem (SetupEff r) a -> Sem r (Maybe StartupError)
- runBotIO'' :: forall r a. Members '[LogEff, MetricEff, CacheEff, Reader Client, AtomicState EventHandlers, Embed IO, Final IO, Async] r => Token -> Intents -> Maybe StatusUpdateData -> Sem (RatelimitEff ': (TokenEff ': (Reader Client ': 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. (BotC r, ReactConstraints s) => (EHType s -> Bool) -> Sem r (EHType s)
- waitUntilM :: forall (s :: EventType) r. (BotC r, ReactConstraints s) => (EHType s -> Sem r Bool) -> Sem r (EHType s)
- data CalamityEvent
- customEvt :: forall a. Typeable a => a -> CalamityEvent
Documentation
react :: forall (s :: EventType) r. (BotC r, ReactConstraints s) => (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:
data MyCustomEvt = MyCustomEvtText
Message
react
('
CustomEvt
MyCustomEvt) $ \(MyCustomEvt 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.
:: forall r a. Members '[Embed IO, Final IO, CacheEff, MetricEff, LogEff] r | |
=> Token | |
-> Intents | The intents the bot should use |
-> Sem (SetupEff r) a | |
-> Sem r (Maybe StartupError) |
Create a bot, run your setup action, and then loop until the bot closes.
:: forall r a. Members '[Embed IO, Final IO, CacheEff, MetricEff, LogEff] r | |
=> Token | |
-> Intents | The intents the bot should use |
-> Maybe StatusUpdateData | The initial status to send to the gateway |
-> Sem (SetupEff r) a | |
-> Sem r (Maybe StartupError) |
Create a bot, run your setup action, and then loop until the bot closes.
This version allows you to specify the initial status
:: forall r a. Members '[LogEff, MetricEff, CacheEff, Reader Client, AtomicState EventHandlers, Embed IO, Final IO, Async] r | |
=> Token | |
-> Intents | The intents the bot should use |
-> Maybe StatusUpdateData | The initial status to send to the gateway |
-> Sem (RatelimitEff ': (TokenEff ': (Reader Client ': r))) a | |
-> Sem r (Maybe StartupError) |
Create a bot, run your setup action, and then loop until the bot closes.
This version only handles the
effect, allowing you to
handle the Reader
Client
yourself.AtomicState
EventHandlers
sendPresence :: BotC r => StatusUpdateData -> Sem r () Source #
Set the bot's presence on all shards.
waitUntil :: forall (s :: EventType) r. (BotC r, ReactConstraints s) => (EHType s -> Bool) -> Sem r (EHType s) Source #
Wait until an event satisfying a condition happens, then returns its parameters.
The check function for this command is pure unlike waitUntilM
This is what it would look like with s ~ '
:MessageCreateEvt
waitUntil
:: (Message
->Bool
) ->Sem
rMessage
And for s ~ '
:MessageUpdateEvt
waitUntil
:: ((Message
,Message
) ->Bool
) ->Sem
r (Message
,Message
)
Examples
Waiting for a message containing the text "hi":
f = do msg <-waitUntil
@'MessageCreateEvt
(\m ->isInfixOf
"hi" $ m ^. #content) print $ msg ^. #content
waitUntilM :: forall (s :: EventType) r. (BotC r, ReactConstraints s) => (EHType s -> Sem r Bool) -> Sem r (EHType s) Source #
Wait until an event satisfying a condition happens, then returns its parameters
This is what it would look like with s ~ '
:MessageCreateEvt
waitUntilM
:: (Message
->Sem
rBool
) ->Sem
rMessage
And for s ~ '
:MessageUpdateEvt
waitUntilM
:: ((Message
,Message
) ->Sem
rBool
) ->Sem
r (Message
,Message
)
Examples
Waiting for a message containing the text "hi":
f = do msg <-waitUntilM
@'MessageCreateEvt
(\m -> (debug
$ "got message: " <>showt
msg) >> (pure
$isInfixOf
"hi" $ m ^. #content)) print $ msg ^. #content
data CalamityEvent Source #
Dispatch | |
| |
ShutDown |