calamity-0.8.0.0: A library for writing discord bots in haskell
Safe HaskellSafe-Inferred
LanguageHaskell2010

Calamity.Client.Client

Description

The client

Synopsis

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 -> print $ "Got message: " <> show msg

Reacting to a custom event:

data MyCustomEvt = MyCustomEvt Text 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.

runBotIO Source #

Arguments

:: 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.

runBotIO' Source #

Arguments

:: 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

runBotIO'' Source #

Arguments

:: 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 Reader Client effect, allowing you to handle the AtomicState EventHandlers yourself.

stopBot :: BotC r => Sem r () Source #

Initiate shutting down the bot.

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 #

Fire an event that the bot will then handle.

Examples

Firing an event named "my-event":

fire $ customEvt @"my-event" ("aha" :: Text, msg)

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 r Message

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 r Bool) -> Sem r Message

And for s ~ 'MessageUpdateEvt:

waitUntilM :: ((Message, Message) -> Sem r Bool) -> 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 #

Constructors

Dispatch 

Fields

ShutDown 

customEvt :: forall a. Typeable a => a -> CalamityEvent Source #

Build a Custom CalamityEvent

The type of a must match up with the event handler you want to receive it.

Examples

customEvt (MyCustomEvent "lol")