{-# OPTIONS_GHC -Wno-name-shadowing #-}

-- | The client
module Calamity.Client.Client (
  react,
  runBotIO,
  runBotIO',
  runBotIO'',
  stopBot,
  sendPresence,
  events,
  fire,
  waitUntil,
  waitUntilM,
  CalamityEvent (Dispatch, ShutDown),
  customEvt,
) where

import Calamity.Cache.Eff
import Calamity.Client.ShardManager
import Calamity.Client.Types
import Calamity.Gateway.DispatchEvents
import Calamity.Gateway.Intents
import Calamity.Gateway.Types
import Calamity.HTTP.Internal.Ratelimit
import Calamity.Internal.ConstructorName
import Calamity.Internal.RunIntoIO
import Calamity.Internal.SnowflakeMap qualified as SM
import Calamity.Internal.UnixTimestamp
import Calamity.Internal.Updateable
import Calamity.Internal.Utils
import Calamity.Metrics.Eff
import Calamity.Types.LogEff
import Calamity.Types.Model.Channel
import Calamity.Types.Model.Guild
import Calamity.Types.Model.Presence (Presence (..))
import Calamity.Types.Model.User
import Calamity.Types.Model.Voice qualified as V
import Calamity.Types.Snowflake
import Calamity.Types.Token
import Calamity.Types.TokenEff
import Control.Concurrent.Chan.Unagi
import Control.Concurrent.MVar
import Control.Concurrent.STM
import Control.Exception (SomeException)
import Control.Monad
import Data.Default.Class
import Data.Dynamic
import Data.Foldable
import Data.IORef
import Data.Maybe
import Data.Proxy
import Data.Text qualified as T
import Data.Time.Clock.POSIX
import Df1 qualified
import Di.Core qualified as DC
import DiPolysemy qualified as Di
import Optics
import Polysemy qualified as P
import Polysemy.Async qualified as P
import Polysemy.AtomicState qualified as P
import Polysemy.Error qualified as P
import Polysemy.Fail qualified as P
import Polysemy.Reader qualified as P
import Polysemy.Resource qualified as P
import TextShow (TextShow (showt))

timeA :: P.Member (P.Embed IO) r => P.Sem r a -> P.Sem r (Double, a)
timeA :: forall (r :: EffectRow) (a :: OpticKind).
Member (Embed IO) r =>
Sem r a -> Sem r (Double, a)
timeA Sem r a
m = do
  POSIXTime
start <- IO POSIXTime -> Sem r POSIXTime
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed IO POSIXTime
getPOSIXTime
  a
res <- Sem r a
m
  POSIXTime
end <- IO POSIXTime -> Sem r POSIXTime
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed IO POSIXTime
getPOSIXTime
  let duration :: Double
duration = Rational -> Double
forall (a :: OpticKind). Fractional a => Rational -> a
fromRational (Rational -> Double)
-> (POSIXTime -> Rational) -> POSIXTime -> Double
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. POSIXTime -> Rational
forall (a :: OpticKind). Real a => a -> Rational
toRational (POSIXTime -> Double) -> POSIXTime -> Double
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ POSIXTime
end POSIXTime -> POSIXTime -> POSIXTime
forall (a :: OpticKind). Num a => a -> a -> a
- POSIXTime
start
  (Double, a) -> Sem r (Double, a)
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Double
duration, a
res)

newClient :: Token -> Maybe (DC.Di Df1.Level Df1.Path Df1.Message) -> IO Client
newClient :: Token -> Maybe (Di Level Path Message) -> IO Client
newClient Token
token Maybe (Di Level Path Message)
initialDi = do
  TVar [(InChan ControlMessage, Async (Maybe ()))]
shards' <- [(InChan ControlMessage, Async (Maybe ()))]
-> IO (TVar [(InChan ControlMessage, Async (Maybe ()))])
forall (a :: OpticKind). a -> IO (TVar a)
newTVarIO []
  MVar Int
numShards' <- IO (MVar Int)
forall (a :: OpticKind). IO (MVar a)
newEmptyMVar
  RateLimitState
rlState' <- IO RateLimitState
newRateLimitState
  (InChan CalamityEvent
inc, OutChan CalamityEvent
outc) <- IO (InChan CalamityEvent, OutChan CalamityEvent)
forall (a :: OpticKind). IO (InChan a, OutChan a)
newChan
  IORef Integer
ehidCounter <- Integer -> IO (IORef Integer)
forall (a :: OpticKind). a -> IO (IORef a)
newIORef Integer
0

  Client -> IO Client
forall (a :: OpticKind). a -> IO a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Client -> IO Client) -> Client -> IO Client
forall (a :: OpticKind) b. (a -> b) -> a -> b
$
    TVar [(InChan ControlMessage, Async (Maybe ()))]
-> MVar Int
-> Token
-> RateLimitState
-> InChan CalamityEvent
-> OutChan CalamityEvent
-> IORef Integer
-> Maybe (Di Level Path Message)
-> Client
Client
      TVar [(InChan ControlMessage, Async (Maybe ()))]
shards'
      MVar Int
numShards'
      Token
token
      RateLimitState
rlState'
      InChan CalamityEvent
inc
      OutChan CalamityEvent
outc
      IORef Integer
ehidCounter
      Maybe (Di Level Path Message)
initialDi

