module Calamity.Types.Model.Guild.Emoji
( Emoji(..)
, Partial(PartialEmoji)
, RawEmoji(..) ) where
import Calamity.Internal.AesonThings
import Calamity.Internal.Utils ()
import Calamity.Types.Model.Guild.Role
import Calamity.Types.Model.User
import Calamity.Types.Snowflake
import Data.Aeson
import Data.Text.Lazy ( Text )
import Data.Vector.Unboxed ( Vector )
import GHC.Generics
import TextShow
import qualified TextShow.Generic as TSG
data Emoji = Emoji
{ Emoji -> Snowflake Emoji
id :: Snowflake Emoji
, Emoji -> Text
name :: Text
, Emoji -> Vector (Snowflake Role)
roles :: Vector (Snowflake Role)
, Emoji -> Maybe (Snowflake User)
user :: Maybe (Snowflake User)
, Emoji -> Bool
requireColons :: Bool
, Emoji -> Bool
managed :: Bool
, Emoji -> Bool
animated :: Bool
}
deriving ( Emoji -> Emoji -> Bool
(Emoji -> Emoji -> Bool) -> (Emoji -> Emoji -> Bool) -> Eq Emoji
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Emoji -> Emoji -> Bool
$c/= :: Emoji -> Emoji -> Bool
== :: Emoji -> Emoji -> Bool
$c== :: Emoji -> Emoji -> Bool
Eq, Int -> Emoji -> ShowS
[Emoji] -> ShowS
Emoji -> String
(Int -> Emoji -> ShowS)
-> (Emoji -> String) -> ([Emoji] -> ShowS) -> Show Emoji
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Emoji] -> ShowS
$cshowList :: [Emoji] -> ShowS
show :: Emoji -> String
$cshow :: Emoji -> String
showsPrec :: Int -> Emoji -> ShowS
$cshowsPrec :: Int -> Emoji -> ShowS
Show, (forall x. Emoji -> Rep Emoji x)
-> (forall x. Rep Emoji x -> Emoji) -> Generic Emoji
forall x. Rep Emoji x -> Emoji
forall x. Emoji -> Rep Emoji x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Emoji x -> Emoji
$cfrom :: forall x. Emoji -> Rep Emoji x
Generic )
deriving ( Int -> Emoji -> Builder
Int -> Emoji -> Text
Int -> Emoji -> Text
[Emoji] -> Builder
[Emoji] -> Text
[Emoji] -> Text
Emoji -> Builder
Emoji -> Text
Emoji -> Text
(Int -> Emoji -> Builder)
-> (Emoji -> Builder)
-> ([Emoji] -> Builder)
-> (Int -> Emoji -> Text)
-> (Emoji -> Text)
-> ([Emoji] -> Text)
-> (Int -> Emoji -> Text)
-> (Emoji -> Text)
-> ([Emoji] -> Text)
-> TextShow Emoji
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
showtlList :: [Emoji] -> Text
$cshowtlList :: [Emoji] -> Text
showtl :: Emoji -> Text
$cshowtl :: Emoji -> Text
showtlPrec :: Int -> Emoji -> Text
$cshowtlPrec :: Int -> Emoji -> Text
showtList :: [Emoji] -> Text
$cshowtList :: [Emoji] -> Text
showt :: Emoji -> Text
$cshowt :: Emoji -> Text
showtPrec :: Int -> Emoji -> Text
$cshowtPrec :: Int -> Emoji -> Text
showbList :: [Emoji] -> Builder
$cshowbList :: [Emoji] -> Builder
showb :: Emoji -> Builder
$cshowb :: Emoji -> Builder
showbPrec :: Int -> Emoji -> Builder
$cshowbPrec :: Int -> Emoji -> Builder
TextShow ) via TSG.FromGeneric Emoji
deriving ( [Emoji] -> Encoding
[Emoji] -> Value
Emoji -> Encoding
Emoji -> Value
(Emoji -> Value)
-> (Emoji -> Encoding)
-> ([Emoji] -> Value)
-> ([Emoji] -> Encoding)
-> ToJSON Emoji
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Emoji] -> Encoding
$ctoEncodingList :: [Emoji] -> Encoding
toJSONList :: [Emoji] -> Value
$ctoJSONList :: [Emoji] -> Value
toEncoding :: Emoji -> Encoding
$ctoEncoding :: Emoji -> Encoding
toJSON :: Emoji -> Value
$ctoJSON :: Emoji -> Value
ToJSON ) via CalamityJSON Emoji
deriving ( Value -> Parser [Emoji]
Value -> Parser Emoji
(Value -> Parser Emoji)
-> (Value -> Parser [Emoji]) -> FromJSON Emoji
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Emoji]
$cparseJSONList :: Value -> Parser [Emoji]
parseJSON :: Value -> Parser Emoji
$cparseJSON :: Value -> Parser Emoji
FromJSON ) via WithSpecialCases '["user" `ExtractField` "id"] Emoji
deriving ( HasID Emoji ) via HasIDField "id" Emoji
data instance Partial Emoji = PartialEmoji
{ Partial Emoji -> Snowflake Emoji
id :: Snowflake Emoji
, Partial Emoji -> Text
name :: Text
}
deriving ( Partial Emoji -> Partial Emoji -> Bool
(Partial Emoji -> Partial Emoji -> Bool)
-> (Partial Emoji -> Partial Emoji -> Bool) -> Eq (Partial Emoji)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Partial Emoji -> Partial Emoji -> Bool
$c/= :: Partial Emoji -> Partial Emoji -> Bool
== :: Partial Emoji -> Partial Emoji -> Bool
$c== :: Partial Emoji -> Partial Emoji -> Bool
Eq, Int -> Partial Emoji -> ShowS
[Partial Emoji] -> ShowS
Partial Emoji -> String
(Int -> Partial Emoji -> ShowS)
-> (Partial Emoji -> String)
-> ([Partial Emoji] -> ShowS)
-> Show (Partial Emoji)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Partial Emoji] -> ShowS
$cshowList :: [Partial Emoji] -> ShowS
show :: Partial Emoji -> String
$cshow :: Partial Emoji -> String
showsPrec :: Int -> Partial Emoji -> ShowS
$cshowsPrec :: Int -> Partial Emoji -> ShowS
Show, (forall x. Partial Emoji -> Rep (Partial Emoji) x)
-> (forall x. Rep (Partial Emoji) x -> Partial Emoji)
-> Generic (Partial Emoji)
forall x. Rep (Partial Emoji) x -> Partial Emoji
forall x. Partial Emoji -> Rep (Partial Emoji) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (Partial Emoji) x -> Partial Emoji
$cfrom :: forall x. Partial Emoji -> Rep (Partial Emoji) x
Generic )
deriving ( Int -> Partial Emoji -> Builder
Int -> Partial Emoji -> Text
Int -> Partial Emoji -> Text
[Partial Emoji] -> Builder
[Partial Emoji] -> Text
[Partial Emoji] -> Text
Partial Emoji -> Builder
Partial Emoji -> Text
Partial Emoji -> Text
(Int -> Partial Emoji -> Builder)
-> (Partial Emoji -> Builder)
-> ([Partial Emoji] -> Builder)
-> (Int -> Partial Emoji -> Text)
-> (Partial Emoji -> Text)
-> ([Partial Emoji] -> Text)
-> (Int -> Partial Emoji -> Text)
-> (Partial Emoji -> Text)
-> ([Partial Emoji] -> Text)
-> TextShow (Partial Emoji)
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
showtlList :: [Partial Emoji] -> Text
$cshowtlList :: [Partial Emoji] -> Text
showtl :: Partial Emoji -> Text
$cshowtl :: Partial Emoji -> Text
showtlPrec :: Int -> Partial Emoji -> Text
$cshowtlPrec :: Int -> Partial Emoji -> Text
showtList :: [Partial Emoji] -> Text
$cshowtList :: [Partial Emoji] -> Text
showt :: Partial Emoji -> Text
$cshowt :: Partial Emoji -> Text
showtPrec :: Int -> Partial Emoji -> Text
$cshowtPrec :: Int -> Partial Emoji -> Text
showbList :: [Partial Emoji] -> Builder
$cshowbList :: [Partial Emoji] -> Builder
showb :: Partial Emoji -> Builder
$cshowb :: Partial Emoji -> Builder
showbPrec :: Int -> Partial Emoji -> Builder
$cshowbPrec :: Int -> Partial Emoji -> Builder
TextShow ) via TSG.FromGeneric (Partial Emoji)
deriving ( [Partial Emoji] -> Encoding
[Partial Emoji] -> Value
Partial Emoji -> Encoding
Partial Emoji -> Value
(Partial Emoji -> Value)
-> (Partial Emoji -> Encoding)
-> ([Partial Emoji] -> Value)
-> ([Partial Emoji] -> Encoding)
-> ToJSON (Partial Emoji)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Partial Emoji] -> Encoding
$ctoEncodingList :: [Partial Emoji] -> Encoding
toJSONList :: [Partial Emoji] -> Value
$ctoJSONList :: [Partial Emoji] -> Value
toEncoding :: Partial Emoji -> Encoding
$ctoEncoding :: Partial Emoji -> Encoding
toJSON :: Partial Emoji -> Value
$ctoJSON :: Partial Emoji -> Value
ToJSON, Value -> Parser [Partial Emoji]
Value -> Parser (Partial Emoji)
(Value -> Parser (Partial Emoji))
-> (Value -> Parser [Partial Emoji]) -> FromJSON (Partial Emoji)
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Partial Emoji]
$cparseJSONList :: Value -> Parser [Partial Emoji]
parseJSON :: Value -> Parser (Partial Emoji)
$cparseJSON :: Value -> Parser (Partial Emoji)
FromJSON ) via CalamityJSON (Partial Emoji)
deriving ( HasID Emoji ) via HasIDField "id" (Partial Emoji)
data RawEmoji
= UnicodeEmoji Text
| CustomEmoji (Partial Emoji)
deriving ( RawEmoji -> RawEmoji -> Bool
(RawEmoji -> RawEmoji -> Bool)
-> (RawEmoji -> RawEmoji -> Bool) -> Eq RawEmoji
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RawEmoji -> RawEmoji -> Bool
$c/= :: RawEmoji -> RawEmoji -> Bool
== :: RawEmoji -> RawEmoji -> Bool
$c== :: RawEmoji -> RawEmoji -> Bool
Eq, Int -> RawEmoji -> ShowS
[RawEmoji] -> ShowS
RawEmoji -> String
(Int -> RawEmoji -> ShowS)
-> (RawEmoji -> String) -> ([RawEmoji] -> ShowS) -> Show RawEmoji
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RawEmoji] -> ShowS
$cshowList :: [RawEmoji] -> ShowS
show :: RawEmoji -> String
$cshow :: RawEmoji -> String
showsPrec :: Int -> RawEmoji -> ShowS
$cshowsPrec :: Int -> RawEmoji -> ShowS
Show, (forall x. RawEmoji -> Rep RawEmoji x)
-> (forall x. Rep RawEmoji x -> RawEmoji) -> Generic RawEmoji
forall x. Rep RawEmoji x -> RawEmoji
forall x. RawEmoji -> Rep RawEmoji x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RawEmoji x -> RawEmoji
$cfrom :: forall x. RawEmoji -> Rep RawEmoji x
Generic )
deriving ( Int -> RawEmoji -> Builder
Int -> RawEmoji -> Text
Int -> RawEmoji -> Text
[RawEmoji] -> Builder
[RawEmoji] -> Text
[RawEmoji] -> Text
RawEmoji -> Builder
RawEmoji -> Text
RawEmoji -> Text
(Int -> RawEmoji -> Builder)
-> (RawEmoji -> Builder)
-> ([RawEmoji] -> Builder)
-> (Int -> RawEmoji -> Text)
-> (RawEmoji -> Text)
-> ([RawEmoji] -> Text)
-> (Int -> RawEmoji -> Text)
-> (RawEmoji -> Text)
-> ([RawEmoji] -> Text)
-> TextShow RawEmoji
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
showtlList :: [RawEmoji] -> Text
$cshowtlList :: [RawEmoji] -> Text
showtl :: RawEmoji -> Text
$cshowtl :: RawEmoji -> Text
showtlPrec :: Int -> RawEmoji -> Text
$cshowtlPrec :: Int -> RawEmoji -> Text
showtList :: [RawEmoji] -> Text
$cshowtList :: [RawEmoji] -> Text
showt :: RawEmoji -> Text
$cshowt :: RawEmoji -> Text
showtPrec :: Int -> RawEmoji -> Text
$cshowtPrec :: Int -> RawEmoji -> Text
showbList :: [RawEmoji] -> Builder
$cshowbList :: [RawEmoji] -> Builder
showb :: RawEmoji -> Builder
$cshowb :: RawEmoji -> Builder
showbPrec :: Int -> RawEmoji -> Builder
$cshowbPrec :: Int -> RawEmoji -> Builder
TextShow ) via TSG.FromGeneric RawEmoji
instance ToJSON RawEmoji where
toEncoding :: RawEmoji -> Encoding
toEncoding (CustomEmoji e :: Partial Emoji
e) = Series -> Encoding
pairs (Series -> Encoding) -> Series -> Encoding
forall a b. (a -> b) -> a -> b
$ "emoji" Text -> Partial Emoji -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Partial Emoji
e
toEncoding (UnicodeEmoji s :: Text
s) = Series -> Encoding
pairs (Series -> Encoding) -> Series -> Encoding
forall a b. (a -> b) -> a -> b
$ "emoji" Text -> Object -> Series
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= (("name" Text -> Text -> Object
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
.= Text
s) :: Object)
instance FromJSON RawEmoji where
parseJSON :: Value -> Parser RawEmoji
parseJSON = String -> (Object -> Parser RawEmoji) -> Value -> Parser RawEmoji
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject "RawEmoji" ((Object -> Parser RawEmoji) -> Value -> Parser RawEmoji)
-> (Object -> Parser RawEmoji) -> Value -> Parser RawEmoji
forall a b. (a -> b) -> a -> b
$ \v :: Object
v -> do
Maybe (Snowflake Emoji)
m_id :: Maybe (Snowflake Emoji) <- Object
v Object -> Text -> Parser (Maybe (Snowflake Emoji))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "id"
Text
name :: Text <- Object
v Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: "name"
RawEmoji -> Parser RawEmoji
forall (f :: * -> *) a. Applicative f => a -> f a
pure (RawEmoji -> Parser RawEmoji) -> RawEmoji -> Parser RawEmoji
forall a b. (a -> b) -> a -> b
$ case Maybe (Snowflake Emoji)
m_id of
Just id :: Snowflake Emoji
id -> Partial Emoji -> RawEmoji
CustomEmoji (Partial Emoji -> RawEmoji) -> Partial Emoji -> RawEmoji
forall a b. (a -> b) -> a -> b
$ Snowflake Emoji -> Text -> Partial Emoji
PartialEmoji Snowflake Emoji
id Text
name
Nothing -> Text -> RawEmoji
UnicodeEmoji Text
name