{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

-- | Data structures pertaining to Discord User
module Discord.Internal.Types.User where

import Data.Aeson
import Data.Text (Text)
import qualified Data.Text as T
import Discord.Internal.Types.Prelude
import Data.Time (UTCTime)

-- | Represents information about a user.
data User = User
  { User -> UserId
userId          :: UserId             -- ^ The user's id.
  , User -> Text
userName        :: T.Text             -- ^ The user's username (not unique)
  , User -> Maybe Text
userDiscrim     :: Maybe T.Text       -- ^ The user's 4-digit discord-tag.
  , User -> Maybe Text
userAvatar      :: Maybe T.Text       -- ^ The user's avatar hash.
  , User -> Bool
userIsBot       :: Bool               -- ^ User is an OAuth2 application.
  , User -> Bool
userIsWebhook   :: Bool               -- ^ User is a webhook.
  , User -> Maybe Bool
userIsSystem    :: Maybe Bool         -- ^ User is an official discord system user.
  , User -> Maybe Bool
userMfa         :: Maybe Bool         -- ^ User has two factor authentication enabled on the account.
  , User -> Maybe Text
userBanner      :: Maybe T.Text       -- ^ User's banner hash
  , User -> Maybe Int
userAccentColor :: Maybe Int          -- ^ User's banner color
  , User -> Maybe Text
userLocale      :: Maybe T.Text       -- ^ User's chosen language
  , User -> Maybe Bool
userVerified    :: Maybe Bool         -- ^ Whether the email has been verified.
  , User -> Maybe Text
userEmail       :: Maybe T.Text       -- ^ The user's email.
  , User -> Maybe Integer
userFlags       :: Maybe Integer      -- ^ The user's flags.
  , User -> Maybe Integer
userPremiumType :: Maybe Integer      -- ^ The user's premium type.
  , User -> Maybe Integer
userPublicFlags :: Maybe Integer      -- ^ The user's public flags.
  , User -> Maybe GuildMember
userMember      :: Maybe GuildMember  -- ^ Some guild member info (message create/update)
  } deriving (Int -> User -> ShowS
[User] -> ShowS
User -> String
(Int -> User -> ShowS)
-> (User -> String) -> ([User] -> ShowS) -> Show User
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [User] -> ShowS
$cshowList :: [User] -> ShowS
show :: User -> String
$cshow :: User -> String
showsPrec :: Int -> User -> ShowS
$cshowsPrec :: Int -> User -> ShowS
Show, ReadPrec [User]
ReadPrec User
Int -> ReadS User
ReadS [User]
(Int -> ReadS User)
-> ReadS [User] -> ReadPrec User -> ReadPrec [User] -> Read User
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [User]
$creadListPrec :: ReadPrec [User]
readPrec :: ReadPrec User
$creadPrec :: ReadPrec User
readList :: ReadS [User]
$creadList :: ReadS [User]
readsPrec :: Int -> ReadS User
$creadsPrec :: Int -> ReadS User
Read, User -> User -> Bool
(User -> User -> Bool) -> (User -> User -> Bool) -> Eq User
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: User -> User -> Bool
$c/= :: User -> User -> Bool
== :: User -> User -> Bool
$c== :: User -> User -> Bool
Eq, Eq User
Eq User
-> (User -> User -> Ordering)
-> (User -> User -> Bool)
-> (User -> User -> Bool)
-> (User -> User -> Bool)
-> (User -> User -> Bool)
-> (User -> User -> User)
-> (User -> User -> User)
-> Ord User
User -> User -> Bool
User -> User -> Ordering
User -> User -> User
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 :: User -> User -> User
$cmin :: User -> User -> User
max :: User -> User -> User
$cmax :: User -> User -> User
>= :: User -> User -> Bool
$c>= :: User -> User -> Bool
> :: User -> User -> Bool
$c> :: User -> User -> Bool
<= :: User -> User -> Bool
$c<= :: User -> User -> Bool
< :: User -> User -> Bool
$c< :: User -> User -> Bool
compare :: User -> User -> Ordering
$ccompare :: User -> User -> Ordering
$cp1Ord :: Eq User
Ord)

instance FromJSON User where
  parseJSON :: Value -> Parser User
parseJSON = String -> (Object -> Parser User) -> Value -> Parser User
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"User" ((Object -> Parser User) -> Value -> Parser User)
-> (Object -> Parser User) -> Value -> Parser User
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    UserId
-> Text
-> Maybe Text
-> Maybe Text
-> Bool
-> Bool
-> Maybe Bool
-> Maybe Bool
-> Maybe Text
-> Maybe Int
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Integer
-> Maybe Integer
-> Maybe Integer
-> Maybe GuildMember
-> User
User (UserId
 -> Text
 -> Maybe Text
 -> Maybe Text
 -> Bool
 -> Bool
 -> Maybe Bool
 -> Maybe Bool
 -> Maybe Text
 -> Maybe Int
 -> Maybe Text
 -> Maybe Bool
 -> Maybe Text
 -> Maybe Integer
 -> Maybe Integer
 -> Maybe Integer
 -> Maybe GuildMember
 -> User)
-> Parser UserId
-> Parser
     (Text
      -> Maybe Text
      -> Maybe Text
      -> Bool
      -> Bool
      -> Maybe Bool
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser UserId
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"id"
         Parser
  (Text
   -> Maybe Text
   -> Maybe Text
   -> Bool
   -> Bool
   -> Maybe Bool
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser Text
-> Parser
     (Maybe Text
      -> Maybe Text
      -> Bool
      -> Bool
      -> Maybe Bool
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"username"
         Parser
  (Maybe Text
   -> Maybe Text
   -> Bool
   -> Bool
   -> Maybe Bool
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Bool
      -> Bool
      -> Maybe Bool
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"discriminator" -- possibly not there in the case of webhooks
         Parser
  (Maybe Text
   -> Bool
   -> Bool
   -> Maybe Bool
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Text)
-> Parser
     (Bool
      -> Bool
      -> Maybe Bool
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"avatar"
         Parser
  (Bool
   -> Bool
   -> Maybe Bool
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser Bool
-> Parser
     (Bool
      -> Maybe Bool
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"bot" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
         Parser
  (Bool
   -> Maybe Bool
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser Bool
-> Parser
     (Maybe Bool
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Parser Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
False -- webhook
         Parser
  (Maybe Bool
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Bool)
-> Parser
     (Maybe Bool
      -> Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"system"
         Parser
  (Maybe Bool
   -> Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Bool)
-> Parser
     (Maybe Text
      -> Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"mfa_enabled"
         Parser
  (Maybe Text
   -> Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Text)
-> Parser
     (Maybe Int
      -> Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"banner"
         Parser
  (Maybe Int
   -> Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Int)
-> Parser
     (Maybe Text
      -> Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"accent_color"
         Parser
  (Maybe Text
   -> Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Text)
-> Parser
     (Maybe Bool
      -> Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"locale"
         Parser
  (Maybe Bool
   -> Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Bool)
-> Parser
     (Maybe Text
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe Integer
      -> Maybe GuildMember
      -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"verified"
         Parser
  (Maybe Text
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe Integer
   -> Maybe GuildMember
   -> User)
-> Parser (Maybe Text)
-> Parser
     (Maybe Integer
      -> Maybe Integer -> Maybe Integer -> Maybe GuildMember -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"email"
         Parser
  (Maybe Integer
   -> Maybe Integer -> Maybe Integer -> Maybe GuildMember -> User)
-> Parser (Maybe Integer)
-> Parser
     (Maybe Integer -> Maybe Integer -> Maybe GuildMember -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"flags"
         Parser
  (Maybe Integer -> Maybe Integer -> Maybe GuildMember -> User)
-> Parser (Maybe Integer)
-> Parser (Maybe Integer -> Maybe GuildMember -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"premium_type"
         Parser (Maybe Integer -> Maybe GuildMember -> User)
-> Parser (Maybe Integer) -> Parser (Maybe GuildMember -> User)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"public_flags"
         Parser (Maybe GuildMember -> User)
-> Parser (Maybe GuildMember) -> Parser User
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe GuildMember)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"member"

instance ToJSON User where
  toJSON :: User -> Value
toJSON User{Bool
Maybe Bool
Maybe Int
Maybe Integer
Maybe Text
Maybe GuildMember
Text
UserId
userMember :: Maybe GuildMember
userPublicFlags :: Maybe Integer
userPremiumType :: Maybe Integer
userFlags :: Maybe Integer
userEmail :: Maybe Text
userVerified :: Maybe Bool
userLocale :: Maybe Text
userAccentColor :: Maybe Int
userBanner :: Maybe Text
userMfa :: Maybe Bool
userIsSystem :: Maybe Bool
userIsWebhook :: Bool
userIsBot :: Bool
userAvatar :: Maybe Text
userDiscrim :: Maybe Text
userName :: Text
userId :: UserId
userMember :: User -> Maybe GuildMember
userPublicFlags :: User -> Maybe Integer
userPremiumType :: User -> Maybe Integer
userFlags :: User -> Maybe Integer
userEmail :: User -> Maybe Text
userVerified :: User -> Maybe Bool
userLocale :: User -> Maybe Text
userAccentColor :: User -> Maybe Int
userBanner :: User -> Maybe Text
userMfa :: User -> Maybe Bool
userIsSystem :: User -> Maybe Bool
userIsWebhook :: User -> Bool
userIsBot :: User -> Bool
userAvatar :: User -> Maybe Text
userDiscrim :: User -> Maybe Text
userName :: User -> Text
userId :: User -> UserId
..} = [Pair] -> Value
object [(Key
name,Value
value) | (Key
name, Just Value
value) <-
              [ (Key
"id",            UserId -> Value
forall a. ToJSON a => a -> Value
toJSON (UserId -> Value) -> Maybe UserId -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UserId -> Maybe UserId
forall (f :: * -> *) a. Applicative f => a -> f a
pure UserId
userId)
              , (Key
"username",      Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
userName)
              , (Key
"discriminator", Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Text
userDiscrim)
              , (Key
"avatar",        Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Text
userAvatar)
              , (Key
"bot",           Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> Maybe Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
userIsBot)
              , (Key
"system",        Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Bool
userIsSystem)
              , (Key
"mfa_enabled",   Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Bool
userMfa)
              , (Key
"banner",        Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Text
userBanner)
              , (Key
"accent_color",  Int -> Value
forall a. ToJSON a => a -> Value
toJSON (Int -> Value) -> Maybe Int -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Int
userAccentColor)
              , (Key
"verified",      Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Bool
userVerified)
              , (Key
"email",         Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Text
userEmail)
              , (Key
"flags",         Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Integer
userFlags)
              , (Key
"premium_type",  Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Integer
userPremiumType)
              , (Key
"public_flags",  Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Integer
userPublicFlags)
              , (Key
"member",        Integer -> Value
forall a. ToJSON a => a -> Value
toJSON (Integer -> Value) -> Maybe Integer -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Integer
userPublicFlags)
              ] ]

-- TODO: fully update webhook structure
data Webhook = Webhook
  { Webhook -> UserId
webhookId :: WebhookId
  , Webhook -> Maybe Text
webhookToken :: Maybe Text
  , Webhook -> UserId
webhookChannelId :: ChannelId
  } deriving (Int -> Webhook -> ShowS
[Webhook] -> ShowS
Webhook -> String
(Int -> Webhook -> ShowS)
-> (Webhook -> String) -> ([Webhook] -> ShowS) -> Show Webhook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Webhook] -> ShowS
$cshowList :: [Webhook] -> ShowS
show :: Webhook -> String
$cshow :: Webhook -> String
showsPrec :: Int -> Webhook -> ShowS
$cshowsPrec :: Int -> Webhook -> ShowS
Show, ReadPrec [Webhook]
ReadPrec Webhook
Int -> ReadS Webhook
ReadS [Webhook]
(Int -> ReadS Webhook)
-> ReadS [Webhook]
-> ReadPrec Webhook
-> ReadPrec [Webhook]
-> Read Webhook
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Webhook]
$creadListPrec :: ReadPrec [Webhook]
readPrec :: ReadPrec Webhook
$creadPrec :: ReadPrec Webhook
readList :: ReadS [Webhook]
$creadList :: ReadS [Webhook]
readsPrec :: Int -> ReadS Webhook
$creadsPrec :: Int -> ReadS Webhook
Read, Webhook -> Webhook -> Bool
(Webhook -> Webhook -> Bool)
-> (Webhook -> Webhook -> Bool) -> Eq Webhook
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Webhook -> Webhook -> Bool
$c/= :: Webhook -> Webhook -> Bool
== :: Webhook -> Webhook -> Bool
$c== :: Webhook -> Webhook -> Bool
Eq, Eq Webhook
Eq Webhook
-> (Webhook -> Webhook -> Ordering)
-> (Webhook -> Webhook -> Bool)
-> (Webhook -> Webhook -> Bool)
-> (Webhook -> Webhook -> Bool)
-> (Webhook -> Webhook -> Bool)
-> (Webhook -> Webhook -> Webhook)
-> (Webhook -> Webhook -> Webhook)
-> Ord Webhook
Webhook -> Webhook -> Bool
Webhook -> Webhook -> Ordering
Webhook -> Webhook -> Webhook
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 :: Webhook -> Webhook -> Webhook
$cmin :: Webhook -> Webhook -> Webhook
max :: Webhook -> Webhook -> Webhook
$cmax :: Webhook -> Webhook -> Webhook
>= :: Webhook -> Webhook -> Bool
$c>= :: Webhook -> Webhook -> Bool
> :: Webhook -> Webhook -> Bool
$c> :: Webhook -> Webhook -> Bool
<= :: Webhook -> Webhook -> Bool
$c<= :: Webhook -> Webhook -> Bool
< :: Webhook -> Webhook -> Bool
$c< :: Webhook -> Webhook -> Bool
compare :: Webhook -> Webhook -> Ordering
$ccompare :: Webhook -> Webhook -> Ordering
$cp1Ord :: Eq Webhook
Ord)

instance FromJSON Webhook where
  parseJSON :: Value -> Parser Webhook
parseJSON = String -> (Object -> Parser Webhook) -> Value -> Parser Webhook
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Webhook" ((Object -> Parser Webhook) -> Value -> Parser Webhook)
-> (Object -> Parser Webhook) -> Value -> Parser Webhook
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    UserId -> Maybe Text -> UserId -> Webhook
Webhook (UserId -> Maybe Text -> UserId -> Webhook)
-> Parser UserId -> Parser (Maybe Text -> UserId -> Webhook)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser UserId
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"id"
            Parser (Maybe Text -> UserId -> Webhook)
-> Parser (Maybe Text) -> Parser (UserId -> Webhook)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"token"
            Parser (UserId -> Webhook) -> Parser UserId -> Parser Webhook
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser UserId
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"channel_id"

data ConnectionObject = ConnectionObject
  { ConnectionObject -> Text
connectionObjectId :: Text
  , ConnectionObject -> Text
connectionObjectName :: Text
  , ConnectionObject -> Text
connectionObjectType :: Text
  , ConnectionObject -> Bool
connectionObjectRevoked :: Bool
  , ConnectionObject -> [UserId]
connectionObjectIntegrations :: [IntegrationId]
  , ConnectionObject -> Bool
connectionObjectVerified :: Bool
  , ConnectionObject -> Bool
connectionObjectFriendSyncOn :: Bool
  , ConnectionObject -> Bool
connectionObjectShownInPresenceUpdates :: Bool
  , ConnectionObject -> Bool
connectionObjectVisibleToOthers :: Bool
  } deriving (Int -> ConnectionObject -> ShowS
[ConnectionObject] -> ShowS
ConnectionObject -> String
(Int -> ConnectionObject -> ShowS)
-> (ConnectionObject -> String)
-> ([ConnectionObject] -> ShowS)
-> Show ConnectionObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConnectionObject] -> ShowS
$cshowList :: [ConnectionObject] -> ShowS
show :: ConnectionObject -> String
$cshow :: ConnectionObject -> String
showsPrec :: Int -> ConnectionObject -> ShowS
$cshowsPrec :: Int -> ConnectionObject -> ShowS
Show, ReadPrec [ConnectionObject]
ReadPrec ConnectionObject
Int -> ReadS ConnectionObject
ReadS [ConnectionObject]
(Int -> ReadS ConnectionObject)
-> ReadS [ConnectionObject]
-> ReadPrec ConnectionObject
-> ReadPrec [ConnectionObject]
-> Read ConnectionObject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConnectionObject]
$creadListPrec :: ReadPrec [ConnectionObject]
readPrec :: ReadPrec ConnectionObject
$creadPrec :: ReadPrec ConnectionObject
readList :: ReadS [ConnectionObject]
$creadList :: ReadS [ConnectionObject]
readsPrec :: Int -> ReadS ConnectionObject
$creadsPrec :: Int -> ReadS ConnectionObject
Read, ConnectionObject -> ConnectionObject -> Bool
(ConnectionObject -> ConnectionObject -> Bool)
-> (ConnectionObject -> ConnectionObject -> Bool)
-> Eq ConnectionObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConnectionObject -> ConnectionObject -> Bool
$c/= :: ConnectionObject -> ConnectionObject -> Bool
== :: ConnectionObject -> ConnectionObject -> Bool
$c== :: ConnectionObject -> ConnectionObject -> Bool
Eq, Eq ConnectionObject
Eq ConnectionObject
-> (ConnectionObject -> ConnectionObject -> Ordering)
-> (ConnectionObject -> ConnectionObject -> Bool)
-> (ConnectionObject -> ConnectionObject -> Bool)
-> (ConnectionObject -> ConnectionObject -> Bool)
-> (ConnectionObject -> ConnectionObject -> Bool)
-> (ConnectionObject -> ConnectionObject -> ConnectionObject)
-> (ConnectionObject -> ConnectionObject -> ConnectionObject)
-> Ord ConnectionObject
ConnectionObject -> ConnectionObject -> Bool
ConnectionObject -> ConnectionObject -> Ordering
ConnectionObject -> ConnectionObject -> ConnectionObject
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 :: ConnectionObject -> ConnectionObject -> ConnectionObject
$cmin :: ConnectionObject -> ConnectionObject -> ConnectionObject
max :: ConnectionObject -> ConnectionObject -> ConnectionObject
$cmax :: ConnectionObject -> ConnectionObject -> ConnectionObject
>= :: ConnectionObject -> ConnectionObject -> Bool
$c>= :: ConnectionObject -> ConnectionObject -> Bool
> :: ConnectionObject -> ConnectionObject -> Bool
$c> :: ConnectionObject -> ConnectionObject -> Bool
<= :: ConnectionObject -> ConnectionObject -> Bool
$c<= :: ConnectionObject -> ConnectionObject -> Bool
< :: ConnectionObject -> ConnectionObject -> Bool
$c< :: ConnectionObject -> ConnectionObject -> Bool
compare :: ConnectionObject -> ConnectionObject -> Ordering
$ccompare :: ConnectionObject -> ConnectionObject -> Ordering
$cp1Ord :: Eq ConnectionObject
Ord)

instance FromJSON ConnectionObject where
  parseJSON :: Value -> Parser ConnectionObject
parseJSON = String
-> (Object -> Parser ConnectionObject)
-> Value
-> Parser ConnectionObject
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"ConnectionObject" ((Object -> Parser ConnectionObject)
 -> Value -> Parser ConnectionObject)
-> (Object -> Parser ConnectionObject)
-> Value
-> Parser ConnectionObject
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
    [Object]
integrations <- Object
o Object -> Key -> Parser [Object]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"integrations"
    Text
-> Text
-> Text
-> Bool
-> [UserId]
-> Bool
-> Bool
-> Bool
-> Bool
-> ConnectionObject
ConnectionObject (Text
 -> Text
 -> Text
 -> Bool
 -> [UserId]
 -> Bool
 -> Bool
 -> Bool
 -> Bool
 -> ConnectionObject)
-> Parser Text
-> Parser
     (Text
      -> Text
      -> Bool
      -> [UserId]
      -> Bool
      -> Bool
      -> Bool
      -> Bool
      -> ConnectionObject)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
               Parser
  (Text
   -> Text
   -> Bool
   -> [UserId]
   -> Bool
   -> Bool
   -> Bool
   -> Bool
   -> ConnectionObject)
-> Parser Text
-> Parser
     (Text
      -> Bool
      -> [UserId]
      -> Bool
      -> Bool
      -> Bool
      -> Bool
      -> ConnectionObject)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
               Parser
  (Text
   -> Bool
   -> [UserId]
   -> Bool
   -> Bool
   -> Bool
   -> Bool
   -> ConnectionObject)
-> Parser Text
-> Parser
     (Bool
      -> [UserId] -> Bool -> Bool -> Bool -> Bool -> ConnectionObject)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
               Parser
  (Bool
   -> [UserId] -> Bool -> Bool -> Bool -> Bool -> ConnectionObject)
-> Parser Bool
-> Parser
     ([UserId] -> Bool -> Bool -> Bool -> Bool -> ConnectionObject)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"revoked"
               Parser
  ([UserId] -> Bool -> Bool -> Bool -> Bool -> ConnectionObject)
-> Parser [UserId]
-> Parser (Bool -> Bool -> Bool -> Bool -> ConnectionObject)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Parser UserId] -> Parser [UserId]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ((Object -> Parser UserId) -> [Object] -> [Parser UserId]
forall a b. (a -> b) -> [a] -> [b]
map (Object -> Key -> Parser UserId
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id") [Object]
integrations)
               Parser (Bool -> Bool -> Bool -> Bool -> ConnectionObject)
-> Parser Bool -> Parser (Bool -> Bool -> Bool -> ConnectionObject)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"verified"
               Parser (Bool -> Bool -> Bool -> ConnectionObject)
-> Parser Bool -> Parser (Bool -> Bool -> ConnectionObject)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"friend_sync"
               Parser (Bool -> Bool -> ConnectionObject)
-> Parser Bool -> Parser (Bool -> ConnectionObject)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"show_activity"
               Parser (Bool -> ConnectionObject)
-> Parser Bool -> Parser ConnectionObject
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ( Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
(==) (Int
1::Int) (Int -> Bool) -> Parser Int -> Parser Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"visibility")


-- | Representation of a guild member.
data GuildMember = GuildMember
      { GuildMember -> Maybe User
memberUser     :: Maybe User -- ^ User object - not included in message_create or update
      , GuildMember -> Maybe Text
memberNick     :: Maybe T.Text -- ^ User's guild nickname
      , GuildMember -> Maybe Text
memberAvatar   :: Maybe T.Text -- ^ User's guild avatar hash
      , GuildMember -> [UserId]
memberRoles    :: [RoleId] -- ^ Array of role ids
      , GuildMember -> UTCTime
memberJoinedAt :: UTCTime -- ^ When the user joined the guild
      , GuildMember -> Maybe UTCTime
memberPremiumSince :: Maybe UTCTime -- ^ When the user started boosting the guild
      , GuildMember -> Bool
memberDeaf     :: Bool -- ^ Whether the user is deafened
      , GuildMember -> Bool
memberMute     :: Bool -- ^ Whether the user is muted
      , GuildMember -> Bool
memberPending     :: Bool -- ^ Whether the user has passed the guild's membership screening
      , GuildMember -> Maybe Text
memberPermissions     :: Maybe T.Text -- ^ total permissions of the member
      } deriving (Int -> GuildMember -> ShowS
[GuildMember] -> ShowS
GuildMember -> String
(Int -> GuildMember -> ShowS)
-> (GuildMember -> String)
-> ([GuildMember] -> ShowS)
-> Show GuildMember
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GuildMember] -> ShowS
$cshowList :: [GuildMember] -> ShowS
show :: GuildMember -> String
$cshow :: GuildMember -> String
showsPrec :: Int -> GuildMember -> ShowS
$cshowsPrec :: Int -> GuildMember -> ShowS
Show, ReadPrec [GuildMember]
ReadPrec GuildMember
Int -> ReadS GuildMember
ReadS [GuildMember]
(Int -> ReadS GuildMember)
-> ReadS [GuildMember]
-> ReadPrec GuildMember
-> ReadPrec [GuildMember]
-> Read GuildMember
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GuildMember]
$creadListPrec :: ReadPrec [GuildMember]
readPrec :: ReadPrec GuildMember
$creadPrec :: ReadPrec GuildMember
readList :: ReadS [GuildMember]
$creadList :: ReadS [GuildMember]
readsPrec :: Int -> ReadS GuildMember
$creadsPrec :: Int -> ReadS GuildMember
Read, GuildMember -> GuildMember -> Bool
(GuildMember -> GuildMember -> Bool)
-> (GuildMember -> GuildMember -> Bool) -> Eq GuildMember
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GuildMember -> GuildMember -> Bool
$c/= :: GuildMember -> GuildMember -> Bool
== :: GuildMember -> GuildMember -> Bool
$c== :: GuildMember -> GuildMember -> Bool
Eq, Eq GuildMember
Eq GuildMember
-> (GuildMember -> GuildMember -> Ordering)
-> (GuildMember -> GuildMember -> Bool)
-> (GuildMember -> GuildMember -> Bool)
-> (GuildMember -> GuildMember -> Bool)
-> (GuildMember -> GuildMember -> Bool)
-> (GuildMember -> GuildMember -> GuildMember)
-> (GuildMember -> GuildMember -> GuildMember)
-> Ord GuildMember
GuildMember -> GuildMember -> Bool
GuildMember -> GuildMember -> Ordering
GuildMember -> GuildMember -> GuildMember
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 :: GuildMember -> GuildMember -> GuildMember
$cmin :: GuildMember -> GuildMember -> GuildMember
max :: GuildMember -> GuildMember -> GuildMember
$cmax :: GuildMember -> GuildMember -> GuildMember
>= :: GuildMember -> GuildMember -> Bool
$c>= :: GuildMember -> GuildMember -> Bool
> :: GuildMember -> GuildMember -> Bool
$c> :: GuildMember -> GuildMember -> Bool
<= :: GuildMember -> GuildMember -> Bool
$c<= :: GuildMember -> GuildMember -> Bool
< :: GuildMember -> GuildMember -> Bool
$c< :: GuildMember -> GuildMember -> Bool
compare :: GuildMember -> GuildMember -> Ordering
$ccompare :: GuildMember -> GuildMember -> Ordering
$cp1Ord :: Eq GuildMember
Ord)

instance FromJSON GuildMember where
  parseJSON :: Value -> Parser GuildMember
parseJSON = String
-> (Object -> Parser GuildMember) -> Value -> Parser GuildMember
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"GuildMember" ((Object -> Parser GuildMember) -> Value -> Parser GuildMember)
-> (Object -> Parser GuildMember) -> Value -> Parser GuildMember
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    Maybe User
-> Maybe Text
-> Maybe Text
-> [UserId]
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> Bool
-> Maybe Text
-> GuildMember
GuildMember (Maybe User
 -> Maybe Text
 -> Maybe Text
 -> [UserId]
 -> UTCTime
 -> Maybe UTCTime
 -> Bool
 -> Bool
 -> Bool
 -> Maybe Text
 -> GuildMember)
-> Parser (Maybe User)
-> Parser
     (Maybe Text
      -> Maybe Text
      -> [UserId]
      -> UTCTime
      -> Maybe UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Maybe Text
      -> GuildMember)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe User)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"user"
                Parser
  (Maybe Text
   -> Maybe Text
   -> [UserId]
   -> UTCTime
   -> Maybe UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Maybe Text
   -> GuildMember)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> [UserId]
      -> UTCTime
      -> Maybe UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Maybe Text
      -> GuildMember)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"nick"
                Parser
  (Maybe Text
   -> [UserId]
   -> UTCTime
   -> Maybe UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Maybe Text
   -> GuildMember)
-> Parser (Maybe Text)
-> Parser
     ([UserId]
      -> UTCTime
      -> Maybe UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Maybe Text
      -> GuildMember)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"avatar"
                Parser
  ([UserId]
   -> UTCTime
   -> Maybe UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Maybe Text
   -> GuildMember)
-> Parser [UserId]
-> Parser
     (UTCTime
      -> Maybe UTCTime
      -> Bool
      -> Bool
      -> Bool
      -> Maybe Text
      -> GuildMember)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser [UserId]
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"roles"
                Parser
  (UTCTime
   -> Maybe UTCTime
   -> Bool
   -> Bool
   -> Bool
   -> Maybe Text
   -> GuildMember)
-> Parser UTCTime
-> Parser
     (Maybe UTCTime
      -> Bool -> Bool -> Bool -> Maybe Text -> GuildMember)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser UTCTime
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"joined_at"
                Parser
  (Maybe UTCTime
   -> Bool -> Bool -> Bool -> Maybe Text -> GuildMember)
-> Parser (Maybe UTCTime)
-> Parser (Bool -> Bool -> Bool -> Maybe Text -> GuildMember)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe UTCTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"premium_since"
                Parser (Bool -> Bool -> Bool -> Maybe Text -> GuildMember)
-> Parser Bool
-> Parser (Bool -> Bool -> Maybe Text -> GuildMember)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"deaf"
                Parser (Bool -> Bool -> Maybe Text -> GuildMember)
-> Parser Bool -> Parser (Bool -> Maybe Text -> GuildMember)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.:  Key
"mute"
                Parser (Bool -> Maybe Text -> GuildMember)
-> Parser Bool -> Parser (Maybe Text -> GuildMember)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"pending" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
                Parser (Maybe Text -> GuildMember)
-> Parser (Maybe Text) -> Parser GuildMember
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"permissions"

instance ToJSON GuildMember where
  toJSON :: GuildMember -> Value
toJSON GuildMember {Bool
[UserId]
Maybe UTCTime
Maybe Text
Maybe User
UTCTime
memberPermissions :: Maybe Text
memberPending :: Bool
memberMute :: Bool
memberDeaf :: Bool
memberPremiumSince :: Maybe UTCTime
memberJoinedAt :: UTCTime
memberRoles :: [UserId]
memberAvatar :: Maybe Text
memberNick :: Maybe Text
memberUser :: Maybe User
memberPermissions :: GuildMember -> Maybe Text
memberPending :: GuildMember -> Bool
memberMute :: GuildMember -> Bool
memberDeaf :: GuildMember -> Bool
memberPremiumSince :: GuildMember -> Maybe UTCTime
memberJoinedAt :: GuildMember -> UTCTime
memberRoles :: GuildMember -> [UserId]
memberAvatar :: GuildMember -> Maybe Text
memberNick :: GuildMember -> Maybe Text
memberUser :: GuildMember -> Maybe User
..} = [Pair] -> Value
object [(Key
name, Value
value) | (Key
name, Just Value
value) <-
      [ (Key
"user",      User -> Value
forall a. ToJSON a => a -> Value
toJSON (User -> Value) -> Maybe User -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe User
memberUser)
      , (Key
"nick",      Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Text
memberNick)
      , (Key
"avatar",    Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Text
memberAvatar)
      , (Key
"roles",     [UserId] -> Value
forall a. ToJSON a => a -> Value
toJSON ([UserId] -> Value) -> Maybe [UserId] -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [UserId] -> Maybe [UserId]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [UserId]
memberRoles)
      , (Key
"joined_at", UTCTime -> Value
forall a. ToJSON a => a -> Value
toJSON (UTCTime -> Value) -> Maybe UTCTime -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UTCTime -> Maybe UTCTime
forall (f :: * -> *) a. Applicative f => a -> f a
pure UTCTime
memberJoinedAt)
      , (Key
"premium_since",    UTCTime -> Value
forall a. ToJSON a => a -> Value
toJSON (UTCTime -> Value) -> Maybe UTCTime -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe UTCTime
memberPremiumSince)
      , (Key
"deaf",      Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> Maybe Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
memberDeaf)
      , (Key
"mute",      Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> Maybe Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
memberMute)
      , (Key
"pending",      Bool -> Value
forall a. ToJSON a => a -> Value
toJSON (Bool -> Value) -> Maybe Bool -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> Maybe Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
memberPending)
      , (Key
"permissions",    Text -> Value
forall a. ToJSON a => a -> Value
toJSON (Text -> Value) -> Maybe Text -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>      Maybe Text
memberPermissions)
      ] ]