-- | Create a bot, run your setup action, and then loop until the bot closes.
runBotIO ::
  forall r a.
  (P.Members '[P.Embed IO, P.Final IO, CacheEff, MetricEff, LogEff] r) =>
  Token ->
  -- | The intents the bot should use
  Intents ->
  P.Sem (SetupEff r) a ->
  P.Sem r (Maybe StartupError)
runBotIO :: forall (r :: EffectRow) (a :: OpticKind).
Members '[Embed IO, Final IO, CacheEff, MetricEff, LogEff] r =>
Token
-> Intents -> Sem (SetupEff r) a -> Sem r (Maybe StartupError)
runBotIO Token
token Intents
intents = Token
-> Intents
-> Maybe StatusUpdateData
-> Sem (SetupEff r) a
-> Sem r (Maybe StartupError)
forall (r :: EffectRow) (a :: OpticKind).
Members '[Embed IO, Final IO, CacheEff, MetricEff, LogEff] r =>
Token
-> Intents
-> Maybe StatusUpdateData
-> Sem (SetupEff r) a
-> Sem r (Maybe StartupError)
runBotIO' Token
token Intents
intents Maybe StatusUpdateData
forall (a :: OpticKind). Maybe a
Nothing

resetDi :: BotC r => P.Sem r a -> P.Sem r a
resetDi :: forall (r :: EffectRow) (a :: OpticKind).
BotC r =>
Sem r a -> Sem r a
resetDi Sem r a
m = do
  Maybe (Di Level Path Message)
initialDi <- (Client -> Maybe (Di Level Path Message))
-> Sem r (Maybe (Di Level Path Message))
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client
-> Optic' A_Lens NoIx Client (Maybe (Di Level Path Message))
-> Maybe (Di Level Path Message)
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Client (Maybe (Di Level Path Message))
#initialDi)
  (Di Level Path Message -> Di Level Path Message)
-> Sem r a -> Sem r a
forall (level :: OpticKind) (path :: OpticKind) (msg :: OpticKind)
       (r :: EffectRow) (a :: OpticKind).
Member (Di level path msg) r =>
(Di level path msg -> Di level path msg) -> Sem r a -> Sem r a
Di.local (Di Level Path Message
-> Maybe (Di Level Path Message) -> Di Level Path Message
forall (a :: OpticKind). a -> Maybe a -> a
`fromMaybe` Maybe (Di Level Path Message)
initialDi) Sem r a
m

interpretRatelimitViaClient :: P.Member (P.Reader Client) r => P.Sem (RatelimitEff ': r) a -> P.Sem r a
interpretRatelimitViaClient :: forall (r :: EffectRow) (a :: OpticKind).
Member (Reader Client) r =>
Sem (RatelimitEff : r) a -> Sem r a
interpretRatelimitViaClient =
  (forall (rInitial :: EffectRow) (x :: OpticKind).
 RatelimitEff (Sem rInitial) x -> Sem r x)
-> Sem (RatelimitEff : r) a -> Sem r a
forall (e :: (OpticKind -> OpticKind) -> OpticKind -> OpticKind)
       (r :: EffectRow) (a :: OpticKind).
FirstOrder e "interpret" =>
(forall (rInitial :: EffectRow) (x :: OpticKind).
 e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
P.interpret
    ( \case
        RatelimitEff (Sem rInitial) x
GetRatelimitState -> (Client -> x) -> Sem r x
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client -> Optic' A_Lens NoIx Client x -> x
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Client x
#rlState)
    )

interpretTokenViaClient :: P.Member (P.Reader Client) r => P.Sem (TokenEff ': r) a -> P.Sem r a
interpretTokenViaClient :: forall (r :: EffectRow) (a :: OpticKind).
Member (Reader Client) r =>
Sem (TokenEff : r) a -> Sem r a
interpretTokenViaClient =
  (forall (rInitial :: EffectRow) (x :: OpticKind).
 TokenEff (Sem rInitial) x -> Sem r x)
-> Sem (TokenEff : r) a -> Sem r a
forall (e :: (OpticKind -> OpticKind) -> OpticKind -> OpticKind)
       (r :: EffectRow) (a :: OpticKind).
FirstOrder e "interpret" =>
(forall (rInitial :: EffectRow) (x :: OpticKind).
 e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
P.interpret
    ( \case
        TokenEff (Sem rInitial) x
GetBotToken -> (Client -> x) -> Sem r x
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client -> Optic' A_Lens NoIx Client x -> x
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Client x
#token)
    )

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

 This version allows you to specify the initial status
-}
runBotIO' ::
  forall r a.
  (P.Members '[P.Embed IO, P.Final IO, CacheEff, MetricEff, LogEff] r) =>
  Token ->
  -- | The intents the bot should use
  Intents ->
  -- | The initial status to send to the gateway
  Maybe StatusUpdateData ->
  P.Sem (SetupEff r) a ->
  P.Sem r (Maybe StartupError)
runBotIO' :: forall (r :: EffectRow) (a :: OpticKind).
Members '[Embed IO, Final IO, CacheEff, MetricEff, LogEff] r =>
Token
-> Intents
-> Maybe StatusUpdateData
-> Sem (SetupEff r) a
-> Sem r (Maybe StartupError)
runBotIO' Token
token Intents
intents Maybe StatusUpdateData
status Sem
  (RatelimitEff
     : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
  a
setup = do
  Maybe (Di Level Path Message)
initialDi <- Sem r (Maybe (Di Level Path Message))
forall (level :: OpticKind) (path :: OpticKind) (msg :: OpticKind)
       (r :: EffectRow).
Member (Di level path msg) r =>
Sem r (Maybe (Di level path msg))
Di.fetch
  Client
client <- IO Client -> Sem r Client
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO Client -> Sem r Client) -> IO Client -> Sem r Client
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Token -> Maybe (Di Level Path Message) -> IO Client
newClient Token
token Maybe (Di Level Path Message)
initialDi
  TVar EventHandlers
handlers <- IO (TVar EventHandlers) -> Sem r (TVar EventHandlers)
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO (TVar EventHandlers) -> Sem r (TVar EventHandlers))
-> IO (TVar EventHandlers) -> Sem r (TVar EventHandlers)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ EventHandlers -> IO (TVar EventHandlers)
forall (a :: OpticKind). a -> IO (TVar a)
newTVarIO EventHandlers
forall (a :: OpticKind). Default a => a
def
  Sem (Async : r) (Maybe StartupError) -> Sem r (Maybe StartupError)
forall (r :: EffectRow) (a :: OpticKind).
Member (Final IO) r =>
Sem (Async : r) a -> Sem r a
P.asyncToIOFinal (Sem (Async : r) (Maybe StartupError)
 -> Sem r (Maybe StartupError))
-> (Sem
      (RatelimitEff
         : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
      (Maybe StartupError)
    -> Sem (Async : r) (Maybe StartupError))
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
-> Sem r (Maybe StartupError)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. TVar EventHandlers
-> Sem (AtomicState EventHandlers : Async : r) (Maybe StartupError)
-> Sem (Async : r) (Maybe StartupError)
forall (r :: EffectRow) (s :: OpticKind) (a :: OpticKind).
Member (Embed IO) r =>
TVar s -> Sem (AtomicState s : r) a -> Sem r a
P.runAtomicStateTVar TVar EventHandlers
handlers (Sem (AtomicState EventHandlers : Async : r) (Maybe StartupError)
 -> Sem (Async : r) (Maybe StartupError))
-> (Sem
      (RatelimitEff
         : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
      (Maybe StartupError)
    -> Sem
         (AtomicState EventHandlers : Async : r) (Maybe StartupError))
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
-> Sem (Async : r) (Maybe StartupError)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Client
-> Sem
     (Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
-> Sem (AtomicState EventHandlers : Async : r) (Maybe StartupError)
forall (i :: OpticKind) (r :: EffectRow) (a :: OpticKind).
i -> Sem (Reader i : r) a -> Sem r a
P.runReader Client
client (Sem
   (Reader Client : AtomicState EventHandlers : Async : r)
   (Maybe StartupError)
 -> Sem
      (AtomicState EventHandlers : Async : r) (Maybe StartupError))
-> (Sem
      (RatelimitEff
         : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
      (Maybe StartupError)
    -> Sem
         (Reader Client : AtomicState EventHandlers : Async : r)
         (Maybe StartupError))
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
-> Sem (AtomicState EventHandlers : Async : r) (Maybe StartupError)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Sem
  (TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
  (Maybe StartupError)
-> Sem
     (Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
forall (r :: EffectRow) (a :: OpticKind).
Member (Reader Client) r =>
Sem (TokenEff : r) a -> Sem r a
interpretTokenViaClient (Sem
   (TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
   (Maybe StartupError)
 -> Sem
      (Reader Client : AtomicState EventHandlers : Async : r)
      (Maybe StartupError))
-> (Sem
      (RatelimitEff
         : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
      (Maybe StartupError)
    -> Sem
         (TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
         (Maybe StartupError))
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
-> Sem
     (Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Sem
  (RatelimitEff
     : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
  (Maybe StartupError)
-> Sem
     (TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
forall (r :: EffectRow) (a :: OpticKind).
Member (Reader Client) r =>
Sem (RatelimitEff : r) a -> Sem r a
interpretRatelimitViaClient (Sem
   (RatelimitEff
      : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
   (Maybe StartupError)
 -> Sem
      (TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
      (Maybe StartupError))
-> (Sem
      (RatelimitEff
         : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
      (Maybe StartupError)
    -> Sem
         (RatelimitEff
            : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
         (Maybe StartupError))
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
-> Sem
     (TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Segment
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
forall (level :: OpticKind) (msg :: OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Di level Path msg) r =>
Segment -> Sem r a -> Sem r a
Di.push Segment
"calamity" (Sem
   (RatelimitEff
      : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
   (Maybe StartupError)
 -> Sem r (Maybe StartupError))
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
-> Sem r (Maybe StartupError)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
    Sem
  (RatelimitEff
     : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
  a
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     ()
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Functor f =>
f a -> f ()
void (Sem
   (RatelimitEff
      : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
   a
 -> Sem
      (RatelimitEff
         : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
      ())
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     a
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Segment
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     a
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     a
forall (level :: OpticKind) (msg :: OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Di level Path msg) r =>
Segment -> Sem r a -> Sem r a
Di.push Segment
"calamity-setup" Sem
  (RatelimitEff
     : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
  a
setup
    Either StartupError ()
r <- Maybe StatusUpdateData
-> Intents
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Either StartupError ())
forall (r :: EffectRow).
BotC r =>
Maybe StatusUpdateData -> Intents -> Sem r (Either StartupError ())
shardBot Maybe StatusUpdateData
status Intents
intents
    case Either StartupError ()
r of
      Left StartupError
e -> Maybe StartupError
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
forall (a :: OpticKind).
a
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (StartupError -> Maybe StartupError
forall (a :: OpticKind). a -> Maybe a
Just StartupError
e)
      Right ()
_ -> do
        Segment
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     ()
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     ()
forall (level :: OpticKind) (msg :: OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Di level Path msg) r =>
Segment -> Sem r a -> Sem r a
Di.push Segment
"calamity-loop" Sem
  (RatelimitEff
     : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
  ()
forall (r :: EffectRow). BotC r => Sem r ()
clientLoop
        Segment
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     ()
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     ()
forall (level :: OpticKind) (msg :: OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Di level Path msg) r =>
Segment -> Sem r a -> Sem r a
Di.push Segment
"calamity-stop" Sem
  (RatelimitEff
     : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
  ()
forall (r :: EffectRow). BotC r => Sem r ()
finishUp
        Maybe StartupError
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     (Maybe StartupError)
forall (a :: OpticKind).
a
-> Sem
     (RatelimitEff
        : TokenEff : Reader Client : AtomicState EventHandlers : Async : r)
     a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure Maybe StartupError
forall (a :: OpticKind). Maybe a
Nothing

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

 This version only handles the @'P.Reader' 'Client'@ effect, allowing you to
 handle the @'P.AtomicState' 'EventHandlers'@ yourself.
-}
runBotIO'' ::
  forall r a.
  ( P.Members
      '[ LogEff
       , MetricEff
       , CacheEff
       , P.Reader Client
       , P.AtomicState EventHandlers
       , P.Embed IO
       , P.Final IO
       , P.Async
       ]
      r
  ) =>
  Token ->
  -- | The intents the bot should use
  Intents ->
  -- | The initial status to send to the gateway
  Maybe StatusUpdateData ->
  P.Sem (RatelimitEff ': TokenEff ': P.Reader Client ': r) a ->
  P.Sem r (Maybe StartupError)
runBotIO'' :: forall (r :: EffectRow) (a :: OpticKind).
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)
runBotIO'' Token
token Intents
intents Maybe StatusUpdateData
status Sem (RatelimitEff : TokenEff : Reader Client : r) a
setup = do
  Maybe (Di Level Path Message)
initialDi <- Sem r (Maybe (Di Level Path Message))
forall (level :: OpticKind) (path :: OpticKind) (msg :: OpticKind)
       (r :: EffectRow).
Member (Di level path msg) r =>
Sem r (Maybe (Di level path msg))
Di.fetch
  Client
client <- IO Client -> Sem r Client
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO Client -> Sem r Client) -> IO Client -> Sem r Client
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Token -> Maybe (Di Level Path Message) -> IO Client
newClient Token
token Maybe (Di Level Path Message)
initialDi
  Client
-> Sem (Reader Client : r) (Maybe StartupError)
-> Sem r (Maybe StartupError)
forall (i :: OpticKind) (r :: EffectRow) (a :: OpticKind).
i -> Sem (Reader i : r) a -> Sem r a
P.runReader Client
client (Sem (Reader Client : r) (Maybe StartupError)
 -> Sem r (Maybe StartupError))
-> (Sem
      (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
    -> Sem (Reader Client : r) (Maybe StartupError))
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
-> Sem r (Maybe StartupError)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Sem (TokenEff : Reader Client : r) (Maybe StartupError)
-> Sem (Reader Client : r) (Maybe StartupError)
forall (r :: EffectRow) (a :: OpticKind).
Member (Reader Client) r =>
Sem (TokenEff : r) a -> Sem r a
interpretTokenViaClient (Sem (TokenEff : Reader Client : r) (Maybe StartupError)
 -> Sem (Reader Client : r) (Maybe StartupError))
-> (Sem
      (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
    -> Sem (TokenEff : Reader Client : r) (Maybe StartupError))
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
-> Sem (Reader Client : r) (Maybe StartupError)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Sem
  (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
-> Sem (TokenEff : Reader Client : r) (Maybe StartupError)
forall (r :: EffectRow) (a :: OpticKind).
Member (Reader Client) r =>
Sem (RatelimitEff : r) a -> Sem r a
interpretRatelimitViaClient (Sem
   (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
 -> Sem (TokenEff : Reader Client : r) (Maybe StartupError))
-> (Sem
      (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
    -> Sem
         (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError))
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
-> Sem (TokenEff : Reader Client : r) (Maybe StartupError)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Segment
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
forall (level :: OpticKind) (msg :: OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Di level Path msg) r =>
Segment -> Sem r a -> Sem r a
Di.push Segment
"calamity" (Sem
   (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
 -> Sem r (Maybe StartupError))
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
-> Sem r (Maybe StartupError)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
    Sem (RatelimitEff : TokenEff : Reader Client : r) a
-> Sem (RatelimitEff : TokenEff : Reader Client : r) ()
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Functor f =>
f a -> f ()
void (Sem (RatelimitEff : TokenEff : Reader Client : r) a
 -> Sem (RatelimitEff : TokenEff : Reader Client : r) ())
-> Sem (RatelimitEff : TokenEff : Reader Client : r) a
-> Sem (RatelimitEff : TokenEff : Reader Client : r) ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Segment
-> Sem (RatelimitEff : TokenEff : Reader Client : r) a
-> Sem (RatelimitEff : TokenEff : Reader Client : r) a
forall (level :: OpticKind) (msg :: OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Di level Path msg) r =>
Segment -> Sem r a -> Sem r a
Di.push Segment
"calamity-setup" Sem (RatelimitEff : TokenEff : Reader Client : r) a
setup
    Either StartupError ()
r <- Maybe StatusUpdateData
-> Intents
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r)
     (Either StartupError ())
forall (r :: EffectRow).
BotC r =>
Maybe StatusUpdateData -> Intents -> Sem r (Either StartupError ())
shardBot Maybe StatusUpdateData
status Intents
intents
    case Either StartupError ()
r of
      Left StartupError
e -> Maybe StartupError
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
forall (a :: OpticKind).
a -> Sem (RatelimitEff : TokenEff : Reader Client : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (StartupError -> Maybe StartupError
forall (a :: OpticKind). a -> Maybe a
Just StartupError
e)
      Right ()
_ -> do
        Segment
-> Sem (RatelimitEff : TokenEff : Reader Client : r) ()
-> Sem (RatelimitEff : TokenEff : Reader Client : r) ()
forall (level :: OpticKind) (msg :: OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Di level Path msg) r =>
Segment -> Sem r a -> Sem r a
Di.push Segment
"calamity-loop" Sem (RatelimitEff : TokenEff : Reader Client : r) ()
forall (r :: EffectRow). BotC r => Sem r ()
clientLoop
        Segment
-> Sem (RatelimitEff : TokenEff : Reader Client : r) ()
-> Sem (RatelimitEff : TokenEff : Reader Client : r) ()
forall (level :: OpticKind) (msg :: OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Di level Path msg) r =>
Segment -> Sem r a -> Sem r a
Di.push Segment
"calamity-stop" Sem (RatelimitEff : TokenEff : Reader Client : r) ()
forall (r :: EffectRow). BotC r => Sem r ()
finishUp
        Maybe StartupError
-> Sem
     (RatelimitEff : TokenEff : Reader Client : r) (Maybe StartupError)
forall (a :: OpticKind).
a -> Sem (RatelimitEff : TokenEff : Reader Client : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure Maybe StartupError
forall (a :: OpticKind). Maybe a
Nothing

{- | 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 'Data.Text.Text' 'Message'

 'react' @(\''CustomEvt' MyCustomEvt) $ \\(MyCustomEvt s m) ->
    'void' $ 'Calamity.Types.Tellable.tell' @'Data.Text.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.
-}
react ::
  forall (s :: EventType) r.
  (BotC r, ReactConstraints s) =>
  (EHType s -> (P.Sem r) ()) ->
  P.Sem r (P.Sem r ())
react :: forall (s :: EventType) (r :: EffectRow).
(BotC r, ReactConstraints s) =>
(EHType s -> Sem r ()) -> Sem r (Sem r ())
react EHType s -> Sem r ()
handler = do
  EHType s -> IO (Maybe ())
handler' <- (EHType s -> Sem r ()) -> Sem r (EHType s -> IO (Maybe ()))
forall (r :: EffectRow) (p :: OpticKind) (a :: OpticKind).
Member (Final IO) r =>
(p -> Sem r a) -> Sem r (p -> IO (Maybe a))
bindSemToIO EHType s -> Sem r ()
handler
  IORef Integer
ehidC <- (Client -> IORef Integer) -> Sem r (IORef Integer)
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client
-> Optic' A_Lens NoIx Client (IORef Integer) -> IORef Integer
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Client (IORef Integer)
#ehidCounter)
  Integer
id' <- IO Integer -> Sem r Integer
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO Integer -> Sem r Integer) -> IO Integer -> Sem r Integer
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ IORef Integer -> (Integer -> (Integer, Integer)) -> IO Integer
forall (a :: OpticKind) (b :: OpticKind).
IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef IORef Integer
ehidC (\Integer
i -> (Integer
i Integer -> Integer -> Integer
forall (a :: OpticKind). Num a => a -> a -> a
+ Integer
1, Integer
i))
  let handlers :: EventHandlers
handlers = Proxy s -> Integer -> StoredEHType s -> EventHandlers
forall (a :: EventType).
InsertEventHandler a =>
Proxy a -> Integer -> StoredEHType a -> EventHandlers
makeEventHandlers (forall {k :: OpticKind} (t :: k). Proxy t
forall (t :: EventType). Proxy t
Proxy @s) Integer
id' (() -> Maybe () -> ()
forall (a :: OpticKind) (b :: OpticKind). a -> b -> a
const () (Maybe () -> ()) -> (EHType s -> IO (Maybe ())) -> StoredEHType s
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind) (c :: OpticKind).
Functor f =>
(a -> b) -> (c -> f a) -> c -> f b
<.> EHType s -> IO (Maybe ())
handler')
  (EventHandlers -> EventHandlers) -> Sem r ()
forall (s :: OpticKind) (r :: EffectRow).
Member (AtomicState s) r =>
(s -> s) -> Sem r ()
P.atomicModify (EventHandlers
handlers EventHandlers -> EventHandlers -> EventHandlers
forall (a :: OpticKind). Semigroup a => a -> a -> a
<>)
  Sem r () -> Sem r (Sem r ())
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Sem r () -> Sem r (Sem r ())) -> Sem r () -> Sem r (Sem r ())
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (s :: EventType) (r :: EffectRow).
(BotC r, RemoveEventHandler s) =>
Integer -> Sem r ()
removeHandler @s Integer
id'

removeHandler :: forall (s :: EventType) r. (BotC r, RemoveEventHandler s) => Integer -> P.Sem r ()
removeHandler :: forall (s :: EventType) (r :: EffectRow).
(BotC r, RemoveEventHandler s) =>
Integer -> Sem r ()
removeHandler Integer
id' = (EventHandlers -> EventHandlers) -> Sem r ()
forall (s :: OpticKind) (r :: EffectRow).
Member (AtomicState s) r =>
(s -> s) -> Sem r ()
P.atomicModify (Proxy s -> Integer -> EventHandlers -> EventHandlers
forall {k :: OpticKind} (a :: k).
RemoveEventHandler a =>
Proxy a -> Integer -> EventHandlers -> EventHandlers
removeEventHandler (forall {k :: OpticKind} (t :: k). Proxy t
forall (t :: EventType). Proxy t
Proxy @s) Integer
id')

{- | Fire an event that the bot will then handle.

 ==== Examples

 Firing an event named \"my-event\":

 @
 'fire' '$' 'customEvt' @"my-event" ("aha" :: 'Data.Text.Text', msg)
 @
-}
fire :: BotC r => CalamityEvent -> P.Sem r ()
fire :: forall (r :: EffectRow). BotC r => CalamityEvent -> Sem r ()
fire CalamityEvent
e = do
  InChan CalamityEvent
inc <- (Client -> InChan CalamityEvent) -> Sem r (InChan CalamityEvent)
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client
-> Optic' A_Lens NoIx Client (InChan CalamityEvent)
-> InChan CalamityEvent
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Client (InChan CalamityEvent)
#eventsIn)
  IO () -> Sem r ()
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO () -> Sem r ()) -> IO () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ InChan CalamityEvent -> CalamityEvent -> IO ()
forall (a :: OpticKind). InChan a -> a -> IO ()
writeChan InChan CalamityEvent
inc CalamityEvent
e

{- | Build a Custom CalamityEvent

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

 ==== Examples

 @
 'customEvt' (MyCustomEvent "lol")
 @
-}
customEvt :: forall a. Typeable a => a -> CalamityEvent
customEvt :: forall (a :: OpticKind). Typeable a => a -> CalamityEvent
customEvt = a -> CalamityEvent
forall (a :: OpticKind). Typeable a => a -> CalamityEvent
Custom

-- | Get a copy of the event stream.
events :: BotC r => P.Sem r (OutChan CalamityEvent)
events :: forall (r :: EffectRow). BotC r => Sem r (OutChan CalamityEvent)
events = do
  InChan CalamityEvent
inc <- (Client -> InChan CalamityEvent) -> Sem r (InChan CalamityEvent)
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client
-> Optic' A_Lens NoIx Client (InChan CalamityEvent)
-> InChan CalamityEvent
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Client (InChan CalamityEvent)
#eventsIn)
  IO (OutChan CalamityEvent) -> Sem r (OutChan CalamityEvent)
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO (OutChan CalamityEvent) -> Sem r (OutChan CalamityEvent))
-> IO (OutChan CalamityEvent) -> Sem r (OutChan CalamityEvent)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ InChan CalamityEvent -> IO (OutChan CalamityEvent)
forall (a :: OpticKind). InChan a -> IO (OutChan a)
dupChan InChan CalamityEvent
inc

{- | 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') -> 'P.Sem' r 'Message'
 @

 And for @s ~ \''MessageUpdateEvt'@:

 @
 'waitUntil' :: (('Message', 'Message') -> 'Bool') -> 'P.Sem' r ('Message', 'Message')
 @

 ==== Examples

 Waiting for a message containing the text \"hi\":

 @
 f = do msg \<\- 'waitUntil' @\''MessageCreateEvt' (\\m -> 'Data.Text.isInfixOf' "hi" $ m ^. #content)
        print $ msg ^. #content
 @
-}
waitUntil ::
  forall (s :: EventType) r.
  (BotC r, ReactConstraints s) =>
  (EHType s -> Bool) ->
  P.Sem r (EHType s)
waitUntil :: forall (s :: EventType) (r :: EffectRow).
(BotC r, ReactConstraints s) =>
(EHType s -> Bool) -> Sem r (EHType s)
waitUntil EHType s -> Bool
f = Sem (Resource : r) (EHType s) -> Sem r (EHType s)
forall (r :: EffectRow) (a :: OpticKind).
Member (Final IO) r =>
Sem (Resource : r) a -> Sem r a
P.resourceToIOFinal (Sem (Resource : r) (EHType s) -> Sem r (EHType s))
-> Sem (Resource : r) (EHType s) -> Sem r (EHType s)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
  MVar (EHType s)
result <- IO (MVar (EHType s)) -> Sem (Resource : r) (MVar (EHType s))
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed IO (MVar (EHType s))
forall (a :: OpticKind). IO (MVar a)
newEmptyMVar
  Sem (Resource : r) (Sem r ())
-> (Sem r () -> Sem (Resource : r) ())
-> (Sem r () -> Sem (Resource : r) (EHType s))
-> Sem (Resource : r) (EHType s)
forall (r :: EffectRow) (a :: OpticKind) (c :: OpticKind)
       (b :: OpticKind).
Member Resource r =>
Sem r a -> (a -> Sem r c) -> (a -> Sem r b) -> Sem r b
P.bracket
    (Sem r (Sem r ()) -> Sem (Resource : r) (Sem r ())
forall (e :: (OpticKind -> OpticKind) -> OpticKind -> OpticKind)
       (r :: EffectRow) (a :: OpticKind).
Sem r a -> Sem (e : r) a
P.raise (Sem r (Sem r ()) -> Sem (Resource : r) (Sem r ()))
-> Sem r (Sem r ()) -> Sem (Resource : r) (Sem r ())
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (s :: EventType) (r :: EffectRow).
(BotC r, ReactConstraints s) =>
(EHType s -> Sem r ()) -> Sem r (Sem r ())
react @s (MVar (EHType s) -> EHType s -> Sem r ()
checker MVar (EHType s)
result))
    Sem r () -> Sem (Resource : r) ()
forall (e :: (OpticKind -> OpticKind) -> OpticKind -> OpticKind)
       (r :: EffectRow) (a :: OpticKind).
Sem r a -> Sem (e : r) a
P.raise
    (Sem (Resource : r) (EHType s)
-> Sem r () -> Sem (Resource : r) (EHType s)
forall (a :: OpticKind) (b :: OpticKind). a -> b -> a
const (Sem (Resource : r) (EHType s)
 -> Sem r () -> Sem (Resource : r) (EHType s))
-> (IO (EHType s) -> Sem (Resource : r) (EHType s))
-> IO (EHType s)
-> Sem r ()
-> Sem (Resource : r) (EHType s)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. IO (EHType s) -> Sem (Resource : r) (EHType s)
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO (EHType s) -> Sem r () -> Sem (Resource : r) (EHType s))
-> IO (EHType s) -> Sem r () -> Sem (Resource : r) (EHType s)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ MVar (EHType s) -> IO (EHType s)
forall (a :: OpticKind). MVar a -> IO a
takeMVar MVar (EHType s)
result)
  where
    checker :: MVar (EHType s) -> EHType s -> P.Sem r ()
    checker :: MVar (EHType s) -> EHType s -> Sem r ()
checker MVar (EHType s)
result EHType s
args = do
      Bool -> Sem r () -> Sem r ()
forall (f :: OpticKind -> OpticKind).
Applicative f =>
Bool -> f () -> f ()
when (EHType s -> Bool
f EHType s
args) (Sem r () -> Sem r ()) -> Sem r () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
        IO () -> Sem r ()
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO () -> Sem r ()) -> IO () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ MVar (EHType s) -> EHType s -> IO ()
forall (a :: OpticKind). MVar a -> a -> IO ()
putMVar MVar (EHType s)
result EHType s
args

{- | Wait until an event satisfying a condition happens, then returns its
 parameters

 This is what it would look like with @s ~ \''MessageCreateEvt'@:

 @
 'waitUntilM' :: ('Message' -> 'P.Sem' r 'Bool') -> 'P.Sem' r 'Message'
 @

 And for @s ~ \''MessageUpdateEvt'@:

 @
 'waitUntilM' :: (('Message', 'Message') -> 'P.Sem' r 'Bool') -> 'P.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' $ 'Data.Text.isInfixOf' "hi" $ m ^. #content))
        print $ msg ^. #content
 @
-}
waitUntilM ::
  forall (s :: EventType) r.
  (BotC r, ReactConstraints s) =>
  (EHType s -> P.Sem r Bool) ->
  P.Sem r (EHType s)
waitUntilM :: forall (s :: EventType) (r :: EffectRow).
(BotC r, ReactConstraints s) =>
(EHType s -> Sem r Bool) -> Sem r (EHType s)
waitUntilM EHType s -> Sem r Bool
f = Sem (Resource : r) (EHType s) -> Sem r (EHType s)
forall (r :: EffectRow) (a :: OpticKind).
Member (Final IO) r =>
Sem (Resource : r) a -> Sem r a
P.resourceToIOFinal (Sem (Resource : r) (EHType s) -> Sem r (EHType s))
-> Sem (Resource : r) (EHType s) -> Sem r (EHType s)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
  MVar (EHType s)
result <- IO (MVar (EHType s)) -> Sem (Resource : r) (MVar (EHType s))
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed IO (MVar (EHType s))
forall (a :: OpticKind). IO (MVar a)
newEmptyMVar
  Sem (Resource : r) (Sem r ())
-> (Sem r () -> Sem (Resource : r) ())
-> (Sem r () -> Sem (Resource : r) (EHType s))
-> Sem (Resource : r) (EHType s)
forall (r :: EffectRow) (a :: OpticKind) (c :: OpticKind)
       (b :: OpticKind).
Member Resource r =>
Sem r a -> (a -> Sem r c) -> (a -> Sem r b) -> Sem r b
P.bracket
    (Sem r (Sem r ()) -> Sem (Resource : r) (Sem r ())
forall (e :: (OpticKind -> OpticKind) -> OpticKind -> OpticKind)
       (r :: EffectRow) (a :: OpticKind).
Sem r a -> Sem (e : r) a
P.raise (Sem r (Sem r ()) -> Sem (Resource : r) (Sem r ()))
-> Sem r (Sem r ()) -> Sem (Resource : r) (Sem r ())
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (s :: EventType) (r :: EffectRow).
(BotC r, ReactConstraints s) =>
(EHType s -> Sem r ()) -> Sem r (Sem r ())
react @s (MVar (EHType s) -> EHType s -> Sem r ()
checker MVar (EHType s)
result))
    Sem r () -> Sem (Resource : r) ()
forall (e :: (OpticKind -> OpticKind) -> OpticKind -> OpticKind)
       (r :: EffectRow) (a :: OpticKind).
Sem r a -> Sem (e : r) a
P.raise
    (Sem (Resource : r) (EHType s)
-> Sem r () -> Sem (Resource : r) (EHType s)
forall (a :: OpticKind) (b :: OpticKind). a -> b -> a
const (Sem (Resource : r) (EHType s)
 -> Sem r () -> Sem (Resource : r) (EHType s))
-> (IO (EHType s) -> Sem (Resource : r) (EHType s))
-> IO (EHType s)
-> Sem r ()
-> Sem (Resource : r) (EHType s)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. IO (EHType s) -> Sem (Resource : r) (EHType s)
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO (EHType s) -> Sem r () -> Sem (Resource : r) (EHType s))
-> IO (EHType s) -> Sem r () -> Sem (Resource : r) (EHType s)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ MVar (EHType s) -> IO (EHType s)
forall (a :: OpticKind). MVar a -> IO a
takeMVar MVar (EHType s)
result)
  where
    checker :: MVar (EHType s) -> EHType s -> P.Sem r ()
    checker :: MVar (EHType s) -> EHType s -> Sem r ()
checker MVar (EHType s)
result EHType s
args = do
      Bool
res <- EHType s -> Sem r Bool
f EHType s
args
      Bool -> Sem r () -> Sem r ()
forall (f :: OpticKind -> OpticKind).
Applicative f =>
Bool -> f () -> f ()
when Bool
res (Sem r () -> Sem r ()) -> Sem r () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
        IO () -> Sem r ()
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO () -> Sem r ()) -> IO () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ MVar (EHType s) -> EHType s -> IO ()
forall (a :: OpticKind). MVar a -> a -> IO ()
putMVar MVar (EHType s)
result EHType s
args

-- | Set the bot's presence on all shards.
sendPresence :: BotC r => StatusUpdateData -> P.Sem r ()
sendPresence :: forall (r :: EffectRow). BotC r => StatusUpdateData -> Sem r ()
sendPresence StatusUpdateData
s = do
  [(InChan ControlMessage, Async (Maybe ()))]
shards <- (Client -> TVar [(InChan ControlMessage, Async (Maybe ()))])
-> Sem r (TVar [(InChan ControlMessage, Async (Maybe ()))])
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client
-> Optic'
     A_Lens
     NoIx
     Client
     (TVar [(InChan ControlMessage, Async (Maybe ()))])
-> TVar [(InChan ControlMessage, Async (Maybe ()))]
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  Client
  (TVar [(InChan ControlMessage, Async (Maybe ()))])
#shards) Sem r (TVar [(InChan ControlMessage, Async (Maybe ()))])
-> (TVar [(InChan ControlMessage, Async (Maybe ()))]
    -> Sem r [(InChan ControlMessage, Async (Maybe ()))])
-> Sem r [(InChan ControlMessage, Async (Maybe ()))]
forall (a :: OpticKind) (b :: OpticKind).
Sem r a -> (a -> Sem r b) -> Sem r b
forall (m :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Monad m =>
m a -> (a -> m b) -> m b
>>= IO [(InChan ControlMessage, Async (Maybe ()))]
-> Sem r [(InChan ControlMessage, Async (Maybe ()))]
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO [(InChan ControlMessage, Async (Maybe ()))]
 -> Sem r [(InChan ControlMessage, Async (Maybe ()))])
-> (TVar [(InChan ControlMessage, Async (Maybe ()))]
    -> IO [(InChan ControlMessage, Async (Maybe ()))])
-> TVar [(InChan ControlMessage, Async (Maybe ()))]
-> Sem r [(InChan ControlMessage, Async (Maybe ()))]
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. TVar [(InChan ControlMessage, Async (Maybe ()))]
-> IO [(InChan ControlMessage, Async (Maybe ()))]
forall (a :: OpticKind). TVar a -> IO a
readTVarIO
  [(InChan ControlMessage, Async (Maybe ()))]
-> ((InChan ControlMessage, Async (Maybe ())) -> Sem r ())
-> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [(InChan ControlMessage, Async (Maybe ()))]
shards (((InChan ControlMessage, Async (Maybe ())) -> Sem r ())
 -> Sem r ())
-> ((InChan ControlMessage, Async (Maybe ())) -> Sem r ())
-> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \(InChan ControlMessage
inc, Async (Maybe ())
_) ->
    IO () -> Sem r ()
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO () -> Sem r ()) -> IO () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ InChan ControlMessage -> ControlMessage -> IO ()
forall (a :: OpticKind). InChan a -> a -> IO ()
writeChan InChan ControlMessage
inc (StatusUpdateData -> ControlMessage
SendPresence StatusUpdateData
s)

-- | Initiate shutting down the bot.
stopBot :: BotC r => P.Sem r ()
stopBot :: forall (r :: EffectRow). BotC r => Sem r ()
stopBot = do
  Text -> Sem r ()
forall (r :: EffectRow). Member LogEff r => Text -> Sem r ()
debug Text
"stopping bot"
  InChan CalamityEvent
inc <- (Client -> InChan CalamityEvent) -> Sem r (InChan CalamityEvent)
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client
-> Optic' A_Lens NoIx Client (InChan CalamityEvent)
-> InChan CalamityEvent
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Client (InChan CalamityEvent)
#eventsIn)
  IO () -> Sem r ()
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO () -> Sem r ()) -> IO () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ InChan CalamityEvent -> CalamityEvent -> IO ()
forall (a :: OpticKind). InChan a -> a -> IO ()
writeChan InChan CalamityEvent
inc CalamityEvent
ShutDown

finishUp :: BotC r => P.Sem r ()
finishUp :: forall (r :: EffectRow). BotC r => Sem r ()
finishUp = do
  Text -> Sem r ()
forall (r :: EffectRow). Member LogEff r => Text -> Sem r ()
debug Text
"finishing up"
  [(InChan ControlMessage, Async (Maybe ()))]
shards <- (Client -> TVar [(InChan ControlMessage, Async (Maybe ()))])
-> Sem r (TVar [(InChan ControlMessage, Async (Maybe ()))])
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client
-> Optic'
     A_Lens
     NoIx
     Client
     (TVar [(InChan ControlMessage, Async (Maybe ()))])
-> TVar [(InChan ControlMessage, Async (Maybe ()))]
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  Client
  (TVar [(InChan ControlMessage, Async (Maybe ()))])
#shards) Sem r (TVar [(InChan ControlMessage, Async (Maybe ()))])
-> (TVar [(InChan ControlMessage, Async (Maybe ()))]
    -> Sem r [(InChan ControlMessage, Async (Maybe ()))])
-> Sem r [(InChan ControlMessage, Async (Maybe ()))]
forall (a :: OpticKind) (b :: OpticKind).
Sem r a -> (a -> Sem r b) -> Sem r b
forall (m :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Monad m =>
m a -> (a -> m b) -> m b
>>= IO [(InChan ControlMessage, Async (Maybe ()))]
-> Sem r [(InChan ControlMessage, Async (Maybe ()))]
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO [(InChan ControlMessage, Async (Maybe ()))]
 -> Sem r [(InChan ControlMessage, Async (Maybe ()))])
-> (TVar [(InChan ControlMessage, Async (Maybe ()))]
    -> IO [(InChan ControlMessage, Async (Maybe ()))])
-> TVar [(InChan ControlMessage, Async (Maybe ()))]
-> Sem r [(InChan ControlMessage, Async (Maybe ()))]
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. TVar [(InChan ControlMessage, Async (Maybe ()))]
-> IO [(InChan ControlMessage, Async (Maybe ()))]
forall (a :: OpticKind). TVar a -> IO a
readTVarIO
  [(InChan ControlMessage, Async (Maybe ()))]
-> ((InChan ControlMessage, Async (Maybe ())) -> Sem r ())
-> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [(InChan ControlMessage, Async (Maybe ()))]
shards (((InChan ControlMessage, Async (Maybe ())) -> Sem r ())
 -> Sem r ())
-> ((InChan ControlMessage, Async (Maybe ())) -> Sem r ())
-> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \(InChan ControlMessage
inc, Async (Maybe ())
_) ->
    IO () -> Sem r ()
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO () -> Sem r ()) -> IO () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ InChan ControlMessage -> ControlMessage -> IO ()
forall (a :: OpticKind). InChan a -> a -> IO ()
writeChan InChan ControlMessage
inc ControlMessage
ShutDownShard
  [(InChan ControlMessage, Async (Maybe ()))]
-> ((InChan ControlMessage, Async (Maybe ())) -> Sem r (Maybe ()))
-> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [(InChan ControlMessage, Async (Maybe ()))]
shards (((InChan ControlMessage, Async (Maybe ())) -> Sem r (Maybe ()))
 -> Sem r ())
-> ((InChan ControlMessage, Async (Maybe ())) -> Sem r (Maybe ()))
-> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \(InChan ControlMessage
_, Async (Maybe ())
shardThread) -> Async (Maybe ()) -> Sem r (Maybe ())
forall (r :: EffectRow) (a :: OpticKind).
Member Async r =>
Async a -> Sem r a
P.await Async (Maybe ())
shardThread
  Text -> Sem r ()
forall (r :: EffectRow). Member LogEff r => Text -> Sem r ()
debug Text
"bot has stopped"

{- | main loop of the client, handles fetching the next event, processing the
 event and invoking its handler functions
-}
clientLoop :: BotC r => P.Sem r ()
clientLoop :: forall (r :: EffectRow). BotC r => Sem r ()
clientLoop = do
  OutChan CalamityEvent
outc <- (Client -> OutChan CalamityEvent) -> Sem r (OutChan CalamityEvent)
forall (i :: OpticKind) (j :: OpticKind) (r :: EffectRow).
Member (Reader i) r =>
(i -> j) -> Sem r j
P.asks (Client
-> Optic' A_Lens NoIx Client (OutChan CalamityEvent)
-> OutChan CalamityEvent
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Client (OutChan CalamityEvent)
#eventsOut)
  Sem r Bool -> Sem r ()
forall (r :: EffectRow).
Member (Final IO) r =>
Sem r Bool -> Sem r ()
whileMFinalIO (Sem r Bool -> Sem r ()) -> Sem r Bool -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
    !CalamityEvent
evt' <- IO CalamityEvent -> Sem r CalamityEvent
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO CalamityEvent -> Sem r CalamityEvent)
-> IO CalamityEvent -> Sem r CalamityEvent
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ OutChan CalamityEvent -> IO CalamityEvent
forall (a :: OpticKind). OutChan a -> IO a
readChan OutChan CalamityEvent
outc
    case CalamityEvent
evt' of
      Dispatch !Int
sid !DispatchData
evt -> Int -> DispatchData -> Sem r ()
forall (r :: EffectRow). BotC r => Int -> DispatchData -> Sem r ()
handleEvent Int
sid DispatchData
evt Sem r () -> Sem r Bool -> Sem r Bool
forall (a :: OpticKind) (b :: OpticKind).
Sem r a -> Sem r b -> Sem r b
forall (m :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Monad m =>
m a -> m b -> m b
>> Bool -> Sem r Bool
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure Bool
True
      Custom a
d -> a -> Sem r ()
forall (a :: OpticKind) (r :: EffectRow).
(Typeable a, BotC r) =>
a -> Sem r ()
handleCustomEvent a
d Sem r () -> Sem r Bool -> Sem r Bool
forall (a :: OpticKind) (b :: OpticKind).
Sem r a -> Sem r b -> Sem r b
forall (m :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Monad m =>
m a -> m b -> m b
>> Bool -> Sem r Bool
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure Bool
True
      CalamityEvent
ShutDown -> Bool -> Sem r Bool
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure Bool
False
  Text -> Sem r ()
forall (r :: EffectRow). Member LogEff r => Text -> Sem r ()
debug Text
"leaving client loop"

handleCustomEvent :: forall a r. (Typeable a, BotC r) => a -> P.Sem r ()
handleCustomEvent :: forall (a :: OpticKind) (r :: EffectRow).
(Typeable a, BotC r) =>
a -> Sem r ()
handleCustomEvent a
d = do
  EventHandlers
eventHandlers <- Sem r EventHandlers
forall (s :: OpticKind) (r :: EffectRow).
Member (AtomicState s) r =>
Sem r s
P.atomicGet

  let handlers :: [a -> IO ()]
handlers = forall (a :: OpticKind).
Typeable a =>
EventHandlers -> [a -> IO ()]
getCustomEventHandlers @a EventHandlers
eventHandlers

  [a -> IO ()]
-> ((a -> IO ()) -> Sem r (Async (Maybe ()))) -> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [a -> IO ()]
handlers (\a -> IO ()
h -> Sem r () -> Sem r (Async (Maybe ()))
forall (r :: EffectRow) (a :: OpticKind).
Member Async r =>
Sem r a -> Sem r (Async (Maybe a))
P.async (Sem r () -> Sem r (Async (Maybe ())))
-> (IO () -> Sem r ()) -> IO () -> Sem r (Async (Maybe ()))
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. IO () -> Sem r ()
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed (IO () -> Sem r (Async (Maybe ())))
-> IO () -> Sem r (Async (Maybe ()))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ a -> IO ()
h a
d)

catchAllLogging :: BotC r => P.Sem r () -> P.Sem r ()
catchAllLogging :: forall (r :: EffectRow). BotC r => Sem r () -> Sem r ()
catchAllLogging Sem r ()
m = do
  Either SomeException ()
r <- Sem (Error SomeException : r) () -> Sem r (Either SomeException ())
forall (e :: OpticKind) (r :: EffectRow) (a :: OpticKind).
Member (Final IO) r =>
Sem (Error e : r) a -> Sem r (Either e a)
P.errorToIOFinal (Sem (Error SomeException : r) ()
 -> Sem r (Either SomeException ()))
-> (Sem (Error SomeException : r) ()
    -> Sem (Error SomeException : r) ())
-> Sem (Error SomeException : r) ()
-> Sem r (Either SomeException ())
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. forall (e :: OpticKind) (r :: EffectRow) (a :: OpticKind).
(Exception e, Member (Error e) r, Member (Final IO) r) =>
Sem r a -> Sem r a
P.fromExceptionSem @SomeException (Sem (Error SomeException : r) ()
 -> Sem r (Either SomeException ()))
-> Sem (Error SomeException : r) ()
-> Sem r (Either SomeException ())
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Sem r () -> Sem (Error SomeException : r) ()
forall (e :: (OpticKind -> OpticKind) -> OpticKind -> OpticKind)
       (r :: EffectRow) (a :: OpticKind).
Sem r a -> Sem (e : r) a
P.raise Sem r ()
m
  case Either SomeException ()
r of
    Right ()
_ -> () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
    Left SomeException
e -> Text -> Sem r ()
forall (r :: EffectRow). Member LogEff r => Text -> Sem r ()
debug (Text -> Sem r ()) -> (String -> Text) -> String -> Sem r ()
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Sem r ()) -> String -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ String
"got exception: " String -> String -> String
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> SomeException -> String
forall (a :: OpticKind). Show a => a -> String
show SomeException
e

handleEvent :: BotC r => Int -> DispatchData -> P.Sem r ()
handleEvent :: forall (r :: EffectRow). BotC r => Int -> DispatchData -> Sem r ()
handleEvent Int
shardID DispatchData
data' = do
  Text -> Sem r ()
forall (r :: EffectRow). Member LogEff r => Text -> Sem r ()
debug (Text -> Sem r ()) -> (String -> Text) -> String -> Sem r ()
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Sem r ()) -> String -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ String
"handling an event: " String -> String -> String
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> DispatchData -> String
forall (a :: OpticKind). CtorName a => a -> String
ctorName DispatchData
data'
  EventHandlers
eventHandlers <- Sem r EventHandlers
forall (s :: OpticKind) (r :: EffectRow).
Member (AtomicState s) r =>
Sem r s
P.atomicGet
  Either String [IO ()]
actions <- Sem (Fail : r) [IO ()] -> Sem r (Either String [IO ()])
forall (r :: EffectRow) (a :: OpticKind).
Sem (Fail : r) a -> Sem r (Either String a)
P.runFail (Sem (Fail : r) [IO ()] -> Sem r (Either String [IO ()]))
-> Sem (Fail : r) [IO ()] -> Sem r (Either String [IO ()])
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
    Counter
evtCounter <- Text -> [(Text, Text)] -> Sem (Fail : r) Counter
forall (r :: EffectRow).
Member MetricEff r =>
Text -> [(Text, Text)] -> Sem r Counter
registerCounter Text
"events_received" [(Text
"type", String -> Text
T.pack (String -> Text) -> String -> Text
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ DispatchData -> String
forall (a :: OpticKind). CtorName a => a -> String
ctorName DispatchData
data'), (Text
"shard", Int -> Text
forall (a :: OpticKind). TextShow a => a -> Text
showt Int
shardID)]
    Sem (Fail : r) Int -> Sem (Fail : r) ()
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Functor f =>
f a -> f ()
void (Sem (Fail : r) Int -> Sem (Fail : r) ())
-> Sem (Fail : r) Int -> Sem (Fail : r) ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Int -> Counter -> Sem (Fail : r) Int
forall (r :: EffectRow).
Member MetricEff r =>
Int -> Counter -> Sem r Int
addCounter Int
1 Counter
evtCounter
    Histogram
cacheUpdateHisto <- Text -> [(Text, Text)] -> [Double] -> Sem (Fail : r) Histogram
forall (r :: EffectRow).
Member MetricEff r =>
Text -> [(Text, Text)] -> [Double] -> Sem r Histogram
registerHistogram Text
"cache_update" [(Text, Text)]
forall (a :: OpticKind). Monoid a => a
mempty [Double
10, Double
20 .. Double
100]
    (Double
time, [IO ()]
res) <- Sem (Fail : r) [IO ()] -> Sem (Fail : r) (Double, [IO ()])
forall (r :: EffectRow) (a :: OpticKind).
Member (Embed IO) r =>
Sem r a -> Sem r (Double, a)
timeA (Sem (Fail : r) [IO ()] -> Sem (Fail : r) (Double, [IO ()]))
-> (Sem (Fail : r) [IO ()] -> Sem (Fail : r) [IO ()])
-> Sem (Fail : r) [IO ()]
-> Sem (Fail : r) (Double, [IO ()])
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Sem (Fail : r) [IO ()] -> Sem (Fail : r) [IO ()]
forall (r :: EffectRow) (a :: OpticKind).
BotC r =>
Sem r a -> Sem r a
resetDi (Sem (Fail : r) [IO ()] -> Sem (Fail : r) (Double, [IO ()]))
-> Sem (Fail : r) [IO ()] -> Sem (Fail : r) (Double, [IO ()])
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ EventHandlers -> DispatchData -> Sem (Fail : r) [IO ()]
forall (r :: EffectRow).
BotC r =>
EventHandlers -> DispatchData -> Sem (Fail : r) [IO ()]
handleEvent' EventHandlers
eventHandlers DispatchData
data'
    Sem (Fail : r) HistogramSample -> Sem (Fail : r) ()
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Functor f =>
f a -> f ()
void (Sem (Fail : r) HistogramSample -> Sem (Fail : r) ())
-> Sem (Fail : r) HistogramSample -> Sem (Fail : r) ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Double -> Histogram -> Sem (Fail : r) HistogramSample
forall (r :: EffectRow).
Member MetricEff r =>
Double -> Histogram -> Sem r HistogramSample
observeHistogram Double
time Histogram
cacheUpdateHisto
    [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure [IO ()]
res

  Histogram
eventHandleHisto <- Text -> [(Text, Text)] -> [Double] -> Sem r Histogram
forall (r :: EffectRow).
Member MetricEff r =>
Text -> [(Text, Text)] -> [Double] -> Sem r Histogram
registerHistogram Text
"event_handle" [(Text, Text)]
forall (a :: OpticKind). Monoid a => a
mempty [Double
10, Double
20 .. Double
100]

  case Either String [IO ()]
actions of
    Right [IO ()]
actions -> [IO ()] -> (IO () -> Sem r (Async (Maybe ()))) -> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [IO ()]
actions ((IO () -> Sem r (Async (Maybe ()))) -> Sem r ())
-> (IO () -> Sem r (Async (Maybe ()))) -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \IO ()
action -> Sem r () -> Sem r (Async (Maybe ()))
forall (r :: EffectRow) (a :: OpticKind).
Member Async r =>
Sem r a -> Sem r (Async (Maybe a))
P.async (Sem r () -> Sem r (Async (Maybe ())))
-> Sem r () -> Sem r (Async (Maybe ()))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ do
      (Double
time, ()
_) <- Sem r () -> Sem r (Double, ())
forall (r :: EffectRow) (a :: OpticKind).
Member (Embed IO) r =>
Sem r a -> Sem r (Double, a)
timeA (Sem r () -> Sem r (Double, ()))
-> (Sem r () -> Sem r ()) -> Sem r () -> Sem r (Double, ())
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Sem r () -> Sem r ()
forall (r :: EffectRow). BotC r => Sem r () -> Sem r ()
catchAllLogging (Sem r () -> Sem r (Double, ())) -> Sem r () -> Sem r (Double, ())
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ IO () -> Sem r ()
forall (m :: OpticKind -> OpticKind) (r :: EffectRow)
       (a :: OpticKind).
Member (Embed m) r =>
m a -> Sem r a
P.embed IO ()
action
      Sem r HistogramSample -> Sem r ()
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Functor f =>
f a -> f ()
void (Sem r HistogramSample -> Sem r ())
-> Sem r HistogramSample -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Double -> Histogram -> Sem r HistogramSample
forall (r :: EffectRow).
Member MetricEff r =>
Double -> Histogram -> Sem r HistogramSample
observeHistogram Double
time Histogram
eventHandleHisto
    -- pattern match failures are usually stuff like events for uncached guilds, etc
    Left String
err -> Text -> Sem r ()
forall (r :: EffectRow). Member LogEff r => Text -> Sem r ()
debug (Text -> Sem r ()) -> (String -> Text) -> String -> Sem r ()
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Sem r ()) -> String -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ String
"Failed handling actions for event: " String -> String -> String
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> String -> String
forall (a :: OpticKind). Show a => a -> String
show String
err

handleEvent' ::
  BotC r =>
  EventHandlers ->
  DispatchData ->
  P.Sem (P.Fail ': r) [IO ()]
handleEvent' :: forall (r :: EffectRow).
BotC r =>
EventHandlers -> DispatchData -> Sem (Fail : r) [IO ()]
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(Ready rd :: ReadyData
rd@ReadyData {}) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((ReadyData -> IO ()) -> IO ()) -> [ReadyData -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((ReadyData -> IO ()) -> ReadyData -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ReadyData
rd) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'ReadyEvt EventHandlers
eh)
handleEvent' EventHandlers
_ DispatchData
Resumed = [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure []
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(ChannelCreate (DMChannel' DMChannel
chan)) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Channel
newChan <- DMChannel -> Channel
DMChannel' (DMChannel -> Channel)
-> Sem (Fail : r) (Maybe DMChannel)
-> Sem (Fail : r) (Maybe Channel)
forall (f :: OpticKind -> OpticKind) (g :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> Snowflake DMChannel -> Sem (Fail : r) (Maybe DMChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> Sem r (Maybe DMChannel)
getDM (DMChannel -> Snowflake DMChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID DMChannel
chan)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((Channel -> IO ()) -> IO ()) -> [Channel -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Channel -> IO ()) -> Channel -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Channel
newChan) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'ChannelCreateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(ChannelCreate (GuildChannel' GuildChannel
chan)) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (GuildChannel -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan)
  Just Channel
newChan <- Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe Channel -> Sem (Fail : r) (Maybe Channel))
-> Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Maybe GuildChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Guild
guild Guild
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
-> Maybe GuildChannel
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
     (Maybe GuildChannel)
     (Maybe GuildChannel)
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap GuildChannel)
-> Lens'
     (SnowflakeMap GuildChannel)
     (Maybe (IxValue (SnowflakeMap GuildChannel)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (GuildChannel -> Snowflake GuildChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((Channel -> IO ()) -> IO ()) -> [Channel -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Channel -> IO ()) -> Channel -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Channel
newChan) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'ChannelCreateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(ChannelUpdate (DMChannel' DMChannel
chan)) = do
  Just Channel
oldChan <- DMChannel -> Channel
DMChannel' (DMChannel -> Channel)
-> Sem (Fail : r) (Maybe DMChannel)
-> Sem (Fail : r) (Maybe Channel)
forall (f :: OpticKind -> OpticKind) (g :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> Snowflake DMChannel -> Sem (Fail : r) (Maybe DMChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> Sem r (Maybe DMChannel)
getDM (DMChannel -> Snowflake DMChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID DMChannel
chan)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Channel
newChan <- DMChannel -> Channel
DMChannel' (DMChannel -> Channel)
-> Sem (Fail : r) (Maybe DMChannel)
-> Sem (Fail : r) (Maybe Channel)
forall (f :: OpticKind -> OpticKind) (g :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> Snowflake DMChannel -> Sem (Fail : r) (Maybe DMChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> Sem r (Maybe DMChannel)
getDM (DMChannel -> Snowflake DMChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID DMChannel
chan)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Channel, Channel) -> IO ()) -> IO ())
-> [(Channel, Channel) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Channel, Channel) -> IO ()) -> (Channel, Channel) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Channel
oldChan, Channel
newChan)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'ChannelUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(ChannelUpdate (GuildChannel' GuildChannel
chan)) = do
  Just Guild
oldGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (GuildChannel -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan)
  Just Channel
oldChan <- Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe Channel -> Sem (Fail : r) (Maybe Channel))
-> Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Maybe GuildChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Guild
oldGuild Guild
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
-> Maybe GuildChannel
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
     (Maybe GuildChannel)
     (Maybe GuildChannel)
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap GuildChannel)
-> Lens'
     (SnowflakeMap GuildChannel)
     (Maybe (IxValue (SnowflakeMap GuildChannel)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (GuildChannel -> Snowflake GuildChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
newGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (GuildChannel -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan)
  Just Channel
newChan <- Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe Channel -> Sem (Fail : r) (Maybe Channel))
-> Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Maybe GuildChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Guild
newGuild Guild
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
-> Maybe GuildChannel
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
     (Maybe GuildChannel)
     (Maybe GuildChannel)
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap GuildChannel)
-> Lens'
     (SnowflakeMap GuildChannel)
     (Maybe (IxValue (SnowflakeMap GuildChannel)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (GuildChannel -> Snowflake GuildChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Channel, Channel) -> IO ()) -> IO ())
-> [(Channel, Channel) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Channel, Channel) -> IO ()) -> (Channel, Channel) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Channel
oldChan, Channel
newChan)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'ChannelUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(ChannelDelete (GuildChannel' GuildChannel
chan)) = do
  Just Guild
oldGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (GuildChannel -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan)
  Just Channel
oldChan <- Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe Channel -> Sem (Fail : r) (Maybe Channel))
-> Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Maybe GuildChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Guild
oldGuild Guild
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
-> Maybe GuildChannel
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
     (Maybe GuildChannel)
     (Maybe GuildChannel)
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap GuildChannel)
-> Lens'
     (SnowflakeMap GuildChannel)
     (Maybe (IxValue (SnowflakeMap GuildChannel)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (GuildChannel -> Snowflake GuildChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((Channel -> IO ()) -> IO ()) -> [Channel -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Channel -> IO ()) -> Channel -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Channel
oldChan) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'ChannelDeleteEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(ChannelDelete (DMChannel' DMChannel
chan)) = do
  Just Channel
oldChan <- DMChannel -> Channel
DMChannel' (DMChannel -> Channel)
-> Sem (Fail : r) (Maybe DMChannel)
-> Sem (Fail : r) (Maybe Channel)
forall (f :: OpticKind -> OpticKind) (g :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> Snowflake DMChannel -> Sem (Fail : r) (Maybe DMChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> Sem r (Maybe DMChannel)
getDM (DMChannel -> Snowflake DMChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID DMChannel
chan)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((Channel -> IO ()) -> IO ()) -> [Channel -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Channel -> IO ()) -> Channel -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Channel
oldChan) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'ChannelDeleteEvt EventHandlers
eh)

-- handleEvent' eh evt@(ChannelPinsUpdate ChannelPinsUpdateData { channelID, lastPinTimestamp }) = do
--   chan <- (GuildChannel' <$> os ^? #channels % at (coerceSnowflake channelID) . _Just)
--     <|> (DMChannel' <$> os ^? #dms % at (coerceSnowflake channelID) . _Just)
--   pure $ map (\f -> f chan lastPinTimestamp) (getEventHandlers @"channelpinsupdate" eh)

handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildCreate Guild
guild) = do
  Bool
isNew <- Bool -> Bool
not (Bool -> Bool) -> Sem (Fail : r) Bool -> Sem (Fail : r) Bool
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Snowflake Guild -> Sem (Fail : r) Bool
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r Bool
isUnavailableGuild (Guild -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Guild
guild)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (Guild -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Guild
guild)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$
    (((Guild, GuildCreateStatus) -> IO ()) -> IO ())
-> [(Guild, GuildCreateStatus) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map
      (((Guild, GuildCreateStatus) -> IO ())
-> (Guild, GuildCreateStatus) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, if Bool
isNew then GuildCreateStatus
GuildCreateNew else GuildCreateStatus
GuildCreateAvailable))
      (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildCreateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildUpdate UpdatedGuild
guild) = do
  Just Guild
oldGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (UpdatedGuild -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID UpdatedGuild
guild)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
newGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild (UpdatedGuild -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID UpdatedGuild
guild)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, Guild) -> IO ()) -> IO ())
-> [(Guild, Guild) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, Guild) -> IO ()) -> (Guild, Guild) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
oldGuild, Guild
newGuild)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildUpdateEvt EventHandlers
eh)

-- NOTE: Guild will be deleted in the new cache if unavailable was false
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildDelete UnavailableGuild {Snowflake Guild
id :: Snowflake Guild
$sel:id:UnavailableGuild :: UnavailableGuild -> Snowflake Guild
id, Bool
unavailable :: Bool
$sel:unavailable:UnavailableGuild :: UnavailableGuild -> Bool
unavailable}) = do
  Just Guild
oldGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
id
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$
    (((Guild, GuildDeleteStatus) -> IO ()) -> IO ())
-> [(Guild, GuildDeleteStatus) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map
      (((Guild, GuildDeleteStatus) -> IO ())
-> (Guild, GuildDeleteStatus) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
oldGuild, if Bool
unavailable then GuildDeleteStatus
GuildDeleteUnavailable else GuildDeleteStatus
GuildDeleteRemoved))
      (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildDeleteEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildBanAdd BanData {Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:BanData :: BanData -> Snowflake Guild
guildID, User
user :: User
$sel:user:BanData :: BanData -> User
user}) = do
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, User) -> IO ()) -> IO ())
-> [(Guild, User) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, User) -> IO ()) -> (Guild, User) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, User
user)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildBanAddEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildBanRemove BanData {Snowflake Guild
$sel:guildID:BanData :: BanData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, User
$sel:user:BanData :: BanData -> User
user :: User
user}) = do
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, User) -> IO ()) -> IO ())
-> [(Guild, User) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, User) -> IO ()) -> (Guild, User) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, User
user)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildBanRemoveEvt EventHandlers
eh)

