calamity-0.1.11.2: A library for writing discord bots
Safe HaskellNone
LanguageHaskell2010

Calamity.Client.Client

Description

The client

Synopsis

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 -> print $ "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.

runBotIO' :: forall r a. (Members '[Embed IO, Final IO, CacheEff, MetricEff] r, Typeable (SetupEff r)) => Token -> Maybe StatusUpdateData -> Maybe Intents -> Sem (SetupEff r) a -> Sem r (Maybe StartupError) Source #

Create a bot, run your setup action, and then loop until the bot closes.

This version allows you to specify the initial status and intents.

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 t eh check. (BotC r, WaitUntilConstraints r s eh check t) => check -> Sem r t Source #

Wait until an event satisfying a condition happens, then returns it's 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 t eh ehB. (BotC r, WaitUntilMConstraints 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:

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 s a. (Typeable s, Typeable a) => a -> CalamityEvent Source #

Build a Custom CalamityEvent

You'll probably want TypeApplications to specify the type of s.

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

Examples

Building an event named "my-event":

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