module Calamity.Types.Model.Guild.Emoji (
Emoji (..),
Partial (PartialEmoji),
RawEmoji (..),
emojiAsRawEmoji,
) where
import Calamity.Internal.AesonThings
import Calamity.Internal.OverriddenVia
import Calamity.Internal.Utils
import Calamity.Types.Model.Guild.Role
import Calamity.Types.Model.User
import Calamity.Types.Snowflake
import Control.DeepSeq (NFData)
import Data.Aeson
import Data.Generics.Product
import qualified Data.Text as T
import Data.Vector.Unboxing (Vector)
import GHC.Generics
import TextShow
import qualified TextShow.Generic as TSG
data Emoji' = Emoji'
{ Emoji' -> Snowflake Emoji
id :: Snowflake Emoji
, Emoji' -> Text
name :: T.Text
, Emoji' -> AesonVector (Snowflake Role)
roles :: AesonVector (Snowflake Role)
, Emoji' -> Maybe (Snowflake User)
user :: Maybe (Snowflake User)
, Emoji' -> Bool
requireColons :: Bool
, Emoji' -> Bool
managed :: Bool
, Emoji' -> Bool
animated :: Bool
}
deriving ((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" `ExtractFieldFrom` "id"
, "roles" `IfNoneThen` DefaultToEmptyArray
]
Emoji'
data Emoji = Emoji
{ Emoji -> Snowflake Emoji
id :: Snowflake Emoji
, Emoji -> Text
name :: T.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, Emoji -> ()
(Emoji -> ()) -> NFData Emoji
forall a. (a -> ()) -> NFData a
rnf :: Emoji -> ()
$crnf :: Emoji -> ()
NFData)
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, [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, 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 OverriddenVia Emoji Emoji'
deriving (HasID Emoji) via HasIDField "id" Emoji
emojiAsRawEmoji :: Emoji -> RawEmoji
emojiAsRawEmoji :: Emoji -> RawEmoji
emojiAsRawEmoji = Partial Emoji -> RawEmoji
CustomEmoji (Partial Emoji -> RawEmoji)
-> (Emoji -> Partial Emoji) -> Emoji -> RawEmoji
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Emoji -> Partial Emoji
forall sup sub. Subtype sup sub => sub -> sup
upcast
data instance Partial Emoji = PartialEmoji
{ Partial Emoji -> Snowflake Emoji
id :: Snowflake Emoji
, Partial Emoji -> Text
name :: T.Text
, Partial Emoji -> Bool
animated :: Bool
}
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, (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 ([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) via CalamityJSON (Partial Emoji)
deriving
(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 WithSpecialCases
'["animated" `IfNoneThen` DefaultToFalse]
(Partial Emoji)
deriving (HasID Emoji) via HasIDField "id" (Partial Emoji)
instance Show (Partial Emoji) where
show :: Partial Emoji -> String
show PartialEmoji{id, name, animated} =
String
"<" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
a String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
":" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
T.unpack Text
name String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
":" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Snowflake Emoji -> String
forall a. Show a => a -> String
show Snowflake Emoji
id String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
">"
where
a :: String
a = if Bool
animated then String
"a" else String
""
instance TextShow (Partial Emoji) where
showb :: Partial Emoji -> Builder
showb PartialEmoji{id, name, animated} =
Builder
"<" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
":" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
fromText Text
name Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
":" Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Snowflake Emoji -> Builder
forall a. TextShow a => a -> Builder
showb Snowflake Emoji
id Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
">"
where
a :: Builder
a = if Bool
animated then Builder
"a" else Builder
""
data RawEmoji
= UnicodeEmoji T.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, (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)
instance Show RawEmoji where
show :: RawEmoji -> String
show (UnicodeEmoji Text
v) = Text -> String
T.unpack Text
v
show (CustomEmoji Partial Emoji
p) = Partial Emoji -> String
forall a. Show a => a -> String
show Partial Emoji
p
instance TextShow RawEmoji where
showb :: RawEmoji -> Builder
showb (UnicodeEmoji Text
v) = Text -> Builder
fromText Text
v
showb (CustomEmoji Partial Emoji
p) = Partial Emoji -> Builder
forall a. TextShow a => a -> Builder
showb Partial Emoji
p
instance ToJSON RawEmoji where
toJSON :: RawEmoji -> Value
toJSON (CustomEmoji Partial Emoji
e) = Partial Emoji -> Value
forall a. ToJSON a => a -> Value
toJSON Partial Emoji
e
toJSON (UnicodeEmoji Text
s) = [Pair] -> Value
object [Key
"name" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
s, Key
"id" Key -> Maybe () -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe ()
forall a. Maybe a
Nothing @()]
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 String
"RawEmoji" ((Object -> Parser RawEmoji) -> Value -> Parser RawEmoji)
-> (Object -> Parser RawEmoji) -> Value -> Parser RawEmoji
forall a b. (a -> b) -> a -> b
$ \Object
v -> do
Maybe (Snowflake Emoji)
m_id :: Maybe (Snowflake Emoji) <- Object
v Object -> Key -> Parser (Maybe (Snowflake Emoji))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"id"
Bool
anim <- Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"animated" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
Text
name :: T.Text <- Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"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 Snowflake Emoji
id -> Partial Emoji -> RawEmoji
CustomEmoji (Partial Emoji -> RawEmoji) -> Partial Emoji -> RawEmoji
forall a b. (a -> b) -> a -> b
$ Snowflake Emoji -> Text -> Bool -> Partial Emoji
PartialEmoji Snowflake Emoji
id Text
name Bool
anim
Maybe (Snowflake Emoji)
Nothing -> Text -> RawEmoji
UnicodeEmoji Text
name