-- | 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.Internal.AesonThings
import           Calamity.Metrics.Eff
import           Calamity.Types.LogEff
import           Calamity.Types.Model.Guild.Guild
import           Calamity.Types.Model.Voice
import           Calamity.Types.Snowflake

import           Control.Concurrent.Async
import           Control.Concurrent.Chan.Unagi

import           Data.Aeson
import qualified Data.Aeson.Types                 as AT
import           Data.Generics.Labels             ()
import           Data.IORef
import           Data.Maybe
import           Data.Text.Lazy                   ( Text )

import           GHC.Generics

import           Network.WebSockets.Connection    ( Connection )

import qualified Polysemy                         as P
import qualified Polysemy.Async                   as P
import qualified Polysemy.AtomicState             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
showList :: [ShardMsg] -> ShowS
$cshowList :: [ShardMsg] -> ShowS
show :: ShardMsg -> String
$cshow :: ShardMsg -> String
showsPrec :: Int -> ShardMsg -> ShowS
$cshowsPrec :: Int -> ShardMsg -> ShowS
Show, (forall x. ShardMsg -> Rep ShardMsg x)
-> (forall x. Rep ShardMsg x -> ShardMsg) -> Generic ShardMsg
forall x. Rep ShardMsg x -> ShardMsg
forall x. ShardMsg -> Rep ShardMsg x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ShardMsg x -> ShardMsg
$cfrom :: forall x. ShardMsg -> Rep ShardMsg x
Generic )

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
showList :: [ReceivedDiscordMessage] -> ShowS
$cshowList :: [ReceivedDiscordMessage] -> ShowS
show :: ReceivedDiscordMessage -> String
$cshow :: ReceivedDiscordMessage -> String
showsPrec :: Int -> ReceivedDiscordMessage -> ShowS
$cshowsPrec :: Int -> ReceivedDiscordMessage -> ShowS
Show, (forall x. ReceivedDiscordMessage -> Rep ReceivedDiscordMessage x)
-> (forall x.
    Rep ReceivedDiscordMessage x -> ReceivedDiscordMessage)
-> Generic ReceivedDiscordMessage
forall x. Rep ReceivedDiscordMessage x -> ReceivedDiscordMessage
forall x. ReceivedDiscordMessage -> Rep ReceivedDiscordMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ReceivedDiscordMessage x -> ReceivedDiscordMessage
$cfrom :: forall x. ReceivedDiscordMessage -> Rep ReceivedDiscordMessage x
Generic )

instance FromJSON ReceivedDiscordMessage where
  parseJSON :: Value -> Parser ReceivedDiscordMessage
parseJSON = String
-> (Object -> Parser ReceivedDiscordMessage)
-> Value
-> Parser ReceivedDiscordMessage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject "ReceivedDiscordMessage" ((Object -> Parser ReceivedDiscordMessage)
 -> Value -> Parser ReceivedDiscordMessage)
-> (Object -> Parser ReceivedDiscordMessage)
-> Value
-> Parser ReceivedDiscordMessage
forall a b. (a -> b) -> a -> b
$ \v :: Object
v -> do
    Int
op :: Int <- Object
v Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
.: "op"
    case Int
op of
      0  -> do
        Value
d <- Object
v Object -> Text -> Parser Value
forall a. FromJSON a => Object -> Text -> Parser a
.: "d"
        DispatchType
t <- Object
v Object -> Text -> Parser DispatchType
forall a. FromJSON a => Object -> Text -> Parser a
.: "t"
        Int
s <- Object
v Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
.: "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

      1  -> ReceivedDiscordMessage -> Parser ReceivedDiscordMessage
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReceivedDiscordMessage
HeartBeatReq

      7  -> ReceivedDiscordMessage -> Parser ReceivedDiscordMessage
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReceivedDiscordMessage
Reconnect

      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 -> Text -> Parser Bool
forall a. FromJSON a => Object -> Text -> Parser a
.: "d"

      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 -> Text -> Parser Object
forall a. FromJSON a => Object -> Text -> Parser a
.: "d"
        Object
d Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
.: "heartbeat_interval"

      11 -> ReceivedDiscordMessage -> Parser ReceivedDiscordMessage