-- NOTE: we fire this event using the guild data with old emojis
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildEmojisUpdate GuildEmojisUpdateData {Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:GuildEmojisUpdateData :: GuildEmojisUpdateData -> Snowflake Guild
guildID, [Emoji]
emojis :: [Emoji]
$sel:emojis:GuildEmojisUpdateData :: GuildEmojisUpdateData -> [Emoji]
emojis}) = do
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, [Emoji]) -> IO ()) -> IO ())
-> [(Guild, [Emoji]) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, [Emoji]) -> IO ()) -> (Guild, [Emoji]) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, [Emoji]
emojis)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildEmojisUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildIntegrationsUpdate GuildIntegrationsUpdateData {Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:GuildIntegrationsUpdateData :: GuildIntegrationsUpdateData -> Snowflake Guild
guildID}) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((Guild -> IO ()) -> IO ()) -> [Guild -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Guild -> IO ()) -> Guild -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
guild) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildIntegrationsUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildMemberAdd Snowflake Guild
gid Member
member) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
gid
  Just IxValue (SnowflakeMap Member)
member <- Maybe (IxValue (SnowflakeMap Member))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member)))
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe (IxValue (SnowflakeMap Member))
 -> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member))))
-> Maybe (IxValue (SnowflakeMap Member))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member)))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
guild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
-> Maybe (IxValue (SnowflakeMap Member))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (Member -> Snowflake Member
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Member
member)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, IxValue (SnowflakeMap Member)) -> IO ()) -> IO ())
-> [(Guild, IxValue (SnowflakeMap Member)) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, IxValue (SnowflakeMap Member)) -> IO ())
-> (Guild, IxValue (SnowflakeMap Member)) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, IxValue (SnowflakeMap Member)
member)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildMemberAddEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildMemberRemove GuildMemberRemoveData {User
user :: User
$sel:user:GuildMemberRemoveData :: GuildMemberRemoveData -> User
user, Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:GuildMemberRemoveData :: GuildMemberRemoveData -> Snowflake Guild
guildID}) = do
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just IxValue (SnowflakeMap Member)
member <- Maybe (IxValue (SnowflakeMap Member))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member)))
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe (IxValue (SnowflakeMap Member))
 -> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member))))
