{-# LANGUAGE TemplateHaskell #-}

-- | Types for shards
module Calamity.Gateway.Types (
  ShardC,
  ShardMsg (..),
  ReceivedDiscordMessage (..),
  SentDiscordMessage (..),
  DispatchType (..),
  IdentifyData (..),
  StatusUpdateData (..),
  ResumeData (..),
  RequestGuildMembersData (..),
  IdentifyProps (..),
  ControlMessage (..),
  ShardFlowControl (..),
  Shard (..),
  ShardState (..),
) where

import Calamity.Gateway.DispatchEvents
import Calamity.Gateway.Intents
import Calamity.Internal.Utils (CalamityToJSON (..), CalamityToJSON' (..), (.=), (.?=))
import Calamity.Metrics.Eff
import Calamity.Types.LogEff
import Calamity.Types.Model.Guild.Guild
import Calamity.Types.Model.Presence.Activity
import Calamity.Types.Model.User
import Calamity.Types.Model.Voice
import Calamity.Types.Snowflake
import Control.Concurrent.Async
import Control.Concurrent.Chan.Unagi
import Data.Aeson qualified as Aeson
import Data.Aeson.Optics
import Data.Aeson.Types (parseMaybe)
import Data.Aeson.Types qualified as AT
import Data.Text (Text)
import Data.Text qualified as T
import GHC.Generics
import Network.WebSockets.Connection (Connection)
import Optics
import Polysemy qualified as P
import Polysemy.Async qualified as P
import Polysemy.AtomicState qualified as P

type ShardC r =
  ( P.Members
      '[ LogEff
       , P.AtomicState ShardState
       , P.Embed IO
       , P.Final IO
       , P.Async
       , MetricEff
       ]
      r
  )

data ShardMsg
  = Discord ReceivedDiscordMessage
  | Control ControlMessage
  deriving (Int -> ShardMsg -> ShowS
[ShardMsg] -> ShowS
ShardMsg -> String
(Int -> ShardMsg -> ShowS)
-> (ShardMsg -> String) -> ([ShardMsg] -> ShowS) -> Show ShardMsg
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShardMsg -> ShowS
showsPrec :: Int -> ShardMsg -> ShowS
$cshow :: ShardMsg -> String
show :: ShardMsg -> String
$cshowList :: [ShardMsg] -> ShowS
showList :: [ShardMsg] -> ShowS
Show)

data ReceivedDiscordMessage
  = EvtDispatch Int !DispatchData
  | HeartBeatReq
  | Reconnect
  | InvalidSession Bool
  | Hello Int
  | HeartBeatAck
  deriving (Int -> ReceivedDiscordMessage -> ShowS
[ReceivedDiscordMessage] -> ShowS
ReceivedDiscordMessage -> String
(Int -> ReceivedDiscordMessage -> ShowS)
-> (ReceivedDiscordMessage -> String)
-> ([ReceivedDiscordMessage] -> ShowS)
-> Show ReceivedDiscordMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReceivedDiscordMessage -> ShowS
showsPrec :: Int -> ReceivedDiscordMessage -> ShowS
$cshow :: ReceivedDiscordMessage -> String
show :: ReceivedDiscordMessage -> String
$cshowList :: [ReceivedDiscordMessage] -> ShowS
showList :: [ReceivedDiscordMessage] -> ShowS
Show)

instance Aeson.FromJSON ReceivedDiscordMessage where
  parseJSON :: Value -> Parser ReceivedDiscordMessage
parseJSON = String
-> (Object -> Parser ReceivedDiscordMessage)
-> Value
-> Parser ReceivedDiscordMessage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"ReceivedDiscordMessage" ((Object -> Parser ReceivedDiscordMessage)
 -> Value -> Parser ReceivedDiscordMessage)
-> (Object -> Parser ReceivedDiscordMessage)
-> Value
-> Parser ReceivedDiscordMessage
forall a b. (a -> b) -> a -> b
$ \Object
v -> do
    Int
op :: Int <- Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"op"
    case Int
op of
      Int
0 -> do
        Value
d <- Object
v Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"d"
        DispatchType
t <- Object
v Object -> Key -> Parser DispatchType
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"t"
        Int
s <- Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"s"
        Int -> DispatchData -> ReceivedDiscordMessage
EvtDispatch Int
s (DispatchData -> ReceivedDiscordMessage)
-> Parser DispatchData -> Parser ReceivedDiscordMessage
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> DispatchType -> Value -> Parser DispatchData
parseDispatchData DispatchType
t Value
d
      Int
1 -> ReceivedDiscordMessage -> Parser ReceivedDiscordMessage
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReceivedDiscordMessage
HeartBeatReq
      Int
7 -> ReceivedDiscordMessage -> Parser ReceivedDiscordMessage
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReceivedDiscordMessage
Reconnect
      Int
9 -> Bool -> ReceivedDiscordMessage
InvalidSession (Bool -> ReceivedDiscordMessage)
-> Parser Bool -> Parser ReceivedDiscordMessage
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"d"
      Int
10 ->
        Int -> ReceivedDiscordMessage
Hello (Int -> ReceivedDiscordMessage)
-> Parser Int -> Parser ReceivedDiscordMessage
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
          Object
d <- Object
v Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"d"
          Object
d Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"heartbeat_interval"
      Int
11 -> ReceivedDiscordMessage -> Parser ReceivedDiscordMessage
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReceivedDiscordMessage
HeartBeatAck
      Int
_ -> String -> Parser ReceivedDiscordMessage
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ReceivedDiscordMessage)
-> String -> Parser ReceivedDiscordMessage
forall a b. (a -> b) -> a -> b
$ String
"invalid opcode: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
op

