module Calamity.Types.Model.Channel
( Channel(..)
, Partial(PartialChannel)
, module Calamity.Types.Model.Channel.DM
, module Calamity.Types.Model.Channel.Group
, module Calamity.Types.Model.Channel.Guild
, module Calamity.Types.Model.Channel.Attachment
, module Calamity.Types.Model.Channel.Reaction
, module Calamity.Types.Model.Channel.Webhook
, module Calamity.Types.Model.Channel.Embed
, module Calamity.Types.Model.Channel.ChannelType
, module Calamity.Types.Model.Channel.Message ) where
import Calamity.Internal.AesonThings
import Calamity.Types.Model.Channel.Attachment
import Calamity.Types.Model.Channel.ChannelType
import Calamity.Types.Model.Channel.DM
import Calamity.Types.Model.Channel.Embed
import Calamity.Types.Model.Channel.Group
import Calamity.Types.Model.Channel.Guild
import {-# SOURCE #-} Calamity.Types.Model.Channel.Message
import Calamity.Types.Model.Channel.Reaction
import Calamity.Types.Model.Channel.Webhook
import Calamity.Types.Partial
import Calamity.Types.Snowflake
import Data.Aeson
import Data.Text.Lazy ( Text )
import GHC.Generics
import TextShow
import qualified TextShow.Generic as TSG
data Channel
= DMChannel' DMChannel
| GroupChannel' GroupChannel
| GuildChannel' GuildChannel
deriving ( Int -> Channel -> ShowS
[Channel] -> ShowS
Channel -> String
(Int -> Channel -> ShowS)
-> (Channel -> String) -> ([Channel] -> ShowS) -> Show Channel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Channel] -> ShowS
$cshowList :: [Channel] -> ShowS
show :: Channel -> String
$cshow :: Channel -> String
showsPrec :: Int -> Channel -> ShowS
$cshowsPrec :: Int -> Channel -> ShowS
Show, Channel -> Channel -> Bool
(Channel -> Channel -> Bool)
-> (Channel -> Channel -> Bool) -> Eq Channel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Channel -> Channel -> Bool
$c/= :: Channel -> Channel -> Bool
== :: Channel -> Channel -> Bool
$c== :: Channel -> Channel -> Bool
Eq, (forall x. Channel -> Rep Channel x)
-> (forall x. Rep Channel x -> Channel) -> Generic Channel
forall x. Rep Channel x -> Channel
forall x. Channel -> Rep Channel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Channel x -> Channel
$cfrom :: forall x. Channel -> Rep Channel x
Generic )
deriving ( Int -> Channel -> Builder
Int -> Channel -> Text
Int -> Channel -> Text
[Channel] -> Builder
[Channel] -> Text
[Channel] -> Text
Channel -> Builder
Channel -> Text
Channel -> Text
(Int -> Channel -> Builder)
-> (Channel -> Builder)
-> ([Channel] -> Builder)
-> (Int -> Channel -> Text)
-> (Channel -> Text)
-> ([Channel] -> Text)
-> (Int -> Channel -> Text)
-> (Channel -> Text)
-> ([Channel] -> Text)
-> TextShow Channel
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 :: [Channel] -> Text
$cshowtlList :: [Channel] -> Text
showtl :: Channel -> Text
$cshowtl :: Channel -> Text
showtlPrec :: Int -> Channel -> Text
$cshowtlPrec :: Int -> Channel -> Text
showtList :: [Channel] -> Text
$cshowtList :: [Channel] -> Text
showt :: Channel -> Text
$cshowt :: Channel -> Text
showtPrec :: Int -> Channel -> Text
$cshowtPrec :: Int -> Channel -> Text
showbList :: [Channel] -> Builder
$cshowbList :: [Channel] -> Builder
showb :: Channel -> Builder
$cshowb :: Channel -> Builder
showbPrec :: Int -> Channel -> Builder
$cshowbPrec :: Int -> Channel -> Builder
TextShow ) via TSG.FromGeneric Channel
instance HasID Channel Channel where
getID :: Channel -> Snowflake Channel
getID (DMChannel' a :: DMChannel
a) = DMChannel -> Snowflake Channel
forall b a. HasID b a => a -> Snowflake b
getID DMChannel
a
getID (GroupChannel' a :: GroupChannel
a) = GroupChannel -> Snowflake Channel
forall b a. HasID b a => a -> Snowflake b
getID GroupChannel
a
getID (GuildChannel' a :: GuildChannel
a) = GuildChannel -> Snowflake Channel
forall b a. HasID b a => a -> Snowflake b
getID GuildChannel
a
instance FromJSON Channel where
parseJSON :: Value -> Parser Channel
parseJSON = String -> (Object -> Parser Channel) -> Value -> Parser Channel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject "Channel" ((Object -> Parser Channel) -> Value -> Parser Channel)
-> (Object -> Parser Channel) -> Value -> Parser Channel
forall a b. (a -> b) -> a -> b
$ \v :: Object
v -> do
ChannelType
type_ <- Object
v Object -> Text -> Parser ChannelType
forall a. FromJSON a => Object -> Text -> Parser a
.: "type"
case ChannelType
type_ of
GuildTextType -> GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Parser GuildChannel -> Parser Channel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildChannel
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
v)
GuildVoiceType -> GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Parser GuildChannel -> Parser Channel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildChannel
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
v)
GuildCategoryType -> GuildChannel -> Channel
GuildChannel' (GuildChannel -> Channel) -> Parser GuildChannel -> Parser Channel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GuildChannel
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
v)
DMType -> DMChannel -> Channel
DMChannel' (DMChannel -> Channel) -> Parser DMChannel -> Parser Channel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser DMChannel
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
v)
GroupDMType -> GroupChannel -> Channel
GroupChannel' (GroupChannel -> Channel) -> Parser GroupChannel -> Parser Channel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser GroupChannel
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
v)
data instance Partial Channel = PartialChannel
{ Partial Channel -> Snowflake Channel
id :: Snowflake Channel
, Partial Channel -> Text
name :: Text
, Partial Channel -> ChannelType
type_ :: ChannelType
, Partial Channel -> Maybe (Snowflake Category)
parentID :: Maybe (Snowflake Category)
}
deriving ( Int -> Partial Channel -> ShowS
[Partial Channel] -> ShowS
Partial Channel -> String
(Int -> Partial Channel -> ShowS)
-> (Partial Channel -> String)
-> ([Partial Channel] -> ShowS)
-> Show (Partial Channel)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Partial Channel] -> ShowS
$cshowList :: [Partial Channel] -> ShowS
show :: Partial Channel -> String
$cshow :: Partial Channel -> String
showsPrec :: Int -> Partial Channel -> ShowS
$cshowsPrec :: Int -> Partial Channel -> ShowS
Show, Partial Channel -> Partial Channel -> Bool
(Partial Channel -> Partial Channel -> Bool)
-> (Partial Channel -> Partial Channel -> Bool)
-> Eq (Partial Channel)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Partial Channel -> Partial Channel -> Bool
$c/= :: Partial Channel -> Partial Channel -> Bool
== :: Partial Channel -> Partial Channel -> Bool
$c== :: Partial Channel -> Partial Channel -> Bool
Eq, (forall x. Partial Channel -> Rep (Partial Channel) x)
-> (forall x. Rep (Partial Channel) x -> Partial Channel)
-> Generic (Partial Channel)
forall x. Rep (Partial Channel) x -> Partial Channel
forall x. Partial Channel -> Rep (Partial Channel) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep (Partial Channel) x -> Partial Channel
$cfrom :: forall x. Partial Channel -> Rep (Partial Channel) x
Generic )
deriving ( Int -> Partial Channel -> Builder
Int -> Partial Channel -> Text
Int -> Partial Channel -> Text
[Partial Channel] -> Builder
[Partial Channel] -> Text
[Partial Channel] -> Text
Partial Channel -> Builder
Partial Channel -> Text
Partial Channel -> Text
(Int -> Partial Channel -> Builder)
-> (Partial Channel -> Builder)
-> ([Partial Channel] -> Builder)
-> (Int -> Partial Channel -> Text)
-> (Partial Channel -> Text)
-> ([Partial Channel] -> Text)
-> (Int -> Partial Channel -> Text)
-> (Partial Channel -> Text)
-> ([Partial Channel] -> Text)
-> TextShow (Partial Channel)
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 Channel] -> Text
$cshowtlList :: [Partial Channel] -> Text
showtl :: Partial Channel -> Text
$cshowtl :: Partial Channel -> Text
showtlPrec :: Int -> Partial Channel -> Text
$cshowtlPrec :: Int -> Partial Channel -> Text
showtList :: [Partial Channel] -> Text
$cshowtList :: [Partial Channel] -> Text
showt :: Partial Channel -> Text
$cshowt :: Partial Channel -> Text
showtPrec :: Int -> Partial Channel -> Text
$cshowtPrec :: Int -> Partial Channel -> Text
showbList :: [Partial Channel] -> Builder
$cshowbList :: [Partial Channel] -> Builder
showb :: Partial Channel -> Builder
$cshowb :: Partial Channel -> Builder
showbPrec :: Int -> Partial Channel -> Builder
$cshowbPrec :: Int -> Partial Channel -> Builder
TextShow ) via TSG.FromGeneric (Partial Channel)
deriving ( [Partial Channel] -> Encoding
[Partial Channel] -> Value
Partial Channel -> Encoding
Partial Channel -> Value
(Partial Channel -> Value)
-> (Partial Channel -> Encoding)
-> ([Partial Channel] -> Value)
-> ([Partial Channel] -> Encoding)
-> ToJSON (Partial Channel)
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [Partial Channel] -> Encoding
$ctoEncodingList :: [Partial Channel] -> Encoding
toJSONList :: [Partial Channel] -> Value
$ctoJSONList :: [Partial Channel] -> Value
toEncoding :: Partial Channel -> Encoding
$ctoEncoding :: Partial Channel -> Encoding
toJSON :: Partial Channel -> Value
$ctoJSON :: Partial Channel -> Value
ToJSON, Value -> Parser [Partial Channel]
Value -> Parser (Partial Channel)
(Value -> Parser (Partial Channel))
-> (Value -> Parser [Partial Channel])
-> FromJSON (Partial Channel)
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [Partial Channel]
$cparseJSONList :: Value -> Parser [Partial Channel]
parseJSON :: Value -> Parser (Partial Channel)
$cparseJSON :: Value -> Parser (Partial Channel)
FromJSON ) via CalamityJSON (Partial Channel)
deriving ( HasID Channel ) via HasIDField "id" (Partial Channel)