-> Maybe (IxValue (SnowflakeMap Member))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member)))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
guild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
-> Maybe (IxValue (SnowflakeMap Member))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (User -> Snowflake Member
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID User
user)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, IxValue (SnowflakeMap Member)) -> IO ()) -> IO ())
-> [(Guild, IxValue (SnowflakeMap Member)) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, IxValue (SnowflakeMap Member)) -> IO ())
-> (Guild, IxValue (SnowflakeMap Member)) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, IxValue (SnowflakeMap Member)
member)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildMemberRemoveEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildMemberUpdate GuildMemberUpdateData {User
user :: User
$sel:user:GuildMemberUpdateData :: GuildMemberUpdateData -> User
user, Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:GuildMemberUpdateData :: GuildMemberUpdateData -> Snowflake Guild
guildID}) = do
  Just Guild
oldGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just IxValue (SnowflakeMap Member)
oldMember <- Maybe (IxValue (SnowflakeMap Member))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member)))
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe (IxValue (SnowflakeMap Member))
 -> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member))))
-> Maybe (IxValue (SnowflakeMap Member))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member)))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
oldGuild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
-> Maybe (IxValue (SnowflakeMap Member))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (User -> Snowflake Member
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID User
user)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
newGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just IxValue (SnowflakeMap Member)
newMember <- Maybe (IxValue (SnowflakeMap Member))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member)))
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe (IxValue (SnowflakeMap Member))
 -> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member))))