parseDispatchData :: DispatchType -> Aeson.Value -> AT.Parser DispatchData
parseDispatchData :: DispatchType -> Value -> Parser DispatchData
parseDispatchData DispatchType
READY Value
data' = ReadyData -> DispatchData
Ready (ReadyData -> DispatchData)
-> Parser ReadyData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser ReadyData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
RESUMED Value
_ = DispatchData -> Parser DispatchData
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure DispatchData
Resumed
parseDispatchData DispatchType
CHANNEL_CREATE Value
data' = Channel -> DispatchData
ChannelCreate (Channel -> DispatchData) -> Parser Channel -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Channel
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
CHANNEL_UPDATE Value
data' = Channel -> DispatchData
ChannelUpdate (Channel -> DispatchData) -> Parser Channel -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Channel
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
CHANNEL_DELETE Value
data' = Channel -> DispatchData
ChannelDelete (Channel -> DispatchData) -> Parser Channel -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Channel
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
CHANNEL_PINS_UPDATE Value
data' = ChannelPinsUpdateData -> DispatchData
ChannelPinsUpdate (ChannelPinsUpdateData -> DispatchData)
-> Parser ChannelPinsUpdateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser ChannelPinsUpdateData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_CREATE Value
data' = Guild -> DispatchData
GuildCreate (Guild -> DispatchData) -> Parser Guild -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Guild
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_UPDATE Value
data' = UpdatedGuild -> DispatchData
GuildUpdate (UpdatedGuild -> DispatchData)
-> Parser UpdatedGuild -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser UpdatedGuild
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_DELETE Value
data' = UnavailableGuild -> DispatchData
GuildDelete (UnavailableGuild -> DispatchData)
-> Parser UnavailableGuild -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser UnavailableGuild
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_BAN_ADD Value
data' = BanData -> DispatchData
GuildBanAdd (BanData -> DispatchData) -> Parser BanData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser BanData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_BAN_REMOVE Value
data' = BanData -> DispatchData
GuildBanRemove (BanData -> DispatchData) -> Parser BanData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser BanData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_EMOJIS_UPDATE Value
data' = GuildEmojisUpdateData -> DispatchData
GuildEmojisUpdate (GuildEmojisUpdateData -> DispatchData)
-> Parser GuildEmojisUpdateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildEmojisUpdateData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_INTEGRATIONS_UPDATE Value
data' = GuildIntegrationsUpdateData -> DispatchData
GuildIntegrationsUpdate (GuildIntegrationsUpdateData -> DispatchData)
-> Parser GuildIntegrationsUpdateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildIntegrationsUpdateData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_MEMBER_ADD Value
data' = do
  Snowflake Guild
guildID <- String
-> (Object -> Parser (Snowflake Guild))
-> Value
-> Parser (Snowflake Guild)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"GuildMemberAdd.guild_id" (Object -> Key -> Parser (Snowflake Guild)
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"guild_id") Value
data'
  Snowflake Guild -> Member -> DispatchData
GuildMemberAdd Snowflake Guild
guildID (Member -> DispatchData) -> Parser Member -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Member
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_MEMBER_REMOVE Value
data' = GuildMemberRemoveData -> DispatchData
GuildMemberRemove (GuildMemberRemoveData -> DispatchData)
-> Parser GuildMemberRemoveData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildMemberRemoveData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_MEMBER_UPDATE Value
data' = GuildMemberUpdateData -> DispatchData
GuildMemberUpdate (GuildMemberUpdateData -> DispatchData)
-> Parser GuildMemberUpdateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildMemberUpdateData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_MEMBERS_CHUNK Value
data' = GuildMembersChunkData -> DispatchData
GuildMembersChunk (GuildMembersChunkData -> DispatchData)
-> Parser GuildMembersChunkData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildMembersChunkData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_ROLE_CREATE Value
data' = GuildRoleData -> DispatchData
GuildRoleCreate (GuildRoleData -> DispatchData)
-> Parser GuildRoleData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildRoleData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_ROLE_UPDATE Value
data' = GuildRoleData -> DispatchData
GuildRoleUpdate (GuildRoleData -> DispatchData)
-> Parser GuildRoleData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildRoleData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
GUILD_ROLE_DELETE Value
data' = GuildRoleDeleteData -> DispatchData
GuildRoleDelete (GuildRoleDeleteData -> DispatchData)
-> Parser GuildRoleDeleteData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildRoleDeleteData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
INVITE_CREATE Value
data' = InviteCreateData -> DispatchData
InviteCreate (InviteCreateData -> DispatchData)
-> Parser InviteCreateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser InviteCreateData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
INVITE_DELETE Value
data' = InviteDeleteData -> DispatchData
InviteDelete (InviteDeleteData -> DispatchData)
-> Parser InviteDeleteData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser InviteDeleteData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
MESSAGE_CREATE Value
data' = do
  Message
message <- Value -> Parser Message
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
  let member :: Maybe Member
member =
        (Value -> Parser Member) -> Value -> Maybe Member
forall a b. (a -> Parser b) -> a -> Maybe b
parseMaybe
          ( String -> (Object -> Parser Member) -> Value -> Parser Member
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"MessageCreate.member" ((Object -> Parser Member) -> Value -> Parser Member)
-> (Object -> Parser Member) -> Value -> Parser Member
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
              Object
userObject :: Aeson.Object <- Object
o Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"author"
              Object
memberObject :: Aeson.Object <- Object
o Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"member"
              Value -> Parser Member
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON (Value -> Parser Member) -> Value -> Parser Member
forall a b. (a -> b) -> a -> b
$ Object -> Value
Aeson.Object (Object
memberObject Object -> Object -> Object
forall a. Semigroup a => a -> a -> a
<> Key
"user" Key -> Object -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Object
Aeson..= Object
userObject)
          )
          Value
data'

  let user :: Maybe User
