From 0caef51105de2c56d0797d87864db53129d778e6 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sat, 11 Feb 2023 18:12:59 +0100 Subject: Update to Bot API 6.5 --- src/Api.cpp | 16 ++++-- src/TgTypeParser.cpp | 148 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 148 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index 54854f8..43a9dba 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1141,13 +1141,17 @@ bool Api::unbanChatMember(boost::variant chatId, bool Api::restrictChatMember(boost::variant chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, - std::int64_t untilDate) const { + std::int64_t untilDate, + bool useIndependentChatPermissions) const { std::vector args; - args.reserve(4); + args.reserve(5); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); + if (useIndependentChatPermissions) { + args.emplace_back("use_independent_chat_permissions", useIndependentChatPermissions); + } if (untilDate) { args.emplace_back("until_date", untilDate); } @@ -1250,12 +1254,16 @@ bool Api::unbanChatSenderChat(boost::variant chatId, } bool Api::setChatPermissions(boost::variant chatId, - ChatPermissions::Ptr permissions) const { + ChatPermissions::Ptr permissions, + bool useIndependentChatPermissions) const { std::vector args; - args.reserve(2); + args.reserve(3); args.emplace_back("chat_id", chatId); args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); + if (useIndependentChatPermissions) { + args.emplace_back("use_independent_chat_permissions", useIndependentChatPermissions); + } return sendRequest("setChatPermissions", args).get("", false); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 24173c4..9e04851 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -278,6 +278,8 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt result->pinnedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); result->invoice = tryParseJson(&TgTypeParser::parseJsonAndGetInvoice, data, "invoice"); result->successfulPayment = tryParseJson(&TgTypeParser::parseJsonAndGetSuccessfulPayment, data, "successful_payment"); + result->userShared = tryParseJson(&TgTypeParser::parseJsonAndGetUserShared, data, "user_shared"); + result->chatShared = tryParseJson(&TgTypeParser::parseJsonAndGetChatShared, data, "chat_shared"); result->connectedWebsite = data.get("connected_website", ""); result->writeAccessAllowed = tryParseJson(&TgTypeParser::parseJsonAndGetWriteAccessAllowed, data, "write_access_allowed"); result->passportData = tryParseJson(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data"); @@ -356,6 +358,8 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage)); appendToJson(result, "invoice", parseInvoice(object->invoice)); appendToJson(result, "successful_payment", parseSuccessfulPayment(object->successfulPayment)); + appendToJson(result, "user_shared", parseUserShared(object->userShared)); + appendToJson(result, "chat_shared", parseChatShared(object->chatShared)); appendToJson(result, "connected_website", object->connectedWebsite); appendToJson(result, "write_access_allowed", parseWriteAccessAllowed(object->writeAccessAllowed)); appendToJson(result, "passport_data", parsePassportData(object->passportData)); @@ -1063,6 +1067,46 @@ std::string TgTypeParser::parseGeneralForumTopicUnhidden(const GeneralForumTopic return result; } +UserShared::Ptr TgTypeParser::parseJsonAndGetUserShared(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->requestId = data.get("request_id", 0); + result->userId = data.get("user_id", 0); + return result; +} + +std::string TgTypeParser::parseUserShared(const UserShared::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "request_id", object->requestId); + appendToJson(result, "user_id", object->userId); + removeLastComma(result); + result += '}'; + return result; +} + +ChatShared::Ptr TgTypeParser::parseJsonAndGetChatShared(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->requestId = data.get("request_id", 0); + result->userId = data.get("user_id", 0); + return result; +} + +std::string TgTypeParser::parseChatShared(const ChatShared::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "request_id", object->requestId); + appendToJson(result, "user_id", object->userId); + removeLastComma(result); + result += '}'; + return result; +} + WriteAccessAllowed::Ptr TgTypeParser::parseJsonAndGetWriteAccessAllowed(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); return result; @@ -1255,6 +1299,8 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt KeyboardButton::Ptr TgTypeParser::parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->text = data.get("text", ""); + result->requestUser = tryParseJson(&TgTypeParser::parseJsonAndGetKeyboardButtonRequestUser, data, "request_user"); + result->requestChat = tryParseJson(&TgTypeParser::parseJsonAndGetKeyboardButtonRequestChat, data, "request_chat"); result->requestContact = data.get("request_contact", false); result->requestLocation = data.get("request_location", false); result->requestPoll = tryParseJson(&TgTypeParser::parseJsonAndGetKeyboardButtonPollType, data, "request_poll"); @@ -1269,6 +1315,8 @@ std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) std::string result; result += '{'; appendToJson(result, "text", object->text); + appendToJson(result, "request_user", parseKeyboardButtonRequestUser(object->requestUser)); + appendToJson(result, "request_chat", parseKeyboardButtonRequestChat(object->requestChat)); appendToJson(result, "request_contact", object->requestContact); appendToJson(result, "request_location", object->requestLocation); appendToJson(result, "request_poll", parseKeyboardButtonPollType(object->requestPoll)); @@ -1278,6 +1326,60 @@ std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) return result; } +KeyboardButtonRequestUser::Ptr TgTypeParser::parseJsonAndGetKeyboardButtonRequestUser(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->requestId = data.get("request_id", 0); + result->userIsBot = data.get("user_is_bot", false); + result->userIsPremium = data.get("user_is_premium", false); + return result; +} + +std::string TgTypeParser::parseKeyboardButtonRequestUser(const KeyboardButtonRequestUser::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "request_id", object->requestId); + appendToJson(result, "user_is_bot", object->userIsBot); + appendToJson(result, "user_is_premium", object->userIsPremium); + removeLastComma(result); + result += '}'; + return result; +} + +KeyboardButtonRequestChat::Ptr TgTypeParser::parseJsonAndGetKeyboardButtonRequestChat(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->requestId = data.get("request_id", 0); + result->chatIsChannel = data.get("chat_is_channel", false); + result->chatIsForum = data.get("chat_is_forum", false); + result->chatHasUsername = data.get("chat_has_username", false); + result->chatIsCreated = data.get("chat_is_created", false); + result->userAdministratorRights = tryParseJson(&TgTypeParser::parseJsonAndGetChatAdministratorRights, data, "user_administrator_rights"); + result->botAdministratorRights = tryParseJson(&TgTypeParser::parseJsonAndGetChatAdministratorRights, data, "bot_administrator_rights"); + result->botIsMember = data.get("bot_is_member", false); + return result; +} + +std::string TgTypeParser::parseKeyboardButtonRequestChat(const KeyboardButtonRequestChat::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "request_id", object->requestId); + appendToJson(result, "chat_is_channel", object->chatIsChannel); + appendToJson(result, "chat_is_forum", object->chatIsForum); + appendToJson(result, "chat_has_username", object->chatHasUsername); + appendToJson(result, "chat_is_created", object->chatIsCreated); + appendToJson(result, "user_administrator_rights", parseChatAdministratorRights(object->userAdministratorRights)); + appendToJson(result, "bot_administrator_rights", parseChatAdministratorRights(object->botAdministratorRights)); + appendToJson(result, "bot_is_member", object->botIsMember); + removeLastComma(result); + result += '}'; + return result; +} + KeyboardButtonPollType::Ptr TgTypeParser::parseJsonAndGetKeyboardButtonPollType(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->type = data.get("type", ""); @@ -1693,15 +1795,20 @@ ChatMemberRestricted::Ptr TgTypeParser::parseJsonAndGetChatMemberRestricted(cons // NOTE: This function will be called by parseJsonAndGetChatMember(). auto result(std::make_shared()); result->isMember = data.get("is_member", false); - result->canChangeInfo = data.get("can_change_info", false); - result->canInviteUsers = data.get("can_invite_users", false); - result->canPinMessages = data.get("can_pin_messages", false); - result->canManageTopics = data.get("can_manage_topics", false); result->canSendMessages = data.get("can_send_messages", false); - result->canSendMediaMessages = data.get("can_send_media_messages", false); + result->canSendAudios = data.get("can_send_audios", false); + result->canSendDocuments = data.get("can_send_documents", false); + result->canSendPhotos = data.get("can_send_photos", false); + result->canSendVideos = data.get("can_send_videos", false); + result->canSendVideoNotes = data.get("can_send_video_notes", false); + result->canSendVoiceNotes = data.get("can_send_voice_notes", false); result->canSendPolls = data.get("can_send_polls", false); result->canSendOtherMessages = data.get("can_send_other_messages", false); result->canAddWebPagePreviews = data.get("can_add_web_page_previews", false); + result->canChangeInfo = data.get("can_change_info", false); + result->canInviteUsers = data.get("can_invite_users", false); + result->canPinMessages = data.get("can_pin_messages", false); + result->canManageTopics = data.get("can_manage_topics", false); result->untilDate = data.get("until_date", 0); return result; } @@ -1714,15 +1821,20 @@ std::string TgTypeParser::parseChatMemberRestricted(const ChatMemberRestricted:: // curly brackets to the result std::string. std::string result; appendToJson(result, "is_member", object->isMember); - appendToJson(result, "can_change_info", object->canChangeInfo); - appendToJson(result, "can_invite_users", object->canInviteUsers); - appendToJson(result, "can_pin_messages", object->canPinMessages); - appendToJson(result, "can_manage_topics", object->canManageTopics); appendToJson(result, "can_send_messages", object->canSendMessages); - appendToJson(result, "can_send_media_messages", object->canSendMediaMessages); + appendToJson(result, "can_send_audios", object->canSendAudios); + appendToJson(result, "can_send_documents", object->canSendDocuments); + appendToJson(result, "can_send_photos", object->canSendPhotos); + appendToJson(result, "can_send_videos", object->canSendVideos); + appendToJson(result, "can_send_video_notes", object->canSendVideoNotes); + appendToJson(result, "can_send_voice_notes", object->canSendVoiceNotes); appendToJson(result, "can_send_polls", object->canSendPolls); appendToJson(result, "can_send_other_messages", object->canSendOtherMessages); appendToJson(result, "can_add_web_page_previews", object->canAddWebPagePreviews); + appendToJson(result, "can_change_info", object->canChangeInfo); + appendToJson(result, "can_invite_users", object->canInviteUsers); + appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "can_manage_topics", object->canManageTopics); appendToJson(result, "until_date", object->untilDate); // The last comma will be erased by parseChatMember(). return result; @@ -1796,6 +1908,7 @@ ChatJoinRequest::Ptr TgTypeParser::parseJsonAndGetChatJoinRequest(const boost::p auto result(std::make_shared()); result->chat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "chat"); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->userChatId = data.get("user_chat_id", 0); result->date = data.get("date", 0); result->bio = data.get("bio", ""); result->inviteLink = tryParseJson(&TgTypeParser::parseJsonAndGetChatInviteLink, data, "invite_link"); @@ -1810,6 +1923,7 @@ std::string TgTypeParser::parseChatJoinRequest(const ChatJoinRequest::Ptr& objec result += '{'; appendToJson(result, "chat", parseChat(object->chat)); appendToJson(result, "from", parseUser(object->from)); + appendToJson(result, "user_chat_id", object->userChatId); appendToJson(result, "date", object->date); appendToJson(result, "bio", object->bio); appendToJson(result, "invite_link", parseChatInviteLink(object->inviteLink)); @@ -1821,7 +1935,12 @@ std::string TgTypeParser::parseChatJoinRequest(const ChatJoinRequest::Ptr& objec ChatPermissions::Ptr TgTypeParser::parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->canSendMessages = data.get("can_send_messages", false); - result->canSendMediaMessages = data.get("can_send_media_messages", false); + result->canSendAudios = data.get("can_send_audios", false); + result->canSendDocuments = data.get("can_send_documents", false); + result->canSendPhotos = data.get("can_send_photos", false); + result->canSendVideos = data.get("can_send_videos", false); + result->canSendVideoNotes = data.get("can_send_video_notes", false); + result->canSendVoiceNotes = data.get("can_send_voice_notes", false); result->canSendPolls = data.get("can_send_polls", false); result->canSendOtherMessages = data.get("can_send_other_messages", false); result->canAddWebPagePreviews = data.get("can_add_web_page_previews", false); @@ -1839,7 +1958,12 @@ std::string TgTypeParser::parseChatPermissions(const ChatPermissions::Ptr& objec std::string result; result += '{'; appendToJson(result, "can_send_messages", object->canSendMessages); - appendToJson(result, "can_send_media_messages", object->canSendMediaMessages); + appendToJson(result, "can_send_audios", object->canSendAudios); + appendToJson(result, "can_send_documents", object->canSendDocuments); + appendToJson(result, "can_send_photos", object->canSendPhotos); + appendToJson(result, "can_send_videos", object->canSendVideos); + appendToJson(result, "can_send_video_notes", object->canSendVideoNotes); + appendToJson(result, "can_send_voice_notes", object->canSendVoiceNotes); appendToJson(result, "can_send_polls", object->canSendPolls); appendToJson(result, "can_send_other_messages", object->canSendOtherMessages); appendToJson(result, "can_add_web_page_previews", object->canAddWebPagePreviews); -- cgit v1.2.3