-> Maybe (IxValue (SnowflakeMap Member))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Member)))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
newGuild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
-> Maybe (IxValue (SnowflakeMap Member))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (User -> Snowflake Member
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID User
user)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, IxValue (SnowflakeMap Member),
   IxValue (SnowflakeMap Member))
  -> IO ())
 -> IO ())
-> [(Guild, IxValue (SnowflakeMap Member),
     IxValue (SnowflakeMap Member))
    -> IO ()]
-> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, IxValue (SnowflakeMap Member),
  IxValue (SnowflakeMap Member))
 -> IO ())
-> (Guild, IxValue (SnowflakeMap Member),
    IxValue (SnowflakeMap Member))
-> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
newGuild, IxValue (SnowflakeMap Member)
oldMember, IxValue (SnowflakeMap Member)
newMember)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildMemberUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildMembersChunk GuildMembersChunkData {[Member]
members :: [Member]
$sel:members:GuildMembersChunkData :: GuildMembersChunkData -> [Member]
members, Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:GuildMembersChunkData :: GuildMembersChunkData -> Snowflake Guild
guildID}) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  let memberIDs :: [Snowflake Member]
memberIDs = (Member -> Snowflake Member) -> [Member] -> [Snowflake Member]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @Member) [Member]
members
  let members' :: [IxValue (SnowflakeMap Member)]
members' = (Snowflake Member -> Maybe (IxValue (SnowflakeMap Member)))
-> [Snowflake Member] -> [IxValue (SnowflakeMap Member)]
forall (a :: OpticKind) (b :: OpticKind).
(a -> Maybe b) -> [a] -> [b]
mapMaybe (\Snowflake Member
mid -> Guild
guild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
-> Maybe (IxValue (SnowflakeMap Member))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Member)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at Index (SnowflakeMap Member)
Snowflake Member
mid) [Snowflake Member]
memberIDs
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, [IxValue (SnowflakeMap Member)]) -> IO ()) -> IO ())
-> [(Guild, [IxValue (SnowflakeMap Member)]) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, [IxValue (SnowflakeMap Member)]) -> IO ())
-> (Guild, [IxValue (SnowflakeMap Member)]) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, [IxValue (SnowflakeMap Member)]
members')) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildMembersChunkEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildRoleCreate GuildRoleData {Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:GuildRoleData :: GuildRoleData -> Snowflake Guild
guildID, Role
role :: Role
$sel:role:GuildRoleData :: GuildRoleData -> Role
role}) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just IxValue (SnowflakeMap Role)
role' <- Maybe (IxValue (SnowflakeMap Role))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role)))
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe (IxValue (SnowflakeMap Role))
 -> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role))))
-> Maybe (IxValue (SnowflakeMap Role))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role)))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
guild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Role)))
-> Maybe (IxValue (SnowflakeMap Role))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
#roles Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     (Maybe (IxValue (SnowflakeMap Role)))
     (Maybe (IxValue (SnowflakeMap Role)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Role)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Role)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     (Maybe (IxValue (SnowflakeMap Role)))
     (Maybe (IxValue (SnowflakeMap Role)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (Role -> Snowflake Role
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Role
role)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, IxValue (SnowflakeMap Role)) -> IO ()) -> IO ())
-> [(Guild, IxValue (SnowflakeMap Role)) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, IxValue (SnowflakeMap Role)) -> IO ())
-> (Guild, IxValue (SnowflakeMap Role)) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, IxValue (SnowflakeMap Role)
role')) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildRoleCreateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildRoleUpdate GuildRoleData {Snowflake Guild
$sel:guildID:GuildRoleData :: GuildRoleData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, Role
$sel:role:GuildRoleData :: GuildRoleData -> Role
role :: Role
role}) = do
  Just Guild
oldGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just IxValue (SnowflakeMap Role)
oldRole <- Maybe (IxValue (SnowflakeMap Role))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role)))
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe (IxValue (SnowflakeMap Role))
 -> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role))))
-> Maybe (IxValue (SnowflakeMap Role))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role)))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
oldGuild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Role)))
-> Maybe (IxValue (SnowflakeMap Role))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
#roles Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     (Maybe (IxValue (SnowflakeMap Role)))
     (Maybe (IxValue (SnowflakeMap Role)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Role)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Role)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     (Maybe (IxValue (SnowflakeMap Role)))
     (Maybe (IxValue (SnowflakeMap Role)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (Role -> Snowflake Role
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Role
role)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
newGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just IxValue (SnowflakeMap Role)
newRole <- Maybe (IxValue (SnowflakeMap Role))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role)))
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe (IxValue (SnowflakeMap Role))
 -> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role))))
-> Maybe (IxValue (SnowflakeMap Role))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role)))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
newGuild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Role)))
-> Maybe (IxValue (SnowflakeMap Role))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
#roles Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     (Maybe (IxValue (SnowflakeMap Role)))
     (Maybe (IxValue (SnowflakeMap Role)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Role)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Role)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     (Maybe (IxValue (SnowflakeMap Role)))
     (Maybe (IxValue (SnowflakeMap Role)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (Role -> Snowflake Role
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Role
role)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, IxValue (SnowflakeMap Role), IxValue (SnowflakeMap Role))
  -> IO ())
 -> IO ())
-> [(Guild, IxValue (SnowflakeMap Role),
     IxValue (SnowflakeMap Role))
    -> IO ()]
-> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, IxValue (SnowflakeMap Role), IxValue (SnowflakeMap Role))
 -> IO ())
-> (Guild, IxValue (SnowflakeMap Role),
    IxValue (SnowflakeMap Role))
-> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
newGuild, IxValue (SnowflakeMap Role)
oldRole, IxValue (SnowflakeMap Role)
newRole)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildRoleUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(GuildRoleDelete GuildRoleDeleteData {Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:GuildRoleDeleteData :: GuildRoleDeleteData -> Snowflake Guild
guildID, Snowflake Role
roleID :: Snowflake Role
$sel:roleID:GuildRoleDeleteData :: GuildRoleDeleteData -> Snowflake Role
roleID}) = do
  Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just IxValue (SnowflakeMap Role)
role <- Maybe (IxValue (SnowflakeMap Role))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role)))
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe (IxValue (SnowflakeMap Role))
 -> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role))))
-> Maybe (IxValue (SnowflakeMap Role))
-> Sem (Fail : r) (Maybe (IxValue (SnowflakeMap Role)))
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
guild Guild
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Role)))
-> Maybe (IxValue (SnowflakeMap Role))
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
#roles Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     (Maybe (IxValue (SnowflakeMap Role)))
     (Maybe (IxValue (SnowflakeMap Role)))
-> Optic' A_Lens NoIx Guild (Maybe (IxValue (SnowflakeMap Role)))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Role)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Role)
     (SnowflakeMap Role)
     (Maybe (IxValue (SnowflakeMap Role)))
     (Maybe (IxValue (SnowflakeMap Role)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at Index (SnowflakeMap Role)
Snowflake Role
roleID
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Guild, IxValue (SnowflakeMap Role)) -> IO ()) -> IO ())
-> [(Guild, IxValue (SnowflakeMap Role)) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, IxValue (SnowflakeMap Role)) -> IO ())
-> (Guild, IxValue (SnowflakeMap Role)) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
guild, IxValue (SnowflakeMap Role)
role)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildRoleDeleteEvt EventHandlers
eh)
handleEvent' EventHandlers
eh (InviteCreate InviteCreateData
d) = do
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((InviteCreateData -> IO ()) -> IO ())
-> [InviteCreateData -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((InviteCreateData -> IO ()) -> InviteCreateData -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ InviteCreateData
d) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'InviteCreateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh (InviteDelete InviteDeleteData
d) = do
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((InviteDeleteData -> IO ()) -> IO ())
-> [InviteDeleteData -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((InviteDeleteData -> IO ()) -> InviteDeleteData -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ InviteDeleteData
d) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'InviteDeleteEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(MessageCreate Message
msg Maybe User
user Maybe Member
member) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Message, Maybe User, Maybe Member) -> IO ()) -> IO ())
-> [(Message, Maybe User, Maybe Member) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Message, Maybe User, Maybe Member) -> IO ())
-> (Message, Maybe User, Maybe Member) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Message
msg, Maybe User
user, Maybe Member
member)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'MessageCreateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(MessageUpdate UpdatedMessage
msg Maybe User
user Maybe Member
member) = do
  Maybe Message
oldMsg <- Snowflake Message -> Sem (Fail : r) (Maybe Message)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r (Maybe Message)
getMessage (UpdatedMessage -> Snowflake Message
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID UpdatedMessage
msg)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Maybe Message
newMsg <- Snowflake Message -> Sem (Fail : r) (Maybe Message)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r (Maybe Message)
getMessage (UpdatedMessage -> Snowflake Message
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID UpdatedMessage
msg)
  let rawActions :: [IO ()]
rawActions = (((UpdatedMessage, Maybe User, Maybe Member) -> IO ()) -> IO ())
-> [(UpdatedMessage, Maybe User, Maybe Member) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((UpdatedMessage, Maybe User, Maybe Member) -> IO ())
-> (UpdatedMessage, Maybe User, Maybe Member) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (UpdatedMessage
msg, Maybe User
user, Maybe Member
member)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'RawMessageUpdateEvt EventHandlers
eh)
  let actions :: [IO ()]
actions = case (Maybe Message
oldMsg, Maybe Message
newMsg) of
        (Just Message
oldMsg', Just Message
newMsg') ->
          (((Message, Message, Maybe User, Maybe Member) -> IO ()) -> IO ())
-> [(Message, Message, Maybe User, Maybe Member) -> IO ()]
-> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Message, Message, Maybe User, Maybe Member) -> IO ())
-> (Message, Message, Maybe User, Maybe Member) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Message
oldMsg', Message
newMsg', Maybe User
user, Maybe Member
member)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'MessageUpdateEvt EventHandlers
eh)
        (Maybe Message, Maybe Message)
_ -> []
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [IO ()]
rawActions [IO ()] -> [IO ()] -> [IO ()]
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [IO ()]
actions
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(MessageDelete MessageDeleteData {Snowflake Message
id :: Snowflake Message
$sel:id:MessageDeleteData :: MessageDeleteData -> Snowflake Message
id}) = do
  Maybe Message
oldMsg <- Snowflake Message -> Sem (Fail : r) (Maybe Message)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r (Maybe Message)
getMessage Snowflake Message
id
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  let rawActions :: [IO ()]
rawActions = ((Snowflake Message -> IO ()) -> IO ())
-> [Snowflake Message -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Snowflake Message -> IO ()) -> Snowflake Message -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Snowflake Message
id) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'RawMessageDeleteEvt EventHandlers
eh)
  let actions :: [IO ()]
actions = case Maybe Message
oldMsg of
        Just Message
oldMsg' ->
          ((Message -> IO ()) -> IO ()) -> [Message -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Message -> IO ()) -> Message -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Message
oldMsg') (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'MessageDeleteEvt EventHandlers
eh)
        Maybe Message
_ -> []
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [IO ()]
rawActions [IO ()] -> [IO ()] -> [IO ()]
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [IO ()]
actions
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(MessageDeleteBulk MessageDeleteBulkData {[Snowflake Message]
ids :: [Snowflake Message]
$sel:ids:MessageDeleteBulkData :: MessageDeleteBulkData -> [Snowflake Message]
ids}) = do
  [Message]
messages <- [Maybe Message] -> [Message]
forall (a :: OpticKind). [Maybe a] -> [a]
catMaybes ([Maybe Message] -> [Message])
-> Sem (Fail : r) [Maybe Message] -> Sem (Fail : r) [Message]
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> (Snowflake Message -> Sem (Fail : r) (Maybe Message))
-> [Snowflake Message] -> Sem (Fail : r) [Maybe Message]
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Snowflake Message -> Sem (Fail : r) (Maybe Message)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r (Maybe Message)
getMessage [Snowflake Message]
ids
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  let rawActions :: [IO ()]
rawActions = (([Snowflake Message] -> IO ()) -> IO ())
-> [[Snowflake Message] -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (([Snowflake Message] -> IO ()) -> [Snowflake Message] -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [Snowflake Message]
ids) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'RawMessageDeleteBulkEvt EventHandlers
eh)
  let actions :: [IO ()]
actions = (([Message] -> IO ()) -> IO ()) -> [[Message] -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (([Message] -> IO ()) -> [Message] -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [Message]
messages) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'MessageDeleteBulkEvt EventHandlers
eh)
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [IO ()]
rawActions [IO ()] -> [IO ()] -> [IO ()]
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [IO ()]
actions
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(MessageReactionAdd ReactionEvtData
reaction) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Maybe Message
msg <- Snowflake Message -> Sem (Fail : r) (Maybe Message)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r (Maybe Message)
getMessage (ReactionEvtData -> Snowflake Message
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID ReactionEvtData
reaction)
  Maybe User
user <- Snowflake User -> Sem (Fail : r) (Maybe User)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake User -> Sem r (Maybe User)
getUser (ReactionEvtData -> Snowflake User
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID ReactionEvtData
reaction)
  Maybe Channel
chan <- case ReactionEvtData
reaction ReactionEvtData
-> Optic' A_Lens NoIx ReactionEvtData (Maybe (Snowflake Guild))
-> Maybe (Snowflake Guild)
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ReactionEvtData (Maybe (Snowflake Guild))
#guildID of
    Just Snowflake Guild
_ -> do
      Maybe GuildChannel
chan <- Snowflake GuildChannel -> Sem (Fail : r) (Maybe GuildChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake GuildChannel -> Sem r (Maybe GuildChannel)
getGuildChannel (Snowflake Channel -> Snowflake GuildChannel
forall (a :: OpticKind) (b :: OpticKind).
Snowflake a -> Snowflake b
coerceSnowflake (Snowflake Channel -> Snowflake GuildChannel)
-> Snowflake Channel -> Snowflake GuildChannel
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @Channel ReactionEvtData
reaction)
      Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Maybe GuildChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Maybe GuildChannel
chan)
    Maybe (Snowflake Guild)
Nothing -> do
      Maybe DMChannel
chan <- Snowflake DMChannel -> Sem (Fail : r) (Maybe DMChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> Sem r (Maybe DMChannel)
getDM (Snowflake Channel -> Snowflake DMChannel
forall (a :: OpticKind) (b :: OpticKind).
Snowflake a -> Snowflake b
coerceSnowflake (Snowflake Channel -> Snowflake DMChannel)
-> Snowflake Channel -> Snowflake DMChannel
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @Channel ReactionEvtData
reaction)
      Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (DMChannel -> Channel
DMChannel' (DMChannel -> Channel) -> Maybe DMChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Maybe DMChannel
chan)
  let rawActions :: [IO ()]
rawActions = ((ReactionEvtData -> IO ()) -> IO ())
-> [ReactionEvtData -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((ReactionEvtData -> IO ()) -> ReactionEvtData -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ReactionEvtData
reaction) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'RawMessageReactionAddEvt EventHandlers
eh)
  let actions :: [IO ()]
actions = case (Maybe Message
msg, Maybe User
user, Maybe Channel
chan) of
        (Just Message
msg', Just User
user', Just Channel
chan') ->
          (((Message, User, Channel, RawEmoji) -> IO ()) -> IO ())
-> [(Message, User, Channel, RawEmoji) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Message, User, Channel, RawEmoji) -> IO ())
-> (Message, User, Channel, RawEmoji) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Message
msg', User
user', Channel
chan', ReactionEvtData
reaction ReactionEvtData
-> Optic' A_Lens NoIx ReactionEvtData RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ReactionEvtData RawEmoji
#emoji)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'MessageReactionAddEvt EventHandlers
eh)
        (Maybe Message, Maybe User, Maybe Channel)
_ -> []
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [IO ()]
rawActions [IO ()] -> [IO ()] -> [IO ()]
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [IO ()]
actions
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(MessageReactionRemove ReactionEvtData
reaction) = do
  Maybe Message
msg <- Snowflake Message -> Sem (Fail : r) (Maybe Message)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r (Maybe Message)
getMessage (ReactionEvtData -> Snowflake Message
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID ReactionEvtData
reaction)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Maybe User
user <- Snowflake User -> Sem (Fail : r) (Maybe User)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake User -> Sem r (Maybe User)
getUser (ReactionEvtData -> Snowflake User
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID ReactionEvtData
reaction)
  Maybe Channel
chan <- case ReactionEvtData
reaction ReactionEvtData
-> Optic' A_Lens NoIx ReactionEvtData (Maybe (Snowflake Guild))
-> Maybe (Snowflake Guild)
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ReactionEvtData (Maybe (Snowflake Guild))
#guildID of
    Just Snowflake Guild
_ -> do
      Maybe GuildChannel
chan <- Snowflake GuildChannel -> Sem (Fail : r) (Maybe GuildChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake GuildChannel -> Sem r (Maybe GuildChannel)
getGuildChannel (Snowflake Channel -> Snowflake GuildChannel
forall (a :: OpticKind) (b :: OpticKind).
Snowflake a -> Snowflake b
coerceSnowflake (Snowflake Channel -> Snowflake GuildChannel)
-> Snowflake Channel -> Snowflake GuildChannel
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @Channel ReactionEvtData
reaction)
      Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Maybe GuildChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Maybe GuildChannel
chan)
    Maybe (Snowflake Guild)
Nothing -> do
      Maybe DMChannel
