{-# LANGUAGE OverloadedStrings #-}
module Discord.Internal.Types.Events where
import Prelude hiding (id)
import Data.Time.ISO8601 (parseISO8601)
import Data.Time (UTCTime)
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import Network.Socket (HostName)
import Data.Aeson
import Data.Aeson.Types
import qualified Data.Text as T
import Discord.Internal.Types.Prelude
import Discord.Internal.Types.Channel
import Discord.Internal.Types.Guild
import Discord.Internal.Types.User (User, GuildMember)
import Discord.Internal.Types.Interactions (Interaction)
import Discord.Internal.Types.Emoji (Emoji)
data Event =
Ready Int User [GuildUnavailable] T.Text HostName (Maybe Shard) PartialApplication
| Resumed [T.Text]
| ChannelCreate Channel
| ChannelUpdate Channel
| ChannelDelete Channel
| ThreadCreate Channel
| ThreadUpdate Channel
| ThreadDelete Channel
| ThreadListSync ThreadListSyncFields
| ThreadMembersUpdate ThreadMembersUpdateFields
| ChannelPinsUpdate ChannelId (Maybe UTCTime)
| GuildCreate Guild
| GuildUpdate Guild
| GuildDelete GuildUnavailable
| GuildBanAdd GuildId User
| GuildBanRemove GuildId User
| GuildEmojiUpdate GuildId [Emoji]
| GuildIntegrationsUpdate GuildId
| GuildMemberAdd GuildId GuildMember
| GuildMemberRemove GuildId User
| GuildMemberUpdate GuildId [RoleId] User (Maybe T.Text)
| GuildMemberChunk GuildId [GuildMember]
| GuildRoleCreate GuildId Role
| GuildRoleUpdate GuildId Role
| GuildRoleDelete GuildId RoleId
| MessageCreate Message
| MessageUpdate ChannelId MessageId
| MessageDelete ChannelId MessageId
| MessageDeleteBulk ChannelId [MessageId]
| MessageReactionAdd ReactionInfo
| MessageReactionRemove ReactionInfo
| MessageReactionRemoveAll ChannelId MessageId
| MessageReactionRemoveEmoji ReactionRemoveInfo
| PresenceUpdate PresenceInfo
| TypingStart TypingInfo
| UserUpdate User
| InteractionCreate Interaction
| UnknownEvent T.Text Object
deriving (Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Show, Event -> Event -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Event -> Event -> Bool
$c/= :: Event -> Event -> Bool
== :: Event -> Event -> Bool
$c== :: Event -> Event -> Bool
Eq)
data EventInternalParse =
InternalReady Int User [GuildUnavailable] T.Text HostName (Maybe Shard) PartialApplication
| InternalResumed [T.Text]
| InternalChannelCreate Channel
| InternalChannelUpdate Channel
| InternalChannelDelete Channel
| InternalThreadCreate Channel
| InternalThreadUpdate Channel
| InternalThreadDelete Channel
| InternalThreadListSync ThreadListSyncFields
| InternalThreadMembersUpdate ThreadMembersUpdateFields
| InternalChannelPinsUpdate ChannelId (Maybe UTCTime)
| InternalGuildCreate Guild
| InternalGuildUpdate Guild
| InternalGuildDelete GuildUnavailable
| InternalGuildBanAdd GuildId User
| InternalGuildBanRemove GuildId User
| InternalGuildEmojiUpdate GuildId [Emoji]
| InternalGuildIntegrationsUpdate GuildId
| InternalGuildMemberAdd GuildId GuildMember
| InternalGuildMemberRemove GuildId User
| InternalGuildMemberUpdate GuildId [RoleId] User (Maybe T.Text)
| InternalGuildMemberChunk GuildId [GuildMember]
| InternalGuildRoleCreate GuildId Role
| InternalGuildRoleUpdate GuildId Role
| InternalGuildRoleDelete GuildId RoleId
| InternalMessageCreate Message
| InternalMessageUpdate ChannelId MessageId
| InternalMessageDelete ChannelId MessageId
| InternalMessageDeleteBulk ChannelId [MessageId]
| InternalMessageReactionAdd ReactionInfo
| InternalMessageReactionRemove ReactionInfo
| InternalMessageReactionRemoveAll ChannelId MessageId
| InternalMessageReactionRemoveEmoji ReactionRemoveInfo
| InternalPresenceUpdate PresenceInfo
| InternalTypingStart TypingInfo
| InternalUserUpdate User
| InternalInteractionCreate Interaction
| InternalUnknownEvent T.Text Object
deriving (Int -> EventInternalParse -> ShowS
[EventInternalParse] -> ShowS
EventInternalParse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EventInternalParse] -> ShowS
$cshowList :: [EventInternalParse] -> ShowS
show :: EventInternalParse -> String
$cshow :: EventInternalParse -> String
showsPrec :: Int -> EventInternalParse -> ShowS
$cshowsPrec :: Int -> EventInternalParse -> ShowS
Show, EventInternalParse -> EventInternalParse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EventInternalParse -> EventInternalParse -> Bool
$c/= :: EventInternalParse -> EventInternalParse -> Bool
== :: EventInternalParse -> EventInternalParse -> Bool
$c== :: EventInternalParse -> EventInternalParse -> Bool
Eq, ReadPrec [EventInternalParse]
ReadPrec EventInternalParse
Int -> ReadS EventInternalParse
ReadS [EventInternalParse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [EventInternalParse]
$creadListPrec :: ReadPrec [EventInternalParse]
readPrec :: ReadPrec EventInternalParse
$creadPrec :: ReadPrec EventInternalParse
readList :: ReadS [EventInternalParse]
$creadList :: ReadS [EventInternalParse]
readsPrec :: Int -> ReadS EventInternalParse
$creadsPrec :: Int -> ReadS EventInternalParse
Read)
data PartialApplication = PartialApplication
{ PartialApplication -> ApplicationId
partialApplicationID :: ApplicationId
, PartialApplication -> Int
partialApplicationFlags :: Int
} deriving (Int -> PartialApplication -> ShowS
[PartialApplication] -> ShowS
PartialApplication -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartialApplication] -> ShowS
$cshowList :: [PartialApplication] -> ShowS
show :: PartialApplication -> String
$cshow :: PartialApplication -> String
showsPrec :: Int -> PartialApplication -> ShowS
$cshowsPrec :: Int -> PartialApplication -> ShowS
Show, PartialApplication -> PartialApplication -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PartialApplication -> PartialApplication -> Bool
$c/= :: PartialApplication -> PartialApplication -> Bool
== :: PartialApplication -> PartialApplication -> Bool
$c== :: PartialApplication -> PartialApplication -> Bool
Eq, ReadPrec [PartialApplication]
ReadPrec PartialApplication
Int -> ReadS PartialApplication
ReadS [PartialApplication]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PartialApplication]
$creadListPrec :: ReadPrec [PartialApplication]
readPrec :: ReadPrec PartialApplication
$creadPrec :: ReadPrec PartialApplication
readList :: ReadS [PartialApplication]
$creadList :: ReadS [PartialApplication]
readsPrec :: Int -> ReadS PartialApplication
$creadsPrec :: Int -> ReadS PartialApplication
Read)
instance FromJSON PartialApplication where
parseJSON :: Value -> Parser PartialApplication
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"PartialApplication" (\Object
v -> ApplicationId -> Int -> PartialApplication
PartialApplication forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"flags")
data ReactionInfo = ReactionInfo
{ ReactionInfo -> UserId
reactionUserId :: UserId
, ReactionInfo -> Maybe GuildId
reactionGuildId :: Maybe GuildId
, ReactionInfo -> ChannelId
reactionChannelId :: ChannelId
, ReactionInfo -> MessageId
reactionMessageId :: MessageId
, ReactionInfo -> Emoji
reactionEmoji :: Emoji
} deriving (Int -> ReactionInfo -> ShowS
[ReactionInfo] -> ShowS
ReactionInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReactionInfo] -> ShowS
$cshowList :: [ReactionInfo] -> ShowS
show :: ReactionInfo -> String
$cshow :: ReactionInfo -> String
showsPrec :: Int -> ReactionInfo -> ShowS
$cshowsPrec :: Int -> ReactionInfo -> ShowS
Show, ReadPrec [ReactionInfo]
ReadPrec ReactionInfo
Int -> ReadS ReactionInfo
ReadS [ReactionInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReactionInfo]
$creadListPrec :: ReadPrec [ReactionInfo]
readPrec :: ReadPrec ReactionInfo
$creadPrec :: ReadPrec ReactionInfo
readList :: ReadS [ReactionInfo]
$creadList :: ReadS [ReactionInfo]
readsPrec :: Int -> ReadS ReactionInfo
$creadsPrec :: Int -> ReadS ReactionInfo
Read, ReactionInfo -> ReactionInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReactionInfo -> ReactionInfo -> Bool
$c/= :: ReactionInfo -> ReactionInfo -> Bool
== :: ReactionInfo -> ReactionInfo -> Bool
$c== :: ReactionInfo -> ReactionInfo -> Bool
Eq, Eq ReactionInfo
ReactionInfo -> ReactionInfo -> Bool
ReactionInfo -> ReactionInfo -> Ordering
ReactionInfo -> ReactionInfo -> ReactionInfo
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ReactionInfo -> ReactionInfo -> ReactionInfo
$cmin :: ReactionInfo -> ReactionInfo -> ReactionInfo
max :: ReactionInfo -> ReactionInfo -> ReactionInfo
$cmax :: ReactionInfo -> ReactionInfo -> ReactionInfo
>= :: ReactionInfo -> ReactionInfo -> Bool
$c>= :: ReactionInfo -> ReactionInfo -> Bool
> :: ReactionInfo -> ReactionInfo -> Bool
$c> :: ReactionInfo -> ReactionInfo -> Bool
<= :: ReactionInfo -> ReactionInfo -> Bool
$c<= :: ReactionInfo -> ReactionInfo -> Bool
< :: ReactionInfo -> ReactionInfo -> Bool
$c< :: ReactionInfo -> ReactionInfo -> Bool
compare :: ReactionInfo -> ReactionInfo -> Ordering
$ccompare :: ReactionInfo -> ReactionInfo -> Ordering
Ord)
instance FromJSON ReactionInfo where
parseJSON :: Value -> Parser ReactionInfo
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ReactionInfo" forall a b. (a -> b) -> a -> b
$ \Object
o ->
UserId
-> Maybe GuildId -> ChannelId -> MessageId -> Emoji -> ReactionInfo
ReactionInfo forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"guild_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"message_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"emoji"
data ReactionRemoveInfo = ReactionRemoveInfo
{ ReactionRemoveInfo -> ChannelId
reactionRemoveChannelId :: ChannelId
, ReactionRemoveInfo -> GuildId
reactionRemoveGuildId :: GuildId
, ReactionRemoveInfo -> MessageId
reactionRemoveMessageId :: MessageId
, ReactionRemoveInfo -> Emoji
reactionRemoveEmoji :: Emoji
} deriving (Int -> ReactionRemoveInfo -> ShowS
[ReactionRemoveInfo] -> ShowS
ReactionRemoveInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReactionRemoveInfo] -> ShowS
$cshowList :: [ReactionRemoveInfo] -> ShowS
show :: ReactionRemoveInfo -> String
$cshow :: ReactionRemoveInfo -> String
showsPrec :: Int -> ReactionRemoveInfo -> ShowS
$cshowsPrec :: Int -> ReactionRemoveInfo -> ShowS
Show, ReadPrec [ReactionRemoveInfo]
ReadPrec ReactionRemoveInfo
Int -> ReadS ReactionRemoveInfo
ReadS [ReactionRemoveInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ReactionRemoveInfo]
$creadListPrec :: ReadPrec [ReactionRemoveInfo]
readPrec :: ReadPrec ReactionRemoveInfo
$creadPrec :: ReadPrec ReactionRemoveInfo
readList :: ReadS [ReactionRemoveInfo]
$creadList :: ReadS [ReactionRemoveInfo]
readsPrec :: Int -> ReadS ReactionRemoveInfo
$creadsPrec :: Int -> ReadS ReactionRemoveInfo
Read, ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
$c/= :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
== :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
$c== :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
Eq, Eq ReactionRemoveInfo
ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
ReactionRemoveInfo -> ReactionRemoveInfo -> Ordering
ReactionRemoveInfo -> ReactionRemoveInfo -> ReactionRemoveInfo
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ReactionRemoveInfo -> ReactionRemoveInfo -> ReactionRemoveInfo
$cmin :: ReactionRemoveInfo -> ReactionRemoveInfo -> ReactionRemoveInfo
max :: ReactionRemoveInfo -> ReactionRemoveInfo -> ReactionRemoveInfo
$cmax :: ReactionRemoveInfo -> ReactionRemoveInfo -> ReactionRemoveInfo
>= :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
$c>= :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
> :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
$c> :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
<= :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
$c<= :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
< :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
$c< :: ReactionRemoveInfo -> ReactionRemoveInfo -> Bool
compare :: ReactionRemoveInfo -> ReactionRemoveInfo -> Ordering
$ccompare :: ReactionRemoveInfo -> ReactionRemoveInfo -> Ordering
Ord)
instance FromJSON ReactionRemoveInfo where
parseJSON :: Value -> Parser ReactionRemoveInfo
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ReactionRemoveInfo" forall a b. (a -> b) -> a -> b
$ \Object
o ->
ChannelId -> GuildId -> MessageId -> Emoji -> ReactionRemoveInfo
ReactionRemoveInfo forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"message_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"emoji"
data TypingInfo = TypingInfo
{ TypingInfo -> UserId
typingUserId :: UserId
, TypingInfo -> ChannelId
typingChannelId :: ChannelId
, TypingInfo -> UTCTime
typingTimestamp :: UTCTime
} deriving (Int -> TypingInfo -> ShowS
[TypingInfo] -> ShowS
TypingInfo -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypingInfo] -> ShowS
$cshowList :: [TypingInfo] -> ShowS
show :: TypingInfo -> String
$cshow :: TypingInfo -> String
showsPrec :: Int -> TypingInfo -> ShowS
$cshowsPrec :: Int -> TypingInfo -> ShowS
Show, ReadPrec [TypingInfo]
ReadPrec TypingInfo
Int -> ReadS TypingInfo
ReadS [TypingInfo]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TypingInfo]
$creadListPrec :: ReadPrec [TypingInfo]
readPrec :: ReadPrec TypingInfo
$creadPrec :: ReadPrec TypingInfo
readList :: ReadS [TypingInfo]
$creadList :: ReadS [TypingInfo]
readsPrec :: Int -> ReadS TypingInfo
$creadsPrec :: Int -> ReadS TypingInfo
Read, TypingInfo -> TypingInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TypingInfo -> TypingInfo -> Bool
$c/= :: TypingInfo -> TypingInfo -> Bool
== :: TypingInfo -> TypingInfo -> Bool
$c== :: TypingInfo -> TypingInfo -> Bool
Eq, Eq TypingInfo
TypingInfo -> TypingInfo -> Bool
TypingInfo -> TypingInfo -> Ordering
TypingInfo -> TypingInfo -> TypingInfo
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TypingInfo -> TypingInfo -> TypingInfo
$cmin :: TypingInfo -> TypingInfo -> TypingInfo
max :: TypingInfo -> TypingInfo -> TypingInfo
$cmax :: TypingInfo -> TypingInfo -> TypingInfo
>= :: TypingInfo -> TypingInfo -> Bool
$c>= :: TypingInfo -> TypingInfo -> Bool
> :: TypingInfo -> TypingInfo -> Bool
$c> :: TypingInfo -> TypingInfo -> Bool
<= :: TypingInfo -> TypingInfo -> Bool
$c<= :: TypingInfo -> TypingInfo -> Bool
< :: TypingInfo -> TypingInfo -> Bool
$c< :: TypingInfo -> TypingInfo -> Bool
compare :: TypingInfo -> TypingInfo -> Ordering
$ccompare :: TypingInfo -> TypingInfo -> Ordering
Ord)
instance FromJSON TypingInfo where
parseJSON :: Value -> Parser TypingInfo
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TypingInfo" forall a b. (a -> b) -> a -> b
$ \Object
o ->
do ChannelId
cid <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id"
UserId
uid <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user_id"
POSIXTime
posix <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"timestamp"
let utc :: UTCTime
utc = POSIXTime -> UTCTime
posixSecondsToUTCTime POSIXTime
posix
forall (f :: * -> *) a. Applicative f => a -> f a
pure (UserId -> ChannelId -> UTCTime -> TypingInfo
TypingInfo UserId
uid ChannelId
cid UTCTime
utc)
reparse :: (ToJSON a, FromJSON b) => a -> Parser b
reparse :: forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse a
val = case forall a b. (a -> Parser b) -> a -> Either String b
parseEither forall a. FromJSON a => Value -> Parser a
parseJSON forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Value
toJSON a
val of
Left String
r -> forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
r
Right b
b -> forall (f :: * -> *) a. Applicative f => a -> f a
pure b
b
extractHostname :: String -> HostName
(Char
'w':Char
's':Char
's':Char
':':Char
'/':Char
'/':String
rest) = ShowS
extractHostname String
rest
extractHostname (Char
'/':[]) = []
extractHostname (Char
a:String
b) = Char
aforall a. a -> [a] -> [a]
:(ShowS
extractHostname String
b)
extractHostname [] = []
eventParse :: T.Text -> Object -> Parser EventInternalParse
eventParse :: Text -> Object -> Parser EventInternalParse
eventParse Text
t Object
o = case Text
t of
Text
"READY" -> Int
-> User
-> [GuildUnavailable]
-> Text
-> String
-> Maybe Shard
-> PartialApplication
-> EventInternalParse
InternalReady forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"v"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guilds"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"session_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ShowS
extractHostname forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"resume_gateway_url")
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"shard"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"application"
Text
"RESUMED" -> [Text] -> EventInternalParse
InternalResumed forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"_trace"
Text
"CHANNEL_CREATE" -> Channel -> EventInternalParse
InternalChannelCreate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"CHANNEL_UPDATE" -> Channel -> EventInternalParse
InternalChannelUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"CHANNEL_DELETE" -> Channel -> EventInternalParse
InternalChannelDelete forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"THREAD_CREATE" -> Channel -> EventInternalParse
InternalThreadCreate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"THREAD_UPDATE" -> Channel -> EventInternalParse
InternalThreadUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"THREAD_DELETE" -> Channel -> EventInternalParse
InternalThreadDelete forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"THREAD_LIST_SYNC" -> ThreadListSyncFields -> EventInternalParse
InternalThreadListSync forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"THREAD_MEMBERS_UPDATE" -> ThreadMembersUpdateFields -> EventInternalParse
InternalThreadMembersUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"CHANNEL_PINS_UPDATE" -> do ChannelId
id <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id"
Maybe String
stamp <- Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"last_pin_timestamp"
let utc :: Maybe UTCTime
utc = Maybe String
stamp forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= String -> Maybe UTCTime
parseISO8601
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ChannelId -> Maybe UTCTime -> EventInternalParse
InternalChannelPinsUpdate ChannelId
id Maybe UTCTime
utc)
Text
"GUILD_CREATE" -> Guild -> EventInternalParse
InternalGuildCreate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"GUILD_UPDATE" -> Guild -> EventInternalParse
InternalGuildUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"GUILD_DELETE" -> GuildUnavailable -> EventInternalParse
InternalGuildDelete forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"GUILD_BAN_ADD" -> GuildId -> User -> EventInternalParse
InternalGuildBanAdd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user"
Text
"GUILD_BAN_REMOVE" -> GuildId -> User -> EventInternalParse
InternalGuildBanRemove forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user"
Text
"GUILD_EMOJI_UPDATE" -> GuildId -> [Emoji] -> EventInternalParse
InternalGuildEmojiUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"emojis"
Text
"GUILD_INTEGRATIONS_UPDATE" -> GuildId -> EventInternalParse
InternalGuildIntegrationsUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id"
Text
"GUILD_MEMBER_ADD" -> GuildId -> GuildMember -> EventInternalParse
InternalGuildMemberAdd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"GUILD_MEMBER_REMOVE" -> GuildId -> User -> EventInternalParse
InternalGuildMemberRemove forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user"
Text
"GUILD_MEMBER_UPDATE" -> GuildId -> [RoleId] -> User -> Maybe Text -> EventInternalParse
InternalGuildMemberUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"roles"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"nick"
Text
"GUILD_MEMBERS_CHUNK" -> GuildId -> [GuildMember] -> EventInternalParse
InternalGuildMemberChunk forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"members"
Text
"GUILD_ROLE_CREATE" -> GuildId -> Role -> EventInternalParse
InternalGuildRoleCreate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"role"
Text
"GUILD_ROLE_UPDATE" -> GuildId -> Role -> EventInternalParse
InternalGuildRoleUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"role"
Text
"GUILD_ROLE_DELETE" -> GuildId -> RoleId -> EventInternalParse
InternalGuildRoleDelete forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"role_id"
Text
"MESSAGE_CREATE" -> Message -> EventInternalParse
InternalMessageCreate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"MESSAGE_UPDATE" -> ChannelId -> MessageId -> EventInternalParse
InternalMessageUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Text
"MESSAGE_DELETE" -> ChannelId -> MessageId -> EventInternalParse
InternalMessageDelete forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Text
"MESSAGE_DELETE_BULK" -> ChannelId -> [MessageId] -> EventInternalParse
InternalMessageDeleteBulk forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id" forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ids"
Text
"MESSAGE_REACTION_ADD" -> ReactionInfo -> EventInternalParse
InternalMessageReactionAdd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"MESSAGE_REACTION_REMOVE" -> ReactionInfo -> EventInternalParse
InternalMessageReactionRemove forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"MESSAGE_REACTION_REMOVE_ALL" -> ChannelId -> MessageId -> EventInternalParse
InternalMessageReactionRemoveAll forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"message_id"
Text
"MESSAGE_REACTION_REMOVE_EMOJI" -> ReactionRemoveInfo -> EventInternalParse
InternalMessageReactionRemoveEmoji forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"PRESENCE_UPDATE" -> PresenceInfo -> EventInternalParse
InternalPresenceUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"TYPING_START" -> TypingInfo -> EventInternalParse
InternalTypingStart forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"USER_UPDATE" -> User -> EventInternalParse
InternalUserUpdate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
"INTERACTION_CREATE" -> Interaction -> EventInternalParse
InternalInteractionCreate forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o
Text
_other_event -> Text -> Object -> EventInternalParse
InternalUnknownEvent Text
t forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. (ToJSON a, FromJSON b) => a -> Parser b
reparse Object
o