tgbotxx  1.1.6.9
Telegram Bot C++ Library
ChatMember.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 namespace tgbotxx {
15  struct ChatMember {
16  ChatMember() = default;
17  explicit ChatMember(const nl::json& json) {
18  fromJson(json);
19  }
20 
22  std::string status;
23 
26 
29  nl::json toJson() const {
30  nl::json json = nl::json::object();
31  OBJECT_SERIALIZE_FIELD(json, "status", status);
32  OBJECT_SERIALIZE_FIELD_PTR(json, "user", user);
33  return json;
34  }
35 
37  void fromJson(const nl::json& json) {
38  OBJECT_DESERIALIZE_FIELD(json, "status", status, "", false);
39  OBJECT_DESERIALIZE_FIELD_PTR(json, "user", user, false);
40  }
41  };
42 
46  ChatMemberOwner() = default;
47  explicit ChatMemberOwner(const nl::json& json) : ChatMember(json) {
48  fromJson(json);
49  ChatMember::status = "creator";
50  }
51 
53  bool isAnonymous{};
54 
56  std::string customTitle;
57 
60  nl::json toJson() const {
61  nl::json json = ChatMember::toJson();
62  OBJECT_SERIALIZE_FIELD(json, "is_anonymous", isAnonymous);
63  OBJECT_SERIALIZE_FIELD(json, "custom_title", customTitle);
64  return json;
65  }
66 
68  void fromJson(const nl::json& json) {
70  OBJECT_DESERIALIZE_FIELD(json, "is_anonymous", isAnonymous, false, false);
71  OBJECT_DESERIALIZE_FIELD(json, "custom_title", customTitle, "", true);
72  }
73  };
74 
75 
80  explicit ChatMemberAdministrator(const nl::json& json) : ChatMember(json) {
81  fromJson(json);
82  ChatMember::status = "administrator";
83  }
84 
86  bool canBeEdited{};
87 
89  bool isAnonymous{};
90 
94  bool canManageChat{};
95 
98 
101 
104 
108 
111 
114 
117 
120 
123 
126 
129 
132 
135 
137  std::string customTitle;
138 
139 
142  nl::json toJson() const {
143  nl::json json = ChatMember::toJson();
144  OBJECT_SERIALIZE_FIELD(json, "can_be_edited", canBeEdited);
145  OBJECT_SERIALIZE_FIELD(json, "is_anonymous", isAnonymous);
146  OBJECT_SERIALIZE_FIELD(json, "can_manage_chat", canManageChat);
147  OBJECT_SERIALIZE_FIELD(json, "can_delete_messages", canDeleteMessages);
148  OBJECT_SERIALIZE_FIELD(json, "can_manage_video_chats", canManageVideoChats);
149  OBJECT_SERIALIZE_FIELD(json, "can_restrict_members", canRestrictMembers);
150  OBJECT_SERIALIZE_FIELD(json, "can_promote_members", canPromoteMembers);
151  OBJECT_SERIALIZE_FIELD(json, "can_change_info", canChangeInfo);
152  OBJECT_SERIALIZE_FIELD(json, "can_invite_users", canInviteUsers);
153  OBJECT_SERIALIZE_FIELD(json, "can_post_messages", canPostMessages);
154  OBJECT_SERIALIZE_FIELD(json, "can_edit_messages", canEditMessages);
155  OBJECT_SERIALIZE_FIELD(json, "can_pin_messages", canPinMessages);
156  OBJECT_SERIALIZE_FIELD(json, "can_post_stories", canPostStories);
157  OBJECT_SERIALIZE_FIELD(json, "can_edit_stories", canEditStories);
158  OBJECT_SERIALIZE_FIELD(json, "can_delete_stories", canDeleteStories);
159  OBJECT_SERIALIZE_FIELD(json, "can_manage_topics", canManageTopics);
160  OBJECT_SERIALIZE_FIELD(json, "custom_title", customTitle);
161  return json;
162  }
163 
165  void fromJson(const nl::json& json) {
166  ChatMember::fromJson(json);
167  OBJECT_DESERIALIZE_FIELD(json, "can_be_edited", canBeEdited, false, false);
168  OBJECT_DESERIALIZE_FIELD(json, "is_anonymous", isAnonymous, false, false);
169  OBJECT_DESERIALIZE_FIELD(json, "can_manage_chat", canManageChat, false, false);
170  OBJECT_DESERIALIZE_FIELD(json, "can_delete_messages", canDeleteMessages, false, false);
171  OBJECT_DESERIALIZE_FIELD(json, "can_manage_video_chats", canManageVideoChats, false, false);
172  OBJECT_DESERIALIZE_FIELD(json, "can_restrict_members", canRestrictMembers, false, false);
173  OBJECT_DESERIALIZE_FIELD(json, "can_promote_members", canPromoteMembers, false, false);
174  OBJECT_DESERIALIZE_FIELD(json, "can_change_info", canChangeInfo, false, false);
175  OBJECT_DESERIALIZE_FIELD(json, "can_invite_users", canInviteUsers, false, false);
176  OBJECT_DESERIALIZE_FIELD(json, "can_post_messages", canPostMessages, false, true);
177  OBJECT_DESERIALIZE_FIELD(json, "can_edit_messages", canEditMessages, false, true);
178  OBJECT_DESERIALIZE_FIELD(json, "can_pin_messages", canPinMessages, false, true);
179  OBJECT_DESERIALIZE_FIELD(json, "can_post_stories", canPostStories, false, true);
180  OBJECT_DESERIALIZE_FIELD(json, "can_edit_stories", canEditStories, false, true);
181  OBJECT_DESERIALIZE_FIELD(json, "can_delete_stories", canDeleteStories, false, true);
182  OBJECT_DESERIALIZE_FIELD(json, "can_manage_topics", canManageTopics, false, true);
183  OBJECT_DESERIALIZE_FIELD(json, "custom_title", customTitle, "", true);
184  }
185  };
186 
187 
191  ChatMemberMember() = default;
192  explicit ChatMemberMember(const nl::json& json) : ChatMember(json) {
193  ChatMember::status = "member";
194  }
195  };
196 
197 
201  ChatMemberRestricted() = default;
202  explicit ChatMemberRestricted(const nl::json& json) : ChatMember(json) {
203  fromJson(json);
204  ChatMember::status = "restricted";
205  }
206 
208  bool isMember{};
209 
212 
215 
218 
221 
224 
227 
230 
232  bool canSendPolls{};
233 
236 
239 
242 
245 
248 
251 
253  std::time_t untilDate{};
254 
255 
258  nl::json toJson() const {
259  nl::json json = ChatMember::toJson();
260  OBJECT_SERIALIZE_FIELD(json, "is_member", isMember);
261  OBJECT_SERIALIZE_FIELD(json, "can_send_messages", canSendMessages);
262  OBJECT_SERIALIZE_FIELD(json, "can_send_audios", canSendAudios);
263  OBJECT_SERIALIZE_FIELD(json, "can_send_documents", canSendDocuments);
264  OBJECT_SERIALIZE_FIELD(json, "can_send_photos", canSendPhotos);
265  OBJECT_SERIALIZE_FIELD(json, "can_send_videos", canSendVideos);
266  OBJECT_SERIALIZE_FIELD(json, "can_send_video_notes", canSendVideoNotes);
267  OBJECT_SERIALIZE_FIELD(json, "can_send_voice_notes", canSendVoiceNotes);
268  OBJECT_SERIALIZE_FIELD(json, "can_send_polls", canSendPolls);
269  OBJECT_SERIALIZE_FIELD(json, "can_send_other_messages", canSendOtherMessages);
270  OBJECT_SERIALIZE_FIELD(json, "can_add_web_page_previews", canAddWebPagePreviews);
271  OBJECT_SERIALIZE_FIELD(json, "can_change_info", canChangeInfo);
272  OBJECT_SERIALIZE_FIELD(json, "can_invite_users", canInviteUsers);
273  OBJECT_SERIALIZE_FIELD(json, "can_pin_messages", canPinMessages);
274  OBJECT_SERIALIZE_FIELD(json, "can_manage_topics", canManageTopics);
275  OBJECT_SERIALIZE_FIELD(json, "until_date", untilDate);
276  return json;
277  }
278 
280  void fromJson(const nl::json& json) {
281  ChatMember::fromJson(json);
282  OBJECT_DESERIALIZE_FIELD(json, "is_member", isMember, false, false);
283  OBJECT_DESERIALIZE_FIELD(json, "can_send_messages", canSendMessages, false, false);
284  OBJECT_DESERIALIZE_FIELD(json, "can_send_audios", canSendAudios, false, false);
285  OBJECT_DESERIALIZE_FIELD(json, "can_send_documents", canSendDocuments, false, false);
286  OBJECT_DESERIALIZE_FIELD(json, "can_send_photos", canSendPhotos, false, false);
287  OBJECT_DESERIALIZE_FIELD(json, "can_send_videos", canSendVideos, false, false);
288  OBJECT_DESERIALIZE_FIELD(json, "can_send_video_notes", canSendVideoNotes, false, false);
289  OBJECT_DESERIALIZE_FIELD(json, "can_send_voice_notes", canSendVoiceNotes, false, false);
290  OBJECT_DESERIALIZE_FIELD(json, "can_send_polls", canSendPolls, false, false);
291  OBJECT_DESERIALIZE_FIELD(json, "can_send_other_messages", canSendOtherMessages, false, false);
292  OBJECT_DESERIALIZE_FIELD(json, "can_add_web_page_previews", canAddWebPagePreviews, false, false);
293  OBJECT_DESERIALIZE_FIELD(json, "can_change_info", canChangeInfo, false, false);
294  OBJECT_DESERIALIZE_FIELD(json, "can_invite_users", canInviteUsers, false, false);
295  OBJECT_DESERIALIZE_FIELD(json, "can_pin_messages", canPinMessages, false, false);
296  OBJECT_DESERIALIZE_FIELD(json, "can_manage_topics", canManageTopics, false, false);
297  OBJECT_DESERIALIZE_FIELD(json, "until_date", untilDate, 0, false);
298  }
299  };
300 
301 
305  ChatMemberLeft() = default;
306  explicit ChatMemberLeft(const nl::json& json) : ChatMember(json) {
307  ChatMember::status = "left";
308  }
309  };
310 
311 
315  ChatMemberBanned() = default;
316  explicit ChatMemberBanned(const nl::json& json) : ChatMember(json) {
317  ChatMember::status = "left";
318  }
319 
321  std::time_t untilDate{};
322 
325  nl::json toJson() const {
326  nl::json json = ChatMember::toJson();
327  OBJECT_SERIALIZE_FIELD(json, "until_date", untilDate);
328  return json;
329  }
330 
332  void fromJson(const nl::json& json) {
333  ChatMember::fromJson(json);
334  OBJECT_DESERIALIZE_FIELD(json, "until_date", untilDate, 0, false);
335  }
336  };
337 
338 }
#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
Definition: Api.hpp:14
std::shared_ptr< T > Ptr
Definition: Ptr.hpp:6
Represents a chat member that has some additional privileges. https://core.telegram....
Definition: ChatMember.hpp:78
bool canManageVideoChats
True, if the administrator can manage video chats.
Definition: ChatMember.hpp:100
bool canRestrictMembers
True, if the administrator can restrict, ban or unban chat members.
Definition: ChatMember.hpp:103
ChatMemberAdministrator(const nl::json &json)
Definition: ChatMember.hpp:80
bool canBeEdited
True, if the bot is allowed to edit administrator privileges of that user.
Definition: ChatMember.hpp:86
bool canDeleteStories
Optional. True, if the administrator can delete stories posted by other users; channels only.
Definition: ChatMember.hpp:131
bool canManageChat
True, if the administrator can access the chat event log, chat statistics, boost list in channels,...
Definition: ChatMember.hpp:94
bool canEditMessages
Optional. True, if the administrator can edit messages of other users and can pin messages; channels ...
Definition: ChatMember.hpp:119
bool canDeleteMessages
True, if the administrator can delete messages of other users.
Definition: ChatMember.hpp:97
nl::json toJson() const
Serializes this object to JSON.
Definition: ChatMember.hpp:142
std::string customTitle
Optional. Custom title for this user.
Definition: ChatMember.hpp:137
bool canChangeInfo
True, if the user is allowed to change the chat title, photo and other settings.
Definition: ChatMember.hpp:110
bool canPinMessages
Optional. True, if the user is allowed to pin messages; groups and supergroups only.
Definition: ChatMember.hpp:122
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: ChatMember.hpp:165
bool canPromoteMembers
True, if the administrator can add new administrators with a subset of their own privileges or demote...
Definition: ChatMember.hpp:107
bool canInviteUsers
True, if the user is allowed to invite new users to the chat.
Definition: ChatMember.hpp:113
bool canEditStories
Optional. True, if the administrator can edit stories posted by other users; channels only.
Definition: ChatMember.hpp:128
bool isAnonymous
True, if the user's presence in the chat is hidden.
Definition: ChatMember.hpp:89
bool canManageTopics
Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups...
Definition: ChatMember.hpp:134
bool canPostStories
Optional. True, if the administrator can post stories in the channel; channels only.
Definition: ChatMember.hpp:125
bool canPostMessages
Optional. True, if the administrator can post messages in the channel; channels only.
Definition: ChatMember.hpp:116
Represents a chat member that was banned in the chat and can't return to the chat or view chat messag...
Definition: ChatMember.hpp:314
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: ChatMember.hpp:332
std::time_t untilDate
Date when restrictions will be lifted for this user; Unix time. If 0, then the user is banned forever...
Definition: ChatMember.hpp:321
ChatMemberBanned(const nl::json &json)
Definition: ChatMember.hpp:316
nl::json toJson() const
Serializes this object to JSON.
Definition: ChatMember.hpp:325
The base class of all chat members objects. This object contains information about one member of a ch...
Definition: ChatMember.hpp:15
ChatMember(const nl::json &json)
Definition: ChatMember.hpp:17
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: ChatMember.hpp:37
Ptr< User > user
Information about the user.
Definition: ChatMember.hpp:25
std::string status
The member's status in the chat.
Definition: ChatMember.hpp:22
nl::json toJson() const
Serializes this object to JSON.
Definition: ChatMember.hpp:29
Represents a chat member that isn't currently a member of the chat, but may join it themselves....
Definition: ChatMember.hpp:304
ChatMemberLeft(const nl::json &json)
Definition: ChatMember.hpp:306
Represents a chat member that has no additional privileges or restrictions. https://core....
Definition: ChatMember.hpp:190
ChatMemberMember(const nl::json &json)
Definition: ChatMember.hpp:192
Represents a chat member that owns the chat and has all administrator privileges. https://core....
Definition: ChatMember.hpp:45
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: ChatMember.hpp:68
nl::json toJson() const
Serializes this object to JSON.
Definition: ChatMember.hpp:60
ChatMemberOwner(const nl::json &json)
Definition: ChatMember.hpp:47
bool isAnonymous
True, if the user's presence in the chat is hidden.
Definition: ChatMember.hpp:53
std::string customTitle
Optional. Custom title for this user.
Definition: ChatMember.hpp:56
Represents a chat member that is under certain restrictions in the chat. Supergroups only....
Definition: ChatMember.hpp:200
bool canSendMessages
True, if the user is allowed to send text messages, contacts, invoices, locations and venues.
Definition: ChatMember.hpp:211
bool canSendAudios
True, if the user is allowed to send audios.
Definition: ChatMember.hpp:214
bool canAddWebPagePreviews
True, if the user is allowed to add web page previews to their messages.
Definition: ChatMember.hpp:238
bool canSendVideos
True, if the user is allowed to send videos.
Definition: ChatMember.hpp:223
bool canManageTopics
True, if the user is allowed to create forum topics.
Definition: ChatMember.hpp:250
bool canChangeInfo
True, if the user is allowed to change the chat title, photo and other settings.
Definition: ChatMember.hpp:241
nl::json toJson() const
Serializes this object to JSON.
Definition: ChatMember.hpp:258
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: ChatMember.hpp:280
bool canSendDocuments
True, if the user is allowed to send documents.
Definition: ChatMember.hpp:217
bool canSendVideoNotes
True, if the user is allowed to send video notes.
Definition: ChatMember.hpp:226
bool isMember
True, if the user is a member of the chat at the moment of the request.
Definition: ChatMember.hpp:208
bool canSendPhotos
True, if the user is allowed to send photos.
Definition: ChatMember.hpp:220
bool canSendOtherMessages
True, if the user is allowed to send animations, games, stickers and use inline bots.
Definition: ChatMember.hpp:235
std::time_t untilDate
Date when restrictions will be lifted for this user; Unix time. If 0, then the user is restricted for...
Definition: ChatMember.hpp:253
bool canSendVoiceNotes
True, if the user is allowed to send voice notes.
Definition: ChatMember.hpp:229
bool canSendPolls
True, if the user is allowed to send polls.
Definition: ChatMember.hpp:232
bool canInviteUsers
True, if the user is allowed to invite new users to the chat.
Definition: ChatMember.hpp:244
bool canPinMessages
True, if the user is allowed to pin messages.
Definition: ChatMember.hpp:247
ChatMemberRestricted(const nl::json &json)
Definition: ChatMember.hpp:202