{-# LANGUAGE TemplateHaskell #-}
module Calamity.Types.Model.Channel.Message (
Message (..),
MessageAuthor (..),
MessageAuthorWebhook (..),
ChannelMention (..),
MessageType (..),
MessageReference (..),
Partial (PartialMessage),
) where
import Calamity.Internal.Utils (AesonVector (..), CalamityToJSON (..), CalamityToJSON' (..), (.=), (.?=))
import {-# SOURCE #-} Calamity.Types.Model.Channel
import Calamity.Types.Model.Channel.Attachment
import Calamity.Types.Model.Channel.ChannelType (ChannelType)
import Calamity.Types.Model.Channel.Component
import Calamity.Types.Model.Channel.Embed
import Calamity.Types.Model.Channel.Reaction
import Calamity.Types.Model.Channel.Webhook
import {-# SOURCE #-} Calamity.Types.Model.Guild.Guild
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.Maybe (isJust)
import Data.Scientific
import Data.Text (Text)
import Data.Time
import Data.Vector.Unboxing qualified as UV
import Data.Word (Word64)
import Optics.TH
import TextShow qualified
import TextShow.TH
data MessageAuthorWebhook = MessageAuthorWebhook
{ MessageAuthorWebhook -> Snowflake Webhook
id :: Snowflake Webhook
, MessageAuthorWebhook -> Text
username :: Text
, MessageAuthorWebhook -> Maybe Text
avatar :: Maybe Text
}
deriving (Int -> MessageAuthorWebhook -> ShowS
[MessageAuthorWebhook] -> ShowS
MessageAuthorWebhook -> String
(Int -> MessageAuthorWebhook -> ShowS)
-> (MessageAuthorWebhook -> String)
-> ([MessageAuthorWebhook] -> ShowS)
-> Show MessageAuthorWebhook
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageAuthorWebhook -> ShowS
showsPrec :: Int -> MessageAuthorWebhook -> ShowS
$cshow :: MessageAuthorWebhook -> String
show :: MessageAuthorWebhook -> String
$cshowList :: [MessageAuthorWebhook] -> ShowS
showList :: [MessageAuthorWebhook] -> ShowS
Show)
deriving (HasID Webhook) via HasIDField "id" MessageAuthorWebhook
data MessageAuthor
= User' User
| Webhook' MessageAuthorWebhook
deriving (Int -> MessageAuthor -> ShowS
[MessageAuthor] -> ShowS
MessageAuthor -> String
(Int -> MessageAuthor -> ShowS)
-> (MessageAuthor -> String)
-> ([MessageAuthor] -> ShowS)
-> Show MessageAuthor
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageAuthor -> ShowS
showsPrec :: Int -> MessageAuthor -> ShowS
$cshow :: MessageAuthor -> String
show :: MessageAuthor -> String
$cshowList :: [MessageAuthor] -> ShowS
showList :: [MessageAuthor] -> ShowS
Show)
instance HasID User MessageAuthor where
getID :: MessageAuthor -> Snowflake User
getID (User' User
u) = User -> Snowflake User
forall b a. HasID b a => a -> Snowflake b
getID User
u
getID (Webhook' MessageAuthorWebhook {Snowflake Webhook
$sel:id:MessageAuthorWebhook :: MessageAuthorWebhook -> Snowflake Webhook
id :: Snowflake Webhook
id}) = Snowflake Webhook -> Snowflake User
forall a b. Snowflake a -> Snowflake b
coerceSnowflake Snowflake Webhook
id
data ChannelMention = ChannelMention
{ ChannelMention -> Snowflake Channel
id :: Snowflake Channel
, ChannelMention -> Snowflake Guild
guildID :: Snowflake Guild
, ChannelMention -> ChannelType
type_ :: ChannelType
, ChannelMention -> Text
name :: Text
}
deriving (Int -> ChannelMention -> ShowS
[ChannelMention] -> ShowS
ChannelMention -> String
(Int -> ChannelMention -> ShowS)
-> (ChannelMention -> String)
-> ([ChannelMention] -> ShowS)
-> Show ChannelMention
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ChannelMention -> ShowS
showsPrec :: Int -> ChannelMention -> ShowS
$cshow :: ChannelMention -> String
show :: ChannelMention -> String
$cshowList :: [ChannelMention] -> ShowS
showList :: [ChannelMention] -> ShowS
Show)
deriving (HasID Channel) via HasIDField "id" ChannelMention
instance Aeson.FromJSON ChannelMention where
parseJSON :: Value -> Parser ChannelMention
parseJSON = String
-> (Object -> Parser ChannelMention)
-> Value
-> Parser ChannelMention
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Message.ChannelMention" ((Object -> Parser ChannelMention)
-> Value -> Parser ChannelMention)
-> (Object -> Parser ChannelMention)
-> Value
-> Parser ChannelMention
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Snowflake Channel
-> Snowflake Guild -> ChannelType -> Text -> ChannelMention
ChannelMention
(Snowflake Channel
-> Snowflake Guild -> ChannelType -> Text -> ChannelMention)
-> Parser (Snowflake Channel)
-> Parser
(Snowflake Guild -> ChannelType -> Text -> ChannelMention)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Snowflake Channel)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Parser (Snowflake Guild -> ChannelType -> Text -> ChannelMention)
-> Parser (Snowflake Guild)
-> Parser (ChannelType -> Text -> ChannelMention)
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 (Snowflake Guild)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"guild_id"
Parser (ChannelType -> Text -> ChannelMention)
-> Parser ChannelType -> Parser (Text -> ChannelMention)
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 ChannelType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
Parser (Text -> ChannelMention)
-> Parser Text -> Parser ChannelMention
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 Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"name"
data Message = Message
{ Message -> Snowflake Message
id :: Snowflake Message
, Message -> Snowflake Channel
channelID :: Snowflake Channel
, Message -> Maybe (Snowflake Guild)
guildID :: Maybe (Snowflake Guild)
, Message -> MessageAuthor
author :: MessageAuthor
, Message -> Text
content :: Text
, Message -> UTCTime
timestamp :: UTCTime
, Message -> Maybe UTCTime
editedTimestamp :: Maybe UTCTime
, Message -> Bool
tts :: Bool
, Message -> Bool
mentionEveryone :: Bool
, Message -> [User]
mentions :: [User]
, Message -> Vector (Snowflake Role)
mentionRoles :: UV.Vector (Snowflake Role)
, Message -> [ChannelMention]
mentionChannels :: [ChannelMention]
, Message -> [Attachment]
attachments :: [Attachment]
, Message -> [Embed]
embeds :: [Embed]
, Message -> [Reaction]
reactions :: [Reaction]
, Message -> Maybe Value
nonce :: Maybe Aeson.Value
, Message -> Bool
pinned :: Bool
, Message -> Maybe (Snowflake Webhook)
webhookID :: Maybe (Snowflake Webhook)
, Message -> MessageType
type_ :: MessageType
, Message -> Maybe Object
activity :: Maybe Aeson.Object
, Message -> Maybe Object
application :: Maybe Aeson.Object
, Message -> Maybe MessageReference
messageReference :: Maybe MessageReference
, Message -> Word64
flags :: Word64
, Message -> Maybe Message
referencedMessage :: Maybe Message
, Message -> Maybe Object
interaction :: Maybe Aeson.Object
, Message -> [Component]
components :: [Component]
}
deriving (Int -> Message -> ShowS
[Message] -> ShowS
Message -> String
(Int -> Message -> ShowS)
-> (Message -> String) -> ([Message] -> ShowS) -> Show Message
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Message -> ShowS
showsPrec :: Int -> Message -> ShowS
$cshow :: Message -> String
show :: Message -> String
$cshowList :: [Message] -> ShowS
showList :: [Message] -> ShowS
Show)
deriving (Int -> Message -> Text
Int -> Message -> Builder
Int -> Message -> Text
[Message] -> Text
[Message] -> Builder
[Message] -> Text
Message -> Text
Message -> Builder
Message -> Text
(Int -> Message -> Builder)
-> (Message -> Builder)
-> ([Message] -> Builder)
-> (Int -> Message -> Text)
-> (Message -> Text)
-> ([Message] -> Text)
-> (Int -> Message -> Text)
-> (Message -> Text)
-> ([Message] -> Text)
-> TextShow Message
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 -> Message -> Builder
showbPrec :: Int -> Message -> Builder
$cshowb :: Message -> Builder
showb :: Message -> Builder
$cshowbList :: [Message] -> Builder
showbList :: [Message] -> Builder
$cshowtPrec :: Int -> Message -> Text
showtPrec :: Int -> Message -> Text
$cshowt :: Message -> Text
showt :: Message -> Text
$cshowtList :: [Message] -> Text
showtList :: [Message] -> Text
$cshowtlPrec :: Int -> Message -> Text
showtlPrec :: Int -> Message -> Text
$cshowtl :: Message -> Text
showtl :: Message -> Text
$cshowtlList :: [Message] -> Text
showtlList :: [Message] -> Text
TextShow.TextShow) via TextShow.FromStringShow Message
deriving (HasID Message) via HasIDField "id" Message
deriving (HasID Channel) via HasIDField "channelID" Message
deriving (HasID User) via HasIDField "author" Message
instance Aeson.FromJSON Message where
parseJSON :: Value -> Parser Message
parseJSON = String -> (Object -> Parser Message) -> Value -> Parser Message
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Message" ((Object -> Parser Message) -> Value -> Parser Message)
-> (Object -> Parser Message) -> Value -> Parser Message
forall a b. (a -> b) -> a -> b
$ \Object
v -> do
Maybe (Snowflake Webhook)
webhookID <- Object
v Object -> Key -> Parser (Maybe (Snowflake Webhook))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"webhook_id"
let author :: Parser MessageAuthor
author =
if Maybe (Snowflake Webhook) -> Bool
forall a. Maybe a -> Bool
isJust Maybe (Snowflake Webhook)
webhookID
then
String
-> (Object -> Parser MessageAuthor)
-> Value
-> Parser MessageAuthor
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject
String
"Message.author"
( \Object
v ->
MessageAuthorWebhook -> MessageAuthor
Webhook'
(MessageAuthorWebhook -> MessageAuthor)
-> Parser MessageAuthorWebhook -> Parser MessageAuthor
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( Snowflake Webhook -> Text -> Maybe Text -> MessageAuthorWebhook
MessageAuthorWebhook
(Snowflake Webhook -> Text -> Maybe Text -> MessageAuthorWebhook)
-> Parser (Snowflake Webhook)
-> Parser (Text -> Maybe Text -> MessageAuthorWebhook)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Snowflake Webhook)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Parser (Text -> Maybe Text -> MessageAuthorWebhook)
-> Parser Text -> Parser (Maybe Text -> MessageAuthorWebhook)
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 Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"username"
Parser (Maybe Text -> MessageAuthorWebhook)
-> Parser (Maybe Text) -> Parser MessageAuthorWebhook
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"
)
)
(Value -> Parser MessageAuthor)
-> Parser Value -> Parser MessageAuthor
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Object
v Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"author"
else User -> MessageAuthor
User' (User -> MessageAuthor) -> Parser User -> Parser MessageAuthor
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value -> Parser User
forall a. FromJSON a => Value -> Parser a
Aeson.parseJSON (Value -> Parser User) -> Parser Value -> Parser User
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Object
v Object -> Key -> Parser Value
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"author"))
Snowflake Message
-> Snowflake Channel
-> Maybe (Snowflake Guild)
-> MessageAuthor
-> Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message
Message
(Snowflake Message
-> Snowflake Channel
-> Maybe (Snowflake Guild)
-> MessageAuthor
-> Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Snowflake Message)
-> Parser
(Snowflake Channel
-> Maybe (Snowflake Guild)
-> MessageAuthor
-> Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Snowflake Message)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"id"
Parser
(Snowflake Channel
-> Maybe (Snowflake Guild)
-> MessageAuthor
-> Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Snowflake Channel)
-> Parser
(Maybe (Snowflake Guild)
-> MessageAuthor
-> Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 (Snowflake Channel)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id"
Parser
(Maybe (Snowflake Guild)
-> MessageAuthor
-> Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Maybe (Snowflake Guild))
-> Parser
(MessageAuthor
-> Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 (Snowflake Guild))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"guild_id"
Parser
(MessageAuthor
-> Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser MessageAuthor
-> Parser
(Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser MessageAuthor
author
Parser
(Text
-> UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser Text
-> Parser
(UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"content"
Parser
(UTCTime
-> Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser UTCTime
-> Parser
(Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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
"timestamp"
Parser
(Maybe UTCTime
-> Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Maybe UTCTime)
-> Parser
(Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 UTCTime)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"edited_timestamp"
Parser
(Bool
-> Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser Bool
-> Parser
(Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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
"tts"
Parser
(Bool
-> [User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser Bool
-> Parser
([User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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
"mention_everyone"
Parser
([User]
-> Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser [User]
-> Parser
(Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 [User]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"mentions"
Parser
(Vector (Snowflake Role)
-> [ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Vector (Snowflake Role))
-> Parser
([ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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)
forall a. AesonVector a -> Vector a
unAesonVector (AesonVector (Snowflake Role) -> Vector (Snowflake Role))
-> Parser (AesonVector (Snowflake Role))
-> Parser (Vector (Snowflake Role))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (AesonVector (Snowflake Role))
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"mention_roles")
Parser
([ChannelMention]
-> [Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser [ChannelMention]
-> Parser
([Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 [ChannelMention])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"mention_channels" Parser (Maybe [ChannelMention])
-> [ChannelMention] -> Parser [ChannelMention]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
Parser
([Attachment]
-> [Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser [Attachment]
-> Parser
([Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 [Attachment]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"attachments"
Parser
([Embed]
-> [Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser [Embed]
-> Parser
([Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 [Embed]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"embeds"
Parser
([Reaction]
-> Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser [Reaction]
-> Parser
(Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 [Reaction])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"reactions" Parser (Maybe [Reaction]) -> [Reaction] -> Parser [Reaction]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
Parser
(Maybe Value
-> Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Maybe Value)
-> Parser
(Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 Value)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"nonce"
Parser
(Bool
-> Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser Bool
-> Parser
(Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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
"pinned"
Parser
(Maybe (Snowflake Webhook)
-> MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Maybe (Snowflake Webhook))
-> Parser
(MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe (Snowflake Webhook) -> Parser (Maybe (Snowflake Webhook))
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Snowflake Webhook)
webhookID
Parser
(MessageType
-> Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser MessageType
-> Parser
(Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 MessageType
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
Parser
(Maybe Object
-> Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Maybe Object)
-> Parser
(Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 Object)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"activity"
Parser
(Maybe Object
-> Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Maybe Object)
-> Parser
(Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
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 Object)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"application"
Parser
(Maybe MessageReference
-> Word64
-> Maybe Message
-> Maybe Object
-> [Component]
-> Message)
-> Parser (Maybe MessageReference)
-> Parser
(Word64 -> Maybe Message -> Maybe Object -> [Component] -> Message)
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 MessageReference)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"message_reference"
Parser
(Word64 -> Maybe Message -> Maybe Object -> [Component] -> Message)
-> Parser Word64
-> Parser (Maybe Message -> Maybe Object -> [Component] -> Message)
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) -> Word64 -> Parser Word64
forall a. Parser (Maybe a) -> a -> Parser a
.!= Word64
0
Parser (Maybe Message -> Maybe Object -> [Component] -> Message)
-> Parser (Maybe Message)
-> Parser (Maybe Object -> [Component] -> Message)
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 Message)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"referenced_message"
Parser (Maybe Object -> [Component] -> Message)
-> Parser (Maybe Object) -> Parser ([Component] -> Message)
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 Object)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"interaction"
Parser ([Component] -> Message)
-> Parser [Component] -> Parser Message
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 [Component])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"components" Parser (Maybe [Component]) -> [Component] -> Parser [Component]
forall a. Parser (Maybe a) -> a -> Parser a
.!= []
data instance Partial Message = PartialMessage
{ Partial Message -> Snowflake Channel
channelID :: Snowflake Channel
, Partial Message -> Maybe (Snowflake Guild)
guildID :: Maybe (Snowflake Guild)
}
deriving (Int -> Partial Message -> ShowS
[Partial Message] -> ShowS
Partial Message -> String
(Int -> Partial Message -> ShowS)
-> (Partial Message -> String)
-> ([Partial Message] -> ShowS)
-> Show (Partial Message)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Partial Message -> ShowS
showsPrec :: Int -> Partial Message -> ShowS
$cshow :: Partial Message -> String
show :: Partial Message -> String
$cshowList :: [Partial Message] -> ShowS
showList :: [Partial Message] -> ShowS
Show)
deriving (HasID Channel) via HasIDField "channelID" (Partial Message)
instance Aeson.FromJSON (Partial Message) where
parseJSON :: Value -> Parser (Partial Message)
parseJSON = String
-> (Object -> Parser (Partial Message))
-> Value
-> Parser (Partial Message)
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Partial Message" ((Object -> Parser (Partial Message))
-> Value -> Parser (Partial Message))
-> (Object -> Parser (Partial Message))
-> Value
-> Parser (Partial Message)
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Snowflake Channel -> Maybe (Snowflake Guild) -> Partial Message
PartialMessage
(Snowflake Channel -> Maybe (Snowflake Guild) -> Partial Message)
-> Parser (Snowflake Channel)
-> Parser (Maybe (Snowflake Guild) -> Partial Message)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Snowflake Channel)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_id"
Parser (Maybe (Snowflake Guild) -> Partial Message)
-> Parser (Maybe (Snowflake Guild)) -> Parser (Partial Message)
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 (Snowflake Guild))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"guild_id"
data MessageReference = MessageReference
{ MessageReference -> Maybe (Snowflake Message)
messageID :: Maybe (Snowflake Message)
, MessageReference -> Maybe (Snowflake Channel)
channelID :: Maybe (Snowflake Channel)
, MessageReference -> Maybe (Snowflake Guild)
guildID :: Maybe (Snowflake Guild)
, MessageReference -> Bool
failIfNotExists :: Bool
}
deriving (MessageReference -> MessageReference -> Bool
(MessageReference -> MessageReference -> Bool)
-> (MessageReference -> MessageReference -> Bool)
-> Eq MessageReference
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageReference -> MessageReference -> Bool
== :: MessageReference -> MessageReference -> Bool
$c/= :: MessageReference -> MessageReference -> Bool
/= :: MessageReference -> MessageReference -> Bool
Eq, Int -> MessageReference -> ShowS
[MessageReference] -> ShowS
MessageReference -> String
(Int -> MessageReference -> ShowS)
-> (MessageReference -> String)
-> ([MessageReference] -> ShowS)
-> Show MessageReference
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageReference -> ShowS
showsPrec :: Int -> MessageReference -> ShowS
$cshow :: MessageReference -> String
show :: MessageReference -> String
$cshowList :: [MessageReference] -> ShowS
showList :: [MessageReference] -> ShowS
Show)
deriving ([MessageReference] -> Value
[MessageReference] -> Encoding
MessageReference -> Value
MessageReference -> Encoding
(MessageReference -> Value)
-> (MessageReference -> Encoding)
-> ([MessageReference] -> Value)
-> ([MessageReference] -> Encoding)
-> ToJSON MessageReference
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
$ctoJSON :: MessageReference -> Value
toJSON :: MessageReference -> Value
$ctoEncoding :: MessageReference -> Encoding
toEncoding :: MessageReference -> Encoding
$ctoJSONList :: [MessageReference] -> Value
toJSONList :: [MessageReference] -> Value
$ctoEncodingList :: [MessageReference] -> Encoding
toEncodingList :: [MessageReference] -> Encoding
Aeson.ToJSON) via CalamityToJSON MessageReference
instance CalamityToJSON' MessageReference where
toPairs :: forall kv. KeyValue kv => MessageReference -> [Maybe kv]
toPairs MessageReference {Bool
Maybe (Snowflake Message)
Maybe (Snowflake Channel)
Maybe (Snowflake Guild)
$sel:messageID:MessageReference :: MessageReference -> Maybe (Snowflake Message)
$sel:channelID:MessageReference :: MessageReference -> Maybe (Snowflake Channel)
$sel:guildID:MessageReference :: MessageReference -> Maybe (Snowflake Guild)
$sel:failIfNotExists:MessageReference :: MessageReference -> Bool
messageID :: Maybe (Snowflake Message)
channelID :: Maybe (Snowflake Channel)
guildID :: Maybe (Snowflake Guild)
failIfNotExists :: Bool
..} =
[ Key
"message_id" Key -> Maybe (Snowflake Message) -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe (Snowflake Message)
messageID
, Key
"channel_id" Key -> Maybe (Snowflake Channel) -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe (Snowflake Channel)
channelID
, Key
"guild_id" Key -> Maybe (Snowflake Guild) -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> Maybe v -> Maybe kv
.?= Maybe (Snowflake Guild)
guildID
, Key
"fail_if_not_exists" Key -> Bool -> Maybe kv
forall v kv. (ToJSON v, KeyValue kv) => Key -> v -> Maybe kv
.= Bool
failIfNotExists
]
instance Aeson.FromJSON MessageReference where
parseJSON :: Value -> Parser MessageReference
parseJSON = String
-> (Object -> Parser MessageReference)
-> Value
-> Parser MessageReference
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"MessageReference" ((Object -> Parser MessageReference)
-> Value -> Parser MessageReference)
-> (Object -> Parser MessageReference)
-> Value
-> Parser MessageReference
forall a b. (a -> b) -> a -> b
$ \Object
v ->
Maybe (Snowflake Message)
-> Maybe (Snowflake Channel)
-> Maybe (Snowflake Guild)
-> Bool
-> MessageReference
MessageReference
(Maybe (Snowflake Message)
-> Maybe (Snowflake Channel)
-> Maybe (Snowflake Guild)
-> Bool
-> MessageReference)
-> Parser (Maybe (Snowflake Message))
-> Parser
(Maybe (Snowflake Channel)
-> Maybe (Snowflake Guild) -> Bool -> MessageReference)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser (Maybe (Snowflake Message))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"message_id"
Parser
(Maybe (Snowflake Channel)
-> Maybe (Snowflake Guild) -> Bool -> MessageReference)
-> Parser (Maybe (Snowflake Channel))
-> Parser (Maybe (Snowflake Guild) -> Bool -> MessageReference)
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 (Snowflake Channel))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"channel_id"
Parser (Maybe (Snowflake Guild) -> Bool -> MessageReference)
-> Parser (Maybe (Snowflake Guild))
-> Parser (Bool -> MessageReference)
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 (Snowflake Guild))
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"guild_id"
Parser (Bool -> MessageReference)
-> Parser Bool -> Parser MessageReference
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
"fail_if_not_exists" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
data MessageType
= Default
| RecipientAdd
| RecipientRemove
| Call
| ChannelNameChange
| ChannelIconChange
| ChannelPinnedMessage
| GuildMemberJoin
| UserPremiumGuildSubscription
| UserPremiumGuildSubscriptionTier1
| UserPremiumGuildSubscriptionTier2
| UserPremiumGuildSubscriptionTier3
| ChannelFollowAdd
| GuildDiscoveryDisqualified
| GuildDiscoveryRequalified
| Reply
| ApplicationCommmand
deriving (MessageType -> MessageType -> Bool
(MessageType -> MessageType -> Bool)
-> (MessageType -> MessageType -> Bool) -> Eq MessageType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MessageType -> MessageType -> Bool
== :: MessageType -> MessageType -> Bool
$c/= :: MessageType -> MessageType -> Bool
/= :: MessageType -> MessageType -> Bool
Eq, Int -> MessageType -> ShowS
[MessageType] -> ShowS
MessageType -> String
(Int -> MessageType -> ShowS)
-> (MessageType -> String)
-> ([MessageType] -> ShowS)
-> Show MessageType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MessageType -> ShowS
showsPrec :: Int -> MessageType -> ShowS
$cshow :: MessageType -> String
show :: MessageType -> String
$cshowList :: [MessageType] -> ShowS
showList :: [MessageType] -> ShowS
Show, Int -> MessageType
MessageType -> Int
MessageType -> [MessageType]
MessageType -> MessageType
MessageType -> MessageType -> [MessageType]
MessageType -> MessageType -> MessageType -> [MessageType]
(MessageType -> MessageType)
-> (MessageType -> MessageType)
-> (Int -> MessageType)
-> (MessageType -> Int)
-> (MessageType -> [MessageType])
-> (MessageType -> MessageType -> [MessageType])
-> (MessageType -> MessageType -> [MessageType])
-> (MessageType -> MessageType -> MessageType -> [MessageType])
-> Enum MessageType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: MessageType -> MessageType
succ :: MessageType -> MessageType
$cpred :: MessageType -> MessageType
pred :: MessageType -> MessageType
$ctoEnum :: Int -> MessageType
toEnum :: Int -> MessageType
$cfromEnum :: MessageType -> Int
fromEnum :: MessageType -> Int
$cenumFrom :: MessageType -> [MessageType]
enumFrom :: MessageType -> [MessageType]
$cenumFromThen :: MessageType -> MessageType -> [MessageType]
enumFromThen :: MessageType -> MessageType -> [MessageType]
$cenumFromTo :: MessageType -> MessageType -> [MessageType]
enumFromTo :: MessageType -> MessageType -> [MessageType]
$cenumFromThenTo :: MessageType -> MessageType -> MessageType -> [MessageType]
enumFromThenTo :: MessageType -> MessageType -> MessageType -> [MessageType]
Enum)
instance Aeson.FromJSON MessageType where
parseJSON :: Value -> Parser MessageType
parseJSON = String
-> (Scientific -> Parser MessageType)
-> Value
-> Parser MessageType
forall a. String -> (Scientific -> Parser a) -> Value -> Parser a
Aeson.withScientific String
"MessageType" ((Scientific -> Parser MessageType) -> Value -> Parser MessageType)
-> (Scientific -> Parser MessageType)
-> Value
-> Parser MessageType
forall a b. (a -> b) -> a -> b
$ \Scientific
n -> case forall i. (Integral i, Bounded i) => Scientific -> Maybe i
toBoundedInteger @Int Scientific
n of
Just Int
v -> case Int
v of
Int
0 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
Default
Int
1 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
RecipientAdd
Int
2 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
RecipientRemove
Int
3 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
Call
Int
4 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
ChannelNameChange
Int
5 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
ChannelIconChange
Int
6 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
ChannelPinnedMessage
Int
7 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
GuildMemberJoin
Int
8 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
UserPremiumGuildSubscription
Int
9 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
UserPremiumGuildSubscriptionTier1
Int
10 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
UserPremiumGuildSubscriptionTier2
Int
11 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
UserPremiumGuildSubscriptionTier3
Int
12 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
ChannelFollowAdd
Int
14 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
GuildDiscoveryDisqualified
Int
15 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
GuildDiscoveryRequalified
Int
19 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
Reply
Int
20 -> MessageType -> Parser MessageType
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MessageType
ApplicationCommmand
Int
_ -> String -> Parser MessageType
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser MessageType) -> String -> Parser MessageType
forall a b. (a -> b) -> a -> b
$ String
"Invalid MessageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
n
Maybe Int
Nothing -> String -> Parser MessageType
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser MessageType) -> String -> Parser MessageType
forall a b. (a -> b) -> a -> b
$ String
"Invalid MessageType: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Scientific -> String
forall a. Show a => a -> String
show Scientific
n
$(deriveTextShow ''MessageAuthorWebhook)
$(deriveTextShow 'PartialMessage)
$(deriveTextShow ''ChannelMention)
$(deriveTextShow ''MessageType)
$(makeFieldLabelsNoPrefix ''MessageAuthorWebhook)
$(makeFieldLabelsNoPrefix ''ChannelMention)
$(makeFieldLabelsNoPrefix 'PartialMessage)
$(makeFieldLabelsNoPrefix ''Message)
$(makeFieldLabelsNoPrefix ''MessageReference)