forall (f :: * -> *) a. Applicative f => a -> f a
pure ReceivedDiscordMessage
HeartBeatAck

      _  -> String -> Parser ReceivedDiscordMessage
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ReceivedDiscordMessage)
-> String -> Parser ReceivedDiscordMessage
forall a b. (a -> b) -> a -> b
$ "invalid opcode: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
op

parseDispatchData :: DispatchType -> Value -> AT.Parser DispatchData
parseDispatchData :: DispatchType -> Value -> Parser DispatchData
parseDispatchData READY data' :: 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
parseJSON Value
data'
parseDispatchData RESUMED _                         = DispatchData -> Parser DispatchData
forall (f :: * -> *) a. Applicative f => a -> f a
pure DispatchData
Resumed
parseDispatchData CHANNEL_CREATE data' :: 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
parseJSON Value
data'
parseDispatchData CHANNEL_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData CHANNEL_DELETE data' :: 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
parseJSON Value
data'
parseDispatchData CHANNEL_PINS_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_CREATE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_DELETE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_BAN_ADD data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_BAN_REMOVE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_EMOJIS_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_INTEGRATIONS_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_MEMBER_ADD data' :: Value
data'            = Member -> DispatchData
GuildMemberAdd (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
parseJSON Value
data'
parseDispatchData GUILD_MEMBER_REMOVE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_MEMBER_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_MEMBERS_CHUNK data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_ROLE_CREATE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_ROLE_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData GUILD_ROLE_DELETE data' :: 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
parseJSON Value
data'
parseDispatchData MESSAGE_CREATE data' :: Value
data'              = Message -> DispatchData
MessageCreate (Message -> DispatchData) -> Parser Message -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Message
forall a. FromJSON a => Value -> Parser a
parseJSON Value
data'
parseDispatchData MESSAGE_UPDATE data' :: Value
data'              = UpdatedMessage -> DispatchData
MessageUpdate (UpdatedMessage -> DispatchData)
-> Parser UpdatedMessage -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser UpdatedMessage
forall a. FromJSON a => Value -> Parser a
parseJSON Value
data'
parseDispatchData MESSAGE_DELETE data' :: 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
parseJSON Value
data'
parseDispatchData MESSAGE_DELETE_BULK data' :: 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
parseJSON Value
data'
parseDispatchData MESSAGE_REACTION_ADD data' :: Value
data'        = Reaction -> DispatchData
MessageReactionAdd (Reaction -> DispatchData)
-> Parser Reaction -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Reaction
forall a. FromJSON a => Value -> Parser a
parseJSON Value
data'
parseDispatchData MESSAGE_REACTION_REMOVE data' :: Value
data'     = Reaction -> DispatchData
MessageReactionRemove (Reaction -> DispatchData)
-> Parser Reaction -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser Reaction
forall a. FromJSON a => Value -> Parser a
parseJSON Value
data'
parseDispatchData MESSAGE_REACTION_REMOVE_ALL data' :: 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
parseJSON Value
data'
parseDispatchData PRESENCE_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData TYPING_START data' :: 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
parseJSON Value
data'
parseDispatchData USER_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData VOICE_STATE_UPDATE data' :: Value
data'          = VoiceStateUpdateData -> DispatchData
VoiceStateUpdate (VoiceStateUpdateData -> DispatchData)
-> Parser VoiceStateUpdateData -> Parser DispatchData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser VoiceStateUpdateData
forall a. FromJSON a => Value -> Parser a
parseJSON Value
data'
parseDispatchData VOICE_SERVER_UPDATE data' :: 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
parseJSON Value
data'
parseDispatchData WEBHOOKS_UPDATE data' :: 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
parseJSON Value
data'

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
showList :: [SentDiscordMessage] -> ShowS
$cshowList :: [SentDiscordMessage] -> ShowS
show :: SentDiscordMessage -> String
$cshow :: SentDiscordMessage -> String
showsPrec :: Int -> SentDiscordMessage -> ShowS
$cshowsPrec :: Int -> SentDiscordMessage -> ShowS
Show, (forall x. SentDiscordMessage -> Rep SentDiscordMessage x)
-> (forall x. Rep SentDiscordMessage x -> SentDiscordMessage)
-> Generic SentDiscordMessage
forall x. Rep SentDiscordMessage x -> SentDiscordMessage
forall x. SentDiscordMessage -> Rep SentDiscordMessage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SentDiscordMessage x -> SentDiscordMessage
$cfrom :: forall x. SentDiscordMessage -> Rep SentDiscordMessage x
Generic )

