{-# LANGUAGE TemplateHaskell #-}
module Calamity.Types.Model.Guild.Member (Member (..)) where
import Calamity.Internal.IntColour
import Calamity.Internal.Utils (AesonVector (unAesonVector))
import Calamity.Types.Model.Avatar (Avatar (..))
import Calamity.Types.Model.Guild.Role
import Calamity.Types.Model.User
import Calamity.Types.Snowflake
import Data.Aeson ((.!=), (.:), (.:?))
import Data.Aeson qualified as Aeson
import Data.Colour (Colour)
import Data.Text (Text)
import Data.Text.Read (decimal)
import Data.Time
import Data.Vector.Unboxing (Vector)
import Data.Vector.Unboxing qualified as V
import Data.Word (Word64)
import Optics.TH
import TextShow qualified
data Member = Member
{ Member -> Snowflake User
id :: Snowflake User
, Member -> Text
username :: Text
, Member -> Text
discriminator :: Text
, Member -> Maybe Bool
bot :: Maybe Bool
, Member -> Avatar
avatar :: Avatar
, Member -> Maybe Text
memberAvatar :: Maybe Text
, Member -> Maybe Bool
mfaEnabled :: Maybe Bool
, Member -> Maybe UserBanner
banner :: Maybe UserBanner
, Member -> Maybe (Colour Double)
accentColour :: Maybe (Colour Double)
, Member -> Maybe Text
locale :: Maybe Text
, Member -> Maybe Bool
verified :: Maybe Bool
, Member -> Maybe Text
email :: Maybe Text
, Member -> Maybe Word64
flags :: Maybe Word64
, Member -> Maybe Word64
premiumType :: Maybe Word64
, Member -> Maybe Text
nick :: Maybe Text
, Member -> Vector (Snowflake Role)
roles :: Vector (Snowflake Role)
, Member -> UTCTime
joinedAt :: UTCTime
, Member -> Bool
deaf :: Bool
, Member -> Bool
mute :: Bool
}
deriving (Member -> Member -> Bool
(Member -> Member -> Bool)
-> (Member -> Member -> Bool) -> Eq Member
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Member -> Member -> Bool
== :: Member -> Member -> Bool
$c/= :: Member -> Member -> Bool
/= :: Member -> Member -> Bool
Eq, Int -> Member -> ShowS
[Member] -> ShowS
Member -> String
(Int -> Member -> ShowS)
-> (Member -> String) -> ([Member] -> ShowS) -> Show Member
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Member -> ShowS
showsPrec :: Int -> Member -> ShowS
$cshow :: Member -> String
show :: Member -> String
$cshowList :: [Member] -> ShowS
showList :: [Member] -> ShowS
Show)
deriving (Int -> Member -> Text
Int -> Member -> Builder
Int -> Member -> Text
[Member] -> Text
[Member] -> Builder
[Member] -> Text
Member -> Text
Member -> Builder
Member -> Text
(Int -> Member -> Builder)
-> (Member -> Builder)
-> ([Member] -> Builder)
-> (Int -> Member -> Text)
-> (Member -> Text)
-> ([Member] -> Text)
-> (Int -> Member -> Text)
-> (Member -> Text)
-> ([Member] -> Text)
-> TextShow Member
forall a.
(Int -> a -> Builder)
-> (a -> Builder)
-> ([a] -> Builder)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> (Int -> a -> Text)
-> (a -> Text)
-> ([a] -> Text)
-> TextShow a
$cshowbPrec :: Int -> Member -> Builder
showbPrec :: Int -> Member -> Builder
$cshowb :: Member -> Builder
showb :: Member -> Builder
$cshowbList :: [Member] -> Builder
showbList :: [Member] -> Builder
$cshowtPrec :: Int -> Member -> Text
showtPrec :: Int -> Member -> Text
$cshowt :: Member -> Text
showt :: Member -> Text
$cshowtList :: [Member] -> Text
showtList :: [Member] -> Text
$cshowtlPrec :: Int -> Member -> Text
showtlPrec :: Int -> Member -> Text
$cshowtl :: Member -> Text
showtl :: Member -> Text
$cshowtlList :: [Member] -> Text
showtlList :: [Member] -> Text
TextShow.TextShow) via TextShow.FromStringShow Member
deriving (HasID Member) via HasIDFieldCoerce "id" Member User
deriving (HasID User) via HasIDField "id" Member
instance Aeson.FromJSON Member where
parseJSON :: Value -> Parser Member
parseJSON = String -> (Object -> Parser Member) -> Value -> Parser Member
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Member" ((Object -> Parser Member) -> Value -> Parser Member)
-> (Object -> Parser Member) -> Value -> Parser Member
forall a b. (a -> b) -> a -> b
$ \Object
v -> do
Object
u :: Aeson.Object <- Object
v Object -> Key -> Parser Object
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"user"
Snowflake User
uid <- Object
u Object -> Key -> Parser (Snowflake User)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Maybe Text
avatarHash <- Object
u Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"avatar"
Text
discrim <- Object
u Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"discriminator"
Int
discrim' <- case Reader Int
forall a. Integral a => Reader a
decimal Text
discrim of
Right (Int
n, Text
_) -> Int -> Parser Int
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
n
Left String
e -> String -> Parser Int
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
e
let avatar :: Avatar
avatar = Maybe Text -> Snowflake User -> Int -> Avatar
Avatar Maybe Text
avatarHash Snowflake User
uid Int
discrim'
Maybe UserBanner
banner <- (Snowflake User -> Text -> UserBanner
UserBanner Snowflake User
uid (Text -> UserBanner) -> Maybe Text -> Maybe UserBanner
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (Maybe Text -> Maybe UserBanner)
-> Parser (Maybe Text) -> Parser (Maybe UserBanner)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"banner"
Snowflake User
-> Text
-> Text
-> Maybe Bool
-> Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member
Member
(Snowflake User
-> Text
-> Text
-> Maybe Bool
-> Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Snowflake User)
-> Parser
(Text
-> Text
-> Maybe Bool
-> Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Snowflake User -> Parser (Snowflake User)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Snowflake User
uid
Parser
(Text
-> Text
-> Maybe Bool
-> Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser Text
-> Parser
(Text
-> Maybe Bool
-> Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
u Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"username"
Parser
(Text
-> Maybe Bool
-> Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser Text
-> Parser
(Maybe Bool
-> Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
u Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"discriminator"
Parser
(Maybe Bool
-> Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe Bool)
-> Parser
(Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"bot"
Parser
(Avatar
-> Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser Avatar
-> Parser
(Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Avatar -> Parser Avatar
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Avatar
avatar
Parser
(Maybe Text
-> Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe Text)
-> Parser
(Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"avatar"
Parser
(Maybe Bool
-> Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe Bool)
-> Parser
(Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"mfa_enabled"
Parser
(Maybe UserBanner
-> Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe UserBanner)
-> Parser
(Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe UserBanner -> Parser (Maybe UserBanner)
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe UserBanner
banner
Parser
(Maybe (Colour Double)
-> Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe (Colour Double))
-> Parser
(Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((IntColour -> Colour Double)
-> Maybe IntColour -> Maybe (Colour Double)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IntColour -> Colour Double
fromIntColour (Maybe IntColour -> Maybe (Colour Double))
-> Parser (Maybe IntColour) -> Parser (Maybe (Colour Double))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe IntColour)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"accent_color")
Parser
(Maybe Text
-> Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe Text)
-> Parser
(Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"locale"
Parser
(Maybe Bool
-> Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe Bool)
-> Parser
(Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"verified"
Parser
(Maybe Text
-> Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe Text)
-> Parser
(Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"email"
Parser
(Maybe Word64
-> Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe Word64)
-> Parser
(Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Word64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"flags"
Parser
(Maybe Word64
-> Maybe Text
-> Vector (Snowflake Role)
-> UTCTime
-> Bool
-> Bool
-> Member)
-> Parser (Maybe Word64)
-> Parser
(Maybe Text
-> Vector (Snowflake Role) -> UTCTime -> Bool -> Bool -> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Word64)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"premium_type"
Parser
(Maybe Text
-> Vector (Snowflake Role) -> UTCTime -> Bool -> Bool -> Member)
-> Parser (Maybe Text)
-> Parser
(Vector (Snowflake Role) -> UTCTime -> Bool -> Bool -> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"nick"
Parser
(Vector (Snowflake Role) -> UTCTime -> Bool -> Bool -> Member)
-> Parser (Vector (Snowflake Role))
-> Parser (UTCTime -> Bool -> Bool -> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((AesonVector (Snowflake Role) -> Vector (Snowflake Role))
-> Maybe (AesonVector (Snowflake Role))
-> Maybe (Vector (Snowflake Role))
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap AesonVector (Snowflake Role) -> Vector (Snowflake Role)
forall a. AesonVector a -> Vector a
unAesonVector (Maybe (AesonVector (Snowflake Role))
-> Maybe (Vector (Snowflake Role)))
-> Parser (Maybe (AesonVector (Snowflake Role)))
-> Parser (Maybe (Vector (Snowflake Role)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe (AesonVector (Snowflake Role)))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"roles") Parser (Maybe (Vector (Snowflake Role)))
-> Vector (Snowflake Role) -> Parser (Vector (Snowflake Role))
forall a. Parser (Maybe a) -> a -> Parser a
.!= Vector (Snowflake Role)
forall a. Unboxable a => Vector a
V.empty
Parser (UTCTime -> Bool -> Bool -> Member)
-> Parser UTCTime -> Parser (Bool -> Bool -> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser UTCTime
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"joined_at"
Parser (Bool -> Bool -> Member)
-> Parser Bool -> Parser (Bool -> Member)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"deaf"
Parser (Bool -> Member) -> Parser Bool -> Parser Member
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v Object -> Key -> Parser Bool
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"mute"
$(makeFieldLabelsNoPrefix ''Member)