diff options
author | llnulldisk <48621230+llnulldisk@users.noreply.github.com> | 2024-04-15 14:06:55 +0200 |
---|---|---|
committer | llnulldisk <48621230+llnulldisk@users.noreply.github.com> | 2024-04-15 14:06:55 +0200 |
commit | 90cb57b61ee3ed9db0164b351ac9a98c83645426 (patch) | |
tree | 8f5706d0bd8e3cd0e44d383bbb732fab972a52b8 | |
parent | 5aaaa79ee2441dd36a3af4e1c869717bf9b2c927 (diff) |
Update to Bot API 6.9
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | include/tgbot/Api.h | 18 | ||||
-rw-r--r-- | include/tgbot/types/Chat.h | 2 | ||||
-rw-r--r-- | include/tgbot/types/ChatAdministratorRights.h | 19 | ||||
-rw-r--r-- | include/tgbot/types/ChatMemberAdministrator.h | 19 | ||||
-rw-r--r-- | include/tgbot/types/ChatMemberBanned.h | 4 | ||||
-rw-r--r-- | include/tgbot/types/ChatMemberRestricted.h | 2 | ||||
-rw-r--r-- | include/tgbot/types/ChatMemberUpdated.h | 2 | ||||
-rw-r--r-- | include/tgbot/types/InlineQueryResultsButton.h | 4 | ||||
-rw-r--r-- | include/tgbot/types/Message.h | 2 | ||||
-rw-r--r-- | include/tgbot/types/WebAppInfo.h | 6 | ||||
-rw-r--r-- | include/tgbot/types/WriteAccessAllowed.h | 14 | ||||
-rw-r--r-- | src/Api.cpp | 46 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 20 | ||||
-rw-r--r-- | src/types/InputFile.cpp | 6 |
15 files changed, 122 insertions, 44 deletions
@@ -9,7 +9,7 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp). ## State -- [x] Telegram Bot API 6.8 +- [x] Telegram Bot API 6.9 - [ ] [Deep Linking](https://core.telegram.org/bots/features#deep-linking) diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index c3df15c..9078da5 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -829,7 +829,7 @@ public: * @param chatId Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername) * @param userId Unique identifier of the target user * @param permissions A JSON-serialized object for new user permissions - * @param untilDate Optional. Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever + * @param untilDate Optional. Date when restrictions will be lifted for the user; Unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever * @param useIndependentChatPermissions Optional. Pass True if chat permissions are set independently. Otherwise, the canSendOtherMessages and canAddWebPagPreviews permissions will imply the canSendMessages, canSendAudios, canSendDocuments, canSendPhotos, canSendVideos, canSendVideoNotes, and canSendVoiceNotes permissions; the canSendPolls permission will imply the canSendMessages permission. * * @return Returns True on success. @@ -837,7 +837,7 @@ public: bool restrictChatMember(boost::variant<std::int64_t, std::string> chatId, std::int64_t userId, ChatPermissions::Ptr permissions, - std::int64_t untilDate = 0, + std::uint32_t untilDate = 0, bool useIndependentChatPermissions = false) const; /** @@ -849,17 +849,20 @@ public: * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) * @param userId Unique identifier of the target user * @param canChangeInfo Optional. Pass True if the administrator can change chat title, photo and other settings - * @param canPostMessages Optional. Pass True if the administrator can create channel posts, channels only - * @param canEditMessages Optional. Pass True if the administrator can edit messages of other users and can pin messages, channels only + * @param canPostMessages Optional. Pass True if the administrator can post messages in the channel; channels only + * @param canEditMessages Optional. Pass True if the administrator can edit messages of other users and can pin messages; channels only * @param canDeleteMessages Optional. Pass True if the administrator can delete messages of other users * @param canInviteUsers Optional. Pass True if the administrator can invite new users to the chat * @param canPinMessages Optional. Pass True if the administrator can pin messages, supergroups only * @param canPromoteMembers Optional. Pass True if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by him) * @param isAnonymous Optional. Pass True if the administrator's presence in the chat is hidden - * @param canManageChat Optional. Pass True if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege + * @param canManageChat Optional. Pass True if the administrator can access the chat event log, chat statistics, boost list in channels, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege * @param canManageVideoChats Optional. Pass True if the administrator can manage video chats * @param canRestrictMembers Optional. Pass True if the administrator can restrict, ban or unban chat members * @param canManageTopics Optional. Pass True if the user is allowed to create, rename, close, and reopen forum topics, supergroups only + * @param canPostStories Optional. Pass True if the administrator can post stories in the channel; channels only + * @param canEditStories Optional. Pass True if the administrator can edit stories posted by other users; channels only + * @param canDeleteStories Optional. Pass True if the administrator can delete stories posted by other users; channels only * * @return Returns True on success. */ @@ -876,7 +879,10 @@ public: bool canManageChat = false, bool canManageVideoChats = false, bool canRestrictMembers = false, - bool canManageTopics = false) const; + bool canManageTopics = false, + bool canPostStories = false, + bool canEditStories = false, + bool canDeleteStories = false) const; /** * @brief Use this method to set a custom title for an administrator in a supergroup promoted by the bot. diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h index e838046..95aa482 100644 --- a/include/tgbot/types/Chat.h +++ b/include/tgbot/types/Chat.h @@ -91,7 +91,7 @@ public: std::string emojiStatusCustomEmojiId; /** - * @brief Optional. Expiration date of the emoji status of the other party in a private chat, if any. + * @brief Optional. Expiration date of the emoji status of the other party in a private chat in Unix time, if any. * * Returned only in Api::getChat. */ diff --git a/include/tgbot/types/ChatAdministratorRights.h b/include/tgbot/types/ChatAdministratorRights.h index d2ee3e5..dcd441f 100644 --- a/include/tgbot/types/ChatAdministratorRights.h +++ b/include/tgbot/types/ChatAdministratorRights.h @@ -20,7 +20,7 @@ public: bool isAnonymous; /** - * @brief True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. + * @brief True, if the administrator can access the chat event log, chat statistics, boost list in channels, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. * * Implied by any other administrator privilege */ @@ -57,7 +57,7 @@ public: bool canInviteUsers; /** - * @brief Optional. True, if the administrator can post in the channel; channels only + * @brief Optional. True, if the administrator can post messages in the channel; channels only */ bool canPostMessages; @@ -72,6 +72,21 @@ public: bool canPinMessages; /** + * @brief Optional. True, if the administrator can post stories in the channel; channels only + */ + bool canPostStories; + + /** + * @brief Optional. True, if the administrator can edit stories posted by other users; channels only + */ + bool canEditStories; + + /** + * @brief Optional. True, if the administrator can delete stories posted by other users; channels only + */ + bool canDeleteStories; + + /** * @brief Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only */ bool canManageTopics; diff --git a/include/tgbot/types/ChatMemberAdministrator.h b/include/tgbot/types/ChatMemberAdministrator.h index d100f85..af94650 100644 --- a/include/tgbot/types/ChatMemberAdministrator.h +++ b/include/tgbot/types/ChatMemberAdministrator.h @@ -34,7 +34,7 @@ public: bool isAnonymous; /** - * @brief True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. + * @brief True, if the administrator can access the chat event log, chat statistics, boost list in channels, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. * * Implied by any other administrator privilege */ @@ -71,7 +71,7 @@ public: bool canInviteUsers; /** - * @brief Optional. True, if the administrator can post in the channel; channels only + * @brief Optional. True, if the administrator can post messages in the channel; channels only */ bool canPostMessages; @@ -86,6 +86,21 @@ public: bool canPinMessages; /** + * @brief Optional. True, if the administrator can post stories in the channel; channels only + */ + bool canPostStories; + + /** + * @brief Optional. True, if the administrator can edit stories posted by other users; channels only + */ + bool canEditStories; + + /** + * @brief Optional. True, if the administrator can delete stories posted by other users; channels only + */ + bool canDeleteStories; + + /** * @brief Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; supergroups only */ bool canManageTopics; diff --git a/include/tgbot/types/ChatMemberBanned.h b/include/tgbot/types/ChatMemberBanned.h index 90ae93e..1e0f251 100644 --- a/include/tgbot/types/ChatMemberBanned.h +++ b/include/tgbot/types/ChatMemberBanned.h @@ -24,7 +24,9 @@ public: } /** - * @brief Date when restrictions will be lifted for this user; unix time + * @brief Date when restrictions will be lifted for this user; Unix time. + * + * If 0, then the user is banned forever */ std::uint32_t untilDate; }; diff --git a/include/tgbot/types/ChatMemberRestricted.h b/include/tgbot/types/ChatMemberRestricted.h index cbc198b..e1eb919 100644 --- a/include/tgbot/types/ChatMemberRestricted.h +++ b/include/tgbot/types/ChatMemberRestricted.h @@ -101,7 +101,7 @@ public: bool canManageTopics; /** - * @brief Date when restrictions will be lifted for this user; unix time. + * @brief Date when restrictions will be lifted for this user; Unix time. * * If 0, then the user is restricted forever */ diff --git a/include/tgbot/types/ChatMemberUpdated.h b/include/tgbot/types/ChatMemberUpdated.h index 1d572e6..1ed4a95 100644 --- a/include/tgbot/types/ChatMemberUpdated.h +++ b/include/tgbot/types/ChatMemberUpdated.h @@ -34,7 +34,7 @@ public: /** * @brief Date the change was done in Unix time */ - std::uint64_t date; + std::uint32_t date; /** * @brief Previous information about the chat member diff --git a/include/tgbot/types/InlineQueryResultsButton.h b/include/tgbot/types/InlineQueryResultsButton.h index 2343ff5..3b5f4e0 100644 --- a/include/tgbot/types/InlineQueryResultsButton.h +++ b/include/tgbot/types/InlineQueryResultsButton.h @@ -25,7 +25,9 @@ public: std::string text; /** - * @brief Optional. Description of the Web App (https://core.telegram.org/bots/webapps) that will be launched when the user presses the button. The Web App will be able to switch back to the inline mode using the method switchInlineQuery (https://core.telegram.org/bots/webapps#initializing-web-apps) inside the Web App. + * @brief Optional. Description of the Web App (https://core.telegram.org/bots/webapps) that will be launched when the user presses the button. + * + * The Web App will be able to switch back to the inline mode using the method switchInlineQuery (https://core.telegram.org/bots/webapps#initializing-mini-apps) inside the Web App. */ WebAppInfo::Ptr webApp; diff --git a/include/tgbot/types/Message.h b/include/tgbot/types/Message.h index a38dd01..880b730 100644 --- a/include/tgbot/types/Message.h +++ b/include/tgbot/types/Message.h @@ -374,7 +374,7 @@ public: std::string connectedWebsite; /** - * @brief Optional. Service message: the user allowed the bot added to the attachment menu to write messages + * @brief Optional. Service message: the user allowed the bot to write messages after adding it to the attachment or side menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method requestWriteAccess (https://core.telegram.org/bots/webapps#initializing-mini-apps) */ WriteAccessAllowed::Ptr writeAccessAllowed; diff --git a/include/tgbot/types/WebAppInfo.h b/include/tgbot/types/WebAppInfo.h index 1e9d314..1bdcf0a 100644 --- a/include/tgbot/types/WebAppInfo.h +++ b/include/tgbot/types/WebAppInfo.h @@ -7,7 +7,9 @@ namespace TgBot { /** - * @brief Contains information about a Web App. + * @brief Describes a Web App. + * + * https://core.telegram.org/bots/webapps * * @ingroup types */ @@ -17,7 +19,7 @@ public: typedef std::shared_ptr<WebAppInfo> Ptr; /** - * @brief An HTTPS URL of a Web App to be opened with additional data as specified in https://core.telegram.org/bots/webapps#initializing-web-apps + * @brief An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps (https://core.telegram.org/bots/webapps#initializing-mini-apps) */ std::string url; }; diff --git a/include/tgbot/types/WriteAccessAllowed.h b/include/tgbot/types/WriteAccessAllowed.h index e3138df..d8ad61e 100644 --- a/include/tgbot/types/WriteAccessAllowed.h +++ b/include/tgbot/types/WriteAccessAllowed.h @@ -7,7 +7,7 @@ namespace TgBot { /** - * @brief This object represents a service message about a user allowing a bot to write messages after adding the bot to the attachment menu or launching a Web App from a link. + * @brief This object represents a service message about a user allowing a bot to write messages after adding it to the attachment menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method requestWriteAccess. * * @ingroup types */ @@ -16,9 +16,19 @@ public: typedef std::shared_ptr<WriteAccessAllowed> Ptr; /** - * @brief Optional. Name of the Web App which was launched from a link + * @brief Optional. True, if the access was granted after the user accepted an explicit request from a Web App sent by the method requestWriteAccess (https://core.telegram.org/bots/webapps#initializing-mini-apps) + */ + bool fromRequest; + + /** + * @brief Optional. Name of the Web App, if the access was granted when the Web App was launched from a link */ std::string webAppName; + + /** + * @brief Optional. True, if the access was granted when the bot was added to the attachment or side menu + */ + bool fromAttachmentMenu; }; } diff --git a/src/Api.cpp b/src/Api.cpp index b3ce4ea..0d11295 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1156,7 +1156,7 @@ bool Api::unbanChatMember(boost::variant<std::int64_t, std::string> chatId, bool Api::restrictChatMember(boost::variant<std::int64_t, std::string> chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, - std::int64_t untilDate, + std::uint32_t untilDate, bool useIndependentChatPermissions) const { std::vector<HttpReqArg> args; args.reserve(5); @@ -1164,10 +1164,10 @@ bool Api::restrictChatMember(boost::variant<std::int64_t, std::string> chatId, args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); - if (useIndependentChatPermissions) { + if (useIndependentChatPermissions != false) { args.emplace_back("use_independent_chat_permissions", useIndependentChatPermissions); } - if (untilDate) { + if (untilDate != 0) { args.emplace_back("until_date", untilDate); } @@ -1187,46 +1187,58 @@ bool Api::promoteChatMember(boost::variant<std::int64_t, std::string> chatId, bool canManageChat, bool canManageVideoChats, bool canRestrictMembers, - bool canManageTopics) const { + bool canManageTopics, + bool canPostStories, + bool canEditStories, + bool canDeleteStories) const { std::vector<HttpReqArg> args; - args.reserve(14); + args.reserve(17); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); - if (isAnonymous) { + if (isAnonymous != false) { args.emplace_back("is_anonymous", isAnonymous); } - if (canManageChat) { + if (canManageChat != false) { args.emplace_back("can_manage_chat", canManageChat); } - if (canPostMessages) { + if (canPostMessages != false) { args.emplace_back("can_post_messages", canPostMessages); } - if (canEditMessages) { + if (canEditMessages != false) { args.emplace_back("can_edit_messages", canEditMessages); } - if (canDeleteMessages) { + if (canDeleteMessages != false) { args.emplace_back("can_delete_messages", canDeleteMessages); } - if (canManageVideoChats) { + if (canPostStories != false) { + args.emplace_back("can_post_stories", canPostStories); + } + if (canEditStories != false) { + args.emplace_back("can_edit_stories", canEditStories); + } + if (canDeleteStories != false) { + args.emplace_back("can_delete_stories", canDeleteStories); + } + if (canManageVideoChats != false) { args.emplace_back("can_manage_video_chats", canManageVideoChats); } - if (canRestrictMembers) { + if (canRestrictMembers != false) { args.emplace_back("can_restrict_members", canRestrictMembers); } - if (canPromoteMembers) { + if (canPromoteMembers != false) { args.emplace_back("can_promote_members", canPromoteMembers); } - if (canChangeInfo) { + if (canChangeInfo != false) { args.emplace_back("can_change_info", canChangeInfo); } - if (canInviteUsers) { + if (canInviteUsers != false) { args.emplace_back("can_invite_users", canInviteUsers); } - if (canPinMessages) { + if (canPinMessages != false) { args.emplace_back("can_pin_messages", canPinMessages); } - if (canManageTopics) { + if (canManageTopics != false) { args.emplace_back("can_manage_topics", canManageTopics); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 86a25c1..6905c89 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1132,7 +1132,9 @@ std::string TgTypeParser::parseChatShared(const ChatShared::Ptr& object) const { WriteAccessAllowed::Ptr TgTypeParser::parseJsonAndGetWriteAccessAllowed(const boost::property_tree::ptree& data) const { auto result(std::make_shared<WriteAccessAllowed>()); + result->fromRequest = data.get<bool>("from_request", false); result->webAppName = data.get<std::string>("web_app_name", ""); + result->fromAttachmentMenu = data.get<bool>("from_attachment_menu", false); return result; } @@ -1142,7 +1144,9 @@ std::string TgTypeParser::parseWriteAccessAllowed(const WriteAccessAllowed::Ptr& } std::string result; result += '{'; + appendToJson(result, "from_request", object->fromRequest); appendToJson(result, "web_app_name", object->webAppName); + appendToJson(result, "from_attachment_menu", object->fromAttachmentMenu); removeLastComma(result); result += '}'; return result; @@ -1682,6 +1686,9 @@ ChatAdministratorRights::Ptr TgTypeParser::parseJsonAndGetChatAdministratorRight result->canPostMessages = data.get<bool>("can_post_messages", false); result->canEditMessages = data.get<bool>("can_edit_messages", false); result->canPinMessages = data.get<bool>("can_pin_messages", false); + result->canPostStories = data.get<bool>("can_post_stories", false); + result->canEditStories = data.get<bool>("can_edit_stories", false); + result->canDeleteStories = data.get<bool>("can_delete_stories", false); result->canManageTopics = data.get<bool>("can_manage_topics", false); return result; } @@ -1703,6 +1710,9 @@ std::string TgTypeParser::parseChatAdministratorRights(const ChatAdministratorRi appendToJson(result, "can_post_messages", object->canPostMessages); appendToJson(result, "can_edit_messages", object->canEditMessages); appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "can_post_stories", object->canPostStories); + appendToJson(result, "can_edit_stories", object->canEditStories); + appendToJson(result, "can_delete_stories", object->canDeleteStories); appendToJson(result, "can_manage_topics", object->canManageTopics); removeLastComma(result); result += '}'; @@ -1799,6 +1809,9 @@ ChatMemberAdministrator::Ptr TgTypeParser::parseJsonAndGetChatMemberAdministrato result->canPostMessages = data.get<bool>("can_post_messages", false); result->canEditMessages = data.get<bool>("can_edit_messages", false); result->canPinMessages = data.get<bool>("can_pin_messages", false); + result->canPostStories = data.get<bool>("can_post_stories", false); + result->canEditStories = data.get<bool>("can_edit_stories", false); + result->canDeleteStories = data.get<bool>("can_delete_stories", false); result->canManageTopics = data.get<bool>("can_manage_topics", false); result->customTitle = data.get<std::string>("custom_title", ""); return result; @@ -1823,6 +1836,9 @@ std::string TgTypeParser::parseChatMemberAdministrator(const ChatMemberAdministr appendToJson(result, "can_post_messages", object->canPostMessages); appendToJson(result, "can_edit_messages", object->canEditMessages); appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "can_post_stories", object->canPostStories); + appendToJson(result, "can_edit_stories", object->canEditStories); + appendToJson(result, "can_delete_stories", object->canDeleteStories); appendToJson(result, "can_manage_topics", object->canManageTopics); appendToJson(result, "custom_title", object->customTitle); // The last comma will be erased by parseChatMember(). @@ -1915,7 +1931,7 @@ std::string TgTypeParser::parseChatMemberLeft(const ChatMemberLeft::Ptr& object) ChatMemberBanned::Ptr TgTypeParser::parseJsonAndGetChatMemberBanned(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetChatMember(). auto result(std::make_shared<ChatMemberBanned>()); - result->untilDate = data.get<uint32_t>("until_date", 0); + result->untilDate = data.get<std::uint32_t>("until_date", 0); return result; } @@ -1935,7 +1951,7 @@ ChatMemberUpdated::Ptr TgTypeParser::parseJsonAndGetChatMemberUpdated(const boos auto result(std::make_shared<ChatMemberUpdated>()); result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); - result->date = data.get<std::uint64_t>("date", 0); + result->date = data.get<std::uint32_t>("date", 0); result->oldChatMember = tryParseJson<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, data, "old_chat_member"); result->newChatMember = tryParseJson<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, data, "new_chat_member"); result->inviteLink = tryParseJson<ChatInviteLink>(&TgTypeParser::parseJsonAndGetChatInviteLink, data, "invite_link"); diff --git a/src/types/InputFile.cpp b/src/types/InputFile.cpp index c4d804d..2deb082 100644 --- a/src/types/InputFile.cpp +++ b/src/types/InputFile.cpp @@ -5,12 +5,10 @@ #include <memory> #include <string> -using namespace std; - namespace TgBot { -InputFile::Ptr InputFile::fromFile(const string& filePath, const string& mimeType) { - auto result(make_shared<InputFile>()); +InputFile::Ptr InputFile::fromFile(const std::string& filePath, const std::string& mimeType) { + auto result(std::make_shared<InputFile>()); result->data = FileTools::read(filePath); result->mimeType = mimeType; result->fileName = std::filesystem::path(filePath).filename().string(); |