instance ToJSON SentDiscordMessage where
  toJSON :: SentDiscordMessage -> Value
toJSON (HeartBeat data' :: Maybe Int
data') = [Pair] -> Value
object ["op" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (1 :: Int), "d" Text -> Maybe Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Maybe Int
data']

  toJSON (Identify data' :: IdentifyData
data') = [Pair] -> Value
object ["op" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (2 :: Int), "d" Text -> IdentifyData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= IdentifyData
data']

  toJSON (StatusUpdate data' :: StatusUpdateData
data') = [Pair] -> Value
object ["op" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (3 :: Int), "d" Text -> StatusUpdateData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= StatusUpdateData
data']

  toJSON (VoiceStatusUpdate data' :: VoiceState
data') = [Pair] -> Value
object ["op" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (4 :: Int), "d" Text -> VoiceState -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= VoiceState
data']

  toJSON (Resume data' :: ResumeData
data') = [Pair] -> Value
object ["op" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (6 :: Int), "d" Text -> ResumeData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= ResumeData
data']

  toJSON (RequestGuildMembers data' :: RequestGuildMembersData
data') = [Pair] -> Value
object ["op" Text -> Int -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (8 :: Int), "d" Text -> RequestGuildMembersData -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= RequestGuildMembersData
data']

  toEncoding :: SentDiscordMessage -> Encoding
toEncoding (HeartBeat data' :: Maybe Int
data') = Series -> Encoding
pairs ("op" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (1 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "d" Text -> Maybe Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Maybe Int
data')

  toEncoding (Identify data' :: IdentifyData
data') = Series -> Encoding
pairs ("op" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (2 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "d" Text -> IdentifyData -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= IdentifyData
data')

  toEncoding (StatusUpdate data' :: StatusUpdateData
data') = Series -> Encoding
pairs ("op" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (3 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "d" Text -> StatusUpdateData -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= StatusUpdateData
data')

  toEncoding (VoiceStatusUpdate data' :: VoiceState
data') = Series -> Encoding
pairs ("op" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (4 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "d" Text -> VoiceState -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= VoiceState
data')

  toEncoding (Resume data' :: ResumeData
data') = Series -> Encoding
pairs ("op" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (6 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "d" Text -> ResumeData -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= ResumeData
data')

  toEncoding (RequestGuildMembers data' :: RequestGuildMembersData
data') = Series -> Encoding
pairs ("op" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (8 :: Int) Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "d" Text -> RequestGuildMembersData -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= RequestGuildMembersData
data')

-- Thanks sbrg:
-- https://github.com/saevarb/haskord/blob/d1bb07bcc4f3dbc29f2dfd3351ff9f16fc100c07/haskord-lib/src/Haskord/Types/Common.hs
data DispatchType
  = READY
  | RESUMED
  | CHANNEL_CREATE
  | CHANNEL_UPDATE
  | CHANNEL_DELETE
  | CHANNEL_PINS_UPDATE
  | GUILD_CREATE
  | GUILD_UPDATE
  | GUILD_DELETE
  | GUILD_BAN_ADD
  | GUILD_BAN_REMOVE
  | GUILD_EMOJIS_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
  | MESSAGE_CREATE
  | MESSAGE_UPDATE
  | MESSAGE_DELETE
  | MESSAGE_DELETE_BULK
  | MESSAGE_REACTION_ADD
  | MESSAGE_REACTION_REMOVE
  | MESSAGE_REACTION_REMOVE_ALL
  | PRESENCE_UPDATE
  | 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
showList :: [DispatchType] -> ShowS
$cshowList :: [DispatchType] -> ShowS
show :: DispatchType -> String
$cshow :: DispatchType -> String
showsPrec :: Int -> DispatchType -> ShowS
$cshowsPrec :: Int -> DispatchType -> ShowS
Show, DispatchType -> DispatchType -> Bool
(DispatchType -> DispatchType -> Bool)
-> (DispatchType -> DispatchType -> Bool) -> Eq DispatchType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DispatchType -> DispatchType -> Bool
$c/= :: DispatchType -> DispatchType -> Bool
== :: DispatchType -> DispatchType -> Bool
$c== :: 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
enumFromThenTo :: DispatchType -> DispatchType -> DispatchType -> [DispatchType]
$cenumFromThenTo :: DispatchType -> DispatchType -> DispatchType -> [DispatchType]
enumFromTo :: DispatchType -> DispatchType -> [DispatchType]
$cenumFromTo :: DispatchType -> DispatchType -> [DispatchType]
enumFromThen :: DispatchType -> DispatchType -> [DispatchType]
$cenumFromThen :: DispatchType -> DispatchType -> [DispatchType]
enumFrom :: DispatchType -> [DispatchType]
$cenumFrom :: DispatchType -> [DispatchType]
fromEnum :: DispatchType -> Int
$cfromEnum :: DispatchType -> Int
toEnum :: Int -> DispatchType
$ctoEnum :: Int -> DispatchType
pred :: DispatchType -> DispatchType
$cpred :: DispatchType -> DispatchType
succ :: DispatchType -> DispatchType
$csucc :: 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
$cto :: forall x. Rep DispatchType x -> DispatchType
$cfrom :: forall x. DispatchType -> Rep DispatchType x
Generic )
  deriving anyclass ( [DispatchType] -> Encoding
[DispatchType] -> Value
DispatchType -> Encoding
DispatchType -> Value
(DispatchType -> Value)
-> (DispatchType -> Encoding)
-> ([DispatchType] -> Value)
-> ([DispatchType] -> Encoding)
-> ToJSON DispatchType
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [DispatchType] -> Encoding
$ctoEncodingList :: [DispatchType] -> Encoding
toJSONList :: [DispatchType] -> Value
$ctoJSONList :: [DispatchType] -> Value
toEncoding :: DispatchType -> Encoding
$ctoEncoding :: DispatchType -> Encoding
toJSON :: DispatchType -> Value
$ctoJSON :: DispatchType -> Value
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
parseJSONList :: Value -> Parser [DispatchType]
$cparseJSONList :: Value -> Parser [DispatchType]
parseJSON :: Value -> Parser DispatchType
$cparseJSON :: Value -> Parser DispatchType
FromJSON )

data IdentifyData = IdentifyData
  { IdentifyData -> Text
token          :: Text
  , IdentifyData -> IdentifyProps
properties     :: IdentifyProps
  , IdentifyData -> Bool
compress       :: Bool
  , IdentifyData -> Int
largeThreshold :: Int
  , IdentifyData -> (Int, Int)
shard          :: (Int, Int)
  , IdentifyData -> Maybe StatusUpdateData
presence       :: Maybe StatusUpdateData
  }
  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
showList :: [IdentifyData] -> ShowS
$cshowList :: [IdentifyData] -> ShowS
show :: IdentifyData -> String
$cshow :: IdentifyData -> String
showsPrec :: Int -> IdentifyData -> ShowS
$cshowsPrec :: Int -> IdentifyData -> ShowS
Show, (forall x. IdentifyData -> Rep IdentifyData x)
-> (forall x. Rep IdentifyData x -> IdentifyData)
-> Generic IdentifyData
forall x. Rep IdentifyData x -> IdentifyData
forall x. IdentifyData -> Rep IdentifyData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IdentifyData x -> IdentifyData
$cfrom :: forall x. IdentifyData -> Rep IdentifyData x
Generic )
  deriving [IdentifyData] -> Encoding
[IdentifyData] -> Value
IdentifyData -> Encoding
IdentifyData -> Value
(IdentifyData -> Value)
-> (IdentifyData -> Encoding)
-> ([IdentifyData] -> Value)
-> ([IdentifyData] -> Encoding)
-> ToJSON IdentifyData
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [IdentifyData] -> Encoding
$ctoEncodingList :: [IdentifyData] -> Encoding
toJSONList :: [IdentifyData] -> Value
$ctoJSONList :: [IdentifyData] -> Value
toEncoding :: IdentifyData -> Encoding
$ctoEncoding :: IdentifyData -> Encoding
toJSON :: IdentifyData -> Value
$ctoJSON :: IdentifyData -> Value
ToJSON via CalamityJSON IdentifyData

data StatusUpdateData = StatusUpdateData
  { StatusUpdateData -> Maybe Integer
since  :: Maybe Integer
  , StatusUpdateData -> Maybe Value
game   :: Maybe Value
  , StatusUpdateData -> Text
status :: Text
  , 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
showList :: [StatusUpdateData] -> ShowS
$cshowList :: [StatusUpdateData] -> ShowS
show :: StatusUpdateData -> String
$cshow :: StatusUpdateData -> String
showsPrec :: Int -> StatusUpdateData -> ShowS
$cshowsPrec :: Int -> StatusUpdateData -> ShowS
Show, (forall x. StatusUpdateData -> Rep StatusUpdateData x)
-> (forall x. Rep StatusUpdateData x -> StatusUpdateData)
-> Generic StatusUpdateData
forall x. Rep StatusUpdateData x -> StatusUpdateData
forall x. StatusUpdateData -> Rep StatusUpdateData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep StatusUpdateData x -> StatusUpdateData
$cfrom :: forall x. StatusUpdateData -> Rep StatusUpdateData x
Generic )
  deriving [StatusUpdateData] -> Encoding
[StatusUpdateData] -> Value
StatusUpdateData -> Encoding
StatusUpdateData -> Value
(StatusUpdateData -> Value)
-> (StatusUpdateData -> Encoding)
-> ([StatusUpdateData] -> Value)
-> ([StatusUpdateData] -> Encoding)
-> ToJSON StatusUpdateData
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [StatusUpdateData] -> Encoding
$ctoEncodingList :: [StatusUpdateData] -> Encoding
toJSONList :: [StatusUpdateData] -> Value
$ctoJSONList :: [StatusUpdateData] -> Value
toEncoding :: StatusUpdateData -> Encoding
$ctoEncoding :: StatusUpdateData -> Encoding
toJSON :: StatusUpdateData -> Value
$ctoJSON :: StatusUpdateData -> Value
ToJSON via CalamityJSON StatusUpdateData

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
showList :: [ResumeData] -> ShowS
$cshowList :: [ResumeData] -> ShowS
show :: ResumeData -> String
$cshow :: ResumeData -> String
showsPrec :: Int -> ResumeData -> ShowS
$cshowsPrec :: Int -> ResumeData -> ShowS
Show, (forall x. ResumeData -> Rep ResumeData x)
-> (forall x. Rep ResumeData x -> ResumeData) -> Generic ResumeData
forall x. Rep ResumeData x -> ResumeData
forall x. ResumeData -> Rep ResumeData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ResumeData x -> ResumeData
$cfrom :: forall x. ResumeData -> Rep ResumeData x
Generic )
  deriving ( [ResumeData] -> Encoding
[ResumeData] -> Value
ResumeData -> Encoding
ResumeData -> Value
(ResumeData -> Value)
-> (ResumeData -> Encoding)
-> ([ResumeData] -> Value)
-> ([ResumeData] -> Encoding)
-> ToJSON ResumeData
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ResumeData] -> Encoding
$ctoEncodingList :: [ResumeData] -> Encoding
toJSONList :: [ResumeData] -> Value
$ctoJSONList :: [ResumeData] -> Value
toEncoding :: ResumeData -> Encoding
$ctoEncoding :: ResumeData -> Encoding
toJSON :: ResumeData -> Value
$ctoJSON :: ResumeData -> Value
ToJSON, Value -> Parser [ResumeData]
Value -> Parser ResumeData
(Value -> Parser ResumeData)
-> (Value -> Parser [ResumeData]) -> FromJSON ResumeData
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [ResumeData]
$cparseJSONList :: Value -> Parser [ResumeData]
parseJSON :: Value -> Parser ResumeData
$cparseJSON :: Value -> Parser ResumeData
FromJSON ) via CalamityJSON ResumeData

data RequestGuildMembersData = RequestGuildMembersData
  { RequestGuildMembersData -> Snowflake Guild
guildID :: Snowflake Guild
  , RequestGuildMembersData -> Maybe Text
query   :: Maybe Text
  , RequestGuildMembersData -> Maybe Int
limit   :: Maybe Int
  }
  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
showList :: [RequestGuildMembersData] -> ShowS
$cshowList :: [RequestGuildMembersData] -> ShowS
show :: RequestGuildMembersData -> String
$cshow :: RequestGuildMembersData -> String
showsPrec :: Int -> RequestGuildMembersData -> ShowS
$cshowsPrec :: Int -> RequestGuildMembersData -> ShowS
Show, (forall x.
 RequestGuildMembersData -> Rep RequestGuildMembersData x)
-> (forall x.
    Rep RequestGuildMembersData x -> RequestGuildMembersData)
-> Generic RequestGuildMembersData
forall x. Rep RequestGuildMembersData x -> RequestGuildMembersData
forall x. RequestGuildMembersData -> Rep RequestGuildMembersData x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RequestGuildMembersData x -> RequestGuildMembersData
$cfrom :: forall x. RequestGuildMembersData -> Rep RequestGuildMembersData x
Generic )

instance ToJSON RequestGuildMembersData where
  toEncoding :: RequestGuildMembersData -> Encoding
toEncoding RequestGuildMembersData { Snowflake Guild
guildID :: Snowflake Guild
$sel:guildID:RequestGuildMembersData :: RequestGuildMembersData -> Snowflake Guild
guildID, Maybe Text
query :: Maybe Text
$sel:query:RequestGuildMembersData :: RequestGuildMembersData -> Maybe Text
query, Maybe Int
limit :: Maybe Int
$sel:limit:RequestGuildMembersData :: RequestGuildMembersData -> Maybe Int
limit } = Series -> Encoding
pairs
    ("guild_id" Text -> Snowflake Guild -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Snowflake Guild
guildID Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "query" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe "" Maybe Text
query Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "limit" Text -> Int -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Int -> Maybe Int -> Int
forall a. a -> Maybe a -> a
fromMaybe 0 Maybe Int
limit)

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
showList :: [IdentifyProps] -> ShowS
$cshowList :: [IdentifyProps] -> ShowS
show :: IdentifyProps -> String
$cshow :: IdentifyProps -> String
showsPrec :: Int -> IdentifyProps -> ShowS
$cshowsPrec :: Int -> IdentifyProps -> ShowS
Show, (forall x. IdentifyProps -> Rep IdentifyProps x)
-> (forall x. Rep IdentifyProps x -> IdentifyProps)
-> Generic IdentifyProps
forall x. Rep IdentifyProps x -> IdentifyProps
forall x. IdentifyProps -> Rep IdentifyProps x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IdentifyProps x -> IdentifyProps
$cfrom :: forall x. IdentifyProps -> Rep IdentifyProps x
Generic )

instance ToJSON IdentifyProps where
  toEncoding :: IdentifyProps -> Encoding
toEncoding IdentifyProps { Text
browser :: Text
$sel:browser:IdentifyProps :: IdentifyProps -> Text
browser, Text
device :: Text
$sel:device:IdentifyProps :: IdentifyProps -> Text
device } = Series -> Encoding
pairs ("$browser" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text
browser Series -> Series -> Series
forall a. Semigroup a => a -> a -> a
<> "$device" Text -> Text -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> 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
showList :: [ControlMessage] -> ShowS
$cshowList :: [ControlMessage] -> ShowS
show :: ControlMessage -> String
$cshow :: ControlMessage -> String
showsPrec :: Int -> ControlMessage -> ShowS
$cshowsPrec :: Int -> 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
showList :: [ShardFlowControl] -> ShowS
$cshowList :: [ShardFlowControl] -> ShowS
show :: ShardFlowControl -> String
$cshow :: ShardFlowControl -> String
showsPrec :: Int -> ShardFlowControl -> ShowS
$cshowsPrec :: Int -> 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 -> IORef ShardState
shardState  :: IORef ShardState
  , Shard -> Text
token       :: Text
  }
  deriving ( (forall x. Shard -> Rep Shard x)
-> (forall x. Rep Shard x -> Shard) -> Generic Shard
forall x. Rep Shard x -> Shard
forall x. Shard -> Rep Shard x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Shard x -> Shard
$cfrom :: forall x. Shard -> Rep Shard x
Generic )

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
  }
  deriving ( (forall x. ShardState -> Rep ShardState x)
-> (forall x. Rep ShardState x -> ShardState) -> Generic ShardState
forall x. Rep ShardState x -> ShardState
forall x. ShardState -> Rep ShardState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ShardState x -> ShardState
$cfrom :: forall x. ShardState -> Rep ShardState x
Generic )