chan <- Snowflake DMChannel -> Sem (Fail : r) (Maybe DMChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> Sem r (Maybe DMChannel)
getDM (Snowflake Channel -> Snowflake DMChannel
forall (a :: OpticKind) (b :: OpticKind).
Snowflake a -> Snowflake b
coerceSnowflake (Snowflake Channel -> Snowflake DMChannel)
-> Snowflake Channel -> Snowflake DMChannel
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @Channel ReactionEvtData
reaction)
      Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (DMChannel -> Channel
DMChannel' (DMChannel -> Channel) -> Maybe DMChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Maybe DMChannel
chan)
  let rawActions :: [IO ()]
rawActions = ((ReactionEvtData -> IO ()) -> IO ())
-> [ReactionEvtData -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((ReactionEvtData -> IO ()) -> ReactionEvtData -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ReactionEvtData
reaction) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'RawMessageReactionRemoveEvt EventHandlers
eh)
  let actions :: [IO ()]
actions = case (Maybe Message
msg, Maybe User
user, Maybe Channel
chan) of
        (Just Message
msg', Just User
user', Just Channel
chan') ->
          (((Message, User, Channel, RawEmoji) -> IO ()) -> IO ())
-> [(Message, User, Channel, RawEmoji) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Message, User, Channel, RawEmoji) -> IO ())
-> (Message, User, Channel, RawEmoji) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Message
msg', User
user', Channel
chan', ReactionEvtData
reaction ReactionEvtData
-> Optic' A_Lens NoIx ReactionEvtData RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ReactionEvtData RawEmoji
#emoji)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'MessageReactionRemoveEvt EventHandlers
eh)
        (Maybe Message, Maybe User, Maybe Channel)
_ -> []
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [IO ()]
rawActions [IO ()] -> [IO ()] -> [IO ()]
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [IO ()]
actions
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(MessageReactionRemoveAll MessageReactionRemoveAllData {Snowflake Message
messageID :: Snowflake Message
$sel:messageID:MessageReactionRemoveAllData :: MessageReactionRemoveAllData -> Snowflake Message
messageID}) = do
  Maybe Message
msg <- Snowflake Message -> Sem (Fail : r) (Maybe Message)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r (Maybe Message)
getMessage Snowflake Message
messageID
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  let rawActions :: [IO ()]
rawActions = ((Snowflake Message -> IO ()) -> IO ())
-> [Snowflake Message -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Snowflake Message -> IO ()) -> Snowflake Message -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Snowflake Message
messageID) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'RawMessageReactionRemoveAllEvt EventHandlers
eh)
  let actions :: [IO ()]
actions = case Maybe Message
msg of
        Just Message
msg' ->
          ((Message -> IO ()) -> IO ()) -> [Message -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Message -> IO ()) -> Message -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Message
msg') (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'MessageReactionRemoveAllEvt EventHandlers
eh)
        Maybe Message
_ -> []
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [IO ()]
rawActions [IO ()] -> [IO ()] -> [IO ()]
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [IO ()]
actions
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(PresenceUpdate PresenceUpdateData {Snowflake User
userID :: Snowflake User
$sel:userID:PresenceUpdateData :: PresenceUpdateData -> Snowflake User
userID, $sel:presence:PresenceUpdateData :: PresenceUpdateData -> Presence
presence = Presence {Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:Presence :: Presence -> Snowflake Guild
guildID}}) = do
  Just Guild
oldGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just Member
oldMember <- Maybe Member -> Sem (Fail : r) (Maybe Member)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe Member -> Sem (Fail : r) (Maybe Member))
-> Maybe Member -> Sem (Fail : r) (Maybe Member)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
oldGuild Guild -> Optic' A_Lens NoIx Guild (Maybe Member) -> Maybe Member
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe Member)
     (Maybe Member)
-> Optic' A_Lens NoIx Guild (Maybe Member)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (Snowflake User -> Snowflake Member
forall (a :: OpticKind) (b :: OpticKind).
Snowflake a -> Snowflake b
coerceSnowflake Snowflake User
userID)
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just Guild
newGuild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  Just Member
newMember <- Maybe Member -> Sem (Fail : r) (Maybe Member)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe Member -> Sem (Fail : r) (Maybe Member))
-> Maybe Member -> Sem (Fail : r) (Maybe Member)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Guild
newGuild Guild -> Optic' A_Lens NoIx Guild (Maybe Member) -> Maybe Member
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe Member)
     (Maybe Member)
-> Optic' A_Lens NoIx Guild (Maybe Member)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (Snowflake User -> Snowflake Member
forall (a :: OpticKind) (b :: OpticKind).
Snowflake a -> Snowflake b
coerceSnowflake Snowflake User
userID)
  let User
oldUser :: User = let Member {Bool
Maybe Bool
Maybe Word64
Maybe Text
Maybe (Colour Double)
Maybe UserBanner
Text
UTCTime
Vector (Snowflake Role)
Snowflake User
Avatar
id :: Snowflake User
username :: Text
discriminator :: Text
bot :: Maybe Bool
avatar :: Avatar
memberAvatar :: Maybe Text
mfaEnabled :: Maybe Bool
banner :: Maybe UserBanner
accentColour :: Maybe (Colour Double)
locale :: Maybe Text
verified :: Maybe Bool
email :: Maybe Text
flags :: Maybe Word64
premiumType :: Maybe Word64
nick :: Maybe Text
roles :: Vector (Snowflake Role)
joinedAt :: UTCTime
deaf :: Bool
mute :: Bool
$sel:id:Member :: Member -> Snowflake User
$sel:username:Member :: Member -> Text
$sel:discriminator:Member :: Member -> Text
$sel:bot:Member :: Member -> Maybe Bool
$sel:avatar:Member :: Member -> Avatar
$sel:memberAvatar:Member :: Member -> Maybe Text
$sel:mfaEnabled:Member :: Member -> Maybe Bool
$sel:banner:Member :: Member -> Maybe UserBanner
$sel:accentColour:Member :: Member -> Maybe (Colour Double)
$sel:locale:Member :: Member -> Maybe Text
$sel:verified:Member :: Member -> Maybe Bool
$sel:email:Member :: Member -> Maybe Text
$sel:flags:Member :: Member -> Maybe Word64
$sel:premiumType:Member :: Member -> Maybe Word64
$sel:nick:Member :: Member -> Maybe Text
$sel:roles:Member :: Member -> Vector (Snowflake Role)
$sel:joinedAt:Member :: Member -> UTCTime
$sel:deaf:Member :: Member -> Bool
$sel:mute:Member :: Member -> Bool
..} = Member
oldMember in User {Maybe Bool
Maybe Word64
Maybe Text
Maybe (Colour Double)
Maybe UserBanner
Text
Snowflake User
Avatar
id :: Snowflake User
username :: Text
discriminator :: Text
bot :: Maybe Bool
avatar :: Avatar
mfaEnabled :: Maybe Bool
banner :: Maybe UserBanner
accentColour :: Maybe (Colour Double)
locale :: Maybe Text
verified :: Maybe Bool
email :: Maybe Text
flags :: Maybe Word64
premiumType :: Maybe Word64
$sel:id:User :: Snowflake User
$sel:username:User :: Text
$sel:discriminator:User :: Text
$sel:bot:User :: Maybe Bool
$sel:avatar:User :: Avatar
$sel:mfaEnabled:User :: Maybe Bool
$sel:banner:User :: Maybe UserBanner
$sel:accentColour:User :: Maybe (Colour Double)
$sel:locale:User :: Maybe Text
$sel:verified:User :: Maybe Bool
$sel:email:User :: Maybe Text
$sel:flags:User :: Maybe Word64
$sel:premiumType:User :: Maybe Word64
..}
      User
newUser :: User = let Member {Bool
Maybe Bool
Maybe Word64
Maybe Text
Maybe (Colour Double)
Maybe UserBanner
Text
UTCTime
Vector (Snowflake Role)
Snowflake User
Avatar
$sel:id:Member :: Member -> Snowflake User
$sel:username:Member :: Member -> Text
$sel:discriminator:Member :: Member -> Text
$sel:bot:Member :: Member -> Maybe Bool
$sel:avatar:Member :: Member -> Avatar
$sel:memberAvatar:Member :: Member -> Maybe Text
$sel:mfaEnabled:Member :: Member -> Maybe Bool
$sel:banner:Member :: Member -> Maybe UserBanner
$sel:accentColour:Member :: Member -> Maybe (Colour Double)
$sel:locale:Member :: Member -> Maybe Text
$sel:verified:Member :: Member -> Maybe Bool
$sel:email:Member :: Member -> Maybe Text
$sel:flags:Member :: Member -> Maybe Word64
$sel:premiumType:Member :: Member -> Maybe Word64
$sel:nick:Member :: Member -> Maybe Text
$sel:roles:Member :: Member -> Vector (Snowflake Role)
$sel:joinedAt:Member :: Member -> UTCTime
$sel:deaf:Member :: Member -> Bool
$sel:mute:Member :: Member -> Bool
id :: Snowflake User
username :: Text
discriminator :: Text
bot :: Maybe Bool
avatar :: Avatar
memberAvatar :: Maybe Text
mfaEnabled :: Maybe Bool
banner :: Maybe UserBanner
accentColour :: Maybe (Colour Double)
locale :: Maybe Text
verified :: Maybe Bool
email :: Maybe Text
flags :: Maybe Word64
premiumType :: Maybe Word64
nick :: Maybe Text
roles :: Vector (Snowflake Role)
joinedAt :: UTCTime
deaf :: Bool
mute :: Bool
..} = Member
newMember in User {Maybe Bool
Maybe Word64
Maybe Text
Maybe (Colour Double)
Maybe UserBanner
Text
Snowflake User
Avatar
$sel:id:User :: Snowflake User
$sel:username:User :: Text
$sel:discriminator:User :: Text
$sel:bot:User :: Maybe Bool
$sel:avatar:User :: Avatar
$sel:mfaEnabled:User :: Maybe Bool
$sel:banner:User :: Maybe UserBanner
$sel:accentColour:User :: Maybe (Colour Double)
$sel:locale:User :: Maybe Text
$sel:verified:User :: Maybe Bool
$sel:email:User :: Maybe Text
$sel:flags:User :: Maybe Word64
$sel:premiumType:User :: Maybe Word64
id :: Snowflake User
username :: Text
discriminator :: Text
bot :: Maybe Bool
avatar :: Avatar
mfaEnabled :: Maybe Bool
banner :: Maybe UserBanner
accentColour :: Maybe (Colour Double)
locale :: Maybe Text
verified :: Maybe Bool
email :: Maybe Text
flags :: Maybe Word64
premiumType :: Maybe Word64
..}
      userUpdates :: [IO ()]
userUpdates =
        if User
oldUser User -> User -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
/= User
newUser
          then (((User, User) -> IO ()) -> IO ())
-> [(User, User) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((User, User) -> IO ()) -> (User, User) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (User
oldUser, User
newUser)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'UserUpdateEvt EventHandlers
eh)
          else [IO ()]
forall (a :: OpticKind). Monoid a => a
mempty
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ [IO ()]
userUpdates [IO ()] -> [IO ()] -> [IO ()]
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> (((Guild, Member, Member) -> IO ()) -> IO ())
-> [(Guild, Member, Member) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Guild, Member, Member) -> IO ())
-> (Guild, Member, Member) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Guild
newGuild, Member
oldMember, Member
newMember)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'GuildMemberUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh (TypingStart TypingStartData {Snowflake Channel
channelID :: Snowflake Channel
$sel:channelID:TypingStartData :: TypingStartData -> Snowflake Channel
channelID, Maybe (Snowflake Guild)
guildID :: Maybe (Snowflake Guild)
$sel:guildID:TypingStartData :: TypingStartData -> Maybe (Snowflake Guild)
guildID, Snowflake User
userID :: Snowflake User
$sel:userID:TypingStartData :: TypingStartData -> Snowflake User
userID, $sel:timestamp:TypingStartData :: TypingStartData -> UnixTimestamp
timestamp = UnixTimestamp UTCTime
timestamp}) =
  case Maybe (Snowflake Guild)
guildID of
    Just Snowflake Guild
gid -> do
      Just Guild
guild <- Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
gid
      Just Channel
chan <- Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure (Maybe Channel -> Sem (Fail : r) (Maybe Channel))
-> Maybe Channel -> Sem (Fail : r) (Maybe Channel)
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Maybe GuildChannel -> Maybe Channel
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Guild
guild Guild
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
-> Maybe GuildChannel
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
     (Maybe GuildChannel)
     (Maybe GuildChannel)
-> Optic' A_Lens NoIx Guild (Maybe GuildChannel)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap GuildChannel)
-> Lens'
     (SnowflakeMap GuildChannel)
     (Maybe (IxValue (SnowflakeMap GuildChannel)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (Snowflake Channel -> Snowflake GuildChannel
forall (a :: OpticKind) (b :: OpticKind).
Snowflake a -> Snowflake b
coerceSnowflake Snowflake Channel
channelID)
      [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Channel, Snowflake User, UTCTime) -> IO ()) -> IO ())
-> [(Channel, Snowflake User, UTCTime) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Channel, Snowflake User, UTCTime) -> IO ())
-> (Channel, Snowflake User, UTCTime) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Channel
chan, Snowflake User
userID, UTCTime
timestamp)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'TypingStartEvt EventHandlers
eh)
    Maybe (Snowflake Guild)
Nothing -> do
      Just Channel
chan <- DMChannel -> Channel
DMChannel' (DMChannel -> Channel)
-> Sem (Fail : r) (Maybe DMChannel)
-> Sem (Fail : r) (Maybe Channel)
forall (f :: OpticKind -> OpticKind) (g :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> Snowflake DMChannel -> Sem (Fail : r) (Maybe DMChannel)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> Sem r (Maybe DMChannel)
getDM (Snowflake Channel -> Snowflake DMChannel
forall (a :: OpticKind) (b :: OpticKind).
Snowflake a -> Snowflake b
coerceSnowflake Snowflake Channel
channelID)
      [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Channel, Snowflake User, UTCTime) -> IO ()) -> IO ())
-> [(Channel, Snowflake User, UTCTime) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Channel, Snowflake User, UTCTime) -> IO ())
-> (Channel, Snowflake User, UTCTime) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Channel
chan, Snowflake User
userID, UTCTime
timestamp)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'TypingStartEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(UserUpdate User
_) = do
  Just User
oldUser <- Sem (Fail : r) (Maybe User)
forall (r :: EffectRow). Member CacheEff r => Sem r (Maybe User)
getBotUser
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  Just User
newUser <- Sem (Fail : r) (Maybe User)
forall (r :: EffectRow). Member CacheEff r => Sem r (Maybe User)
getBotUser
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((User, User) -> IO ()) -> IO ())
-> [(User, User) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((User, User) -> IO ()) -> (User, User) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (User
oldUser, User
newUser)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'UserUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(VoiceStateUpdate newVoiceState :: VoiceState
newVoiceState@V.VoiceState {$sel:guildID:VoiceState :: VoiceState -> Maybe (Snowflake Guild)
guildID = Just Snowflake Guild
guildID}) = do
  Maybe VoiceState
oldVoiceState <- (((VoiceState -> Bool) -> [VoiceState] -> Maybe VoiceState
forall (t :: OpticKind -> OpticKind) (a :: OpticKind).
Foldable t =>
(a -> Bool) -> t a -> Maybe a
find ((Text -> Text -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
== VoiceState -> Text
V.sessionID VoiceState
newVoiceState) (Text -> Bool) -> (VoiceState -> Text) -> VoiceState -> Bool
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. VoiceState -> Text
V.sessionID) ([VoiceState] -> Maybe VoiceState)
-> (Guild -> [VoiceState]) -> Guild -> Maybe VoiceState
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Guild -> [VoiceState]
voiceStates) (Guild -> Maybe VoiceState) -> Maybe Guild -> Maybe VoiceState
forall (m :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Monad m =>
(a -> m b) -> m a -> m b
=<<) (Maybe Guild -> Maybe VoiceState)
-> Sem (Fail : r) (Maybe Guild)
-> Sem (Fail : r) (Maybe VoiceState)
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Snowflake Guild -> Sem (Fail : r) (Maybe Guild)
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r (Maybe Guild)
getGuild Snowflake Guild
guildID
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (((Maybe VoiceState, VoiceState) -> IO ()) -> IO ())
-> [(Maybe VoiceState, VoiceState) -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map (((Maybe VoiceState, VoiceState) -> IO ())
-> (Maybe VoiceState, VoiceState) -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (Maybe VoiceState
oldVoiceState, VoiceState
newVoiceState)) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'VoiceStateUpdateEvt EventHandlers
eh)
handleEvent' EventHandlers
eh evt :: DispatchData
evt@(InteractionCreate Interaction
interaction) = do
  DispatchData -> Sem (Fail : r) ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache DispatchData
evt
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ([IO ()] -> Sem (Fail : r) [IO ()])
-> [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ ((Interaction -> IO ()) -> IO ())
-> [Interaction -> IO ()] -> [IO ()]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map ((Interaction -> IO ()) -> Interaction -> IO ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Interaction
interaction) (forall (a :: EventType).
GetEventHandlers a =>
EventHandlers -> [StoredEHType a]
getEventHandlers @'InteractionEvt EventHandlers
eh)
handleEvent' EventHandlers
_ (UNHANDLED Text
e) = do
  Text -> Sem (Fail : r) ()
forall (r :: EffectRow). Member LogEff r => Text -> Sem r ()
debug (Text -> Sem (Fail : r) ())
-> (String -> Text) -> String -> Sem (Fail : r) ()
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Sem (Fail : r) ()) -> String -> Sem (Fail : r) ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ String
"Not handling event: " String -> String -> String
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> Text -> String
forall (a :: OpticKind). Show a => a -> String
show Text
e
  [IO ()] -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). a -> Sem (Fail : r) a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure []
handleEvent' EventHandlers
_ DispatchData
e = String -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind). String -> Sem (Fail : r) a
forall (m :: OpticKind -> OpticKind) (a :: OpticKind).
MonadFail m =>
String -> m a
fail (String -> Sem (Fail : r) [IO ()])
-> String -> Sem (Fail : r) [IO ()]
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ String
"Unhandled event: " String -> String -> String
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> DispatchData -> String
forall (a :: OpticKind). Show a => a -> String
show DispatchData
e

updateCache :: P.Members '[CacheEff, P.Fail] r => DispatchData -> P.Sem r ()
updateCache :: forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache (Ready ReadyData {User
user :: User
$sel:user:ReadyData :: ReadyData -> User
user, [UnavailableGuild]
guilds :: [UnavailableGuild]
$sel:guilds:ReadyData :: ReadyData -> [UnavailableGuild]
guilds}) = do
  User -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => User -> Sem r ()
