-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from fizruk/bot-api-7.3
Bot API 7.3
- Loading branch information
Showing
18 changed files
with
379 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
telegram-bot-api/src/Telegram/Bot/API/Types/BackgroundFill.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{-# LANGUAGE BlockArguments #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Telegram.Bot.API.Types.BackgroundFill where | ||
|
||
import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), (.=), (.:), withObject) | ||
import Data.Aeson.Types (Parser) | ||
import Data.Text | ||
import GHC.Generics (Generic) | ||
|
||
import qualified Data.Text as Text | ||
|
||
import Telegram.Bot.API.Types.Common | ||
import Telegram.Bot.API.Internal.Utils | ||
|
||
-- ** 'BackgroundFill' | ||
|
||
-- | This object describes the way a background is filled based on the selected colors. Currently, it can be one of | ||
-- | ||
-- * BackgroundFillSolid | ||
-- * BackgroundFillGradient | ||
-- * BackgroundFillFreeformGradient | ||
-- | ||
data BackgroundFill | ||
-- | The background is filled using the selected color. | ||
= BackgroundFillSolid | ||
{ backgroundFillSolidType :: Text -- ^ Type of the background fill, always “solid”. | ||
, backgroundFillSolidColor :: Int -- ^ The color of the background fill in the RGB24 format. | ||
} | ||
-- | The background is a gradient fill. | ||
| BackgroundFillGradient | ||
{ backgroundFillGradientType :: Text -- ^ Type of the background fill, always “gradient”. | ||
, backgroundFillGradientTopColor :: Int -- ^ Top color of the gradient in the RGB24 format. | ||
, backgroundFillGradientBottomColor :: Int -- ^ Bottom color of the gradient in the RGB24 format. | ||
, backgroundFillGradientRotationAngle :: Int -- ^ Clockwise rotation angle of the background fill in degrees; @0-359@. | ||
} | ||
-- | The background is a freeform gradient that rotates after every message in the chat. | ||
| BackgroundFillFreeformGradient | ||
{ backgroundFillFreeformGradientType :: Text -- ^ Type of the background fill, always “freeform_gradient”. | ||
, backgroundFillFreeformGradientColors :: [Int] -- ^ A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format. | ||
} | ||
deriving (Generic, Show) | ||
|
||
instance ToJSON BackgroundFill where | ||
toJSON = \case | ||
BackgroundFillSolid _t c -> addJsonFields | ||
(Object mempty) | ||
(addType "solid" ["color" .= c]) | ||
BackgroundFillGradient _t tc bc ra -> addJsonFields | ||
(Object mempty) | ||
(addType "gradient" ["top_color" .= tc, "bottom_color" .= bc, "rotation_angle" .= ra]) | ||
BackgroundFillFreeformGradient _t cs -> addJsonFields | ||
(Object mempty) | ||
(addType "freeform_gradient" ["colors" .= cs]) | ||
|
||
instance FromJSON BackgroundFill where | ||
parseJSON = withObject "BackgroundFill" \o -> | ||
(o .: "type" :: Parser Text) >>= \case | ||
"solid" -> BackgroundFillSolid | ||
<$> o .: "type" | ||
<*> o .: "color" | ||
"gradient" ->BackgroundFillGradient | ||
<$> o .: "type" | ||
<*> o .: "top_color" | ||
<*> o .: "bottom_color" | ||
<*> o .: "rotation_angle" | ||
"freeform_gradient" -> BackgroundFillFreeformGradient | ||
<$> o .: "type" | ||
<*> o .: "colors" | ||
t -> fail $ Text.unpack ("Unknown type: " <> t) |
97 changes: 97 additions & 0 deletions
97
telegram-bot-api/src/Telegram/Bot/API/Types/BackgroundType.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{-# LANGUAGE BlockArguments #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Telegram.Bot.API.Types.BackgroundType where | ||
|
||
import Data.Aeson (FromJSON (..), ToJSON (..), Value (..), (.=), (.:), withObject) | ||
import Data.Aeson.Types (Parser) | ||
import Data.Text (Text) | ||
import GHC.Generics (Generic) | ||
|
||
import qualified Data.Text as Text | ||
|
||
import Telegram.Bot.API.Types.BackgroundFill | ||
import Telegram.Bot.API.Types.Common | ||
import Telegram.Bot.API.Types.Document | ||
import Telegram.Bot.API.Internal.Utils | ||
|
||
-- ** 'BackgroundType' | ||
|
||
-- | This object describes the type of a background. Currently, it can be one of | ||
-- | ||
-- * BackgroundTypeFill | ||
-- * BackgroundTypeWallpaper | ||
-- * BackgroundTypePattern | ||
-- * BackgroundTypeChatTheme | ||
-- | ||
data BackgroundType | ||
-- | The background is automatically filled based on the selected colors. | ||
= BackgroundTypeFill | ||
{ backgroundTypeFillType :: Text -- ^ Type of the background, always “fill”. | ||
, backgroundTypeFillFill :: BackgroundFill -- ^ The background fill. | ||
, backgroundTypeFillDarkThemeDimming :: Int -- ^ Dimming of the background in dark themes, as a percentage; @0-100@. | ||
} | ||
-- | The background is a wallpaper in the JPEG format. | ||
| BackgroundTypeWallpaper | ||
{ backgroundTypeWallpaperType :: Text -- ^ Type of the background, always “wallpaper”. | ||
, backgroundTypeWallpaperDocument :: Document -- ^ Document with the wallpaper. | ||
, backgroundTypeWallpaperDarkThemeDimming :: Int -- ^ Dimming of the background in dark themes, as a percentage; @0-100@. | ||
, backgroundTypeWallpaperIsBlurred :: Maybe Bool -- ^ 'True', if the wallpaper is downscaled to fit in a @450x450@ square and then box-blurred with radius 12. | ||
, backgroundTypeWallpaperIsMoving :: Maybe Bool -- ^ 'True', if the background moves slightly when the device is tilted. | ||
} | ||
-- | The background is a PNG or TGV (gzipped subset of SVG with MIME type “application/x-tgwallpattern”) pattern to be combined with the background fill chosen by the user. | ||
| BackgroundTypePattern | ||
{ backgroundTypePatternType :: Text -- ^ Type of the background, always “pattern”. | ||
, backgroundTypePatternDocument :: Document -- ^ Document with the pattern. | ||
, backgroundTypePatternFill :: BackgroundFill -- ^ The background fill that is combined with the pattern. | ||
, backgroundTypePatternIntensity :: Int -- ^ Intensity of the pattern when it is shown above the filled background; @0-100@. | ||
, backgroundTypePatternIsInverted :: Maybe Bool -- ^ 'True', if the background fill must be applied only to the pattern itself. All other pixels are black in this case. For dark themes only. | ||
, backgroundTypePatternIsMoving :: Maybe Bool -- ^ 'True', if the background moves slightly when the device is tilted. | ||
} | ||
-- | The background is taken directly from a built-in chat theme. | ||
| BackgroundTypeChatTheme | ||
{ backgroundTypeChatThemeType :: Text -- ^ Type of the background, always “chat_theme”. | ||
, backgroundTypeChatThemeThemeName :: Text -- ^ Name of the chat theme, which is usually an emoji. | ||
} | ||
deriving (Generic, Show) | ||
|
||
instance ToJSON BackgroundType where | ||
toJSON = \case | ||
BackgroundTypeFill _t f dtd -> addJsonFields | ||
(Object mempty) | ||
(addType "fill" ["fill" .= f, "dark_theme_dimming" .= dtd]) | ||
BackgroundTypeWallpaper _t d dtd ib im -> addJsonFields | ||
(Object mempty) | ||
(addType "wallpaper" ["document" .= d, "dark_theme_dimming" .= dtd, "is_blurred" .= ib, "is_moving" .= im]) | ||
BackgroundTypePattern _t d f i ii im -> addJsonFields | ||
(Object mempty) | ||
(addType "pattern" ["document" .= d, "fill" .= f, "intensity" .= i, "is_inverted" .= ii, "is_moving" .= im]) | ||
BackgroundTypeChatTheme _t tn -> addJsonFields | ||
(Object mempty) | ||
(addType "chat_theme" ["theme_name" .= tn]) | ||
|
||
instance FromJSON BackgroundType where | ||
parseJSON = withObject "BackgroundType" \o -> | ||
(o .: "type" :: Parser Text) >>= \case | ||
"fill" -> BackgroundTypeFill | ||
<$> o .: "type" | ||
<*> o .: "fill" | ||
<*> o .: "dark_theme_dimming" | ||
"wallpaper" -> BackgroundTypeWallpaper | ||
<$> o .: "type" | ||
<*> o .: "document" | ||
<*> o .: "dark_theme_dimming" | ||
<*> o .: "is_blurred" | ||
<*> o .: "is_moving" | ||
"pattern" -> BackgroundTypePattern | ||
<$> o .: "type" | ||
<*> o .: "document" | ||
<*> o .: "fill" | ||
<*> o .: "intensity" | ||
<*> o .: "is_inverted" | ||
<*> o .: "is_moving" | ||
"chat_theme" -> BackgroundTypeChatTheme | ||
<$> o .: "type" | ||
<*> o .: "theme_name" | ||
t -> fail $ Text.unpack ("Unknown type: " <> t) |
Oops, something went wrong.