user = (Value -> Parser User) -> Value -> Maybe User
forall a b. (a -> Parser b) -> a -> Maybe b
parseMaybe Value -> Parser User
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON (Value -> Maybe User) -> Maybe Value -> Maybe User
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value
data' Value -> Optic' An_AffineTraversal NoIx Value Value -> Maybe Value
forall k s (is :: IxList) a.
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Prism' Value Object
forall t. AsValue t => Prism' t Object
_Object Prism' Value Object
-> Optic An_AffineTraversal NoIx Object Object Value Value
-> Optic' An_AffineTraversal NoIx Value Value
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(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 Object -> Optic' (IxKind Object) NoIx Object (IxValue Object)
forall m. Ixed m => Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Key
Index Object
"author"
  DispatchData -> Parser DispatchData
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DispatchData -> Parser DispatchData)
-> DispatchData -> Parser DispatchData
forall a b. (a -> b) -> a -> b
$ Message -> Maybe User -> Maybe Member -> DispatchData
MessageCreate Message
message Maybe User
user Maybe Member
member
parseDispatchData DispatchType
MESSAGE_UPDATE Value
data' = do
  UpdatedMessage
message <- Value -> Parser UpdatedMessage
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
  let member :: Maybe Member
member =
        (Value -> Parser Member) -> Value -> Maybe Member
forall a b. (a -> Parser b) -> a -> Maybe b
parseMaybe
          ( String -> (Object -> Parser Member) -> Value -> Parser Member
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"MessageCreate.member" ((Object -> Parser Member) -> Value -> Parser Member)
-> (Object -> Parser Member) -> Value -> Parser Member
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
              Object
userObject :: Aeson.Object <- Object
o Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"author"
              Object
memberObject :: Aeson.Object <- Object
o Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"member"
              Value -> Parser Member
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON (Value -> Parser Member) -> Value -> Parser Member
forall a b. (a -> b) -> a -> b
$ Object -> Value
Aeson.Object (Object
memberObject Object -> Object -> Object
forall a. Semigroup a => a -> a -> a
<> Key
"user" Key -> Object -> Object
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Object
Aeson..= Object
userObject)
          )
          Value
data'
  let user :: Maybe User
user = (Value -> Parser User) -> Value -> Maybe User
forall a b. (a -> Parser b) -> a -> Maybe b
parseMaybe Value -> Parser User
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON (Value -> Maybe User) -> Maybe Value -> Maybe User
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Value
data' Value -> Optic' An_AffineTraversal NoIx Value Value -> Maybe Value
forall k s (is :: IxList) a.
Is k An_AffineFold =>
s -> Optic' k is s a -> Maybe a
^? Prism' Value Object
forall t. AsValue t => Prism' t Object
_Object Prism' Value Object
-> Optic An_AffineTraversal NoIx Object Object Value Value
-> Optic' An_AffineTraversal NoIx Value Value
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(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 Object -> Optic' (IxKind Object) NoIx Object (IxValue Object)
forall m. Ixed m => Index m -> Optic' (IxKind m) NoIx m (IxValue m)
ix Key
Index Object
"author"
  DispatchData -> Parser DispatchData
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DispatchData -> Parser DispatchData)
-> DispatchData -> Parser DispatchData
forall a b. (a -> b) -> a -> b
$ UpdatedMessage -> Maybe User -> Maybe Member -> DispatchData
MessageUpdate UpdatedMessage
message Maybe User
user Maybe Member
member
parseDispatchData DispatchType
MESSAGE_DELETE Value
data' = MessageDeleteData -> DispatchData
MessageDelete (MessageDeleteData -> DispatchData)
-> Parser MessageDeleteData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser MessageDeleteData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
MESSAGE_DELETE_BULK Value
data' = MessageDeleteBulkData -> DispatchData
MessageDeleteBulk (MessageDeleteBulkData -> DispatchData)
-> Parser MessageDeleteBulkData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser MessageDeleteBulkData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
MESSAGE_REACTION_ADD Value
data' = ReactionEvtData -> DispatchData
MessageReactionAdd (ReactionEvtData -> DispatchData)
-> Parser ReactionEvtData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser ReactionEvtData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
MESSAGE_REACTION_REMOVE Value
data' = ReactionEvtData -> DispatchData
MessageReactionRemove (ReactionEvtData -> DispatchData)
-> Parser ReactionEvtData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser ReactionEvtData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
MESSAGE_REACTION_REMOVE_ALL Value
data' = MessageReactionRemoveAllData -> DispatchData
MessageReactionRemoveAll (MessageReactionRemoveAllData -> DispatchData)
-> Parser MessageReactionRemoveAllData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser MessageReactionRemoveAllData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
PRESENCE_UPDATE Value
data' = PresenceUpdateData -> DispatchData
PresenceUpdate (PresenceUpdateData -> DispatchData)
-> Parser PresenceUpdateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser PresenceUpdateData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
TYPING_START Value
data' = TypingStartData -> DispatchData
TypingStart (TypingStartData -> DispatchData)
-> Parser TypingStartData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser TypingStartData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
USER_UPDATE Value
data' = User -> DispatchData
UserUpdate (User -> DispatchData) -> Parser User -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser User
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
VOICE_STATE_UPDATE Value
data' = VoiceState -> DispatchData
VoiceStateUpdate (VoiceState -> DispatchData)
-> Parser VoiceState -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser VoiceState
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
VOICE_SERVER_UPDATE Value
data' = VoiceServerUpdateData -> DispatchData
VoiceServerUpdate (VoiceServerUpdateData -> DispatchData)
-> Parser VoiceServerUpdateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser VoiceServerUpdateData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
WEBHOOKS_UPDATE Value
data' = WebhooksUpdateData -> DispatchData
WebhooksUpdate (WebhooksUpdateData -> DispatchData)
-> Parser WebhooksUpdateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser WebhooksUpdateData
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
INTERACTION_CREATE Value
data' = Interaction -> DispatchData
InteractionCreate (Interaction -> DispatchData)
-> Parser Interaction -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Interaction
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON Value
data'
parseDispatchData DispatchType
e Value
_ = DispatchData -> Parser DispatchData
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (DispatchData -> Parser DispatchData)
-> (DispatchType -> DispatchData)
-> DispatchType
-> Parser DispatchData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> DispatchData
UNHANDLED (Text -> DispatchData)
-> (DispatchType -> Text) -> DispatchType -> DispatchData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack (String -> Text)
-> (DispatchType -> String) -> DispatchType -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DispatchType -> String
forall a. Show a => a -> String
show (DispatchType -> Parser DispatchData)
-> DispatchType -> Parser DispatchData
forall a b. (a -> b) -> a -> b
$ DispatchType
e

