tgbotxx 1.1.6.9
Telegram Bot C++ Library
Loading...
Searching...
No Matches
Sticker.hpp
Go to the documentation of this file.
1#pragma once
6
7namespace tgbotxx {
10 struct Sticker {
11 Sticker() = default;
12 explicit Sticker(const nl::json& json) {
13 fromJson(json);
14 }
15
17 std::string fileId;
18
21 std::string fileUniqueId;
22
24 enum class Type : std::uint8_t {
25 Regular = 0,
26 Mask,
28 };
29 inline static constexpr const char *Type2Str[] = {"regular", "mask", "custom_emoji"};
30 inline static constexpr Type Str2Type(const std::string& str) {
31 std::uint8_t i = 0;
32 for (const char *v: Type2Str) {
33 if (str == v)
34 return static_cast<Type>(i);
35 ++i;
36 }
37 throw Exception("Could not convert Sticker type string \"" + str + "\" to enum Type");
38 }
42
44 std::int32_t width{};
45
47 std::int32_t height{};
48
50 bool isAnimated{};
51
53 bool isVideo{};
54
57
59 std::string emoji;
60
62 std::string setName;
63
66
69
71 std::string customEmojiId;
72
77
79 std::int64_t fileSize{};
80
81
84 nl::json toJson() const {
85 nl::json json = nl::json::object();
86 OBJECT_SERIALIZE_FIELD(json, "file_id", fileId);
87 OBJECT_SERIALIZE_FIELD(json, "file_unique_id", fileUniqueId);
88 json["type"] = Type2Str[static_cast<std::size_t>(type)];// enum
89 OBJECT_SERIALIZE_FIELD(json, "width", width);
90 OBJECT_SERIALIZE_FIELD(json, "height", height);
91 OBJECT_SERIALIZE_FIELD(json, "is_animated", isAnimated);
92 OBJECT_SERIALIZE_FIELD(json, "is_video", isVideo);
93 OBJECT_SERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail);
94 OBJECT_SERIALIZE_FIELD(json, "emoji", emoji);
95 OBJECT_SERIALIZE_FIELD(json, "set_name", setName);
96 OBJECT_SERIALIZE_FIELD_PTR(json, "premium_animation", premiumAnimation);
97 OBJECT_SERIALIZE_FIELD_PTR(json, "mask_position", maskPosition);
98 OBJECT_SERIALIZE_FIELD(json, "custom_emoji_id", customEmojiId);
99 OBJECT_SERIALIZE_FIELD(json, "needs_repainting", needsRepainting);
100 OBJECT_SERIALIZE_FIELD(json, "file_size", fileSize);
101 return json;
102 }
103
105 void fromJson(const nl::json& json) {
106 OBJECT_DESERIALIZE_FIELD(json, "file_id", fileId, "", false);
107 OBJECT_DESERIALIZE_FIELD(json, "file_unique_id", fileUniqueId, "", false);
108 type = Str2Type(json["type"]);// enum
109 OBJECT_DESERIALIZE_FIELD(json, "width", width, 0, false);
110 OBJECT_DESERIALIZE_FIELD(json, "height", height, 0, false);
111 OBJECT_DESERIALIZE_FIELD(json, "is_animated", isAnimated, false, false);
112 OBJECT_DESERIALIZE_FIELD(json, "is_video", isVideo, false, false);
113 OBJECT_DESERIALIZE_FIELD_PTR(json, "thumbnail", thumbnail, true);
114 OBJECT_DESERIALIZE_FIELD(json, "emoji", emoji, "", true);
115 OBJECT_DESERIALIZE_FIELD(json, "set_name", setName, "", true);
116 OBJECT_DESERIALIZE_FIELD_PTR(json, "premium_animation", premiumAnimation, true);
117 OBJECT_DESERIALIZE_FIELD_PTR(json, "mask_position", maskPosition, true);
118 OBJECT_DESERIALIZE_FIELD(json, "custom_emoji_id", customEmojiId, "", true);
119 OBJECT_DESERIALIZE_FIELD(json, "needs_repainting", needsRepainting, false, true);
120 OBJECT_DESERIALIZE_FIELD(json, "file_size", fileSize, 0, true);
121 }
122 };
123}
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition Object.hpp:22
#define OBJECT_DESERIALIZE_FIELD_PTR(json, json_field, field, optional)
Definition Object.hpp:70
#define OBJECT_SERIALIZE_FIELD(json, json_field, field)
Available objects: https://core.telegram.org/bots/api#available-types.
Definition Object.hpp:19
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition Object.hpp:44
tgbotxx::Exception
Definition Exception.hpp:91
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
This object represents a sticker. https://core.telegram.org/bots/api#sticker.
Definition Sticker.hpp:10
Type type
Type of the sticker, currently one of “regular”, “mask”, “custom_emoji”. The type of the sticker is i...
Definition Sticker.hpp:41
Sticker()=default
static constexpr const char * Type2Str[]
Definition Sticker.hpp:29
std::string emoji
Optional. Emoji associated with the sticker.
Definition Sticker.hpp:59
bool isVideo
True, if the sticker is a video sticker.
Definition Sticker.hpp:53
std::string fileUniqueId
Unique identifier for this file, which is supposed to be the same over time and for different bots....
Definition Sticker.hpp:21
Sticker(const nl::json &json)
Definition Sticker.hpp:12
Type
Enum of possible types of a Sticker.
Definition Sticker.hpp:24
std::int64_t fileSize
Optional. File size in bytes.
Definition Sticker.hpp:79
std::int32_t height
Sticker height.
Definition Sticker.hpp:47
bool needsRepainting
Optional. True, if the sticker must be repainted to a text color in messages, the color of the Telegr...
Definition Sticker.hpp:76
static constexpr Type Str2Type(const std::string &str)
Definition Sticker.hpp:30
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition Sticker.hpp:105
std::string customEmojiId
Optional. For custom emoji stickers, unique identifier of the custom emoji.
Definition Sticker.hpp:71
std::string setName
Optional. Name of the sticker set to which the sticker belongs.
Definition Sticker.hpp:62
std::int32_t width
Sticker width.
Definition Sticker.hpp:44
Ptr< File > premiumAnimation
Optional. For premium regular stickers, premium animation for the sticker.
Definition Sticker.hpp:65
nl::json toJson() const
Serializes this object to JSON.
Definition Sticker.hpp:84
std::string fileId
Identifier for this file, which can be used to download or reuse the file.
Definition Sticker.hpp:17
Ptr< MaskPosition > maskPosition
Optional. For mask stickers, the position where the mask should be placed.
Definition Sticker.hpp:68
bool isAnimated
True, if the sticker is animated.
Definition Sticker.hpp:50
Ptr< PhotoSize > thumbnail
Optional. Sticker thumbnail in the .WEBP or .JPG format.
Definition Sticker.hpp:56