From 349a54107d23ab58cff9afccad27741fa3ad8937 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Fri, 9 Sep 2022 16:57:08 +0200 Subject: Update to API 5.6 --- src/Api.cpp | 342 ++++++++++++++++++++++++++++++++------------------- src/TgTypeParser.cpp | 8 +- 2 files changed, 222 insertions(+), 128 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index c1c86d2..bb63721 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -109,9 +109,10 @@ Message::Ptr Api::sendMessage(boost::variant c const std::string& parseMode, bool disableNotification, const std::vector& entities, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(9); + args.reserve(10); args.emplace_back("chat_id", chatId); args.emplace_back("text", text); @@ -127,6 +128,9 @@ Message::Ptr Api::sendMessage(boost::variant c if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -140,24 +144,40 @@ Message::Ptr Api::sendMessage(boost::variant c return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); } -Message::Ptr Api::forwardMessage(std::int64_t chatId, std::int64_t fromChatId, std::int32_t messageId, bool disableNotification) const { +Message::Ptr Api::forwardMessage(boost::variant chatId, + boost::variant fromChatId, + std::int32_t messageId, + bool disableNotification, + bool protectContent) const { vector args; - args.reserve(4); + args.reserve(5); + args.emplace_back("chat_id", chatId); args.emplace_back("from_chat_id", fromChatId); - args.emplace_back("message_id", messageId); if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + args.emplace_back("message_id", messageId); + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args)); } -MessageId::Ptr Api::copyMessage(std::int64_t chatId, std::int64_t fromChatId, std::int32_t messageId, - const std::string& caption, const std::string& parseMode, const std::vector& captionEntities, - bool disableNotification, std::int32_t replyToMessageId, bool allowSendingWithoutReply, - GenericReply::Ptr replyMarkup) const { +MessageId::Ptr Api::copyMessage(boost::variant chatId, + boost::variant fromChatId, + std::int32_t messageId, + const std::string& caption, + const std::string& parseMode, + const std::vector& captionEntities, + bool disableNotification, + std::int32_t replyToMessageId, + bool allowSendingWithoutReply, + GenericReply::Ptr replyMarkup, + bool protectContent) const { vector args; - args.reserve(10); + args.reserve(11); args.emplace_back("chat_id", chatId); args.emplace_back("from_chat_id", fromChatId); @@ -174,6 +194,9 @@ MessageId::Ptr Api::copyMessage(std::int64_t chatId, std::int64_t fromChatId, st if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -187,24 +210,25 @@ MessageId::Ptr Api::copyMessage(std::int64_t chatId, std::int64_t fromChatId, st return _tgTypeParser.parseJsonAndGetMessageId(sendRequest("copyMessage", args)); } -Message::Ptr Api::sendPhoto(std::int64_t chatId, - boost::variant photo, +Message::Ptr Api::sendPhoto(boost::variant chatId, + boost::variant photo, const std::string& caption, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(9); + args.reserve(10); args.emplace_back("chat_id", chatId); - if (photo.which() == 0 /* InputFile::Ptr */) { + if (photo.which() == 0) { // InputFile::Ptr auto file = boost::get(photo); args.emplace_back("photo", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("photo", boost::get(photo)); + } else { // const std::string& + args.emplace_back("photo", boost::get(photo)); } if (!caption.empty()) { args.emplace_back("caption", caption); @@ -218,6 +242,9 @@ Message::Ptr Api::sendPhoto(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -231,28 +258,29 @@ Message::Ptr Api::sendPhoto(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendAudio(std::int64_t chatId, - boost::variant audio, +Message::Ptr Api::sendAudio(boost::variant chatId, + boost::variant audio, const std::string& caption, std::int32_t duration, const std::string& performer, const std::string& title, - boost::variant thumb, + boost::variant thumb, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(13); + args.reserve(14); args.emplace_back("chat_id", chatId); - if (audio.which() == 0 /* InputFile::Ptr */) { + if (audio.which() == 0) { // InputFile::Ptr auto file = boost::get(audio); args.emplace_back("audio", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("audio", boost::get(audio)); + } else { // const std::string& + args.emplace_back("audio", boost::get(audio)); } if (!caption.empty()) { args.emplace_back("caption", caption); @@ -272,11 +300,11 @@ Message::Ptr Api::sendAudio(std::int64_t chatId, if (!title.empty()) { args.emplace_back("title", title); } - if (thumb.which() == 0 /* InputFile::Ptr */) { + if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - auto thumbStr = boost::get(thumb); + } else { // const std::string& + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -284,6 +312,9 @@ Message::Ptr Api::sendAudio(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -297,9 +328,9 @@ Message::Ptr Api::sendAudio(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendDocument(std::int64_t chatId, - boost::variant document, - boost::variant thumb, +Message::Ptr Api::sendDocument(boost::variant chatId, + boost::variant document, + boost::variant thumb, const std::string& caption, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, @@ -307,22 +338,23 @@ Message::Ptr Api::sendDocument(std::int64_t chatId, bool disableNotification, const std::vector& captionEntities, bool disableContentTypeDetection, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(11); + args.reserve(12); args.emplace_back("chat_id", chatId); - if (document.which() == 0 /* InputFile::Ptr */) { + if (document.which() == 0) { // InputFile::Ptr auto file = boost::get(document); args.emplace_back("document", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("document", boost::get(document)); + } else { // const std::string& + args.emplace_back("document", boost::get(document)); } - if (thumb.which() == 0 /* InputFile::Ptr */) { + if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - auto thumbStr = boost::get(thumb); + } else { // const std::string& + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -342,6 +374,9 @@ Message::Ptr Api::sendDocument(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -355,29 +390,30 @@ Message::Ptr Api::sendDocument(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDocument", args)); } -Message::Ptr Api::sendVideo(std::int64_t chatId, - boost::variant video, +Message::Ptr Api::sendVideo(boost::variant chatId, + boost::variant video, bool supportsStreaming, std::int32_t duration, std::int32_t width, std::int32_t height, - boost::variant thumb, - const std::string& caption, + boost::variant thumb, + const std::string& caption , std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(14); + args.reserve(15); args.emplace_back("chat_id", chatId); - if (video.which() == 0 /* InputFile::Ptr */) { + if (video.which() == 0) { // InputFile::Ptr auto file = boost::get(video); args.emplace_back("video", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("video", boost::get(video)); + } else { // const std::string& + args.emplace_back("video", boost::get(video)); } if (duration) { args.emplace_back("duration", duration); @@ -388,11 +424,11 @@ Message::Ptr Api::sendVideo(std::int64_t chatId, if (height) { args.emplace_back("height", height); } - if (thumb.which() == 0 /* InputFile::Ptr */) { + if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - auto thumbStr = boost::get(thumb); + } else { // const std::string& + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -412,6 +448,9 @@ Message::Ptr Api::sendVideo(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -425,28 +464,29 @@ Message::Ptr Api::sendVideo(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendAnimation(std::int64_t chatId, - boost::variant animation, +Message::Ptr Api::sendAnimation(boost::variant chatId, + boost::variant animation, std::int32_t duration, std::int32_t width, std::int32_t height, - boost::variant thumb, + boost::variant thumb, const std::string& caption, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(13); + args.reserve(14); args.emplace_back("chat_id", chatId); - if (animation.which() == 0 /* InputFile::Ptr */) { + if (animation.which() == 0) { // InputFile::Ptr auto file = boost::get(animation); args.emplace_back("animation", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("animation", boost::get(animation)); + } else { // const std::string& + args.emplace_back("animation", boost::get(animation)); } if (duration) { args.emplace_back("duration", duration); @@ -457,11 +497,11 @@ Message::Ptr Api::sendAnimation(std::int64_t chatId, if (height) { args.emplace_back("height", height); } - if (thumb.which() == 0 /* InputFile::Ptr */) { + if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - auto thumbStr = boost::get(thumb); + } else { // const std::string& + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -478,6 +518,9 @@ Message::Ptr Api::sendAnimation(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -491,8 +534,8 @@ Message::Ptr Api::sendAnimation(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); } -Message::Ptr Api::sendVoice(std::int64_t chatId, - boost::variant voice, +Message::Ptr Api::sendVoice(boost::variant chatId, + boost::variant voice, const std::string& caption, std::int32_t duration, std::int32_t replyToMessageId, @@ -500,16 +543,17 @@ Message::Ptr Api::sendVoice(std::int64_t chatId, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(10); + args.reserve(11); args.emplace_back("chat_id", chatId); - if (voice.which() == 0 /* InputFile::Ptr */) { + if (voice.which() == 0) { // InputFile::Ptr auto file = boost::get(voice); args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("voice", boost::get(voice)); + } else { // const std::string& + args.emplace_back("voice", boost::get(voice)); } if (!caption.empty()) { args.emplace_back("caption", caption); @@ -526,6 +570,9 @@ Message::Ptr Api::sendVoice(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -539,24 +586,25 @@ Message::Ptr Api::sendVoice(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args)); } -Message::Ptr Api::sendVideoNote(std::int64_t chatId, - boost::variant videoNote, +Message::Ptr Api::sendVideoNote(boost::variant chatId, + boost::variant videoNote, std::int64_t replyToMessageId, bool disableNotification, std::int32_t duration, std::int32_t length, - boost::variant thumb, + boost::variant thumb, GenericReply::Ptr replyMarkup, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(9); + args.reserve(10); args.emplace_back("chat_id", chatId); - if (videoNote.which() == 0 /* InputFile::Ptr */) { + if (videoNote.which() == 0) { // InputFile::Ptr auto file = boost::get(videoNote); args.emplace_back("video_note", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("video_note", boost::get(videoNote)); + } else { // const std::string& + args.emplace_back("video_note", boost::get(videoNote)); } if (duration) { args.emplace_back("duration", duration); @@ -564,11 +612,11 @@ Message::Ptr Api::sendVideoNote(std::int64_t chatId, if (length) { args.emplace_back("length", length); } - if (thumb.which() == 0 /* InputFile::Ptr */) { + if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - auto thumbStr = boost::get(thumb); + } else { // const std::string& + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -576,6 +624,9 @@ Message::Ptr Api::sendVideoNote(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -589,16 +640,23 @@ Message::Ptr Api::sendVideoNote(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideoNote", args)); } -vector Api::sendMediaGroup(std::int64_t chatId, const std::vector& media, bool disableNotification, - std::int32_t replyToMessageId, bool allowSendingWithoutReply) const { +vector Api::sendMediaGroup(boost::variant chatId, + const std::vector& media, + bool disableNotification, + std::int32_t replyToMessageId, + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(5); + args.reserve(6); args.emplace_back("chat_id", chatId); args.emplace_back("media", _tgTypeParser.parseArray(&TgTypeParser::parseInputMedia, media)); if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId != 0) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -609,19 +667,20 @@ vector Api::sendMediaGroup(std::int64_t chatId, const std::vector< return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); } -Message::Ptr Api::sendLocation(std::int64_t chatId, +Message::Ptr Api::sendLocation(boost::variant chatId, float latitude, float longitude, - std::uint32_t livePeriod, + std::int32_t livePeriod, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, bool disableNotification, float horizontalAccuracy, - std::uint32_t heading, - std::uint32_t proximityAlertRadius, - bool allowSendingWithoutReply) const { + std::int32_t heading, + std::int32_t proximityAlertRadius, + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(11); + args.reserve(12); args.emplace_back("chat_id", chatId); args.emplace_back("latitude", latitude); @@ -641,6 +700,9 @@ Message::Ptr Api::sendLocation(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -711,7 +773,7 @@ Message::Ptr Api::stopMessageLiveLocation(std::int64_t chatId, std::int32_t mess return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); } -Message::Ptr Api::sendVenue(std::int64_t chatId, +Message::Ptr Api::sendVenue(boost::variant chatId, float latitude, float longitude, const std::string& title, @@ -723,9 +785,10 @@ Message::Ptr Api::sendVenue(std::int64_t chatId, GenericReply::Ptr replyMarkup, const std::string& googlePlaceId, const std::string& googlePlaceType, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(13); + args.reserve(14); args.emplace_back("chat_id", chatId); args.emplace_back("latitude", latitude); @@ -747,6 +810,9 @@ Message::Ptr Api::sendVenue(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -760,17 +826,18 @@ Message::Ptr Api::sendVenue(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args)); } -Message::Ptr Api::sendContact(std::int64_t chatId, - const std::string& phoneNumber, - const std::string& firstName, - const std::string& lastName, - const std::string& vcard, - bool disableNotification, - std::int32_t replyToMessageId, - GenericReply::Ptr replyMarkup, - bool allowSendingWithoutReply) const { +Message::Ptr Api::sendContact(boost::variant chatId, + const std::string& phoneNumber, + const std::string& firstName, + const std::string& lastName , + const std::string& vcard, + bool disableNotification, + std::int32_t replyToMessageId, + GenericReply::Ptr replyMarkup, + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(9); + args.reserve(10); args.emplace_back("chat_id", chatId); args.emplace_back("phone_number", phoneNumber); @@ -784,6 +851,9 @@ Message::Ptr Api::sendContact(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -797,7 +867,7 @@ Message::Ptr Api::sendContact(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendContact", args)); } -Message::Ptr Api::sendPoll(std::int64_t chatId, +Message::Ptr Api::sendPoll(boost::variant chatId, const std::string& question, const std::vector& options, bool disableNotification, @@ -813,9 +883,10 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, std::int32_t openPeriod, std::int32_t closeDate, bool isClosed, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(17); + args.reserve(18); args.emplace_back("chat_id", chatId); args.emplace_back("question", question); @@ -855,6 +926,9 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId != 0) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -868,24 +942,32 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); } -Message::Ptr Api::sendDice(std::int64_t chatId, +Message::Ptr Api::sendDice(boost::variant chatId, bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& emoji, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(6); + args.reserve(7); args.emplace_back("chat_id", chatId); if (!emoji.empty()) { args.emplace_back("emoji", emoji); } - args.emplace_back("disable_notification", disableNotification); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId != 0) { args.emplace_back("reply_to_message_id", replyToMessageId); } - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (allowSendingWithoutReply) { + args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } @@ -1104,7 +1186,7 @@ ChatInviteLink::Ptr Api::createChatInviteLink(std::int64_t chatId, } ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId, - std::string inviteLink, + const std::string& inviteLink, std::int32_t expireDate, std::int32_t memberLimit, const std::string& name, @@ -1131,7 +1213,7 @@ ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId, } ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId, - std::string inviteLink) const { + const std::string& inviteLink) const { vector args; args.reserve(2); @@ -1493,25 +1575,29 @@ void Api::deleteMessage(std::int64_t chatId, std::int32_t messageId) const { sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) }); } -Message::Ptr Api::sendSticker(std::int64_t chatId, - boost::variant sticker, +Message::Ptr Api::sendSticker(boost::variant chatId, + boost::variant sticker, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, bool disableNotification, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(6); + args.reserve(7); args.emplace_back("chat_id", chatId); - if (sticker.which() == 0 /* InputFile::Ptr */) { + if (sticker.which() == 0) { // InputFile::Ptr auto file = boost::get(sticker); args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("sticker", boost::get(sticker)); + } else { // const std::string& + args.emplace_back("sticker", boost::get(sticker)); } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -1666,7 +1752,7 @@ bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector("", false); } -Message::Ptr Api::sendInvoice(std::int64_t chatId, +Message::Ptr Api::sendInvoice(boost::variant chatId, const std::string& title, const std::string& description, const std::string& payload, @@ -1691,9 +1777,10 @@ Message::Ptr Api::sendInvoice(std::int64_t chatId, bool allowSendingWithoutReply, std::int32_t maxTipAmount, const std::vector& suggestedTipAmounts, - const std::string& startParameter) const { + const std::string& startParameter, + bool protectContent) const { vector args; - args.reserve(26); + args.reserve(27); args.emplace_back("chat_id", chatId); args.emplace_back("title", title); @@ -1750,6 +1837,9 @@ Message::Ptr Api::sendInvoice(std::int64_t chatId, if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } @@ -1803,15 +1893,19 @@ Message::Ptr Api::sendGame(std::int64_t chatId, std::int32_t replyToMessageId, InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification, - bool allowSendingWithoutReply) const { + bool allowSendingWithoutReply, + bool protectContent) const { vector args; - args.reserve(6); + args.reserve(7); args.emplace_back("chat_id", chatId); args.emplace_back("game_short_name", gameShortName); if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } if (replyToMessageId) { args.emplace_back("reply_to_message_id", replyToMessageId); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index e8a81d7..85b44e8 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1519,7 +1519,7 @@ ChatMemberRestricted::Ptr TgTypeParser::parseJsonAndGetChatMemberRestricted(cons 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->untilDate = data.get("until_date", 0); + result->untilDate = data.get("until_date", 0); return result; } @@ -1666,9 +1666,9 @@ ChatInviteLink::Ptr TgTypeParser::parseJsonAndGetChatInviteLink(const boost::pro result->isPrimary = data.get("is_primary", false); result->isRevoked = data.get("is_revoked", false); result->name = data.get("name", ""); - result->expireDate = data.get("expire_date", 0); - result->memberLimit = data.get("member_limit", 0); - result->pendingJoinRequestCount = data.get("pending_join_request_count", 0); + result->expireDate = data.get("expire_date", 0); + result->memberLimit = data.get("member_limit", 0); + result->pendingJoinRequestCount = data.get("pending_join_request_count", 0); return result; } -- cgit v1.2.3 From 707bcac4dd0fffd961dbb325e7d11752ee55392d Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Fri, 9 Sep 2022 17:33:11 +0200 Subject: Update to API 5.7 --- src/Api.cpp | 57 +++++++++++++++++++++++++++------------------------- src/TgTypeParser.cpp | 4 ++++ 2 files changed, 34 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index bb63721..9538485 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1634,27 +1634,28 @@ bool Api::createNewStickerSet(std::int64_t userId, const std::string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition, - boost::variant pngSticker, - boost::variant tgsSticker) const { + boost::variant pngSticker, + InputFile::Ptr tgsSticker, + InputFile::Ptr webmSticker) const { vector args; - args.reserve(8); + args.reserve(9); args.emplace_back("user_id", userId); args.emplace_back("name", name); args.emplace_back("title", title); - args.emplace_back("emojis", emojis); - if (pngSticker.which() == 0 /* InputFile::Ptr */) { + if (pngSticker.which() == 0) { // InputFile::Ptr auto file = boost::get(pngSticker); args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("png_sticker", boost::get(pngSticker)); + } else { // const std::string& + args.emplace_back("png_sticker", boost::get(pngSticker)); } - if (tgsSticker.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(tgsSticker); - args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("tgs_sticker", boost::get(tgsSticker)); + if (tgsSticker != nullptr) { + args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName); + } + if (webmSticker != nullptr) { + args.emplace_back("webm_sticker", webmSticker->data, true, webmSticker->mimeType, webmSticker->fileName); } + args.emplace_back("emojis", emojis); if (containsMasks) { args.emplace_back("contains_mask", containsMasks); } @@ -1666,29 +1667,31 @@ bool Api::createNewStickerSet(std::int64_t userId, } bool Api::addStickerToSet(std::int64_t userId, - const std::string& name, - const std::string& emojis, - MaskPosition::Ptr maskPosition, - boost::variant pngSticker, - boost::variant tgsSticker) const { + const std::string& name, + const std::string& emojis, + MaskPosition::Ptr maskPosition, + boost::variant pngSticker, + InputFile::Ptr tgsSticker, + InputFile::Ptr webmSticker) const { vector args; - args.reserve(6); + args.reserve(7); args.emplace_back("user_id", userId); args.emplace_back("name", name); - args.emplace_back("emojis", emojis); - if (pngSticker.which() == 0 /* InputFile::Ptr */) { + + if (pngSticker.which() == 0) { // InputFile::Ptr auto file = boost::get(pngSticker); args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("png_sticker", boost::get(pngSticker)); + } else { // const std::string& + args.emplace_back("png_sticker", boost::get(pngSticker)); } - if (tgsSticker.which() == 0 /* InputFile::Ptr */) { - auto file = boost::get(tgsSticker); - args.emplace_back("tgs_sticker", file->data, true, file->mimeType, file->fileName); - } else /* std::string */ { - args.emplace_back("tgs_sticker", boost::get(tgsSticker)); + if (tgsSticker != nullptr) { + args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName); } + if (webmSticker != nullptr) { + args.emplace_back("webm_sticker", webmSticker->data, true, webmSticker->mimeType, webmSticker->fileName); + } + args.emplace_back("emojis", emojis); if (maskPosition != nullptr) { args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 85b44e8..daf80c8 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -386,6 +386,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::pt result->width = data.get("width", 0); result->height = data.get("height", 0); result->isAnimated = data.get("is_animated", false); + result->isVideo = data.get("is_video", false); result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->emoji = data.get("emoji", ""); result->setName = data.get("set_name", ""); @@ -405,6 +406,7 @@ std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "is_animated", object->isAnimated); + appendToJson(result, "is_video", object->isVideo); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); appendToJson(result, "emoji", object->emoji); appendToJson(result, "set_name", object->setName); @@ -420,6 +422,7 @@ StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const boost::property_tr result->name = data.get("name", ""); result->title = data.get("title", ""); result->isAnimated = data.get("is_animated", false); + result->isVideo = data.get("is_video", false); result->containsMasks = data.get("contains_masks", false); result->stickers = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, data, "stickers"); result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); @@ -435,6 +438,7 @@ std::string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const { appendToJson(result, "name", object->name); appendToJson(result, "title", object->title); appendToJson(result, "is_animated", object->isAnimated); + appendToJson(result, "is_video", object->isVideo); appendToJson(result, "contains_masks", object->containsMasks); appendToJson(result, "stickers", parseArray(&TgTypeParser::parseSticker, object->stickers)); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); -- cgit v1.2.3 From 924dd8b38b588fad05f55424f547e521ccfe71f5 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sun, 11 Sep 2022 12:32:11 +0200 Subject: Update to API 6.0 --- src/Api.cpp | 71 ++++++++++- src/TgTypeParser.cpp | 305 +++++++++++++++++++++++++++++++++++++++++------ src/types/MenuButton.cpp | 11 ++ 3 files changed, 349 insertions(+), 38 deletions(-) create mode 100644 src/types/MenuButton.cpp (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index 9538485..ee17b51 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1057,7 +1057,7 @@ bool Api::restrictChatMember(std::int64_t chatId, std::int64_t userId, TgBot::Ch return sendRequest("restrictChatMember", args).get("", false); } -bool Api::promoteChatMember(std::int64_t chatId, +bool Api::promoteChatMember(boost::variant chatId, std::int64_t userId, bool canChangeInfo, bool canPostMessages, @@ -1068,7 +1068,7 @@ bool Api::promoteChatMember(std::int64_t chatId, bool canPromoteMembers, bool isAnonymous, bool canManageChat, - bool canManageVoiceChats, + bool canManageVideoChats, bool canRestrictMembers) const { vector args; args.reserve(13); @@ -1090,8 +1090,8 @@ bool Api::promoteChatMember(std::int64_t chatId, if (canDeleteMessages) { args.emplace_back("can_delete_messages", canDeleteMessages); } - if (canManageVoiceChats) { - args.emplace_back("can_manage_voice_chats", canManageVoiceChats); + if (canManageVideoChats) { + args.emplace_back("can_manage_video_chats", canManageVideoChats); } if (canRestrictMembers) { args.emplace_back("can_restrict_members", canRestrictMembers); @@ -1427,6 +1427,58 @@ std::vector Api::getMyCommands(BotCommandScope::Ptr scope, return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands", args)); } +bool Api::setChatMenuButton(std::int64_t chatId, + MenuButton::Ptr menuButton) const { + vector args; + args.reserve(2); + + if (chatId != 0) { + args.emplace_back("chat_id", chatId); + } + if (menuButton != nullptr) { + args.emplace_back("menu_button", _tgTypeParser.parseMenuButton(menuButton)); + } + + return sendRequest("setChatMenuButton", args).get("", false); +} + +MenuButton::Ptr Api::getChatMenuButton(std::int64_t chatId) const { + vector args; + args.reserve(1); + + if (chatId != 0) { + args.emplace_back("chat_id", chatId); + } + + return _tgTypeParser.parseJsonAndGetMenuButton(sendRequest("getChatMenuButton", args)); +} + +bool Api::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights, + bool forChannels) const { + vector args; + args.reserve(2); + + if (rights != nullptr) { + args.emplace_back("rights", _tgTypeParser.parseChatAdministratorRights(rights)); + } + if (forChannels) { + args.emplace_back("for_channels", forChannels); + } + + return sendRequest("setMyDefaultAdministratorRights", args).get("", false); +} + +ChatAdministratorRights::Ptr Api::getMyDefaultAdministratorRights(bool forChannels) const { + vector args; + args.reserve(1); + + if (forChannels) { + args.emplace_back("for_channels", forChannels); + } + + return _tgTypeParser.parseJsonAndGetChatAdministratorRights(sendRequest("getMyDefaultAdministratorRights", args)); +} + Message::Ptr Api::editMessageText(const std::string& text, std::int64_t chatId, std::int32_t messageId, @@ -1755,6 +1807,17 @@ bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector("", false); } +SentWebAppMessage::Ptr Api::answerWebAppQuery(const std::string& webAppQueryId, + InlineQueryResult::Ptr result) const { + vector args; + args.reserve(2); + + args.emplace_back("web_app_query_id", webAppQueryId); + args.emplace_back("result", _tgTypeParser.parseInlineQueryResult(result)); + + return _tgTypeParser.parseJsonAndGetSentWebAppMessage(sendRequest("answerWebAppQuery", args)); +} + Message::Ptr Api::sendInvoice(boost::variant chatId, const std::string& title, const std::string& description, diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index daf80c8..27e96ae 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -196,10 +196,11 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt result->passportData = tryParseJson(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data"); result->passportData = tryParseJson(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data"); result->proximityAlertTriggered = tryParseJson(&TgTypeParser::parseJsonAndGetProximityAlertTriggered, data, "proximity_alert_triggered"); - result->voiceChatScheduled = tryParseJson(&TgTypeParser::parseJsonAndGetVoiceChatScheduled, data, "voice_chat_scheduled"); - result->voiceChatStarted = tryParseJson(&TgTypeParser::parseJsonAndGetVoiceChatStarted, data, "voice_chat_started"); - result->voiceChatEnded = tryParseJson(&TgTypeParser::parseJsonAndGetVoiceChatEnded, data, "voice_chat_ended"); - result->voiceChatParticipantsInvited = tryParseJson(&TgTypeParser::parseJsonAndGetVoiceChatParticipantsInvited, data, "voice_chat_participants_invited"); + result->videoChatScheduled = tryParseJson(&TgTypeParser::parseJsonAndGetVideoChatScheduled, data, "video_chat_scheduled"); + result->videoChatStarted = tryParseJson(&TgTypeParser::parseJsonAndGetVideoChatStarted, data, "video_chat_started"); + result->videoChatEnded = tryParseJson(&TgTypeParser::parseJsonAndGetVideoChatEnded, data, "video_chat_ended"); + result->videoChatParticipantsInvited = tryParseJson(&TgTypeParser::parseJsonAndGetVideoChatParticipantsInvited, data, "video_chat_participants_invited"); + result->webAppData = tryParseJson(&TgTypeParser::parseJsonAndGetWebAppData, data, "web_app_data"); result->replyMarkup = tryParseJson(&TgTypeParser::parseJsonAndGetInlineKeyboardMarkup, data, "reply_markup"); return result; } @@ -263,10 +264,11 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "connected_website", object->connectedWebsite); appendToJson(result, "passport_data", parsePassportData(object->passportData)); appendToJson(result, "proximity_alert_triggered", parseProximityAlertTriggered(object->proximityAlertTriggered)); - appendToJson(result, "voice_chat_scheduled", parseVoiceChatScheduled(object->voiceChatScheduled)); - appendToJson(result, "voice_chat_started", parseVoiceChatStarted(object->voiceChatStarted)); - appendToJson(result, "voice_chat_ended", parseVoiceChatEnded(object->voiceChatEnded)); - appendToJson(result, "voice_chat_participants_invited", parseVoiceChatParticipantsInvited(object->voiceChatParticipantsInvited)); + appendToJson(result, "video_chat_scheduled", parseVideoChatScheduled(object->videoChatScheduled)); + appendToJson(result, "video_chat_started", parseVideoChatStarted(object->videoChatStarted)); + appendToJson(result, "video_chat_ended", parseVideoChatEnded(object->videoChatEnded)); + appendToJson(result, "video_chat_participants_invited", parseVideoChatParticipantsInvited(object->videoChatParticipantsInvited)); + appendToJson(result, "web_app_data", parseWebAppData(object->webAppData)); appendToJson(result, "reply_markup", parseInlineKeyboardMarkup(object->replyMarkup)); removeLastComma(result); result += '}'; @@ -747,6 +749,21 @@ std::string TgTypeParser::parseGame(const Game::Ptr& object) const { return result; } +CallbackGame::Ptr TgTypeParser::parseJsonAndGetCallbackGame(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + return result; +} + +std::string TgTypeParser::parseCallbackGame(const CallbackGame::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + result += '}'; + return result; +} + GameHighScore::Ptr TgTypeParser::parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->position = data.get("position", ""); @@ -887,6 +904,26 @@ std::string TgTypeParser::parseVenue(const Venue::Ptr& object) const { return result; } +WebAppData::Ptr TgTypeParser::parseJsonAndGetWebAppData(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->data = data.get("data", ""); + result->buttonText = data.get("button_text", ""); + return result; +} + +std::string TgTypeParser::parseWebAppData(const WebAppData::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "data", object->data); + appendToJson(result, "button_text", object->buttonText); + removeLastComma(result); + result += '}'; + return result; +} + ProximityAlertTriggered::Ptr TgTypeParser::parseJsonAndGetProximityAlertTriggered(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->traveler = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "traveler"); @@ -927,13 +964,13 @@ std::string TgTypeParser::parseMessageAutoDeleteTimerChanged(const MessageAutoDe return result; } -VoiceChatScheduled::Ptr TgTypeParser::parseJsonAndGetVoiceChatScheduled(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); +VideoChatScheduled::Ptr TgTypeParser::parseJsonAndGetVideoChatScheduled(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); result->startDate = data.get("start_date", 0); return result; } -std::string TgTypeParser::parseVoiceChatScheduled(const VoiceChatScheduled::Ptr& object) const { +std::string TgTypeParser::parseVideoChatScheduled(const VideoChatScheduled::Ptr& object) const { if (!object) { return ""; } @@ -945,25 +982,28 @@ std::string TgTypeParser::parseVoiceChatScheduled(const VoiceChatScheduled::Ptr& return result; } -VoiceChatStarted::Ptr TgTypeParser::parseJsonAndGetVoiceChatStarted(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); +VideoChatStarted::Ptr TgTypeParser::parseJsonAndGetVideoChatStarted(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); return result; } -std::string TgTypeParser::parseVoiceChatStarted(const VoiceChatStarted::Ptr& object) const { +std::string TgTypeParser::parseVideoChatStarted(const VideoChatStarted::Ptr& object) const { if (!object) { return ""; } - return "{}"; + std::string result; + result += '{'; + result += '}'; + return result; } -VoiceChatEnded::Ptr TgTypeParser::parseJsonAndGetVoiceChatEnded(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); +VideoChatEnded::Ptr TgTypeParser::parseJsonAndGetVideoChatEnded(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); result->duration = data.get("duration", 0); return result; } -std::string TgTypeParser::parseVoiceChatEnded(const VoiceChatEnded::Ptr& object) const { +std::string TgTypeParser::parseVideoChatEnded(const VideoChatEnded::Ptr& object) const { if (!object) { return ""; } @@ -975,13 +1015,13 @@ std::string TgTypeParser::parseVoiceChatEnded(const VoiceChatEnded::Ptr& object) return result; } -VoiceChatParticipantsInvited::Ptr TgTypeParser::parseJsonAndGetVoiceChatParticipantsInvited(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); +VideoChatParticipantsInvited::Ptr TgTypeParser::parseJsonAndGetVideoChatParticipantsInvited(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); result->users = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUser, data, "users"); return result; } -std::string TgTypeParser::parseVoiceChatParticipantsInvited(const VoiceChatParticipantsInvited::Ptr& object) const { +std::string TgTypeParser::parseVideoChatParticipantsInvited(const VideoChatParticipantsInvited::Ptr& object) const { if (!object) { return ""; } @@ -1254,6 +1294,24 @@ std::string TgTypeParser::parseFile(const File::Ptr& object) const { return result; } +WebAppInfo::Ptr TgTypeParser::parseJsonAndGetWebAppInfo(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->url = data.get("url", ""); + return result; +} + +std::string TgTypeParser::parseWebAppInfo(const WebAppInfo::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "url", object->url); + removeLastComma(result); + result += '}'; + return result; +} + ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); for (const auto& item : data.find("keyboard")->second){ @@ -1300,6 +1358,7 @@ KeyboardButton::Ptr TgTypeParser::parseJsonAndGetKeyboardButton(const boost::pro result->requestContact = data.get("request_contact", false); result->requestLocation = data.get("request_location", false); result->requestPoll = tryParseJson(&TgTypeParser::parseJsonAndGetKeyboardButtonPollType, data, "request_poll"); + result->webApp = tryParseJson(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app"); return result; } @@ -1313,6 +1372,7 @@ std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) appendToJson(result, "request_contact", object->requestContact); appendToJson(result, "request_location", object->requestLocation); appendToJson(result, "request_poll", parseKeyboardButtonPollType(object->requestPoll)); + appendToJson(result, "web_app", parseWebAppInfo(object->webApp)); removeLastComma(result); result += '}'; return result; @@ -1455,18 +1515,18 @@ ChatMemberAdministrator::Ptr TgTypeParser::parseJsonAndGetChatMemberAdministrato // NOTE: This function will be called by parseJsonAndGetChatMember(). auto result(std::make_shared()); result->canBeEdited = data.get("can_be_edited", false); - result->customTitle = data.get("custom_title", ""); result->isAnonymous = data.get("is_anonymous", false); result->canManageChat = data.get("can_manage_chat", false); - result->canPostMessages = data.get("can_post_messages", false); - result->canEditMessages = data.get("can_edit_messages", false); result->canDeleteMessages = data.get("can_delete_messages", false); - result->canManageVoiceChats = data.get("can_manage_voice_chats", false); + result->canManageVideoChats = data.get("can_manage_video_chats", false); result->canRestrictMembers = data.get("can_restrict_members", false); result->canPromoteMembers = data.get("can_promote_members", false); result->canChangeInfo = data.get("can_change_info", false); result->canInviteUsers = data.get("can_invite_users", false); + result->canPostMessages = data.get("can_post_messages", false); + result->canEditMessages = data.get("can_edit_messages", false); result->canPinMessages = data.get("can_pin_messages", false); + result->customTitle = data.get("custom_title", ""); return result; } @@ -1478,18 +1538,18 @@ std::string TgTypeParser::parseChatMemberAdministrator(const ChatMemberAdministr // curly brackets to the result std::string. std::string result; appendToJson(result, "can_be_edited", object->canBeEdited); - appendToJson(result, "custom_title", object->customTitle); appendToJson(result, "is_anonymous", object->isAnonymous); appendToJson(result, "can_manage_chat", object->canManageChat); - appendToJson(result, "can_post_messages", object->canPostMessages); - appendToJson(result, "can_edit_messages", object->canEditMessages); appendToJson(result, "can_delete_messages", object->canDeleteMessages); - appendToJson(result, "can_manage_voice_chats", object->canManageVoiceChats); + appendToJson(result, "can_manage_video_chats", object->canManageVideoChats); appendToJson(result, "can_restrict_members", object->canRestrictMembers); appendToJson(result, "can_promote_members", object->canPromoteMembers); appendToJson(result, "can_change_info", object->canChangeInfo); appendToJson(result, "can_invite_users", object->canInviteUsers); + appendToJson(result, "can_post_messages", object->canPostMessages); + appendToJson(result, "can_edit_messages", object->canEditMessages); appendToJson(result, "can_pin_messages", object->canPinMessages); + appendToJson(result, "custom_title", object->customTitle); // The last comma will be erased by parseChatMember(). return result; } @@ -1696,6 +1756,44 @@ std::string TgTypeParser::parseChatInviteLink(const ChatInviteLink::Ptr& object) return result; } +ChatAdministratorRights::Ptr TgTypeParser::parseJsonAndGetChatAdministratorRights(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->isAnonymous = data.get("is_anonymous", false); + result->canManageChat = data.get("can_manage_chat", false); + result->canDeleteMessages = data.get("can_delete_messages", false); + result->canManageVideoChats = data.get("can_manage_video_chats", false); + result->canRestrictMembers = data.get("can_restrict_members", false); + result->canPromoteMembers = data.get("can_promote_members", false); + result->canChangeInfo = data.get("can_change_info", false); + result->canInviteUsers = data.get("can_invite_users", false); + result->canPostMessages = data.get("can_post_messages", false); + result->canEditMessages = data.get("can_edit_messages", false); + result->canPinMessages = data.get("can_pin_messages", false); + return result; +} + +std::string TgTypeParser::parseChatAdministratorRights(const ChatAdministratorRights::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "is_anonymous", object->isAnonymous); + appendToJson(result, "can_manage_chat", object->canManageChat); + appendToJson(result, "can_delete_messages", object->canDeleteMessages); + appendToJson(result, "can_manage_video_chats", object->canManageVideoChats); + appendToJson(result, "can_restrict_members", object->canRestrictMembers); + appendToJson(result, "can_promote_members", object->canPromoteMembers); + appendToJson(result, "can_change_info", object->canChangeInfo); + appendToJson(result, "can_invite_users", object->canInviteUsers); + appendToJson(result, "can_post_messages", object->canPostMessages); + appendToJson(result, "can_edit_messages", object->canEditMessages); + appendToJson(result, "can_pin_messages", object->canPinMessages); + removeLastComma(result); + result += '}'; + return result; +} + ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->migrateToChatId = data.get("migrate_to_chat_id", 0); @@ -2582,6 +2680,24 @@ std::string TgTypeParser::parseChosenInlineResult(const ChosenInlineResult::Ptr& return result; } +SentWebAppMessage::Ptr TgTypeParser::parseJsonAndGetSentWebAppMessage(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->inlineMessageId = data.get("inline_message_id", ""); + return result; +} + +std::string TgTypeParser::parseSentWebAppMessage(const SentWebAppMessage::Ptr& object) const { + if (!object){ + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "inline_message_id", object->inlineMessageId); + removeLastComma(result); + result += '}'; + return result; +} + CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->id = data.get("id"); @@ -2645,13 +2761,14 @@ std::string TgTypeParser::parseInlineKeyboardMarkup(const InlineKeyboardMarkup:: InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); - result->text = data.get("text"); + result->text = data.get("text", ""); result->url = data.get("url", ""); - result->loginUrl = std::make_shared(); result->callbackData = data.get("callback_data", ""); + result->webApp = tryParseJson(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app"); + result->loginUrl = tryParseJson(&TgTypeParser::parseJsonAndGetLoginUrl, data, "login_url"); result->switchInlineQuery = data.get("switch_inline_query", ""); result->switchInlineQueryCurrentChat = data.get("switch_inline_query_current_chat", ""); - result->callbackGame = std::make_shared(); + result->callbackGame = tryParseJson(&TgTypeParser::parseJsonAndGetCallbackGame, data, "callback_game"); result->pay = data.get("pay", false); return result; } @@ -2661,8 +2778,7 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton:: } std::string result; result += '{'; - if(object->pay) - appendToJson(result, "pay", object->pay); + appendToJson(result, "pay", object->pay); appendToJson(result, "text", object->text); appendToJson(result, "url", object->url); appendToJson(result, "callback_data", object->callbackData); @@ -2673,6 +2789,30 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton:: return result; } +LoginUrl::Ptr TgTypeParser::parseJsonAndGetLoginUrl(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->url = data.get("url", ""); + result->forwardText = data.get("forward_text", ""); + result->botUsername = data.get("bot_username", ""); + result->requestWriteAccess = data.get("request_write_access", false); + return result; +} + +std::string TgTypeParser::parseLoginUrl(const LoginUrl::Ptr& object) const { + if (!object){ + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "url", object->url); + appendToJson(result, "forward_text", object->forwardText); + appendToJson(result, "bot_username", object->botUsername); + appendToJson(result, "request_write_access", object->requestWriteAccess); + removeLastComma(result); + result += '}'; + return result; +} + WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->url = data.get("url", ""); @@ -2681,6 +2821,7 @@ WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_ result->ipAddress = data.get("ip_address", ""); result->lastErrorDate = data.get("last_error_date", 0); result->lastErrorMessage = data.get("last_error_message", ""); + result->lastSynchronizationErrorDate = data.get("last_synchronization_error_date", 0); result->maxConnections = data.get("max_connections", 0); result->allowedUpdates = parseJsonAndGetArray( [](const boost::property_tree::ptree& innerData)->std::string { @@ -2702,6 +2843,7 @@ std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const appendToJson(result, "ip_address", object->ipAddress); appendToJson(result, "last_error_date", object->lastErrorDate); appendToJson(result, "last_error_message", object->lastErrorMessage); + appendToJson(result, "last_synchronization_error_date", object->lastSynchronizationErrorDate); appendToJson(result, "max_connections", object->maxConnections); appendToJson(result, "allowed_updates", parseArray([](const std::string &s)->std::string { @@ -3174,6 +3316,101 @@ std::string TgTypeParser::parseBotCommandScopeChatMember(const BotCommandScopeCh return result; } +MenuButton::Ptr TgTypeParser::parseJsonAndGetMenuButton(const boost::property_tree::ptree& data) const { + std::string type = data.get("type", ""); + MenuButton::Ptr result; + + if (type == MenuButtonCommands::TYPE) { + result = std::static_pointer_cast(parseJsonAndGetMenuButtonCommands(data)); + } else if (type == MenuButtonWebApp::TYPE) { + result = std::static_pointer_cast(parseJsonAndGetMenuButtonWebApp(data)); + } else if (type == MenuButtonDefault::TYPE) { + result = std::static_pointer_cast(parseJsonAndGetMenuButtonDefault(data)); + } else { + result = std::make_shared(); + } + + result->type = type; + + return result; +} + +std::string TgTypeParser::parseMenuButton(const MenuButton::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "type", object->type); + + if (object->type == MenuButtonCommands::TYPE) { + result += parseMenuButtonCommands(std::static_pointer_cast(object)); + } else if (object->type == MenuButtonWebApp::TYPE) { + result += parseMenuButtonWebApp(std::static_pointer_cast(object)); + } else if (object->type == MenuButtonDefault::TYPE) { + result += parseMenuButtonDefault(std::static_pointer_cast(object)); + } + + removeLastComma(result); + result += '}'; + return result; +} + +MenuButtonCommands::Ptr TgTypeParser::parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetMenuButton(). + auto result(std::make_shared()); + return result; +} + +std::string TgTypeParser::parseMenuButtonCommands(const MenuButtonCommands::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseMenuButton(), so I don't add + // curly brackets to the result std::string. + std::string result; + // The last comma will be erased by parseMenuButton(). + return result; +} + +MenuButtonWebApp::Ptr TgTypeParser::parseJsonAndGetMenuButtonWebApp(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetMenuButton(). + auto result(std::make_shared()); + result->text = data.get("text", ""); + result->webApp = tryParseJson(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app"); + return result; +} + +std::string TgTypeParser::parseMenuButtonWebApp(const MenuButtonWebApp::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseMenuButton(), so I don't add + // curly brackets to the result std::string. + std::string result; + appendToJson(result, "text", object->text); + appendToJson(result, "web_app", parseWebAppInfo(object->webApp)); + // The last comma will be erased by parseMenuButton(). + return result; +} + +MenuButtonDefault::Ptr TgTypeParser::parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetMenuButton(). + auto result(std::make_shared()); + return result; +} + +std::string TgTypeParser::parseMenuButtonDefault(const MenuButtonDefault::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseMenuButton(), so I don't add + // curly brackets to the result std::string. + std::string result; + // The last comma will be erased by parseMenuButton(). + return result; +} + OrderInfo::Ptr TgTypeParser::parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const { auto result(std::make_shared()); result->name = data.get("name", ""); diff --git a/src/types/MenuButton.cpp b/src/types/MenuButton.cpp new file mode 100644 index 0000000..54e3868 --- /dev/null +++ b/src/types/MenuButton.cpp @@ -0,0 +1,11 @@ +#include "tgbot/types/MenuButtonCommands.h" +#include "tgbot/types/MenuButtonWebApp.h" +#include "tgbot/types/MenuButtonDefault.h" + +#include + +using namespace TgBot; + +const std::string MenuButtonCommands::TYPE = "commands"; +const std::string MenuButtonWebApp::TYPE = "web_app"; +const std::string MenuButtonDefault::TYPE = "default"; -- cgit v1.2.3 From 0c3b44cead20fb421bdacaba7613348f7573b282 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sun, 11 Sep 2022 13:58:09 +0200 Subject: Update to API 6.1 --- src/Api.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/TgTypeParser.cpp | 22 ++++++++++---- 2 files changed, 97 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index ee17b51..8d5ef2d 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -45,9 +45,10 @@ bool Api::setWebhook(const std::string& url, std::int32_t maxConnection, const StringArrayPtr& allowedUpdates, const std::string& ipAddress, - bool dropPendingUpdates) const { + bool dropPendingUpdates, + const std::string& secretToken) const { vector args; - args.reserve(6); + args.reserve(7); args.emplace_back("url", url); if (certificate != nullptr) { @@ -69,6 +70,9 @@ bool Api::setWebhook(const std::string& url, if (dropPendingUpdates) { args.emplace_back("drop_pending_updates", dropPendingUpdates); } + if (!secretToken.empty()) { + args.emplace_back("secret_token", secretToken); + } return sendRequest("setWebhook").get("", false); } @@ -1919,6 +1923,81 @@ Message::Ptr Api::sendInvoice(boost::variant c return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendInvoice", args)); } +std::string Api::createInvoiceLink(const std::string& title, + const std::string& description, + const std::string& payload, + const std::string& providerToken, + const std::string& currency, + const std::vector& prices, + std::int32_t maxTipAmount, + const std::vector& suggestedTipAmounts, + const std::string& providerData, + const std::string& photoUrl, + std::int32_t photoSize, + std::int32_t photoWidth, + std::int32_t photoHeight, + bool needName, + bool needPhoneNumber, + bool needEmail, + bool needShippingAddress, + bool sendPhoneNumberToProvider, + bool sendEmailToProvider, + bool isFlexible) const { + vector args; + args.reserve(20); + + args.emplace_back("title", title); + args.emplace_back("description", description); + args.emplace_back("payload", payload); + args.emplace_back("provider_token", providerToken); + args.emplace_back("currency", currency); + args.emplace_back("prices", _tgTypeParser.parseArray(&TgTypeParser::parseLabeledPrice, prices)); + args.emplace_back("max_tip_amount", maxTipAmount); + if (!suggestedTipAmounts.empty()) { + args.emplace_back("suggested_tip_amounts", _tgTypeParser.parseArray([] (const std::int32_t& option) -> std::int32_t { + return option; + }, suggestedTipAmounts)); + } + if (!providerData.empty()) { + args.emplace_back("provider_data", providerData); + } + if (!photoUrl.empty()) { + args.emplace_back("photo_url", photoUrl); + } + if (photoSize) { + args.emplace_back("photo_size", photoSize); + } + if (photoWidth) { + args.emplace_back("photo_width", photoWidth); + } + if (photoHeight) { + args.emplace_back("photo_height", photoHeight); + } + if (needName) { + args.emplace_back("need_name", needName); + } + if (needPhoneNumber) { + args.emplace_back("need_phone_number", needPhoneNumber); + } + if (needEmail) { + args.emplace_back("need_email", needEmail); + } + if (needShippingAddress) { + args.emplace_back("need_shipping_address", needShippingAddress); + } + if (sendPhoneNumberToProvider) { + args.emplace_back("send_phone_number_to_provider", sendPhoneNumberToProvider); + } + if (sendEmailToProvider) { + args.emplace_back("send_email_to_provider", sendEmailToProvider); + } + if (isFlexible) { + args.emplace_back("is_flexible", isFlexible); + } + + return sendRequest("createInvoiceLink", args).get("", ""); +} + bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector& shippingOptions, const std::string& errorMessage) const { vector args; args.reserve(4); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 27e96ae..e6a4317 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -25,6 +25,8 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& d result->photo = tryParseJson(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo"); result->bio = data.get("bio", ""); result->hasPrivateForwards = data.get("has_private_forwards", false); + result->joinToSendMessages = data.get("join_to_send_messages", false); + result->joinByRequest = data.get("join_by_request", false); result->description = data.get("description", ""); result->inviteLink = data.get("invite_link", ""); result->pinnedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); @@ -62,6 +64,8 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const { appendToJson(result, "photo", parseChatPhoto(object->photo)); appendToJson(result, "bio", object->bio); appendToJson(result, "has_private_forwards", object->hasPrivateForwards); + appendToJson(result, "join_to_send_messages", object->joinToSendMessages); + appendToJson(result, "join_by_request", object->joinByRequest); appendToJson(result, "description", object->description); appendToJson(result, "invite_link", object->inviteLink); appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage)); @@ -86,6 +90,8 @@ User::Ptr TgTypeParser::parseJsonAndGetUser(const boost::property_tree::ptree& d result->lastName = data.get("last_name", ""); result->username = data.get("username", ""); result->languageCode = data.get("language_code", ""); + result->isPremium = data.get("is_premium", false); + result->addedToAttachmentMenu = data.get("added_to_attachment_menu", false); result->canJoinGroups = data.get("can_join_groups", false); result->canReadAllGroupMessages = data.get("can_read_all_group_messages", false); result->supportsInlineQueries = data.get("supports_inline_queries", false); @@ -104,6 +110,8 @@ std::string TgTypeParser::parseUser(const User::Ptr& object) const { appendToJson(result, "last_name", object->lastName); appendToJson(result, "username", object->username); appendToJson(result, "language_code", object->languageCode); + appendToJson(result, "is_premium", object->isPremium); + appendToJson(result, "added_to_attachment_menu", object->addedToAttachmentMenu); appendToJson(result, "can_join_groups", object->canJoinGroups); appendToJson(result, "can_read_all_group_messages", object->canReadAllGroupMessages); appendToJson(result, "supports_inline_queries", object->supportsInlineQueries); @@ -328,7 +336,7 @@ Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const boost::property_tree::ptree& result->title = data.get("title", ""); result->fileName = data.get("file_name", ""); result->mimeType = data.get("mime_type", ""); - result->fileSize = data.get("file_size", 0); + result->fileSize = data.get("file_size", 0); result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); return result; } @@ -360,7 +368,7 @@ Document::Ptr TgTypeParser::parseJsonAndGetDocument(const boost::property_tree:: result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->fileName = data.get("file_name", ""); result->mimeType = data.get("mime_type", ""); - result->fileSize = data.get("file_size", 0); + result->fileSize = data.get("file_size", 0); return result; } @@ -392,6 +400,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::pt result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->emoji = data.get("emoji", ""); result->setName = data.get("set_name", ""); + result->premiumAnimation = tryParseJson(&TgTypeParser::parseJsonAndGetFile, data, "premium_animation"); result->maskPosition = tryParseJson(&TgTypeParser::parseJsonAndGetMaskPosition, data, "mask_position"); result->fileSize = data.get("file_size", 0); return result; @@ -412,6 +421,7 @@ std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { appendToJson(result, "thumb", parsePhotoSize(object->thumb)); appendToJson(result, "emoji", object->emoji); appendToJson(result, "set_name", object->setName); + appendToJson(result, "premium_animation", parseFile(object->premiumAnimation)); appendToJson(result, "mask_position", parseMaskPosition(object->maskPosition)); appendToJson(result, "file_size", object->fileSize); removeLastComma(result); @@ -643,7 +653,7 @@ Video::Ptr TgTypeParser::parseJsonAndGetVideo(const boost::property_tree::ptree& result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->fileName = data.get("file_name", ""); result->mimeType = data.get("mime_type", ""); - result->fileSize = data.get("file_size", 0); + result->fileSize = data.get("file_size", 0); return result; } @@ -673,7 +683,7 @@ Voice::Ptr TgTypeParser::parseJsonAndGetVoice(const boost::property_tree::ptree& result->fileUniqueId = data.get("file_unique_id", ""); result->duration = data.get("duration", 0); result->mimeType = data.get("mime_type", ""); - result->fileSize = data.get("file_size", 0); + result->fileSize = data.get("file_size", 0); return result; } @@ -796,7 +806,7 @@ Animation::Ptr TgTypeParser::parseJsonAndGetAnimation(const boost::property_tree result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->fileName = data.get("file_name", ""); result->mimeType = data.get("mime_type", ""); - result->fileSize = data.get("file_size", 0); + result->fileSize = data.get("file_size", 0); return result; } @@ -1274,7 +1284,7 @@ File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& d auto result(std::make_shared()); result->fileId = data.get("file_id", ""); result->fileUniqueId = data.get("file_unique_id", ""); - result->fileSize = data.get("file_size", 0); + result->fileSize = data.get("file_size", 0); result->filePath = data.get("file_path", ""); return result; } -- cgit v1.2.3 From 270612dc36df84fe25d7fa5e59ca20647b1e5da9 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sun, 11 Sep 2022 15:13:51 +0200 Subject: Update to API 6.2 --- src/Api.cpp | 23 ++++++++--- src/TgTypeParser.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 125 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/Api.cpp b/src/Api.cpp index 8d5ef2d..4107a4e 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1676,6 +1676,17 @@ StickerSet::Ptr Api::getStickerSet(const string& name) const { return _tgTypeParser.parseJsonAndGetStickerSet(sendRequest("getStickerSet", args)); } +std::vector Api::getCustomEmojiStickers(const std::vector& customEmojiIds) const { + vector args; + args.reserve(1); + + args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray([] (const std::string& customEmojiId) -> std::string { + return "\"" + StringTools::urlEncode(customEmojiId) + "\""; + }, customEmojiIds)); + + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args)); +} + File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSticker) const { vector args; args.reserve(2); @@ -1688,13 +1699,13 @@ bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, const std::string& emojis, - bool containsMasks, MaskPosition::Ptr maskPosition, boost::variant pngSticker, InputFile::Ptr tgsSticker, - InputFile::Ptr webmSticker) const { + InputFile::Ptr webmSticker, + const std::string& stickerType) const { vector args; - args.reserve(9); + args.reserve(10); args.emplace_back("user_id", userId); args.emplace_back("name", name); @@ -1711,10 +1722,10 @@ bool Api::createNewStickerSet(std::int64_t userId, if (webmSticker != nullptr) { args.emplace_back("webm_sticker", webmSticker->data, true, webmSticker->mimeType, webmSticker->fileName); } - args.emplace_back("emojis", emojis); - if (containsMasks) { - args.emplace_back("contains_mask", containsMasks); + if (!stickerType.empty()) { + args.emplace_back("sticker_type", stickerType); } + args.emplace_back("emojis", emojis); if (maskPosition != nullptr) { args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); } diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index e6a4317..d251da6 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -25,6 +25,7 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& d result->photo = tryParseJson(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo"); result->bio = data.get("bio", ""); result->hasPrivateForwards = data.get("has_private_forwards", false); + result->hasRestrictedVoiceAndVideoMessages = data.get("has_restricted_voice_and_video_messages", false); result->joinToSendMessages = data.get("join_to_send_messages", false); result->joinByRequest = data.get("join_by_request", false); result->description = data.get("description", ""); @@ -64,6 +65,7 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const { appendToJson(result, "photo", parseChatPhoto(object->photo)); appendToJson(result, "bio", object->bio); appendToJson(result, "has_private_forwards", object->hasPrivateForwards); + appendToJson(result, "has_restricted_voice_and_video_messages", object->hasRestrictedVoiceAndVideoMessages); appendToJson(result, "join_to_send_messages", object->joinToSendMessages); appendToJson(result, "join_by_request", object->joinByRequest); appendToJson(result, "description", object->description); @@ -122,12 +124,48 @@ std::string TgTypeParser::parseUser(const User::Ptr& object) const { MessageEntity::Ptr TgTypeParser::parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const{ auto result(std::make_shared()); - result->type = data.get("type", ""); + std::string type = data.get("type", ""); + if (type == "mention") { + result->type = MessageEntity::Type::Mention; + } else if (type == "hashtag") { + result->type = MessageEntity::Type::Hashtag; + } else if (type == "cashtag") { + result->type = MessageEntity::Type::Cashtag; + } else if (type == "bot_command") { + result->type = MessageEntity::Type::BotCommand; + } else if (type == "url") { + result->type = MessageEntity::Type::Url; + } else if (type == "email") { + result->type = MessageEntity::Type::Email; + } else if (type == "phone_number") { + result->type = MessageEntity::Type::PhoneNumber; + } else if (type == "bold") { + result->type = MessageEntity::Type::Bold; + } else if (type == "italic") { + result->type = MessageEntity::Type::Italic; + } else if (type == "underline") { + result->type = MessageEntity::Type::Underline; + } else if (type == "strikethrough") { + result->type = MessageEntity::Type::Strikethrough; + } else if (type == "spoiler") { + result->type = MessageEntity::Type::Spoiler; + } else if (type == "code") { + result->type = MessageEntity::Type::Code; + } else if (type == "pre") { + result->type = MessageEntity::Type::Pre; + } else if (type == "text_link") { + result->type = MessageEntity::Type::TextLink; + } else if (type == "text_mention") { + result->type = MessageEntity::Type::TextMention; + } else if (type == "custom_emoji") { + result->type = MessageEntity::Type::CustomEmoji; + } result->offset = data.get("offset", 0); result->length = data.get("length", 0); result->url = data.get("url", ""); result->user = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); result->language = data.get("language", ""); + result->customEmojiId = data.get("custom_emoji_id", ""); return result; } @@ -137,12 +175,47 @@ std::string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) c } std::string result; result += '{'; - appendToJson(result, "type", object->type); + if (object->type == MessageEntity::Type::Mention) { + appendToJson(result, "type", "mention"); + } else if (object->type == MessageEntity::Type::Hashtag) { + appendToJson(result, "type", "hashtag"); + } else if (object->type == MessageEntity::Type::Cashtag) { + appendToJson(result, "type", "cashtag"); + } else if (object->type == MessageEntity::Type::BotCommand) { + appendToJson(result, "type", "bot_command"); + } else if (object->type == MessageEntity::Type::Url) { + appendToJson(result, "type", "url"); + } else if (object->type == MessageEntity::Type::Email) { + appendToJson(result, "type", "email"); + } else if (object->type == MessageEntity::Type::PhoneNumber) { + appendToJson(result, "type", "phone_number"); + } else if (object->type == MessageEntity::Type::Bold) { + appendToJson(result, "type", "bold"); + } else if (object->type == MessageEntity::Type::Italic) { + appendToJson(result, "type", "italic"); + } else if (object->type == MessageEntity::Type::Underline) { + appendToJson(result, "type", "underline"); + } else if (object->type == MessageEntity::Type::Strikethrough) { + appendToJson(result, "type", "strikethrough"); + } else if (object->type == MessageEntity::Type::Spoiler) { + appendToJson(result, "type", "spoiler"); + } else if (object->type == MessageEntity::Type::Code) { + appendToJson(result, "type", "code"); + } else if (object->type == MessageEntity::Type::Pre) { + appendToJson(result, "type", "pre"); + } else if (object->type == MessageEntity::Type::TextLink) { + appendToJson(result, "type", "text_link"); + } else if (object->type == MessageEntity::Type::TextMention) { + appendToJson(result, "type", "text_mention"); + } else if (object->type == MessageEntity::Type::CustomEmoji) { + appendToJson(result, "type", "custom_emoji"); + } appendToJson(result, "offset", object->offset); appendToJson(result, "length", object->length); appendToJson(result, "url", object->url); appendToJson(result, "user", parseUser(object->user)); - appendToJson(result, "language", object->url); + appendToJson(result, "language", object->language); + appendToJson(result, "custom_emoji_id", object->customEmojiId); removeLastComma(result); result += '}'; return result; @@ -393,6 +466,14 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::pt auto result(std::make_shared()); result->fileId = data.get("file_id", ""); result->fileUniqueId = data.get("file_unique_id", ""); + std::string type = data.get("type", ""); + if (type == "regular") { + result->type = Sticker::Type::Regular; + } else if (type == "mask") { + result->type = Sticker::Type::Mask; + } else if (type == "custom_emoji") { + result->type = Sticker::Type::CustomEmoji; + } result->width = data.get("width", 0); result->height = data.get("height", 0); result->isAnimated = data.get("is_animated", false); @@ -402,6 +483,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::pt result->setName = data.get("set_name", ""); result->premiumAnimation = tryParseJson(&TgTypeParser::parseJsonAndGetFile, data, "premium_animation"); result->maskPosition = tryParseJson(&TgTypeParser::parseJsonAndGetMaskPosition, data, "mask_position"); + result->customEmojiId = data.get("custom_emoji_id", ""); result->fileSize = data.get("file_size", 0); return result; } @@ -414,6 +496,13 @@ std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { result += '{'; appendToJson(result, "file_id", object->fileId); appendToJson(result, "file_unique_id", object->fileUniqueId); + if (object->type == Sticker::Type::Regular) { + appendToJson(result, "type", "regular"); + } else if (object->type == Sticker::Type::Mask) { + appendToJson(result, "type", "mask"); + } else if (object->type == Sticker::Type::CustomEmoji) { + appendToJson(result, "type", "custom_emoji"); + } appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "is_animated", object->isAnimated); @@ -423,6 +512,7 @@ std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { appendToJson(result, "set_name", object->setName); appendToJson(result, "premium_animation", parseFile(object->premiumAnimation)); appendToJson(result, "mask_position", parseMaskPosition(object->maskPosition)); + appendToJson(result, "custom_emoji_id", object->customEmojiId); appendToJson(result, "file_size", object->fileSize); removeLastComma(result); result += '}'; @@ -433,9 +523,16 @@ StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const boost::property_tr auto result(std::make_shared()); result->name = data.get("name", ""); result->title = data.get("title", ""); + std::string type = data.get("type", ""); + if (type == "regular") { + result->type = StickerSet::Type::Regular; + } else if (type == "mask") { + result->type = StickerSet::Type::Mask; + } else if (type == "custom_emoji") { + result->type = StickerSet::Type::CustomEmoji; + } result->isAnimated = data.get("is_animated", false); result->isVideo = data.get("is_video", false); - result->containsMasks = data.get("contains_masks", false); result->stickers = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, data, "stickers"); result->thumb = tryParseJson(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); return result; @@ -449,9 +546,15 @@ std::string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const { result += '{'; appendToJson(result, "name", object->name); appendToJson(result, "title", object->title); + if (object->type == StickerSet::Type::Regular) { + appendToJson(result, "type", "regular"); + } else if (object->type == StickerSet::Type::Mask) { + appendToJson(result, "type", "mask"); + } else if (object->type == StickerSet::Type::CustomEmoji) { + appendToJson(result, "type", "custom_emoji"); + } appendToJson(result, "is_animated", object->isAnimated); appendToJson(result, "is_video", object->isVideo); - appendToJson(result, "contains_masks", object->containsMasks); appendToJson(result, "stickers", parseArray(&TgTypeParser::parseSticker, object->stickers)); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); removeLastComma(result); -- cgit v1.2.3