{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Discord.Internal.Types.Components
( ActionRow (..),
Button (..),
ButtonStyle (..),
mkButton,
SelectMenu (..),
mkSelectMenu,
SelectMenuData (..),
SelectOption (..),
mkSelectOption,
TextInput (..),
mkTextInput,
)
where
import Data.Aeson
import Data.Aeson.Types (Parser)
import Data.Foldable (Foldable (toList))
import Data.Scientific (Scientific)
import qualified Data.Text as T
import Discord.Internal.Types.Emoji (Emoji)
import Discord.Internal.Types.Prelude (objectFromMaybes, (.==), (.=?), ChannelTypeOption)
data ActionRow = ActionRowButtons [Button] | SelectMenu
deriving (Int -> ActionRow -> ShowS
[ActionRow] -> ShowS
ActionRow -> String
(Int -> ActionRow -> ShowS)
-> (ActionRow -> String)
-> ([ActionRow] -> ShowS)
-> Show ActionRow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ActionRow -> ShowS
showsPrec :: Int -> ActionRow -> ShowS
$cshow :: ActionRow -> String
show :: ActionRow -> String
$cshowList :: [ActionRow] -> ShowS
showList :: [ActionRow] -> ShowS
Show, ReadPrec [ActionRow]
ReadPrec ActionRow
Int -> ReadS ActionRow
ReadS [ActionRow]
(Int -> ReadS ActionRow)
-> ReadS [ActionRow]
-> ReadPrec ActionRow
-> ReadPrec [ActionRow]
-> Read ActionRow
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ActionRow
readsPrec :: Int -> ReadS ActionRow
$creadList :: ReadS [ActionRow]
readList :: ReadS [ActionRow]
$creadPrec :: ReadPrec ActionRow
readPrec :: ReadPrec ActionRow
$creadListPrec :: ReadPrec [ActionRow]
readListPrec :: ReadPrec [ActionRow]
Read, ActionRow -> ActionRow -> Bool
(ActionRow -> ActionRow -> Bool)
-> (ActionRow -> ActionRow -> Bool) -> Eq ActionRow
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ActionRow -> ActionRow -> Bool
== :: ActionRow -> ActionRow -> Bool
$c/= :: ActionRow -> ActionRow -> Bool
/= :: ActionRow -> ActionRow -> Bool
Eq, Eq ActionRow
Eq ActionRow =>
(ActionRow -> ActionRow -> Ordering)
-> (ActionRow -> ActionRow -> Bool)
-> (ActionRow -> ActionRow -> Bool)
-> (ActionRow -> ActionRow -> Bool)
-> (ActionRow -> ActionRow -> Bool)
-> (ActionRow -> ActionRow -> ActionRow)
-> (ActionRow -> ActionRow -> ActionRow)
-> Ord ActionRow
ActionRow -> ActionRow -> Bool
ActionRow -> ActionRow -> Ordering
ActionRow -> ActionRow -> ActionRow
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ActionRow -> ActionRow -> Ordering
compare :: ActionRow -> ActionRow -> Ordering
$c< :: ActionRow -> ActionRow -> Bool
< :: ActionRow -> ActionRow -> Bool
$c<= :: ActionRow -> ActionRow -> Bool
<= :: ActionRow -> ActionRow -> Bool
$c> :: ActionRow -> ActionRow -> Bool
> :: ActionRow -> ActionRow -> Bool
$c>= :: ActionRow -> ActionRow -> Bool
>= :: ActionRow -> ActionRow -> Bool
$cmax :: ActionRow -> ActionRow -> ActionRow
max :: ActionRow -> ActionRow -> ActionRow
$cmin :: ActionRow -> ActionRow -> ActionRow
min :: ActionRow -> ActionRow -> ActionRow
Ord)
instance FromJSON ActionRow where
parseJSON :: Value -> Parser ActionRow
parseJSON =
String -> (Object -> Parser ActionRow) -> Value -> Parser ActionRow
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject
String
"ActionRow"
( \Object
cs -> do
Int
t <- Object
cs Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" :: Parser Int
case Int
t of
Int
1 -> do
Array
a <- Object
cs Object -> Key -> Parser Array
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"components" :: Parser Array
let a' :: [Value]
a' = Array -> [Value]
forall a. Vector a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList Array
a
case [Value]
a' of
[] -> ActionRow -> Parser ActionRow
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return (ActionRow -> Parser ActionRow) -> ActionRow -> Parser ActionRow
forall a b. (a -> b) -> a -> b
$ [Button] -> ActionRow
ActionRowButtons []
(Value
c : [Value]
_) ->
String -> (Object -> Parser ActionRow) -> Value -> Parser ActionRow
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject
String
"ActionRow item"
( \Object
v -> do
Int
t' <- Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" :: Parser Int
case Int
t' of
Int
2 -> [Button] -> ActionRow
ActionRowButtons ([Button] -> ActionRow) -> Parser [Button] -> Parser ActionRow
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value -> Parser Button) -> [Value] -> Parser [Button]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM Value -> Parser Button
forall a. FromJSON a => Value -> Parser a
parseJSON [Value]
a'
Int
_ | Int
t' Int -> [Int] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Int
3, Int
5, Int
6, Int
7, Int
8] -> SelectMenu -> ActionRow
ActionRowSelectMenu (SelectMenu -> ActionRow) -> Parser SelectMenu -> Parser ActionRow
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Value -> Parser SelectMenu
forall a. FromJSON a => Value -> Parser a
parseJSON Value
c
Int
_ -> String -> Parser ActionRow
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ActionRow) -> String -> Parser ActionRow
forall a b. (a -> b) -> a -> b
$ String
"unknown component type: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
t'
)
Value
c
Int
_ -> String -> Parser ActionRow
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ActionRow) -> String -> Parser ActionRow
forall a b. (a -> b) -> a -> b
$ String
"expected action row type (1), got: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
t
)
instance ToJSON ActionRow where
toJSON :: ActionRow -> Value
toJSON (ActionRowButtons [Button]
bs) = [Pair] -> Value
object [(Key
"type", Scientific -> Value
Number Scientific
1), (Key
"components", [Button] -> Value
forall a. ToJSON a => a -> Value
toJSON [Button]
bs)]
toJSON (ActionRowSelectMenu SelectMenu
bs) = [Pair] -> Value
object [(Key
"type", Scientific -> Value
Number Scientific
1), (Key
"components", [SelectMenu] -> Value
forall a. ToJSON a => a -> Value
toJSON [SelectMenu
bs])]
data Button
= Button
{
Button -> Text
buttonCustomId :: T.Text,
Button -> Bool
buttonDisabled :: Bool,
Button -> ButtonStyle
buttonStyle :: ButtonStyle,
Button -> Maybe Text
buttonLabel :: Maybe T.Text,
Button -> Maybe Emoji
buttonEmoji :: Maybe Emoji
}
| ButtonUrl
{
Button -> Text
buttonUrl :: T.Text,
buttonDisabled :: Bool,
buttonLabel :: Maybe T.Text,
buttonEmoji :: Maybe Emoji
}
deriving (Int -> Button -> ShowS
[Button] -> ShowS
Button -> String
(Int -> Button -> ShowS)
-> (Button -> String) -> ([Button] -> ShowS) -> Show Button
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Button -> ShowS
showsPrec :: Int -> Button -> ShowS
$cshow :: Button -> String
show :: Button -> String
$cshowList :: [Button] -> ShowS
showList :: [Button] -> ShowS
Show, ReadPrec [Button]
ReadPrec Button
Int -> ReadS Button
ReadS [Button]
(Int -> ReadS Button)
-> ReadS [Button]
-> ReadPrec Button
-> ReadPrec [Button]
-> Read Button
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Button
readsPrec :: Int -> ReadS Button
$creadList :: ReadS [Button]
readList :: ReadS [Button]
$creadPrec :: ReadPrec Button
readPrec :: ReadPrec Button
$creadListPrec :: ReadPrec [Button]
readListPrec :: ReadPrec [Button]
Read, Button -> Button -> Bool
(Button -> Button -> Bool)
-> (Button -> Button -> Bool) -> Eq Button
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Button -> Button -> Bool
== :: Button -> Button -> Bool
$c/= :: Button -> Button -> Bool
/= :: Button -> Button -> Bool
Eq, Eq Button
Eq Button =>
(Button -> Button -> Ordering)
-> (Button -> Button -> Bool)
-> (Button -> Button -> Bool)
-> (Button -> Button -> Bool)
-> (Button -> Button -> Bool)
-> (Button -> Button -> Button)
-> (Button -> Button -> Button)
-> Ord Button
Button -> Button -> Bool
Button -> Button -> Ordering
Button -> Button -> Button
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Button -> Button -> Ordering
compare :: Button -> Button -> Ordering
$c< :: Button -> Button -> Bool
< :: Button -> Button -> Bool
$c<= :: Button -> Button -> Bool
<= :: Button -> Button -> Bool
$c> :: Button -> Button -> Bool
> :: Button -> Button -> Bool
$c>= :: Button -> Button -> Bool
>= :: Button -> Button -> Bool
$cmax :: Button -> Button -> Button
max :: Button -> Button -> Button
$cmin :: Button -> Button -> Button
min :: Button -> Button -> Button
Ord)
mkButton :: T.Text -> T.Text -> Button
mkButton :: Text -> Text -> Button
mkButton Text
label Text
customId = Text -> Bool -> ButtonStyle -> Maybe Text -> Maybe Emoji -> Button
Button Text
customId Bool
False ButtonStyle
ButtonStyleSecondary (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
label) Maybe Emoji
forall a. Maybe a
Nothing
instance FromJSON Button where
parseJSON :: Value -> Parser Button
parseJSON =
String -> (Object -> Parser Button) -> Value -> Parser Button
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject
String
"Button"
( \Object
v -> do
Int
t <- Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" :: Parser Int
case Int
t of
Int
2 -> do
Bool
disabled <- Object
v Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"disabled" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
Maybe Text
label <- Object
v Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"label"
Maybe Emoji
partialEmoji <- Object
v Object -> Key -> Parser (Maybe Emoji)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"emoji"
Scientific
style <- Object
v Object -> Key -> Parser Scientific
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"style" :: Parser Scientific
case Scientific
style of
Scientific
5 ->
Text -> Bool -> Maybe Text -> Maybe Emoji -> Button
ButtonUrl
(Text -> Bool -> Maybe Text -> Maybe Emoji -> Button)
-> Parser Text
-> Parser (Bool -> Maybe Text -> Maybe Emoji -> Button)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"url"
Parser (Bool -> Maybe Text -> Maybe Emoji -> Button)
-> Parser Bool -> Parser (Maybe Text -> Maybe Emoji -> Button)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Parser Bool
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
disabled
Parser (Maybe Text -> Maybe Emoji -> Button)
-> Parser (Maybe Text) -> Parser (Maybe Emoji -> Button)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Text -> Parser (Maybe Text)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
label
Parser (Maybe Emoji -> Button)
-> Parser (Maybe Emoji) -> Parser Button
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Emoji -> Parser (Maybe Emoji)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Emoji
partialEmoji
Scientific
_ ->
Text -> Bool -> ButtonStyle -> Maybe Text -> Maybe Emoji -> Button
Button
(Text
-> Bool -> ButtonStyle -> Maybe Text -> Maybe Emoji -> Button)
-> Parser Text
-> Parser
(Bool -> ButtonStyle -> Maybe Text -> Maybe Emoji -> Button)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"custom_id"
Parser (Bool -> ButtonStyle -> Maybe Text -> Maybe Emoji -> Button)
-> Parser Bool
-> Parser (ButtonStyle -> Maybe Text -> Maybe Emoji -> Button)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> Parser Bool
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
disabled
Parser (ButtonStyle -> Maybe Text -> Maybe Emoji -> Button)
-> Parser ButtonStyle
-> Parser (Maybe Text -> Maybe Emoji -> Button)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value -> Parser ButtonStyle
forall a. FromJSON a => Value -> Parser a
parseJSON (Scientific -> Value
Number Scientific
style)
Parser (Maybe Text -> Maybe Emoji -> Button)
-> Parser (Maybe Text) -> Parser (Maybe Emoji -> Button)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Text -> Parser (Maybe Text)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
label
Parser (Maybe Emoji -> Button)
-> Parser (Maybe Emoji) -> Parser Button
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Emoji -> Parser (Maybe Emoji)
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Emoji
partialEmoji
Int
_ -> String -> Parser Button
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"expected button type, got a different component"
)
instance ToJSON Button where
toJSON :: Button -> Value
toJSON ButtonUrl {Bool
Maybe Text
Maybe Emoji
Text
buttonDisabled :: Button -> Bool
buttonLabel :: Button -> Maybe Text
buttonEmoji :: Button -> Maybe Emoji
buttonUrl :: Button -> Text
buttonUrl :: Text
buttonDisabled :: Bool
buttonLabel :: Maybe Text
buttonEmoji :: Maybe Emoji
..} =
[Maybe Pair] -> Value
objectFromMaybes
[ Key
"type" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
2,
Key
"style" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
5,
Key
"label" Key -> Maybe Text -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Text
buttonLabel,
Key
"disabled" Key -> Bool -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Bool
buttonDisabled,
Key
"url" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
buttonUrl,
Key
"emoji" Key -> Maybe Emoji -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Emoji
buttonEmoji
]
toJSON Button {Bool
Maybe Text
Maybe Emoji
Text
ButtonStyle
buttonCustomId :: Button -> Text
buttonDisabled :: Button -> Bool
buttonStyle :: Button -> ButtonStyle
buttonLabel :: Button -> Maybe Text
buttonEmoji :: Button -> Maybe Emoji
buttonCustomId :: Text
buttonDisabled :: Bool
buttonStyle :: ButtonStyle
buttonLabel :: Maybe Text
buttonEmoji :: Maybe Emoji
..} =
[Maybe Pair] -> Value
objectFromMaybes
[ Key
"type" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
2,
Key
"style" Key -> ButtonStyle -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== ButtonStyle
buttonStyle,
Key
"label" Key -> Maybe Text -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Text
buttonLabel,
Key
"disabled" Key -> Bool -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Bool
buttonDisabled,
Key
"custom_id" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
buttonCustomId,
Key
"emoji" Key -> Maybe Emoji -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Emoji
buttonEmoji
]
data ButtonStyle
=
ButtonStylePrimary
|
ButtonStyleSecondary
|
ButtonStyleSuccess
|
ButtonStyleDanger
deriving (Int -> ButtonStyle -> ShowS
[ButtonStyle] -> ShowS
ButtonStyle -> String
(Int -> ButtonStyle -> ShowS)
-> (ButtonStyle -> String)
-> ([ButtonStyle] -> ShowS)
-> Show ButtonStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ButtonStyle -> ShowS
showsPrec :: Int -> ButtonStyle -> ShowS
$cshow :: ButtonStyle -> String
show :: ButtonStyle -> String
$cshowList :: [ButtonStyle] -> ShowS
showList :: [ButtonStyle] -> ShowS
Show, ReadPrec [ButtonStyle]
ReadPrec ButtonStyle
Int -> ReadS ButtonStyle
ReadS [ButtonStyle]
(Int -> ReadS ButtonStyle)
-> ReadS [ButtonStyle]
-> ReadPrec ButtonStyle
-> ReadPrec [ButtonStyle]
-> Read ButtonStyle
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS ButtonStyle
readsPrec :: Int -> ReadS ButtonStyle
$creadList :: ReadS [ButtonStyle]
readList :: ReadS [ButtonStyle]
$creadPrec :: ReadPrec ButtonStyle
readPrec :: ReadPrec ButtonStyle
$creadListPrec :: ReadPrec [ButtonStyle]
readListPrec :: ReadPrec [ButtonStyle]
Read, ButtonStyle -> ButtonStyle -> Bool
(ButtonStyle -> ButtonStyle -> Bool)
-> (ButtonStyle -> ButtonStyle -> Bool) -> Eq ButtonStyle
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ButtonStyle -> ButtonStyle -> Bool
== :: ButtonStyle -> ButtonStyle -> Bool
$c/= :: ButtonStyle -> ButtonStyle -> Bool
/= :: ButtonStyle -> ButtonStyle -> Bool
Eq, Eq ButtonStyle
Eq ButtonStyle =>
(ButtonStyle -> ButtonStyle -> Ordering)
-> (ButtonStyle -> ButtonStyle -> Bool)
-> (ButtonStyle -> ButtonStyle -> Bool)
-> (ButtonStyle -> ButtonStyle -> Bool)
-> (ButtonStyle -> ButtonStyle -> Bool)
-> (ButtonStyle -> ButtonStyle -> ButtonStyle)
-> (ButtonStyle -> ButtonStyle -> ButtonStyle)
-> Ord ButtonStyle
ButtonStyle -> ButtonStyle -> Bool
ButtonStyle -> ButtonStyle -> Ordering
ButtonStyle -> ButtonStyle -> ButtonStyle
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ButtonStyle -> ButtonStyle -> Ordering
compare :: ButtonStyle -> ButtonStyle -> Ordering
$c< :: ButtonStyle -> ButtonStyle -> Bool
< :: ButtonStyle -> ButtonStyle -> Bool
$c<= :: ButtonStyle -> ButtonStyle -> Bool
<= :: ButtonStyle -> ButtonStyle -> Bool
$c> :: ButtonStyle -> ButtonStyle -> Bool
> :: ButtonStyle -> ButtonStyle -> Bool
$c>= :: ButtonStyle -> ButtonStyle -> Bool
>= :: ButtonStyle -> ButtonStyle -> Bool
$cmax :: ButtonStyle -> ButtonStyle -> ButtonStyle
max :: ButtonStyle -> ButtonStyle -> ButtonStyle
$cmin :: ButtonStyle -> ButtonStyle -> ButtonStyle
min :: ButtonStyle -> ButtonStyle -> ButtonStyle
Ord)
instance FromJSON ButtonStyle where
parseJSON :: Value -> Parser ButtonStyle
parseJSON =
String
-> (Scientific -> Parser ButtonStyle)
-> Value
-> Parser ButtonStyle
forall a. String -> (Scientific -> Parser a) -> Value -> Parser a
withScientific
String
"ButtonStyle"
( \case
Scientific
1 -> ButtonStyle -> Parser ButtonStyle
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return ButtonStyle
ButtonStylePrimary
Scientific
2 -> ButtonStyle -> Parser ButtonStyle
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return ButtonStyle
ButtonStyleSecondary
Scientific
3 -> ButtonStyle -> Parser ButtonStyle
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return ButtonStyle
ButtonStyleSuccess
Scientific
4 -> ButtonStyle -> Parser ButtonStyle
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return ButtonStyle
ButtonStyleDanger
Scientific
_ -> String -> Parser ButtonStyle
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"unrecognised non-url button style"
)
instance ToJSON ButtonStyle where
toJSON :: ButtonStyle -> Value
toJSON ButtonStyle
ButtonStylePrimary = Scientific -> Value
Number Scientific
1
toJSON ButtonStyle
ButtonStyleSecondary = Scientific -> Value
Number Scientific
2
toJSON ButtonStyle
ButtonStyleSuccess = Scientific -> Value
Number Scientific
3
toJSON ButtonStyle
ButtonStyleDanger = Scientific -> Value
Number Scientific
4
data =
{
:: T.Text,
:: Bool,
:: SelectMenuData,
:: Maybe T.Text,
:: Maybe Integer,
:: Maybe Integer
}
deriving (Int -> SelectMenu -> ShowS
[SelectMenu] -> ShowS
SelectMenu -> String
(Int -> SelectMenu -> ShowS)
-> (SelectMenu -> String)
-> ([SelectMenu] -> ShowS)
-> Show SelectMenu
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SelectMenu -> ShowS
showsPrec :: Int -> SelectMenu -> ShowS
$cshow :: SelectMenu -> String
show :: SelectMenu -> String
$cshowList :: [SelectMenu] -> ShowS
showList :: [SelectMenu] -> ShowS
Show, ReadPrec [SelectMenu]
ReadPrec SelectMenu
Int -> ReadS SelectMenu
ReadS [SelectMenu]
(Int -> ReadS SelectMenu)
-> ReadS [SelectMenu]
-> ReadPrec SelectMenu
-> ReadPrec [SelectMenu]
-> Read SelectMenu
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SelectMenu
readsPrec :: Int -> ReadS SelectMenu
$creadList :: ReadS [SelectMenu]
readList :: ReadS [SelectMenu]
$creadPrec :: ReadPrec SelectMenu
readPrec :: ReadPrec SelectMenu
$creadListPrec :: ReadPrec [SelectMenu]
readListPrec :: ReadPrec [SelectMenu]
Read, SelectMenu -> SelectMenu -> Bool
(SelectMenu -> SelectMenu -> Bool)
-> (SelectMenu -> SelectMenu -> Bool) -> Eq SelectMenu
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SelectMenu -> SelectMenu -> Bool
== :: SelectMenu -> SelectMenu -> Bool
$c/= :: SelectMenu -> SelectMenu -> Bool
/= :: SelectMenu -> SelectMenu -> Bool
Eq, Eq SelectMenu
Eq SelectMenu =>
(SelectMenu -> SelectMenu -> Ordering)
-> (SelectMenu -> SelectMenu -> Bool)
-> (SelectMenu -> SelectMenu -> Bool)
-> (SelectMenu -> SelectMenu -> Bool)
-> (SelectMenu -> SelectMenu -> Bool)
-> (SelectMenu -> SelectMenu -> SelectMenu)
-> (SelectMenu -> SelectMenu -> SelectMenu)
-> Ord SelectMenu
SelectMenu -> SelectMenu -> Bool
SelectMenu -> SelectMenu -> Ordering
SelectMenu -> SelectMenu -> SelectMenu
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SelectMenu -> SelectMenu -> Ordering
compare :: SelectMenu -> SelectMenu -> Ordering
$c< :: SelectMenu -> SelectMenu -> Bool
< :: SelectMenu -> SelectMenu -> Bool
$c<= :: SelectMenu -> SelectMenu -> Bool
<= :: SelectMenu -> SelectMenu -> Bool
$c> :: SelectMenu -> SelectMenu -> Bool
> :: SelectMenu -> SelectMenu -> Bool
$c>= :: SelectMenu -> SelectMenu -> Bool
>= :: SelectMenu -> SelectMenu -> Bool
$cmax :: SelectMenu -> SelectMenu -> SelectMenu
max :: SelectMenu -> SelectMenu -> SelectMenu
$cmin :: SelectMenu -> SelectMenu -> SelectMenu
min :: SelectMenu -> SelectMenu -> SelectMenu
Ord)
mkSelectMenu :: T.Text -> [SelectOption] -> SelectMenu
Text
customId [SelectOption]
sos = Text
-> Bool
-> SelectMenuData
-> Maybe Text
-> Maybe Integer
-> Maybe Integer
-> SelectMenu
SelectMenu Text
customId Bool
False ([SelectOption] -> SelectMenuData
SelectMenuDataText [SelectOption]
sos) Maybe Text
forall a. Maybe a
Nothing Maybe Integer
forall a. Maybe a
Nothing Maybe Integer
forall a. Maybe a
Nothing
instance FromJSON SelectMenu where
parseJSON :: Value -> Parser SelectMenu
parseJSON =
String
-> (Object -> Parser SelectMenu) -> Value -> Parser SelectMenu
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject
String
"SelectMenu"
((Object -> Parser SelectMenu) -> Value -> Parser SelectMenu)
-> (Object -> Parser SelectMenu) -> Value -> Parser SelectMenu
forall a b. (a -> b) -> a -> b
$ \Object
v ->
do
Text
-> Bool
-> SelectMenuData
-> Maybe Text
-> Maybe Integer
-> Maybe Integer
-> SelectMenu
SelectMenu
(Text
-> Bool
-> SelectMenuData
-> Maybe Text
-> Maybe Integer
-> Maybe Integer
-> SelectMenu)
-> Parser Text
-> Parser
(Bool
-> SelectMenuData
-> Maybe Text
-> Maybe Integer
-> Maybe Integer
-> SelectMenu)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"custom_id"
Parser
(Bool
-> SelectMenuData
-> Maybe Text
-> Maybe Integer
-> Maybe Integer
-> SelectMenu)
-> Parser Bool
-> Parser
(SelectMenuData
-> Maybe Text -> Maybe Integer -> Maybe Integer -> SelectMenu)
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
"disabled" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
Parser
(SelectMenuData
-> Maybe Text -> Maybe Integer -> Maybe Integer -> SelectMenu)
-> Parser SelectMenuData
-> Parser
(Maybe Text -> Maybe Integer -> Maybe Integer -> SelectMenu)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Value -> Parser SelectMenuData
forall a. FromJSON a => Value -> Parser a
parseJSON (Object -> Value
Object Object
v)
Parser (Maybe Text -> Maybe Integer -> Maybe Integer -> SelectMenu)
-> Parser (Maybe Text)
-> Parser (Maybe Integer -> Maybe Integer -> SelectMenu)
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
"placeholder"
Parser (Maybe Integer -> Maybe Integer -> SelectMenu)
-> Parser (Maybe Integer) -> Parser (Maybe Integer -> SelectMenu)
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 Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_values"
Parser (Maybe Integer -> SelectMenu)
-> Parser (Maybe Integer) -> Parser SelectMenu
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 Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_values"
instance ToJSON SelectMenu where
toJSON :: SelectMenu -> Value
toJSON SelectMenu {Bool
Maybe Integer
Maybe Text
Text
SelectMenuData
selectMenuCustomId :: SelectMenu -> Text
selectMenuDisabled :: SelectMenu -> Bool
selectMenuData :: SelectMenu -> SelectMenuData
selectMenuPlaceholder :: SelectMenu -> Maybe Text
selectMenuMinValues :: SelectMenu -> Maybe Integer
selectMenuMaxValues :: SelectMenu -> Maybe Integer
selectMenuCustomId :: Text
selectMenuDisabled :: Bool
selectMenuData :: SelectMenuData
selectMenuPlaceholder :: Maybe Text
selectMenuMinValues :: Maybe Integer
selectMenuMaxValues :: Maybe Integer
..} =
[Maybe Pair] -> Value
objectFromMaybes ([Maybe Pair] -> Value) -> [Maybe Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[ Key
"custom_id" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
selectMenuCustomId,
Key
"disabled" Key -> Bool -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Bool
selectMenuDisabled,
Key
"placeholder" Key -> Maybe Text -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Text
selectMenuPlaceholder,
Key
"min_values" Key -> Maybe Integer -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Integer
selectMenuMinValues,
Key
"max_values" Key -> Maybe Integer -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Integer
selectMenuMaxValues
] [Maybe Pair] -> [Maybe Pair] -> [Maybe Pair]
forall a. Semigroup a => a -> a -> a
<> case SelectMenuData
selectMenuData of
SelectMenuDataText [SelectOption]
sos -> [Key
"type" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
3, Key
"options" Key -> [SelectOption] -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== [SelectOption]
sos]
SelectMenuData
SelectMenuDataUser -> [Key
"type" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
5]
SelectMenuData
SelectMenuDataRole -> [Key
"type" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
6]
SelectMenuData
SelectMenuDataMentionable -> [Key
"type" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
7]
SelectMenuDataChannels [ChannelTypeOption]
ctos -> [Key
"type" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
8, Key
"channel_types" Key -> [ChannelTypeOption] -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== [ChannelTypeOption]
ctos]
data =
[SelectOption]
|
|
|
| [ChannelTypeOption]
deriving (Int -> SelectMenuData -> ShowS
[SelectMenuData] -> ShowS
SelectMenuData -> String
(Int -> SelectMenuData -> ShowS)
-> (SelectMenuData -> String)
-> ([SelectMenuData] -> ShowS)
-> Show SelectMenuData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SelectMenuData -> ShowS
showsPrec :: Int -> SelectMenuData -> ShowS
$cshow :: SelectMenuData -> String
show :: SelectMenuData -> String
$cshowList :: [SelectMenuData] -> ShowS
showList :: [SelectMenuData] -> ShowS
Show, ReadPrec [SelectMenuData]
ReadPrec SelectMenuData
Int -> ReadS SelectMenuData
ReadS [SelectMenuData]
(Int -> ReadS SelectMenuData)
-> ReadS [SelectMenuData]
-> ReadPrec SelectMenuData
-> ReadPrec [SelectMenuData]
-> Read SelectMenuData
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SelectMenuData
readsPrec :: Int -> ReadS SelectMenuData
$creadList :: ReadS [SelectMenuData]
readList :: ReadS [SelectMenuData]
$creadPrec :: ReadPrec SelectMenuData
readPrec :: ReadPrec SelectMenuData
$creadListPrec :: ReadPrec [SelectMenuData]
readListPrec :: ReadPrec [SelectMenuData]
Read, SelectMenuData -> SelectMenuData -> Bool
(SelectMenuData -> SelectMenuData -> Bool)
-> (SelectMenuData -> SelectMenuData -> Bool) -> Eq SelectMenuData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SelectMenuData -> SelectMenuData -> Bool
== :: SelectMenuData -> SelectMenuData -> Bool
$c/= :: SelectMenuData -> SelectMenuData -> Bool
/= :: SelectMenuData -> SelectMenuData -> Bool
Eq, Eq SelectMenuData
Eq SelectMenuData =>
(SelectMenuData -> SelectMenuData -> Ordering)
-> (SelectMenuData -> SelectMenuData -> Bool)
-> (SelectMenuData -> SelectMenuData -> Bool)
-> (SelectMenuData -> SelectMenuData -> Bool)
-> (SelectMenuData -> SelectMenuData -> Bool)
-> (SelectMenuData -> SelectMenuData -> SelectMenuData)
-> (SelectMenuData -> SelectMenuData -> SelectMenuData)
-> Ord SelectMenuData
SelectMenuData -> SelectMenuData -> Bool
SelectMenuData -> SelectMenuData -> Ordering
SelectMenuData -> SelectMenuData -> SelectMenuData
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SelectMenuData -> SelectMenuData -> Ordering
compare :: SelectMenuData -> SelectMenuData -> Ordering
$c< :: SelectMenuData -> SelectMenuData -> Bool
< :: SelectMenuData -> SelectMenuData -> Bool
$c<= :: SelectMenuData -> SelectMenuData -> Bool
<= :: SelectMenuData -> SelectMenuData -> Bool
$c> :: SelectMenuData -> SelectMenuData -> Bool
> :: SelectMenuData -> SelectMenuData -> Bool
$c>= :: SelectMenuData -> SelectMenuData -> Bool
>= :: SelectMenuData -> SelectMenuData -> Bool
$cmax :: SelectMenuData -> SelectMenuData -> SelectMenuData
max :: SelectMenuData -> SelectMenuData -> SelectMenuData
$cmin :: SelectMenuData -> SelectMenuData -> SelectMenuData
min :: SelectMenuData -> SelectMenuData -> SelectMenuData
Ord)
instance FromJSON SelectMenuData where
parseJSON :: Value -> Parser SelectMenuData
parseJSON =
String
-> (Object -> Parser SelectMenuData)
-> Value
-> Parser SelectMenuData
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"SelectMenuData" ((Object -> Parser SelectMenuData)
-> Value -> Parser SelectMenuData)
-> (Object -> Parser SelectMenuData)
-> Value
-> Parser SelectMenuData
forall a b. (a -> b) -> a -> b
$ \Object
v ->
do
Int
t <- Object
v Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type"
case Int
t::Int of
Int
3 -> [SelectOption] -> SelectMenuData
SelectMenuDataText ([SelectOption] -> SelectMenuData)
-> Parser [SelectOption] -> Parser SelectMenuData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser [SelectOption]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"options"
Int
5 -> SelectMenuData -> Parser SelectMenuData
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SelectMenuData
SelectMenuDataUser
Int
6 -> SelectMenuData -> Parser SelectMenuData
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SelectMenuData
SelectMenuDataRole
Int
7 -> SelectMenuData -> Parser SelectMenuData
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SelectMenuData
SelectMenuDataMentionable
Int
8 -> [ChannelTypeOption] -> SelectMenuData
SelectMenuDataChannels ([ChannelTypeOption] -> SelectMenuData)
-> Parser [ChannelTypeOption] -> Parser SelectMenuData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v Object -> Key -> Parser [ChannelTypeOption]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"channel_types"
Int
_ -> String -> Parser SelectMenuData
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String
"unknown select menu data type: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
t)
data SelectOption = SelectOption
{
SelectOption -> Text
selectOptionLabel :: T.Text,
SelectOption -> Text
selectOptionValue :: T.Text,
SelectOption -> Maybe Text
selectOptionDescription :: Maybe T.Text,
SelectOption -> Maybe Emoji
selectOptionEmoji :: Maybe Emoji,
SelectOption -> Maybe Bool
selectOptionDefault :: Maybe Bool
}
deriving (Int -> SelectOption -> ShowS
[SelectOption] -> ShowS
SelectOption -> String
(Int -> SelectOption -> ShowS)
-> (SelectOption -> String)
-> ([SelectOption] -> ShowS)
-> Show SelectOption
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SelectOption -> ShowS
showsPrec :: Int -> SelectOption -> ShowS
$cshow :: SelectOption -> String
show :: SelectOption -> String
$cshowList :: [SelectOption] -> ShowS
showList :: [SelectOption] -> ShowS
Show, ReadPrec [SelectOption]
ReadPrec SelectOption
Int -> ReadS SelectOption
ReadS [SelectOption]
(Int -> ReadS SelectOption)
-> ReadS [SelectOption]
-> ReadPrec SelectOption
-> ReadPrec [SelectOption]
-> Read SelectOption
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS SelectOption
readsPrec :: Int -> ReadS SelectOption
$creadList :: ReadS [SelectOption]
readList :: ReadS [SelectOption]
$creadPrec :: ReadPrec SelectOption
readPrec :: ReadPrec SelectOption
$creadListPrec :: ReadPrec [SelectOption]
readListPrec :: ReadPrec [SelectOption]
Read, SelectOption -> SelectOption -> Bool
(SelectOption -> SelectOption -> Bool)
-> (SelectOption -> SelectOption -> Bool) -> Eq SelectOption
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SelectOption -> SelectOption -> Bool
== :: SelectOption -> SelectOption -> Bool
$c/= :: SelectOption -> SelectOption -> Bool
/= :: SelectOption -> SelectOption -> Bool
Eq, Eq SelectOption
Eq SelectOption =>
(SelectOption -> SelectOption -> Ordering)
-> (SelectOption -> SelectOption -> Bool)
-> (SelectOption -> SelectOption -> Bool)
-> (SelectOption -> SelectOption -> Bool)
-> (SelectOption -> SelectOption -> Bool)
-> (SelectOption -> SelectOption -> SelectOption)
-> (SelectOption -> SelectOption -> SelectOption)
-> Ord SelectOption
SelectOption -> SelectOption -> Bool
SelectOption -> SelectOption -> Ordering
SelectOption -> SelectOption -> SelectOption
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: SelectOption -> SelectOption -> Ordering
compare :: SelectOption -> SelectOption -> Ordering
$c< :: SelectOption -> SelectOption -> Bool
< :: SelectOption -> SelectOption -> Bool
$c<= :: SelectOption -> SelectOption -> Bool
<= :: SelectOption -> SelectOption -> Bool
$c> :: SelectOption -> SelectOption -> Bool
> :: SelectOption -> SelectOption -> Bool
$c>= :: SelectOption -> SelectOption -> Bool
>= :: SelectOption -> SelectOption -> Bool
$cmax :: SelectOption -> SelectOption -> SelectOption
max :: SelectOption -> SelectOption -> SelectOption
$cmin :: SelectOption -> SelectOption -> SelectOption
min :: SelectOption -> SelectOption -> SelectOption
Ord)
mkSelectOption :: T.Text -> T.Text -> SelectOption
mkSelectOption :: Text -> Text -> SelectOption
mkSelectOption Text
label Text
value = Text
-> Text -> Maybe Text -> Maybe Emoji -> Maybe Bool -> SelectOption
SelectOption Text
label Text
value Maybe Text
forall a. Maybe a
Nothing Maybe Emoji
forall a. Maybe a
Nothing Maybe Bool
forall a. Maybe a
Nothing
instance FromJSON SelectOption where
parseJSON :: Value -> Parser SelectOption
parseJSON = String
-> (Object -> Parser SelectOption) -> Value -> Parser SelectOption
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"SelectOption" ((Object -> Parser SelectOption) -> Value -> Parser SelectOption)
-> (Object -> Parser SelectOption) -> Value -> Parser SelectOption
forall a b. (a -> b) -> a -> b
$ \Object
o ->
Text
-> Text -> Maybe Text -> Maybe Emoji -> Maybe Bool -> SelectOption
SelectOption (Text
-> Text -> Maybe Text -> Maybe Emoji -> Maybe Bool -> SelectOption)
-> Parser Text
-> Parser
(Text -> Maybe Text -> Maybe Emoji -> Maybe Bool -> SelectOption)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"label"
Parser
(Text -> Maybe Text -> Maybe Emoji -> Maybe Bool -> SelectOption)
-> Parser Text
-> Parser (Maybe Text -> Maybe Emoji -> Maybe Bool -> SelectOption)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"value"
Parser (Maybe Text -> Maybe Emoji -> Maybe Bool -> SelectOption)
-> Parser (Maybe Text)
-> Parser (Maybe Emoji -> Maybe Bool -> SelectOption)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"description"
Parser (Maybe Emoji -> Maybe Bool -> SelectOption)
-> Parser (Maybe Emoji) -> Parser (Maybe Bool -> SelectOption)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Emoji)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"emoji"
Parser (Maybe Bool -> SelectOption)
-> Parser (Maybe Bool) -> Parser SelectOption
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"default"
instance ToJSON SelectOption where
toJSON :: SelectOption -> Value
toJSON SelectOption {Maybe Bool
Maybe Text
Maybe Emoji
Text
selectOptionLabel :: SelectOption -> Text
selectOptionValue :: SelectOption -> Text
selectOptionDescription :: SelectOption -> Maybe Text
selectOptionEmoji :: SelectOption -> Maybe Emoji
selectOptionDefault :: SelectOption -> Maybe Bool
selectOptionLabel :: Text
selectOptionValue :: Text
selectOptionDescription :: Maybe Text
selectOptionEmoji :: Maybe Emoji
selectOptionDefault :: Maybe Bool
..} =
[Maybe Pair] -> Value
objectFromMaybes
[ Key
"label" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
selectOptionLabel,
Key
"value" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
selectOptionValue,
Key
"description" Key -> Maybe Text -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Text
selectOptionDescription,
Key
"emoji" Key -> Maybe Emoji -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Emoji
selectOptionEmoji,
Key
"default" Key -> Maybe Bool -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Bool
selectOptionDefault
]
data TextInput = TextInput
{
TextInput -> Text
textInputCustomId :: T.Text,
TextInput -> Bool
textInputIsParagraph :: Bool,
TextInput -> Text
textInputLabel :: T.Text,
TextInput -> Maybe Integer
textInputMinLength :: Maybe Integer,
TextInput -> Maybe Integer
textInputMaxLength :: Maybe Integer,
TextInput -> Bool
textInputRequired :: Bool,
TextInput -> Text
textInputValue :: T.Text,
TextInput -> Text
textInputPlaceholder :: T.Text
}
deriving (Int -> TextInput -> ShowS
[TextInput] -> ShowS
TextInput -> String
(Int -> TextInput -> ShowS)
-> (TextInput -> String)
-> ([TextInput] -> ShowS)
-> Show TextInput
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TextInput -> ShowS
showsPrec :: Int -> TextInput -> ShowS
$cshow :: TextInput -> String
show :: TextInput -> String
$cshowList :: [TextInput] -> ShowS
showList :: [TextInput] -> ShowS
Show, ReadPrec [TextInput]
ReadPrec TextInput
Int -> ReadS TextInput
ReadS [TextInput]
(Int -> ReadS TextInput)
-> ReadS [TextInput]
-> ReadPrec TextInput
-> ReadPrec [TextInput]
-> Read TextInput
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS TextInput
readsPrec :: Int -> ReadS TextInput
$creadList :: ReadS [TextInput]
readList :: ReadS [TextInput]
$creadPrec :: ReadPrec TextInput
readPrec :: ReadPrec TextInput
$creadListPrec :: ReadPrec [TextInput]
readListPrec :: ReadPrec [TextInput]
Read, TextInput -> TextInput -> Bool
(TextInput -> TextInput -> Bool)
-> (TextInput -> TextInput -> Bool) -> Eq TextInput
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TextInput -> TextInput -> Bool
== :: TextInput -> TextInput -> Bool
$c/= :: TextInput -> TextInput -> Bool
/= :: TextInput -> TextInput -> Bool
Eq, Eq TextInput
Eq TextInput =>
(TextInput -> TextInput -> Ordering)
-> (TextInput -> TextInput -> Bool)
-> (TextInput -> TextInput -> Bool)
-> (TextInput -> TextInput -> Bool)
-> (TextInput -> TextInput -> Bool)
-> (TextInput -> TextInput -> TextInput)
-> (TextInput -> TextInput -> TextInput)
-> Ord TextInput
TextInput -> TextInput -> Bool
TextInput -> TextInput -> Ordering
TextInput -> TextInput -> TextInput
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: TextInput -> TextInput -> Ordering
compare :: TextInput -> TextInput -> Ordering
$c< :: TextInput -> TextInput -> Bool
< :: TextInput -> TextInput -> Bool
$c<= :: TextInput -> TextInput -> Bool
<= :: TextInput -> TextInput -> Bool
$c> :: TextInput -> TextInput -> Bool
> :: TextInput -> TextInput -> Bool
$c>= :: TextInput -> TextInput -> Bool
>= :: TextInput -> TextInput -> Bool
$cmax :: TextInput -> TextInput -> TextInput
max :: TextInput -> TextInput -> TextInput
$cmin :: TextInput -> TextInput -> TextInput
min :: TextInput -> TextInput -> TextInput
Ord)
instance ToJSON TextInput where
toJSON :: TextInput -> Value
toJSON TextInput {Bool
Maybe Integer
Text
textInputCustomId :: TextInput -> Text
textInputIsParagraph :: TextInput -> Bool
textInputLabel :: TextInput -> Text
textInputMinLength :: TextInput -> Maybe Integer
textInputMaxLength :: TextInput -> Maybe Integer
textInputRequired :: TextInput -> Bool
textInputValue :: TextInput -> Text
textInputPlaceholder :: TextInput -> Text
textInputCustomId :: Text
textInputIsParagraph :: Bool
textInputLabel :: Text
textInputMinLength :: Maybe Integer
textInputMaxLength :: Maybe Integer
textInputRequired :: Bool
textInputValue :: Text
textInputPlaceholder :: Text
..} =
[Maybe Pair] -> Value
objectFromMaybes
[ Key
"type" Key -> Value -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Scientific -> Value
Number Scientific
4,
Key
"custom_id" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
textInputCustomId,
Key
"style" Key -> Int -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== (Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Bool -> Int
forall a. Enum a => a -> Int
fromEnum Bool
textInputIsParagraph),
Key
"label" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
textInputLabel,
Key
"min_length" Key -> Maybe Integer -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Integer
textInputMinLength,
Key
"max_length" Key -> Maybe Integer -> Maybe Pair
forall a. ToJSON a => Key -> Maybe a -> Maybe Pair
.=? Maybe Integer
textInputMaxLength,
Key
"required" Key -> Bool -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Bool
textInputRequired,
Key
"value" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
textInputValue,
Key
"placeholder" Key -> Text -> Maybe Pair
forall a. ToJSON a => Key -> a -> Maybe Pair
.== Text
textInputPlaceholder
]
instance FromJSON TextInput where
parseJSON :: Value -> Parser TextInput
parseJSON = String -> (Object -> Parser TextInput) -> Value -> Parser TextInput
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"TextInput" ((Object -> Parser TextInput) -> Value -> Parser TextInput)
-> (Object -> Parser TextInput) -> Value -> Parser TextInput
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Int
t <- Object
o Object -> Key -> Parser Int
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"type" :: Parser Int
case Int
t of
Int
4 ->
Text
-> Bool
-> Text
-> Maybe Integer
-> Maybe Integer
-> Bool
-> Text
-> Text
-> TextInput
TextInput (Text
-> Bool
-> Text
-> Maybe Integer
-> Maybe Integer
-> Bool
-> Text
-> Text
-> TextInput)
-> Parser Text
-> Parser
(Bool
-> Text
-> Maybe Integer
-> Maybe Integer
-> Bool
-> Text
-> Text
-> TextInput)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"custom_id"
Parser
(Bool
-> Text
-> Maybe Integer
-> Maybe Integer
-> Bool
-> Text
-> Text
-> TextInput)
-> Parser Bool
-> Parser
(Text
-> Maybe Integer
-> Maybe Integer
-> Bool
-> Text
-> Text
-> TextInput)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> Bool) -> Parser Int -> Parser Bool
forall a b. (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== (Int
2 :: Int)) (Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"style" Parser (Maybe Int) -> Int -> Parser Int
forall a. Parser (Maybe a) -> a -> Parser a
.!= Int
1)
Parser
(Text
-> Maybe Integer
-> Maybe Integer
-> Bool
-> Text
-> Text
-> TextInput)
-> Parser Text
-> Parser
(Maybe Integer
-> Maybe Integer -> Bool -> Text -> Text -> TextInput)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"label" Parser (Maybe Text) -> Text -> Parser Text
forall a. Parser (Maybe a) -> a -> Parser a
.!= Text
""
Parser
(Maybe Integer
-> Maybe Integer -> Bool -> Text -> Text -> TextInput)
-> Parser (Maybe Integer)
-> Parser (Maybe Integer -> Bool -> Text -> Text -> TextInput)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"min_length"
Parser (Maybe Integer -> Bool -> Text -> Text -> TextInput)
-> Parser (Maybe Integer)
-> Parser (Bool -> Text -> Text -> TextInput)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"max_length"
Parser (Bool -> Text -> Text -> TextInput)
-> Parser Bool -> Parser (Text -> Text -> TextInput)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"required" Parser (Maybe Bool) -> Bool -> Parser Bool
forall a. Parser (Maybe a) -> a -> Parser a
.!= Bool
False
Parser (Text -> Text -> TextInput)
-> Parser Text -> Parser (Text -> TextInput)
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"value" Parser (Maybe Text) -> Text -> Parser Text
forall a. Parser (Maybe a) -> a -> Parser a
.!= Text
""
Parser (Text -> TextInput) -> Parser Text -> Parser TextInput
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"placeholder" Parser (Maybe Text) -> Text -> Parser Text
forall a. Parser (Maybe a) -> a -> Parser a
.!= Text
""
Int
_ -> String -> Parser TextInput
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"expected text input, found other type of component"
mkTextInput :: T.Text -> T.Text -> TextInput
mkTextInput :: Text -> Text -> TextInput
mkTextInput Text
cid Text
label = Text
-> Bool
-> Text
-> Maybe Integer
-> Maybe Integer
-> Bool
-> Text
-> Text
-> TextInput
TextInput Text
cid Bool
False Text
label Maybe Integer
forall a. Maybe a
Nothing Maybe Integer
forall a. Maybe a
Nothing Bool
True Text
"" Text
""