setBotUser User
user
  [Snowflake Guild] -> (Snowflake Guild -> Sem r ()) -> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ ((UnavailableGuild -> Snowflake Guild)
-> [UnavailableGuild] -> [Snowflake Guild]
forall (a :: OpticKind) (b :: OpticKind). (a -> b) -> [a] -> [b]
map UnavailableGuild -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID [UnavailableGuild]
guilds) Snowflake Guild -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r ()
setUnavailableGuild
updateCache DispatchData
Resumed = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (ChannelCreate (DMChannel' DMChannel
chan)) =
  DMChannel -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => DMChannel -> Sem r ()
setDM DMChannel
chan
updateCache (ChannelCreate (GuildChannel' GuildChannel
chan)) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild (GuildChannel -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan) (Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> (SnowflakeMap GuildChannel -> SnowflakeMap GuildChannel)
-> Guild
-> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ GuildChannel
-> SnowflakeMap GuildChannel -> SnowflakeMap GuildChannel
forall (a :: OpticKind).
HasID' a =>
a -> SnowflakeMap a -> SnowflakeMap a
SM.insert GuildChannel
chan)
updateCache (ChannelUpdate (DMChannel' DMChannel
chan)) =
  Snowflake DMChannel -> (DMChannel -> DMChannel) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> (DMChannel -> DMChannel) -> Sem r ()
updateDM (DMChannel -> Snowflake DMChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID DMChannel
chan) (Updated DMChannel -> DMChannel -> DMChannel
forall (a :: OpticKind). Updateable a => Updated a -> a -> a
update DMChannel
Updated DMChannel
chan)
updateCache (ChannelUpdate (GuildChannel' GuildChannel
chan)) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild (GuildChannel -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan) (Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> Optic
     (IxKind (SnowflakeMap GuildChannel))
     NoIx
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
     (IxValue (SnowflakeMap GuildChannel))
     (IxValue (SnowflakeMap GuildChannel))
-> Optic
     An_AffineTraversal
     NoIx
     Guild
     Guild
     (IxValue (SnowflakeMap GuildChannel))
     (IxValue (SnowflakeMap GuildChannel))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap GuildChannel)
-> Optic
     (IxKind (SnowflakeMap GuildChannel))
     NoIx
     (SnowflakeMap GuildChannel)
     (SnowflakeMap GuildChannel)
     (IxValue (SnowflakeMap GuildChannel))
     (IxValue (SnowflakeMap GuildChannel))
forall (m :: OpticKind).
Ixed m =>
Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix (GuildChannel -> Snowflake GuildChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan) Optic
  An_AffineTraversal
  NoIx
  Guild
  Guild
  (IxValue (SnowflakeMap GuildChannel))
  (IxValue (SnowflakeMap GuildChannel))
-> (IxValue (SnowflakeMap GuildChannel)
    -> IxValue (SnowflakeMap GuildChannel))
-> Guild
-> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Updated (IxValue (SnowflakeMap GuildChannel))
-> IxValue (SnowflakeMap GuildChannel)
-> IxValue (SnowflakeMap GuildChannel)
forall (a :: OpticKind). Updateable a => Updated a -> a -> a
update GuildChannel
Updated (IxValue (SnowflakeMap GuildChannel))
chan)
updateCache (ChannelDelete (DMChannel' DMChannel
chan)) =
  Snowflake DMChannel -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake DMChannel -> Sem r ()
delDM (DMChannel -> Snowflake DMChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID DMChannel
chan)
updateCache (ChannelDelete (GuildChannel' GuildChannel
chan)) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild (GuildChannel -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan) (Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
#channels Optic
  A_Lens
  NoIx
  Guild
  Guild
  (SnowflakeMap GuildChannel)
  (SnowflakeMap GuildChannel)
-> (SnowflakeMap GuildChannel -> SnowflakeMap GuildChannel)
-> Guild
-> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Index (SnowflakeMap GuildChannel)
-> SnowflakeMap GuildChannel -> SnowflakeMap GuildChannel
forall (m :: OpticKind). At m => Index m -> m -> m
sans (GuildChannel -> Snowflake GuildChannel
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID GuildChannel
chan))
updateCache (GuildCreate Guild
guild) = do
  Bool
isNew <- Snowflake Guild -> Sem r Bool
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r Bool
isUnavailableGuild (Guild -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Guild
guild)
  Bool -> Sem r () -> Sem r ()
forall (f :: OpticKind -> OpticKind).
Applicative f =>
Bool -> f () -> f ()
when Bool
isNew (Sem r () -> Sem r ()) -> Sem r () -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ Snowflake Guild -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r ()
delUnavailableGuild (Guild -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Guild
guild)
  Guild -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => Guild -> Sem r ()
setGuild Guild
guild
  [Member] -> (Member -> Sem r ()) -> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ (SnowflakeMap Member -> [Member]
forall (a :: OpticKind). SnowflakeMap a -> [a]
SM.elems (Guild
guild Guild
-> Optic
     A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> SnowflakeMap Member
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members)) (\Member {Bool
Maybe Bool
Maybe Word64
Maybe Text
Maybe (Colour Double)
Maybe UserBanner
Text
UTCTime
Vector (Snowflake Role)
Snowflake User
Avatar
$sel:id:Member :: Member -> Snowflake User
$sel:username:Member :: Member -> Text
$sel:discriminator:Member :: Member -> Text
$sel:bot:Member :: Member -> Maybe Bool
$sel:avatar:Member :: Member -> Avatar
$sel:memberAvatar:Member :: Member -> Maybe Text
$sel:mfaEnabled:Member :: Member -> Maybe Bool
$sel:banner:Member :: Member -> Maybe UserBanner
$sel:accentColour:Member :: Member -> Maybe (Colour Double)
$sel:locale:Member :: Member -> Maybe Text
$sel:verified:Member :: Member -> Maybe Bool
$sel:email:Member :: Member -> Maybe Text
$sel:flags:Member :: Member -> Maybe Word64
$sel:premiumType:Member :: Member -> Maybe Word64
$sel:nick:Member :: Member -> Maybe Text
$sel:roles:Member :: Member -> Vector (Snowflake Role)
$sel:joinedAt:Member :: Member -> UTCTime
$sel:deaf:Member :: Member -> Bool
$sel:mute:Member :: Member -> Bool
id :: Snowflake User
username :: Text
discriminator :: Text
bot :: Maybe Bool
avatar :: Avatar
memberAvatar :: Maybe Text
mfaEnabled :: Maybe Bool
banner :: Maybe UserBanner
accentColour :: Maybe (Colour Double)
locale :: Maybe Text
verified :: Maybe Bool
email :: Maybe Text
flags :: Maybe Word64
premiumType :: Maybe Word64
nick :: Maybe Text
roles :: Vector (Snowflake Role)
joinedAt :: UTCTime
deaf :: Bool
mute :: Bool
..} -> User -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => User -> Sem r ()
setUser User {Maybe Bool
Maybe Word64
Maybe Text
Maybe (Colour Double)
Maybe UserBanner
Text
Snowflake User
Avatar
$sel:id:User :: Snowflake User
$sel:username:User :: Text
$sel:discriminator:User :: Text
$sel:bot:User :: Maybe Bool
$sel:avatar:User :: Avatar
$sel:mfaEnabled:User :: Maybe Bool
$sel:banner:User :: Maybe UserBanner
$sel:accentColour:User :: Maybe (Colour Double)
$sel:locale:User :: Maybe Text
$sel:verified:User :: Maybe Bool
$sel:email:User :: Maybe Text
$sel:flags:User :: Maybe Word64
$sel:premiumType:User :: Maybe Word64
id :: Snowflake User
username :: Text
discriminator :: Text
bot :: Maybe Bool
avatar :: Avatar
mfaEnabled :: Maybe Bool
banner :: Maybe UserBanner
accentColour :: Maybe (Colour Double)
locale :: Maybe Text
verified :: Maybe Bool
email :: Maybe Text
flags :: Maybe Word64
premiumType :: Maybe Word64
..})
updateCache (GuildUpdate UpdatedGuild
guild) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild (UpdatedGuild -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID UpdatedGuild
guild) (Updated Guild -> Guild -> Guild
forall (a :: OpticKind). Updateable a => Updated a -> a -> a
update UpdatedGuild
Updated Guild
guild)
updateCache (GuildDelete UnavailableGuild {Snowflake Guild
$sel:id:UnavailableGuild :: UnavailableGuild -> Snowflake Guild
id :: Snowflake Guild
id, Bool
$sel:unavailable:UnavailableGuild :: UnavailableGuild -> Bool
unavailable :: Bool
unavailable}) =
  if Bool
unavailable
    then Snowflake Guild -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r ()
setUnavailableGuild Snowflake Guild
id
    else Snowflake Guild -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> Sem r ()
delGuild Snowflake Guild
id
updateCache (GuildEmojisUpdate GuildEmojisUpdateData {Snowflake Guild
$sel:guildID:GuildEmojisUpdateData :: GuildEmojisUpdateData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, [Emoji]
$sel:emojis:GuildEmojisUpdateData :: GuildEmojisUpdateData -> [Emoji]
emojis :: [Emoji]
emojis}) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild Snowflake Guild
guildID (Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Emoji) (SnowflakeMap Emoji)
#emojis Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Emoji) (SnowflakeMap Emoji)
-> SnowflakeMap Emoji -> Guild -> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
.~ [Emoji] -> SnowflakeMap Emoji
forall (a :: OpticKind). HasID' a => [a] -> SnowflakeMap a
SM.fromList [Emoji]
emojis)
updateCache (GuildMemberAdd Snowflake Guild
gid Member
member) = do
  User -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => User -> Sem r ()