data SentDiscordMessage
  = StatusUpdate StatusUpdateData
  | Identify IdentifyData
  | HeartBeat (Maybe Int)
  | VoiceStatusUpdate VoiceState
  | Resume ResumeData
  | RequestGuildMembers RequestGuildMembersData
  deriving (Int -> SentDiscordMessage -> ShowS
[SentDiscordMessage] -> ShowS
SentDiscordMessage -> String
(Int -> SentDiscordMessage -> ShowS)
-> (SentDiscordMessage -> String)
-> ([SentDiscordMessage] -> ShowS)
-> Show SentDiscordMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SentDiscordMessage -> ShowS
showsPrec :: Int -> SentDiscordMessage -> ShowS
$cshow :: SentDiscordMessage -> String
show :: SentDiscordMessage -> String
$cshowList :: [SentDiscordMessage] -> ShowS
showList :: [SentDiscordMessage] -> ShowS
Show)

instance Aeson.ToJSON SentDiscordMessage where
  toJSON :: SentDiscordMessage -> Value
toJSON (HeartBeat Maybe Int
data') = [Pair] -> Value
Aeson.object [Key
"op" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= (Int
1 :: Int), Key
"d" Key -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= Maybe Int
data']
  toJSON (Identify IdentifyData
data') = [Pair] -> Value
Aeson.object [Key
"op" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= (Int
2 :: Int), Key
"d" Key -> IdentifyData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= IdentifyData
data']
  toJSON (StatusUpdate StatusUpdateData
data') = [Pair] -> Value
Aeson.object [Key
"op" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= (Int
3 :: Int), Key
"d" Key -> StatusUpdateData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= StatusUpdateData
data']
  toJSON (VoiceStatusUpdate VoiceState
data') = [Pair] -> Value
Aeson.object [Key
"op" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= (Int
4 :: Int), Key
"d" Key -> VoiceState -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= VoiceState
data']
  toJSON (Resume ResumeData
data') = [Pair] -> Value
Aeson.object [Key
"op" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= (Int
6 :: Int), Key
"d" Key -> ResumeData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= ResumeData
data']
  toJSON (RequestGuildMembers RequestGuildMembersData
data') = [Pair] -> Value
Aeson.object [Key
"op" Key -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= (Int
8 :: Int), Key
"d" Key -> RequestGuildMembersData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
Aeson..= RequestGuildMembersData
data']

  toEncoding :: SentDiscordMessage -> Encoding
toEncoding (HeartBeat Maybe Int
data') = Series -> Encoding
Aeson.pairs (Key
"op" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= (Int
1 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Key
"d" Key -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= Maybe Int
data')
  toEncoding (Identify IdentifyData
data') = Series -> Encoding
Aeson.pairs (Key
"op" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= (Int
2 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Key
"d" Key -> IdentifyData -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= IdentifyData
data')
  toEncoding (StatusUpdate StatusUpdateData
data') = Series -> Encoding
Aeson.pairs (Key
"op" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= (Int
3 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Key
"d" Key -> StatusUpdateData -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= StatusUpdateData
data')
  toEncoding (VoiceStatusUpdate VoiceState
data') = Series -> Encoding
Aeson.pairs (Key
"op" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= (Int
4 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Key
"d" Key -> VoiceState -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= VoiceState
data')
  toEncoding (Resume ResumeData
data') = Series -> Encoding
Aeson.pairs (Key
"op" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= (Int
6 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Key
"d" Key -> ResumeData -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= ResumeData
data')
  toEncoding (RequestGuildMembers RequestGuildMembersData
data') = Series -> Encoding
Aeson.pairs (Key
"op" Key -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= (Int
8 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> Key
"d" Key -> RequestGuildMembersData -> Series
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Series
Aeson..= RequestGuildMembersData
data')

-- Thanks sbrg:
-- https://github.com/saevarb/haskord/blob/d1bb07bcc4f3dbc29f2dfd3351ff9f16fc100c07/haskord-lib/src/Haskord/Types/Common.hs
data DispatchType
  = READY
  | RESUMED
  | APPLICATION_COMMAND_PERMISSIONS_UPDATE
  | AUTO_MODERATION_RULE_CREATE
  | AUTO_MODERATION_RULE_UPDATE
  | AUTO_MODERATION_RULE_DELETE
  | AUTO_MODERATION_ACTION_EXECUTION
  | CHANNEL_CREATE
  | CHANNEL_UPDATE
  | CHANNEL_DELETE
  | CHANNEL_PINS_UPDATE
  | THREAD_CREATE
  | THREAD_UPDATE
  | THREAD_DELETE
  | THREAD_LIST_SYNC
  | THREAD_MEMBER_UPDATE
  | THREAD_MEMBERS_UPDATE
  | GUILD_CREATE
  | GUILD_UPDATE
  | GUILD_DELETE
  | GUILD_AUDIT_LOG_ENTRY_CREATE
  | GUILD_BAN_ADD
  | GUILD_BAN_REMOVE
  | GUILD_EMOJIS_UPDATE
  | GUILD_STICKERS_UPDATE
  | GUILD_INTEGRATIONS_UPDATE
  | GUILD_MEMBER_ADD
  | GUILD_MEMBER_REMOVE
  | GUILD_MEMBER_UPDATE
  | GUILD_MEMBERS_CHUNK
  | GUILD_ROLE_CREATE
  | GUILD_ROLE_UPDATE
  | GUILD_ROLE_DELETE
  | GUILD_SCHEDULED_EVENT_CREATE
  | GUILD_SCHEDULED_EVENT_UPDATE
  | GUILD_SCHEDULED_EVENT_DELETE
  | GUILD_SCHEDULED_EVENT_USER_ADD
  | GUILD_SCHEDULED_EVENT_USER_REMOVE
  | INTEGRATION_CREATE
  | INTEGRATION_UPDATE
  | INTEGRATION_DELETE
  | INTERACTION_CREATE
  | INVITE_CREATE
  | INVITE_DELETE
  | MESSAGE_CREATE
  | MESSAGE_UPDATE
  | MESSAGE_DELETE
  | MESSAGE_DELETE_BULK
  | MESSAGE_REACTION_ADD
  | MESSAGE_REACTION_REMOVE
  | MESSAGE_REACTION_REMOVE_ALL
  | MESSAGE_REACTION_REMOVE_EMOJI
  | PRESENCE_UPDATE
  | STAGE_INSTANCE_CREATE
  | STAGE_INSTANCE_UPDATE
  | STATE_INSTANCE_DELETE
  | TYPING_START
  | USER_UPDATE
  | VOICE_STATE_UPDATE
  | VOICE_SERVER_UPDATE
  | WEBHOOKS_UPDATE
  deriving (Int -> DispatchType -> ShowS
[DispatchType] -> ShowS
DispatchType -> String
(Int -> DispatchType -> ShowS)
-> (DispatchType -> String)
-> ([DispatchType] -> ShowS)
-> Show DispatchType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DispatchType -> ShowS
showsPrec :: Int -> DispatchType -> ShowS
$cshow :: DispatchType -> String
show :: DispatchType -> String
$cshowList :: [DispatchType] -> ShowS
showList :: [DispatchType] -> ShowS
Show, DispatchType -> DispatchType -> Bool
(DispatchType -> DispatchType -> Bool)
-> (DispatchType -> DispatchType -> Bool) -> Eq DispatchType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DispatchType -> DispatchType -> Bool
== :: DispatchType -> DispatchType -> Bool
$c/= :: DispatchType -> DispatchType -> Bool
/= :: DispatchType -> DispatchType -> Bool
Eq, Int -> DispatchType
DispatchType -> Int
DispatchType -> [DispatchType]
DispatchType -> DispatchType
DispatchType -> DispatchType -> [DispatchType]
DispatchType -> DispatchType -> DispatchType -> [DispatchType]
(DispatchType -> DispatchType)
-> (DispatchType -> DispatchType)
-> (Int -> DispatchType)
-> (DispatchType -> Int)
-> (DispatchType -> [DispatchType])
-> (DispatchType -> DispatchType -> [DispatchType])
-> (DispatchType -> DispatchType -> [DispatchType])
-> (DispatchType -> DispatchType -> DispatchType -> [DispatchType])
-> Enum DispatchType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: DispatchType -> DispatchType
succ :: DispatchType -> DispatchType
$cpred :: DispatchType -> DispatchType
pred :: DispatchType -> DispatchType
$ctoEnum :: Int -> DispatchType
toEnum :: Int -> DispatchType
$cfromEnum :: DispatchType -> Int
fromEnum :: DispatchType -> Int
$cenumFrom :: DispatchType -> [DispatchType]
enumFrom :: DispatchType -> [DispatchType]
$cenumFromThen :: DispatchType -> DispatchType -> [DispatchType]
enumFromThen :: DispatchType -> DispatchType -> [DispatchType]
$cenumFromTo :: DispatchType -> DispatchType -> [DispatchType]
enumFromTo :: DispatchType -> DispatchType -> [DispatchType]
$cenumFromThenTo :: DispatchType -> DispatchType -> DispatchType -> [DispatchType]
enumFromThenTo :: DispatchType -> DispatchType -> DispatchType -> [DispatchType]
Enum, (forall x. DispatchType -> Rep DispatchType x)
-> (forall x. Rep DispatchType x -> DispatchType)
-> Generic DispatchType
forall x. Rep DispatchType x -> DispatchType
forall x. DispatchType -> Rep DispatchType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DispatchType -> Rep DispatchType x
from :: forall x. DispatchType -> Rep DispatchType x
$cto :: forall x. Rep DispatchType x -> DispatchType
to :: forall x. Rep DispatchType x -> DispatchType
Generic)
  deriving ([DispatchType] -> Value
[DispatchType] -> Encoding
DispatchType -> Value
DispatchType -> Encoding
(DispatchType -> Value)
-> (DispatchType -> Encoding)
-> ([DispatchType] -> Value)
-> ([DispatchType] -> Encoding)
-> ToJSON DispatchType
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: DispatchType -> Value
toJSON :: DispatchType -> Value
$ctoEncoding :: DispatchType -> Encoding
toEncoding :: DispatchType -> Encoding
$ctoJSONList :: [DispatchType] -> Value
toJSONList :: [DispatchType] -> Value
$ctoEncodingList :: [DispatchType] -> Encoding
toEncodingList :: [DispatchType] -> Encoding
Aeson.ToJSON, Value -> Parser [DispatchType]
Value -> Parser DispatchType
(Value -> Parser DispatchType)
-> (Value -> Parser [DispatchType]) -> FromJSON DispatchType
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
$cparseJSON :: Value -> Parser DispatchType
parseJSON :: Value -> Parser DispatchType
$cparseJSONList :: Value -> Parser [DispatchType]
parseJSONList :: Value -> Parser [DispatchType]
Aeson.FromJSON)

data IdentifyData = IdentifyData
  { IdentifyData -> Text
token :: Text
  , IdentifyData -> IdentifyProps
properties :: IdentifyProps
  , IdentifyData -> Bool
compress :: Bool
  , IdentifyData -> Maybe Int
largeThreshold :: Maybe Int
  , IdentifyData -> Maybe (Int, Int)
shard :: Maybe (Int, Int)
  , IdentifyData -> Maybe StatusUpdateData
presence :: Maybe StatusUpdateData
  , IdentifyData -> Intents
intents :: Intents
  }
  deriving (Int -> IdentifyData -> ShowS
[IdentifyData] -> ShowS
IdentifyData -> String
(Int -> IdentifyData -> ShowS)
-> (IdentifyData -> String)
-> ([IdentifyData] -> ShowS)
-> Show IdentifyData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IdentifyData -> ShowS
showsPrec :: Int -> IdentifyData -> ShowS
$cshow :: IdentifyData -> String
show :: IdentifyData -> String
$cshowList :: [IdentifyData] -> ShowS
showList :: [IdentifyData] -> ShowS
Show)
  deriving ([IdentifyData] -> Value
[IdentifyData] -> Encoding
IdentifyData -> Value
IdentifyData -> Encoding
(IdentifyData -> Value)
-> (IdentifyData -> Encoding)
-> ([IdentifyData] -> Value)
-> ([IdentifyData] -> Encoding)
-> ToJSON IdentifyData
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: IdentifyData -> Value
toJSON :: IdentifyData -> Value
$ctoEncoding :: IdentifyData -> Encoding
toEncoding :: IdentifyData -> Encoding
$ctoJSONList :: [IdentifyData] -> Value
toJSONList :: [IdentifyData] -> Value
$ctoEncodingList :: [IdentifyData] -> Encoding
toEncodingList :: [IdentifyData] -> Encoding
Aeson.ToJSON) via CalamityToJSON IdentifyData

instance CalamityToJSON' IdentifyData where
  toPairs :: forall kv. KeyValue kv => IdentifyData -> [Maybe kv]
toPairs IdentifyData {Bool
Maybe Int
Maybe (Int, Int)
Maybe StatusUpdateData
Text
Intents
IdentifyProps
$sel:token:IdentifyData :: IdentifyData -> Text
$sel:properties:IdentifyData :: IdentifyData -> IdentifyProps
$sel:compress:IdentifyData :: IdentifyData -> Bool
$sel:largeThreshold:IdentifyData :: IdentifyData -> Maybe Int
$sel:shard:IdentifyData :: IdentifyData -> Maybe (Int, Int)
$sel:presence:IdentifyData :: IdentifyData -> Maybe StatusUpdateData
$sel:intents:IdentifyData :: IdentifyData -> Intents
token :: Text
properties :: IdentifyProps
compress :: Bool
largeThreshold :: Maybe Int
shard :: Maybe (Int, Int)
presence :: Maybe StatusUpdateData
intents :: Intents
..} =
    [ Key
"token" Key -> Text -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Text
token
    , Key
"properties" Key -> IdentifyProps -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= IdentifyProps
properties
    , Key
"compress" Key -> Bool -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Bool
compress
    , Key
"large_threshold" Key -> Maybe Int -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Int
largeThreshold
    , Key
"shard" Key -> Maybe (Int, Int) -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe (Int, Int)
shard
    , Key
"presence" Key -> Maybe StatusUpdateData -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe StatusUpdateData
presence
    , Key
"intents" Key -> Intents -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Intents
intents
    ]

data StatusUpdateData = StatusUpdateData
  { StatusUpdateData -> Maybe Integer
since :: Maybe Integer
  , StatusUpdateData -> [Activity]
activities :: [Activity]
  , StatusUpdateData -> StatusType
status :: StatusType
  , StatusUpdateData -> Bool
afk :: Bool
  }
  deriving (Int -> StatusUpdateData -> ShowS
[StatusUpdateData] -> ShowS
StatusUpdateData -> String
(Int -> StatusUpdateData -> ShowS)
-> (StatusUpdateData -> String)
-> ([StatusUpdateData] -> ShowS)
-> Show StatusUpdateData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StatusUpdateData -> ShowS
showsPrec :: Int -> StatusUpdateData -> ShowS
$cshow :: StatusUpdateData -> String
show :: StatusUpdateData -> String
$cshowList :: [StatusUpdateData] -> ShowS
showList :: [StatusUpdateData] -> ShowS
Show)
  deriving ([StatusUpdateData] -> Value
[StatusUpdateData] -> Encoding
StatusUpdateData -> Value
StatusUpdateData -> Encoding
(StatusUpdateData -> Value)
-> (StatusUpdateData -> Encoding)
-> ([StatusUpdateData] -> Value)
-> ([StatusUpdateData] -> Encoding)
-> ToJSON StatusUpdateData
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: StatusUpdateData -> Value
toJSON :: StatusUpdateData -> Value
$ctoEncoding :: StatusUpdateData -> Encoding
toEncoding :: StatusUpdateData -> Encoding
$ctoJSONList :: [StatusUpdateData] -> Value
toJSONList :: [StatusUpdateData] -> Value
$ctoEncodingList :: [StatusUpdateData] -> Encoding
toEncodingList :: [StatusUpdateData] -> Encoding
Aeson.ToJSON) via CalamityToJSON StatusUpdateData

instance CalamityToJSON' StatusUpdateData where
  toPairs :: forall kv. KeyValue kv => StatusUpdateData -> [Maybe kv]
toPairs StatusUpdateData {Bool
[Activity]
Maybe Integer
StatusType
$sel:since:StatusUpdateData :: StatusUpdateData -> Maybe Integer
$sel:activities:StatusUpdateData :: StatusUpdateData -> [Activity]
$sel:status:StatusUpdateData :: StatusUpdateData -> StatusType
$sel:afk:StatusUpdateData :: StatusUpdateData -> Bool
since :: Maybe Integer
activities :: [Activity]
status :: StatusType
afk :: Bool
..} =
    [ Key
"since" Key -> Maybe Integer -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Maybe Integer
since
    , Key
"activities" Key -> [Activity] -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= [Activity]
activities
    , Key
"status" Key -> StatusType -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= StatusType
status
    , Key
"afk" Key -> Bool -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Bool
afk
    ]

data ResumeData = ResumeData
  { ResumeData -> Text
token :: Text
  , ResumeData -> Text
sessionID :: Text
  , ResumeData -> Int
seq :: Int
  }
  deriving (Int -> ResumeData -> ShowS
[ResumeData] -> ShowS
ResumeData -> String
(Int -> ResumeData -> ShowS)
-> (ResumeData -> String)
-> ([ResumeData] -> ShowS)
-> Show ResumeData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ResumeData -> ShowS
showsPrec :: Int -> ResumeData -> ShowS
$cshow :: ResumeData -> String
show :: ResumeData -> String
$cshowList :: [ResumeData] -> ShowS
showList :: [ResumeData] -> ShowS
Show)
  deriving ([ResumeData] -> Value
[ResumeData] -> Encoding
ResumeData -> Value
ResumeData -> Encoding
(ResumeData -> Value)
-> (ResumeData -> Encoding)
-> ([ResumeData] -> Value)
-> ([ResumeData] -> Encoding)
-> ToJSON ResumeData
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: ResumeData -> Value
toJSON :: ResumeData -> Value
$ctoEncoding :: ResumeData -> Encoding
toEncoding :: ResumeData -> Encoding
$ctoJSONList :: [ResumeData] -> Value
toJSONList :: [ResumeData] -> Value
$ctoEncodingList :: [ResumeData] -> Encoding
toEncodingList :: [ResumeData] -> Encoding
Aeson.ToJSON) via CalamityToJSON ResumeData

instance CalamityToJSON' ResumeData where
  toPairs :: forall kv. KeyValue kv => ResumeData -> [Maybe kv]
toPairs ResumeData {Int
Text
$sel:token:ResumeData :: ResumeData -> Text
$sel:sessionID:ResumeData :: ResumeData -> Text
$sel:seq:ResumeData :: ResumeData -> Int
token :: Text
sessionID :: Text
seq :: Int
..} =
    [ Key
"token" Key -> Text -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Text
token
    , Key
"session_id" Key -> Text -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Text
sessionID
    , Key
"seq" Key -> Int -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Int
seq
    ]

data RequestGuildMembersData = RequestGuildMembersData
  { RequestGuildMembersData -> Snowflake Guild
guildID :: Snowflake Guild
  , RequestGuildMembersData -> Maybe Text
query :: Maybe Text
  , RequestGuildMembersData -> Int
limit :: Int
  , RequestGuildMembersData -> Maybe Bool
presences :: Maybe Bool
  , RequestGuildMembersData -> Maybe [Snowflake User]
userIDs :: Maybe [Snowflake User]
  , RequestGuildMembersData -> Maybe Text
nonce :: Maybe Text
  }
  deriving (Int -> RequestGuildMembersData -> ShowS
[RequestGuildMembersData] -> ShowS
RequestGuildMembersData -> String
(Int -> RequestGuildMembersData -> ShowS)
-> (RequestGuildMembersData -> String)
-> ([RequestGuildMembersData] -> ShowS)
-> Show RequestGuildMembersData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RequestGuildMembersData -> ShowS
showsPrec :: Int -> RequestGuildMembersData -> ShowS
$cshow :: RequestGuildMembersData -> String
show :: RequestGuildMembersData -> String
$cshowList :: [RequestGuildMembersData] -> ShowS
showList :: [RequestGuildMembersData] -> ShowS
Show)
  deriving ([RequestGuildMembersData] -> Value
[RequestGuildMembersData] -> Encoding
RequestGuildMembersData -> Value
RequestGuildMembersData -> Encoding
(RequestGuildMembersData -> Value)
-> (RequestGuildMembersData -> Encoding)
-> ([RequestGuildMembersData] -> Value)
-> ([RequestGuildMembersData] -> Encoding)
-> ToJSON RequestGuildMembersData
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: RequestGuildMembersData -> Value
toJSON :: RequestGuildMembersData -> Value
$ctoEncoding :: RequestGuildMembersData -> Encoding
toEncoding :: RequestGuildMembersData -> Encoding
$ctoJSONList :: [RequestGuildMembersData] -> Value
toJSONList :: [RequestGuildMembersData] -> Value
$ctoEncodingList :: [RequestGuildMembersData] -> Encoding
toEncodingList :: [RequestGuildMembersData] -> Encoding
Aeson.ToJSON) via CalamityToJSON RequestGuildMembersData

instance CalamityToJSON' RequestGuildMembersData where
  toPairs :: forall kv. KeyValue kv => RequestGuildMembersData -> [Maybe kv]
toPairs RequestGuildMembersData {Int
Maybe Bool
Maybe [Snowflake User]
Maybe Text
Snowflake Guild
$sel:guildID:RequestGuildMembersData :: RequestGuildMembersData -> Snowflake Guild
$sel:query:RequestGuildMembersData :: RequestGuildMembersData -> Maybe Text
$sel:limit:RequestGuildMembersData :: RequestGuildMembersData -> Int
$sel:presences:RequestGuildMembersData :: RequestGuildMembersData -> Maybe Bool
$sel:userIDs:RequestGuildMembersData :: RequestGuildMembersData -> Maybe [Snowflake User]
$sel:nonce:RequestGuildMembersData :: RequestGuildMembersData -> Maybe Text
guildID :: Snowflake Guild
query :: Maybe Text
limit :: Int
presences :: Maybe Bool
userIDs :: Maybe [Snowflake User]
nonce :: Maybe Text
..} =
    [ Key
"guild_id" Key -> Snowflake Guild -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Snowflake Guild
guildID
    , Key
"query" Key -> Maybe Text -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
query
    , Key
"limit" Key -> Int -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Int
limit
    , Key
"presences" Key -> Maybe Bool -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Bool
presences
    , Key
"user_ids" Key -> Maybe [Snowflake User] -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe [Snowflake User]
userIDs
    , Key
"nonce" Key -> Maybe Text -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe Text
nonce
    ]

data IdentifyProps = IdentifyProps
  { IdentifyProps -> Text
browser :: Text
  , IdentifyProps -> Text
device :: Text
  }
  deriving (Int -> IdentifyProps -> ShowS
[IdentifyProps] -> ShowS
IdentifyProps -> String
(Int -> IdentifyProps -> ShowS)
-> (IdentifyProps -> String)
-> ([IdentifyProps] -> ShowS)
-> Show IdentifyProps
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IdentifyProps -> ShowS
showsPrec :: Int -> IdentifyProps -> ShowS
$cshow :: IdentifyProps -> String
show :: IdentifyProps -> String
$cshowList :: [IdentifyProps] -> ShowS
showList :: [IdentifyProps] -> ShowS
Show)
  deriving ([IdentifyProps] -> Value
[IdentifyProps] -> Encoding
IdentifyProps -> Value
IdentifyProps -> Encoding
(IdentifyProps -> Value)
-> (IdentifyProps -> Encoding)
-> ([IdentifyProps] -> Value)
-> ([IdentifyProps] -> Encoding)
-> ToJSON IdentifyProps
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: IdentifyProps -> Value
toJSON :: IdentifyProps -> Value
$ctoEncoding :: IdentifyProps -> Encoding
toEncoding :: IdentifyProps -> Encoding
$ctoJSONList :: [IdentifyProps] -> Value
toJSONList :: [IdentifyProps] -> Value
$ctoEncodingList :: [IdentifyProps] -> Encoding
toEncodingList :: [IdentifyProps] -> Encoding
Aeson.ToJSON) via CalamityToJSON IdentifyProps

instance CalamityToJSON' IdentifyProps where
  toPairs :: forall kv. KeyValue kv => IdentifyProps -> [Maybe kv]
toPairs IdentifyProps {Text
$sel:browser:IdentifyProps :: IdentifyProps -> Text
$sel:device:IdentifyProps :: IdentifyProps -> Text
browser :: Text
device :: Text
..} = [Key
"$browser" Key -> Text -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Text
browser, Key
"$device" Key -> Text -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Text
device]

data ControlMessage
  = RestartShard
  | ShutDownShard
  | SendPresence StatusUpdateData
  deriving (Int -> ControlMessage -> ShowS
[ControlMessage] -> ShowS
ControlMessage -> String
(Int -> ControlMessage -> ShowS)
-> (ControlMessage -> String)
-> ([ControlMessage] -> ShowS)
-> Show ControlMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ControlMessage -> ShowS
showsPrec :: Int -> ControlMessage -> ShowS
$cshow :: ControlMessage -> String
show :: ControlMessage -> String
$cshowList :: [ControlMessage] -> ShowS
showList :: [ControlMessage] -> ShowS
Show)

data ShardFlowControl
  = ShardFlowRestart
  | ShardFlowShutDown
  deriving (Int -> ShardFlowControl -> ShowS
[ShardFlowControl] -> ShowS
ShardFlowControl -> String
(Int -> ShardFlowControl -> ShowS)
-> (ShardFlowControl -> String)
-> ([ShardFlowControl] -> ShowS)
-> Show ShardFlowControl
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ShardFlowControl -> ShowS
showsPrec :: Int -> ShardFlowControl -> ShowS
$cshow :: ShardFlowControl -> String
show :: ShardFlowControl -> String
$cshowList :: [ShardFlowControl] -> ShowS
showList :: [ShardFlowControl] -> ShowS
Show)

data Shard = Shard
  { Shard -> Int
shardID :: Int
  , Shard -> Int
shardCount :: Int
  , Shard -> Text
gateway :: Text
  , Shard -> InChan CalamityEvent
evtIn :: InChan CalamityEvent
  , Shard -> OutChan ControlMessage
cmdOut :: OutChan ControlMessage
  , Shard -> Text
token :: Text
  , Shard -> Maybe StatusUpdateData
initialStatus :: Maybe StatusUpdateData
  , Shard -> Intents
intents :: Intents
  }

data ShardState = ShardState
  { ShardState -> Shard
shardS :: Shard
  , ShardState -> Maybe Int
seqNum :: Maybe Int
  , ShardState -> Maybe (Async (Maybe ()))
hbThread :: Maybe (Async (Maybe ()))
  , ShardState -> Bool
hbResponse :: Bool
  , ShardState -> Maybe Text
wsHost :: Maybe Text
  , ShardState -> Maybe Text
sessionID :: Maybe Text
  , ShardState -> Maybe Connection
wsConn :: Maybe Connection
  }

$(makeFieldLabelsNoPrefix ''Shard)
$(makeFieldLabelsNoPrefix ''ShardState)