setUser (User -> Sem r ()) -> User -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ (\Member {Bool
Maybe Bool
Maybe Word64
Maybe Text
Maybe (Colour Double)
Maybe UserBanner
Text
UTCTime
Vector (Snowflake Role)
Snowflake User
Avatar
$sel:id:Member :: Member -> Snowflake User
$sel:username:Member :: Member -> Text
$sel:discriminator:Member :: Member -> Text
$sel:bot:Member :: Member -> Maybe Bool
$sel:avatar:Member :: Member -> Avatar
$sel:memberAvatar:Member :: Member -> Maybe Text
$sel:mfaEnabled:Member :: Member -> Maybe Bool
$sel:banner:Member :: Member -> Maybe UserBanner
$sel:accentColour:Member :: Member -> Maybe (Colour Double)
$sel:locale:Member :: Member -> Maybe Text
$sel:verified:Member :: Member -> Maybe Bool
$sel:email:Member :: Member -> Maybe Text
$sel:flags:Member :: Member -> Maybe Word64
$sel:premiumType:Member :: Member -> Maybe Word64
$sel:nick:Member :: Member -> Maybe Text
$sel:roles:Member :: Member -> Vector (Snowflake Role)
$sel:joinedAt:Member :: Member -> UTCTime
$sel:deaf:Member :: Member -> Bool
$sel:mute:Member :: Member -> Bool
id :: Snowflake User
username :: Text
discriminator :: Text
bot :: Maybe Bool
avatar :: Avatar
memberAvatar :: Maybe Text
mfaEnabled :: Maybe Bool
banner :: Maybe UserBanner
accentColour :: Maybe (Colour Double)
locale :: Maybe Text
verified :: Maybe Bool
email :: Maybe Text
flags :: Maybe Word64
premiumType :: Maybe Word64
nick :: Maybe Text
roles :: Vector (Snowflake Role)
joinedAt :: UTCTime
deaf :: Bool
mute :: Bool
..} -> User {Maybe Bool
Maybe Word64
Maybe Text
Maybe (Colour Double)
Maybe UserBanner
Text
Snowflake User
Avatar
$sel:id:User :: Snowflake User
$sel:username:User :: Text
$sel:discriminator:User :: Text
$sel:bot:User :: Maybe Bool
$sel:avatar:User :: Avatar
$sel:mfaEnabled:User :: Maybe Bool
$sel:banner:User :: Maybe UserBanner
$sel:accentColour:User :: Maybe (Colour Double)
$sel:locale:User :: Maybe Text
$sel:verified:User :: Maybe Bool
$sel:email:User :: Maybe Text
$sel:flags:User :: Maybe Word64
$sel:premiumType:User :: Maybe Word64
id :: Snowflake User
username :: Text
discriminator :: Text
bot :: Maybe Bool
avatar :: Avatar
mfaEnabled :: Maybe Bool
banner :: Maybe UserBanner
accentColour :: Maybe (Colour Double)
locale :: Maybe Text
verified :: Maybe Bool
email :: Maybe Text
flags :: Maybe Word64
premiumType :: Maybe Word64
..}) Member
member
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild Snowflake Guild
gid (Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe Member)
-> Optic
     A_Lens
     NoIx
     Guild
     Guild
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe Member)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     A_Lens
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (Maybe (IxValue (SnowflakeMap Member)))
     (Maybe (IxValue (SnowflakeMap Member)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at (Member -> Snowflake Member
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Member
member) Optic
  A_Lens
  NoIx
  Guild
  Guild
  (Maybe (IxValue (SnowflakeMap Member)))
  (Maybe Member)
-> Member -> Guild -> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a (Maybe b) -> b -> s -> t
?~ Member
member)
updateCache (GuildMemberRemove GuildMemberRemoveData {Snowflake Guild
$sel:guildID:GuildMemberRemoveData :: GuildMemberRemoveData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, User
$sel:user:GuildMemberRemoveData :: GuildMemberRemoveData -> User
user :: User
user}) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild Snowflake Guild
guildID (Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> (SnowflakeMap Member -> SnowflakeMap Member) -> Guild -> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Index (SnowflakeMap Member)
-> SnowflakeMap Member -> SnowflakeMap Member
forall (m :: OpticKind). At m => Index m -> m -> m
sans (User -> Snowflake Member
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID User
user))
updateCache (GuildMemberUpdate GuildMemberUpdateData {Snowflake Guild
$sel:guildID:GuildMemberUpdateData :: GuildMemberUpdateData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, $sel:roles:GuildMemberUpdateData :: GuildMemberUpdateData -> AesonVector (Snowflake Role)
roles = AesonVector Vector (Snowflake Role)
roles, User
$sel:user:GuildMemberUpdateData :: GuildMemberUpdateData -> User
user :: User
user, Maybe Text
nick :: Maybe Text
$sel:nick:GuildMemberUpdateData :: GuildMemberUpdateData -> Maybe Text
nick}) = do
  User -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => User -> Sem r ()
setUser User
user
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild Snowflake Guild
guildID (Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
#members Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Member) (SnowflakeMap Member)
-> Optic
     (IxKind (SnowflakeMap Member))
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (IxValue (SnowflakeMap Member))
     (IxValue (SnowflakeMap Member))
-> Optic
     An_AffineTraversal
     NoIx
     Guild
     Guild
     (IxValue (SnowflakeMap Member))
     (IxValue (SnowflakeMap Member))
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (SnowflakeMap Member)
-> Optic
     (IxKind (SnowflakeMap Member))
     NoIx
     (SnowflakeMap Member)
     (SnowflakeMap Member)
     (IxValue (SnowflakeMap Member))
     (IxValue (SnowflakeMap Member))
forall (m :: OpticKind).
Ixed m =>
Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix (User -> Snowflake Member
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID User
user) Optic
  An_AffineTraversal
  NoIx
  Guild
  Guild
  (IxValue (SnowflakeMap Member))
  (IxValue (SnowflakeMap Member))
-> (IxValue (SnowflakeMap Member) -> IxValue (SnowflakeMap Member))
-> Guild
-> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ (Optic
  A_Lens
  NoIx
  Member
  (IxValue (SnowflakeMap Member))
  (Vector (Snowflake Role))
  (Vector (Snowflake Role))
#roles Optic
  A_Lens
  NoIx
  Member
  (IxValue (SnowflakeMap Member))
  (Vector (Snowflake Role))
  (Vector (Snowflake Role))
-> Vector (Snowflake Role)
-> Member
-> IxValue (SnowflakeMap Member)
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
.~ Vector (Snowflake Role)
roles) (Member -> IxValue (SnowflakeMap Member))
-> (IxValue (SnowflakeMap Member) -> Member)
-> IxValue (SnowflakeMap Member)
-> IxValue (SnowflakeMap Member)
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. (Optic
  A_Lens
  NoIx
  (IxValue (SnowflakeMap Member))
  Member
  (Maybe Text)
  (Maybe Text)
#nick Optic
  A_Lens
  NoIx
  (IxValue (SnowflakeMap Member))
  Member
  (Maybe Text)
  (Maybe Text)
-> Maybe Text -> IxValue (SnowflakeMap Member) -> Member
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
.~ Maybe Text
nick))
updateCache (GuildMembersChunk GuildMembersChunkData {Snowflake Guild
$sel:guildID:GuildMembersChunkData :: GuildMembersChunkData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, [Member]
$sel:members:GuildMembersChunkData :: GuildMembersChunkData -> [Member]
members :: [Member]
members}) =
  (Member -> Sem r ()) -> [Member] -> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_ (DispatchData -> Sem r ()
forall (r :: EffectRow).
Members '[CacheEff, Fail] r =>
DispatchData -> Sem r ()
updateCache (DispatchData -> Sem r ())
-> (Member -> DispatchData) -> Member -> Sem r ()
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. Snowflake Guild -> Member -> DispatchData
GuildMemberAdd Snowflake Guild
guildID) [Member]
members
updateCache (GuildRoleCreate GuildRoleData {Snowflake Guild
$sel:guildID:GuildRoleData :: GuildRoleData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, Role
$sel:role:GuildRoleData :: GuildRoleData -> Role
role :: Role
role}) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild Snowflake Guild
guildID (Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
#roles Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
-> (SnowflakeMap Role -> SnowflakeMap Role) -> Guild -> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Role -> SnowflakeMap Role -> SnowflakeMap Role
forall (a :: OpticKind).
HasID' a =>
a -> SnowflakeMap a -> SnowflakeMap a
SM.insert Role
role)
updateCache (GuildRoleUpdate GuildRoleData {Snowflake Guild
$sel:guildID:GuildRoleData :: GuildRoleData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, Role
$sel:role:GuildRoleData :: GuildRoleData -> Role
role :: Role
role}) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild Snowflake Guild
guildID (Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
#roles Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
-> (SnowflakeMap Role -> SnowflakeMap Role) -> Guild -> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Role -> SnowflakeMap Role -> SnowflakeMap Role
forall (a :: OpticKind).
HasID' a =>
a -> SnowflakeMap a -> SnowflakeMap a
SM.insert Role
role)
updateCache (GuildRoleDelete GuildRoleDeleteData {Snowflake Guild
$sel:guildID:GuildRoleDeleteData :: GuildRoleDeleteData -> Snowflake Guild
guildID :: Snowflake Guild
guildID, Snowflake Role
$sel:roleID:GuildRoleDeleteData :: GuildRoleDeleteData -> Snowflake Role
roleID :: Snowflake Role
roleID}) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild Snowflake Guild
guildID (Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
#roles Optic
  A_Lens NoIx Guild Guild (SnowflakeMap Role) (SnowflakeMap Role)
-> (SnowflakeMap Role -> SnowflakeMap Role) -> Guild -> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Index (SnowflakeMap Role) -> SnowflakeMap Role -> SnowflakeMap Role
forall (m :: OpticKind). At m => Index m -> m -> m
sans Index (SnowflakeMap Role)
Snowflake Role
roleID)
updateCache (MessageCreate !Message
msg !Maybe User
user !Maybe Member
_) = do
  Message -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => Message -> Sem r ()
setMessage Message
msg
  Maybe User -> (User -> Sem r ()) -> Sem r ()
forall (m :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative m =>
Maybe a -> (a -> m ()) -> m ()
whenJust Maybe User
user ((User -> Sem r ()) -> Sem r ()) -> (User -> Sem r ()) -> Sem r ()
forall (a :: OpticKind) b. (a -> b) -> a -> b
$ \User
u ->
    User -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => User -> Sem r ()
setUser User
u
updateCache (MessageUpdate UpdatedMessage
msg !Maybe User
_ !Maybe Member
_) =
  Snowflake Message -> (Message -> Message) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> (Message -> Message) -> Sem r ()
updateMessage (UpdatedMessage -> Snowflake Message
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID UpdatedMessage
msg) (Updated Message -> Message -> Message
forall (a :: OpticKind). Updateable a => Updated a -> a -> a
update UpdatedMessage
Updated Message
msg)
updateCache (MessageDelete MessageDeleteData {Snowflake Message
$sel:id:MessageDeleteData :: MessageDeleteData -> Snowflake Message
id :: Snowflake Message
id}) = Snowflake Message -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r ()
delMessage Snowflake Message
id
updateCache (MessageDeleteBulk MessageDeleteBulkData {[Snowflake Message]
$sel:ids:MessageDeleteBulkData :: MessageDeleteBulkData -> [Snowflake Message]
ids :: [Snowflake Message]
ids}) =
  [Snowflake Message] -> (Snowflake Message -> Sem r ()) -> Sem r ()
forall (t :: OpticKind -> OpticKind) (f :: OpticKind -> OpticKind)
       (a :: OpticKind) (b :: OpticKind).
(Foldable t, Applicative f) =>
t a -> (a -> f b) -> f ()
for_ [Snowflake Message]
ids Snowflake Message -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> Sem r ()
delMessage
updateCache (MessageReactionAdd ReactionEvtData
reaction) = do
  Bool
isMe <- (\Maybe User
u -> Snowflake User -> Maybe (Snowflake User)
forall (a :: OpticKind). a -> Maybe a
Just (forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @User ReactionEvtData
reaction) Maybe (Snowflake User) -> Maybe (Snowflake User) -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
== (forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @User (User -> Snowflake User) -> Maybe User -> Maybe (Snowflake User)
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Maybe User
u)) (Maybe User -> Bool) -> Sem r (Maybe User) -> Sem r Bool
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Sem r (Maybe User)
forall (r :: EffectRow). Member CacheEff r => Sem r (Maybe User)
getBotUser
  Snowflake Message -> (Message -> Message) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> (Message -> Message) -> Sem r ()
updateMessage
    (ReactionEvtData -> Snowflake Message
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID ReactionEvtData
reaction)
    ( \Message
m ->
        case Message
m Message -> Optic' A_Lens NoIx Message [Reaction] -> [Reaction]
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Message [Reaction]
#reactions [Reaction] -> ([Reaction] -> [Reaction]) -> [Reaction]
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& (Reaction -> Bool) -> [Reaction] -> [Reaction]
forall (a :: OpticKind). (a -> Bool) -> [a] -> [a]
filter ((RawEmoji -> RawEmoji -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
== (ReactionEvtData
reaction ReactionEvtData
-> Optic' A_Lens NoIx ReactionEvtData RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ReactionEvtData RawEmoji
#emoji)) (RawEmoji -> Bool) -> (Reaction -> RawEmoji) -> Reaction -> Bool
forall (b :: OpticKind) (c :: OpticKind) (a :: OpticKind).
(b -> c) -> (a -> b) -> a -> c
. (Reaction -> Optic' A_Lens NoIx Reaction RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Reaction RawEmoji
#emoji)) of
          [] -> Message
m Message -> (Message -> Message) -> Message
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& Optic' A_Lens NoIx Message [Reaction]
#reactions Optic' A_Lens NoIx Message [Reaction]
-> ([Reaction] -> [Reaction]) -> Message -> Message
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ ([Reaction] -> [Reaction] -> [Reaction]
forall (a :: OpticKind). Semigroup a => a -> a -> a
<> [Integer -> Bool -> RawEmoji -> Reaction
Reaction Integer
1 Bool
isMe (ReactionEvtData
reaction ReactionEvtData
-> Optic' A_Lens NoIx ReactionEvtData RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ReactionEvtData RawEmoji
#emoji)])
          [Reaction]
_ ->
            Message
m Message -> (Message -> Message) -> Message
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& Optic' A_Lens NoIx Message [Reaction]
#reactions Optic' A_Lens NoIx Message [Reaction]
-> Optic A_Traversal NoIx [Reaction] [Reaction] Reaction Reaction
-> Optic A_Traversal NoIx Message Message Reaction Reaction
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Traversal NoIx [Reaction] [Reaction] Reaction Reaction
forall (t :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic A_Traversal NoIx Message Message Reaction Reaction
-> (Reaction -> Reaction) -> Message -> Message
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Bool -> RawEmoji -> Reaction -> Reaction
updateReactionAdd Bool
isMe (ReactionEvtData
reaction ReactionEvtData
-> Optic' A_Lens NoIx ReactionEvtData RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ReactionEvtData RawEmoji
#emoji)
    )
updateCache (MessageReactionRemove ReactionEvtData
reaction) = do
  Bool
isMe <- (\Maybe User
u -> Snowflake User -> Maybe (Snowflake User)
forall (a :: OpticKind). a -> Maybe a
Just (forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @User ReactionEvtData
reaction) Maybe (Snowflake User) -> Maybe (Snowflake User) -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
== (forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID @User (User -> Snowflake User) -> Maybe User -> Maybe (Snowflake User)
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Maybe User
u)) (Maybe User -> Bool) -> Sem r (Maybe User) -> Sem r Bool
forall (f :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Functor f =>
(a -> b) -> f a -> f b
<$> Sem r (Maybe User)
forall (r :: EffectRow). Member CacheEff r => Sem r (Maybe User)
getBotUser
  Snowflake Message -> (Message -> Message) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> (Message -> Message) -> Sem r ()
updateMessage
    (ReactionEvtData -> Snowflake Message
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID ReactionEvtData
reaction)
    ( \Message
m ->
        Message
m
          Message -> (Message -> Message) -> Message
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& Optic' A_Lens NoIx Message [Reaction]
#reactions Optic' A_Lens NoIx Message [Reaction]
-> Optic A_Traversal NoIx [Reaction] [Reaction] Reaction Reaction
-> Optic A_Traversal NoIx Message Message Reaction Reaction
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Traversal NoIx [Reaction] [Reaction] Reaction Reaction
forall (t :: OpticKind -> OpticKind) (a :: OpticKind)
       (b :: OpticKind).
Traversable t =>
Traversal (t a) (t b) a b
traversed Optic A_Traversal NoIx Message Message Reaction Reaction
-> (Reaction -> Reaction) -> Message -> Message
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Bool -> RawEmoji -> Reaction -> Reaction
updateReactionRemove Bool
isMe (ReactionEvtData
reaction ReactionEvtData
-> Optic' A_Lens NoIx ReactionEvtData RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx ReactionEvtData RawEmoji
#emoji)
          Message -> (Message -> Message) -> Message
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& Optic' A_Lens NoIx Message [Reaction]
#reactions Optic' A_Lens NoIx Message [Reaction]
-> ([Reaction] -> [Reaction]) -> Message -> Message
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ (Reaction -> Bool) -> [Reaction] -> [Reaction]
forall (a :: OpticKind). (a -> Bool) -> [a] -> [a]
filter (\Reaction
r -> Reaction
r Reaction
-> Optic A_Lens NoIx Reaction Reaction Integer Integer -> Integer
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic A_Lens NoIx Reaction Reaction Integer Integer
#count Integer -> Integer -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
/= Integer
0)
    )
updateCache (MessageReactionRemoveAll MessageReactionRemoveAllData {Snowflake Message
$sel:messageID:MessageReactionRemoveAllData :: MessageReactionRemoveAllData -> Snowflake Message
messageID :: Snowflake Message
messageID}) =
  Snowflake Message -> (Message -> Message) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Message -> (Message -> Message) -> Sem r ()
updateMessage Snowflake Message
messageID (Optic' A_Lens NoIx Message [Reaction]
#reactions Optic' A_Lens NoIx Message [Reaction]
-> [Reaction] -> Message -> Message
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
.~ [Reaction]
forall (a :: OpticKind). Monoid a => a
mempty)
updateCache (PresenceUpdate PresenceUpdateData {Snowflake User
$sel:userID:PresenceUpdateData :: PresenceUpdateData -> Snowflake User
userID :: Snowflake User
userID, Presence
$sel:presence:PresenceUpdateData :: PresenceUpdateData -> Presence
presence :: Presence
presence}) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild (Presence -> Snowflake Guild
forall (b :: OpticKind) (a :: OpticKind).
HasID b a =>
a -> Snowflake b
getID Presence
presence) (Optic
  A_Lens
  NoIx
  Guild
  Guild
  (HashMap (Snowflake User) Presence)
  (HashMap (Snowflake User) Presence)
#presences Optic
  A_Lens
  NoIx
  Guild
  Guild
  (HashMap (Snowflake User) Presence)
  (HashMap (Snowflake User) Presence)
-> Optic
     A_Lens
     NoIx
     (HashMap (Snowflake User) Presence)
     (HashMap (Snowflake User) Presence)
     (Maybe (IxValue (HashMap (Snowflake User) Presence)))
     (Maybe Presence)
-> Optic
     A_Lens
     NoIx
     Guild
     Guild
     (Maybe (IxValue (HashMap (Snowflake User) Presence)))
     (Maybe Presence)
forall (k :: OpticKind) (l :: OpticKind) (m :: OpticKind)
       (is :: IxList) (js :: IxList) (ks :: IxList) (s :: OpticKind)
       (t :: OpticKind) (u :: OpticKind) (v :: OpticKind) (a :: OpticKind)
       (b :: OpticKind).
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Index (HashMap (Snowflake User) Presence)
-> Lens'
     (HashMap (Snowflake User) Presence)
     (Maybe (IxValue (HashMap (Snowflake User) Presence)))
forall (m :: OpticKind).
At m =>
Index m -> Lens' m (Maybe (IxValue m))
at Index (HashMap (Snowflake User) Presence)
Snowflake User
userID Optic
  A_Lens
  NoIx
  Guild
  Guild
  (Maybe (IxValue (HashMap (Snowflake User) Presence)))
  (Maybe Presence)
-> Presence -> Guild -> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a (Maybe b) -> b -> s -> t
?~ Presence
presence)
updateCache (UserUpdate User
user) = User -> Sem r ()
forall (r :: EffectRow). Member CacheEff r => User -> Sem r ()
setBotUser User
user
-- we don't handle group channels currently
updateCache (ChannelCreate (GroupChannel' GroupChannel
_)) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (ChannelUpdate (GroupChannel' GroupChannel
_)) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (ChannelDelete (GroupChannel' GroupChannel
_)) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
-- these don't modify state
updateCache (GuildBanAdd BanData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (GuildBanRemove BanData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (GuildIntegrationsUpdate GuildIntegrationsUpdateData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (TypingStart TypingStartData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (ChannelPinsUpdate ChannelPinsUpdateData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (WebhooksUpdate WebhooksUpdateData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (InviteCreate InviteCreateData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (InviteDelete InviteDeleteData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (VoiceStateUpdate voiceState :: VoiceState
voiceState@V.VoiceState {$sel:guildID:VoiceState :: VoiceState -> Maybe (Snowflake Guild)
guildID = Just Snowflake Guild
guildID}) =
  Snowflake Guild -> (Guild -> Guild) -> Sem r ()
forall (r :: EffectRow).
Member CacheEff r =>
Snowflake Guild -> (Guild -> Guild) -> Sem r ()
updateGuild Snowflake Guild
guildID (Optic A_Lens NoIx Guild Guild [VoiceState] [VoiceState]
#voiceStates Optic A_Lens NoIx Guild Guild [VoiceState] [VoiceState]
-> ([VoiceState] -> [VoiceState]) -> Guild -> Guild
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ [VoiceState] -> [VoiceState]
updateVoiceStates)
  where
    updateVoiceStates :: [VoiceState] -> [VoiceState]
updateVoiceStates [] = [VoiceState
voiceState]
    updateVoiceStates (VoiceState
x : [VoiceState]
xs)
      | VoiceState -> Text
V.sessionID VoiceState
x Text -> Text -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
== VoiceState -> Text
V.sessionID VoiceState
voiceState = VoiceState
voiceState VoiceState -> [VoiceState] -> [VoiceState]
forall (a :: OpticKind). a -> [a] -> [a]
: [VoiceState]
xs
      | Bool
otherwise = VoiceState
x VoiceState -> [VoiceState] -> [VoiceState]
forall (a :: OpticKind). a -> [a] -> [a]
: [VoiceState] -> [VoiceState]
updateVoiceStates [VoiceState]
xs

-- we don't handle voice server update and direct voice connections currently
updateCache (VoiceStateUpdate V.VoiceState {$sel:guildID:VoiceState :: VoiceState -> Maybe (Snowflake Guild)
guildID = Maybe (Snowflake Guild)
Nothing}) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (VoiceServerUpdate VoiceServerUpdateData
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
-- we don't update the cache from interactions
-- TODO: should we?
updateCache (InteractionCreate Interaction
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()
updateCache (UNHANDLED Text
_) = () -> Sem r ()
forall (a :: OpticKind). a -> Sem r a
forall (f :: OpticKind -> OpticKind) (a :: OpticKind).
Applicative f =>
a -> f a
pure ()

updateReactionAdd :: Bool -> RawEmoji -> Reaction -> Reaction
updateReactionAdd :: Bool -> RawEmoji -> Reaction -> Reaction
updateReactionAdd Bool
isMe RawEmoji
emoji Reaction
reaction =
  if RawEmoji
emoji RawEmoji -> RawEmoji -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
== Reaction
reaction Reaction -> Optic' A_Lens NoIx Reaction RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Reaction RawEmoji
#emoji
    then
      Reaction
reaction
        Reaction -> (Reaction -> Reaction) -> Reaction
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& Optic A_Lens NoIx Reaction Reaction Integer Integer
#count Optic A_Lens NoIx Reaction Reaction Integer Integer
-> (Integer -> Integer) -> Reaction -> Reaction
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Integer -> Integer
forall (a :: OpticKind). Enum a => a -> a
succ
        Reaction -> (Reaction -> Reaction) -> Reaction
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& Optic A_Lens NoIx Reaction Reaction Bool Bool
#me Optic A_Lens NoIx Reaction Reaction Bool Bool
-> (Bool -> Bool) -> Reaction -> Reaction
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ (Bool -> Bool -> Bool
|| Bool
isMe)
    else Reaction
reaction

updateReactionRemove :: Bool -> RawEmoji -> Reaction -> Reaction
updateReactionRemove :: Bool -> RawEmoji -> Reaction -> Reaction
updateReactionRemove Bool
isMe RawEmoji
emoji Reaction
reaction =
  if RawEmoji
emoji RawEmoji -> RawEmoji -> Bool
forall (a :: OpticKind). Eq a => a -> a -> Bool
== Reaction
reaction Reaction -> Optic' A_Lens NoIx Reaction RawEmoji -> RawEmoji
forall (k :: OpticKind) (s :: OpticKind) (is :: IxList)
       (a :: OpticKind).
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Reaction RawEmoji
#emoji
    then
      Reaction
reaction
        Reaction -> (Reaction -> Reaction) -> Reaction
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& Optic A_Lens NoIx Reaction Reaction Integer Integer
#count Optic A_Lens NoIx Reaction Reaction Integer Integer
-> (Integer -> Integer) -> Reaction -> Reaction
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ Integer -> Integer
forall (a :: OpticKind). Enum a => a -> a
pred
        Reaction -> (Reaction -> Reaction) -> Reaction
forall (a :: OpticKind) (b :: OpticKind). a -> (a -> b) -> b
& Optic A_Lens NoIx Reaction Reaction Bool Bool
#me Optic A_Lens NoIx Reaction Reaction Bool Bool
-> (Bool -> Bool) -> Reaction -> Reaction
forall (k :: OpticKind) (is :: IxList) (s :: OpticKind)
       (t :: OpticKind) (a :: OpticKind) (b :: OpticKind).
Is k A_Setter =>
Optic k is s t a b -> (a -> b) -> s -> t
%~ (Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
isMe)
    else Reaction
reaction