From 35244ca7b80d5e1dca016e7722b05ae54d16f065 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Wed, 14 Sep 2022 16:27:13 +0200 Subject: Update API --- src/Api.cpp | 394 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 213 insertions(+), 181 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 4107a4e..062dddf 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1,53 +1,46 @@ #include "tgbot/Api.h" -#include "tgbot/tools/StringTools.h" - -#include "tgbot/TgException.h" -#include "tgbot/TgTypeParser.h" - -#include -#include -#include -#include - -using namespace std; -using namespace boost::property_tree; - namespace TgBot { -Api::Api(string token, const HttpClient& httpClient, const std::string& url) +Api::Api(std::string token, const HttpClient& httpClient, const std::string& url) : _token(std::move(token)), _httpClient(httpClient), _tgTypeParser(), _url(url) { } -vector Api::getUpdates(std::int32_t offset, std::int32_t limit, std::int32_t timeout, const StringArrayPtr& allowedUpdates) const { - vector args; +std::vector Api::getUpdates(std::int32_t offset, + std::int32_t limit, + std::int32_t timeout, + const StringArrayPtr& allowedUpdates) const { + std::vector args; args.reserve(4); - if (offset) { + + if (offset != 0) { args.emplace_back("offset", offset); } - limit = max(1, min(100, limit)); - args.emplace_back("limit", limit); - if (timeout) { + if (limit != 100) { + args.emplace_back("limit", std::max(1, std::min(100, limit))); + } + if (timeout != 0) { args.emplace_back("timeout", timeout); } if (allowedUpdates != nullptr) { - string allowedUpdatesJson = _tgTypeParser.parseArray( - [] (const string& s)->string { + std::string allowedUpdatesJson = _tgTypeParser.parseArray( + [] (const std::string& s)->std::string { return s; }, *allowedUpdates); args.emplace_back("allowed_updates", allowedUpdatesJson); } + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); } bool Api::setWebhook(const std::string& url, InputFile::Ptr certificate, - std::int32_t maxConnection, + std::int32_t maxConnections, const StringArrayPtr& allowedUpdates, const std::string& ipAddress, bool dropPendingUpdates, const std::string& secretToken) const { - vector args; + std::vector args; args.reserve(7); args.emplace_back("url", url); @@ -57,12 +50,12 @@ bool Api::setWebhook(const std::string& url, if (!ipAddress.empty()) { args.emplace_back("ip_address", ipAddress); } - if (maxConnection != 40) { - args.emplace_back("max_connections", maxConnection); + if (maxConnections != 40) { + args.emplace_back("max_connections", std::max(1, std::min(100, maxConnections))); } if (allowedUpdates != nullptr) { - auto allowedUpdatesJson = _tgTypeParser.parseArray( - [] (const string& s)->string { + auto allowedUpdatesJson = _tgTypeParser.parseArray( + [] (const std::string& s)->std::string { return s; }, *allowedUpdates); args.emplace_back("allowed_updates", allowedUpdatesJson); @@ -78,7 +71,7 @@ bool Api::setWebhook(const std::string& url, } bool Api::deleteWebhook(bool dropPendingUpdates) const { - vector args; + std::vector args; args.reserve(1); if (dropPendingUpdates) { @@ -89,12 +82,13 @@ bool Api::deleteWebhook(bool dropPendingUpdates) const { } WebhookInfo::Ptr Api::getWebhookInfo() const { - ptree p = sendRequest("getWebhookInfo"); + boost::property_tree::ptree p = sendRequest("getWebhookInfo"); if (!p.get_child_optional("url")) { return nullptr; } - if (p.get("url", "") != string("")) { + + if (p.get("url", "") != std::string("")) { return _tgTypeParser.parseJsonAndGetWebhookInfo(p); } else { return nullptr; @@ -105,6 +99,14 @@ User::Ptr Api::getMe() const { return _tgTypeParser.parseJsonAndGetUser(sendRequest("getMe")); } +bool Api::logOut() const { + return sendRequest("logOut").get("", false); +} + +bool Api::close() const { + return sendRequest("close").get("", false); +} + Message::Ptr Api::sendMessage(boost::variant chatId, const std::string& text, bool disableWebPagePreview, @@ -115,7 +117,7 @@ Message::Ptr Api::sendMessage(boost::variant c const std::vector& entities, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(10); args.emplace_back("chat_id", chatId); @@ -135,7 +137,7 @@ Message::Ptr Api::sendMessage(boost::variant c if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { + if (replyToMessageId != 0) { args.emplace_back("reply_to_message_id", replyToMessageId); } if (allowSendingWithoutReply) { @@ -153,7 +155,7 @@ Message::Ptr Api::forwardMessage(boost::variant args; + std::vector args; args.reserve(5); args.emplace_back("chat_id", chatId); @@ -180,7 +182,7 @@ MessageId::Ptr Api::copyMessage(boost::variant bool allowSendingWithoutReply, GenericReply::Ptr replyMarkup, bool protectContent) const { - vector args; + std::vector args; args.reserve(11); args.emplace_back("chat_id", chatId); @@ -224,7 +226,7 @@ Message::Ptr Api::sendPhoto(boost::variant cha const std::vector& captionEntities, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(10); args.emplace_back("chat_id", chatId); @@ -276,7 +278,7 @@ Message::Ptr Api::sendAudio(boost::variant cha const std::vector& captionEntities, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(14); args.emplace_back("chat_id", chatId); @@ -344,7 +346,7 @@ Message::Ptr Api::sendDocument(boost::variant bool disableContentTypeDetection, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(12); args.emplace_back("chat_id", chatId); @@ -409,7 +411,7 @@ Message::Ptr Api::sendVideo(boost::variant cha const std::vector& captionEntities, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(15); args.emplace_back("chat_id", chatId); @@ -482,7 +484,7 @@ Message::Ptr Api::sendAnimation(boost::variant const std::vector& captionEntities, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(14); args.emplace_back("chat_id", chatId); @@ -549,7 +551,7 @@ Message::Ptr Api::sendVoice(boost::variant cha const std::vector& captionEntities, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(11); args.emplace_back("chat_id", chatId); @@ -600,7 +602,7 @@ Message::Ptr Api::sendVideoNote(boost::variant GenericReply::Ptr replyMarkup, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(10); args.emplace_back("chat_id", chatId); @@ -644,13 +646,13 @@ Message::Ptr Api::sendVideoNote(boost::variant return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideoNote", args)); } -vector Api::sendMediaGroup(boost::variant chatId, - const std::vector& media, - bool disableNotification, - std::int32_t replyToMessageId, - bool allowSendingWithoutReply, - bool protectContent) const { - vector args; +std::vector Api::sendMediaGroup(boost::variant chatId, + const std::vector& media, + bool disableNotification, + std::int32_t replyToMessageId, + bool allowSendingWithoutReply, + bool protectContent) const { + std::vector args; args.reserve(6); args.emplace_back("chat_id", chatId); @@ -683,7 +685,7 @@ Message::Ptr Api::sendLocation(boost::variant std::int32_t proximityAlertRadius, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(12); args.emplace_back("chat_id", chatId); @@ -693,13 +695,13 @@ Message::Ptr Api::sendLocation(boost::variant args.emplace_back("horizontal_accuracy", horizontalAccuracy); } if (livePeriod) { - args.emplace_back("live_period", livePeriod); + args.emplace_back("live_period", std::max(60, std::min(86400, livePeriod))); } if (heading) { - args.emplace_back("heading", heading); + args.emplace_back("heading", std::max(1, std::min(360, heading))); } if (proximityAlertRadius) { - args.emplace_back("proximity_alert_radius", proximityAlertRadius); + args.emplace_back("proximity_alert_radius", std::max(1, std::min(100000, proximityAlertRadius))); } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); @@ -722,23 +724,23 @@ Message::Ptr Api::sendLocation(boost::variant Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, - std::int64_t chatId, + boost::variant chatId, std::int32_t messageId, - std::int32_t inlineMessageId, + const std::string& inlineMessageId, InlineKeyboardMarkup::Ptr replyMarkup, float horizontalAccuracy, std::int32_t heading, std::int32_t proximityAlertRadius) const { - vector args; + std::vector args; args.reserve(9); - if (chatId) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { args.emplace_back("message_id", messageId); } - if (inlineMessageId) { + if (!inlineMessageId.empty()) { args.emplace_back("inline_message_id", inlineMessageId); } args.emplace_back("latitude", latitude); @@ -759,22 +761,27 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); } -Message::Ptr Api::stopMessageLiveLocation(std::int64_t chatId, std::int32_t messageId, std::int32_t inlineMessageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { - vector args; +Message::Ptr Api::stopMessageLiveLocation(boost::variant chatId, + std::int32_t messageId, + const std::string& inlineMessageId, + InlineKeyboardMarkup::Ptr replyMarkup) const { + std::vector args; args.reserve(4); - if (chatId) { + + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { args.emplace_back("message_id", messageId); } - if (inlineMessageId) { + if (!inlineMessageId.empty()) { args.emplace_back("inline_message_id", inlineMessageId); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); + + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("stopMessageLiveLocation", args)); } Message::Ptr Api::sendVenue(boost::variant chatId, @@ -791,7 +798,7 @@ Message::Ptr Api::sendVenue(boost::variant cha const std::string& googlePlaceType, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(14); args.emplace_back("chat_id", chatId); @@ -840,7 +847,7 @@ Message::Ptr Api::sendContact(boost::variant c GenericReply::Ptr replyMarkup, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(10); args.emplace_back("chat_id", chatId); @@ -873,7 +880,7 @@ Message::Ptr Api::sendContact(boost::variant c Message::Ptr Api::sendPoll(boost::variant chatId, const std::string& question, - const std::vector& options, + const StringArrayPtr& options, bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, @@ -889,14 +896,15 @@ Message::Ptr Api::sendPoll(boost::variant chat bool isClosed, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(18); args.emplace_back("chat_id", chatId); args.emplace_back("question", question); - args.emplace_back("options", _tgTypeParser.parseArray([] (const std::string& option) -> std::string { + args.emplace_back("options", _tgTypeParser.parseArray( + [](const std::string& option)->std::string { return "\"" + StringTools::urlEncode(option) + "\""; - }, options)); + }, *options)); if (!isAnonymous) { args.emplace_back("is_anonymous", isAnonymous); } @@ -953,7 +961,7 @@ Message::Ptr Api::sendDice(boost::variant chat const std::string& emoji, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(7); args.emplace_back("chat_id", chatId); @@ -981,7 +989,7 @@ Message::Ptr Api::sendDice(boost::variant chat bool Api::sendChatAction(std::int64_t chatId, const std::string& action) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); @@ -990,67 +998,84 @@ bool Api::sendChatAction(std::int64_t chatId, return sendRequest("sendChatAction", args).get("", false); } -UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, std::int32_t offset, std::int32_t limit) const { - vector args; +UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, + std::int32_t offset, + std::int32_t limit) const { + std::vector args; args.reserve(3); + args.emplace_back("user_id", userId); if (offset) { args.emplace_back("offset", offset); } - limit = max(1, min(100, limit)); - args.emplace_back("limit", limit); + if (limit != 100) { + args.emplace_back("limit", std::max(1, std::min(100, limit))); + } + return _tgTypeParser.parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); } -File::Ptr Api::getFile(const string& fileId) const { - vector args; +File::Ptr Api::getFile(const std::string& fileId) const { + std::vector args; args.reserve(1); + args.emplace_back("file_id", fileId); + return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args)); } -string Api::downloadFile(const string& filePath, const std::vector& args) const { - string url(_url); +std::string Api::downloadFile(const std::string& filePath, + const std::vector& args) const { + std::string url(_url); url += "/file/bot"; url += _token; url += "/"; url += filePath; - string serverResponse = _httpClient.makeRequest(url, args); - - return serverResponse; + return _httpClient.makeRequest(url, args); } -bool Api::banChatMember(std::int64_t chatId, +bool Api::banChatMember(boost::variant chatId, std::int64_t userId, - std::uint64_t untilDate, + std::int32_t untilDate, bool revokeMessages) const { - vector args; + std::vector args; args.reserve(4); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); - args.emplace_back("until_date", untilDate); - args.emplace_back("revoke_messages", revokeMessages); + if (untilDate != 0) { + args.emplace_back("until_date", untilDate); + } + if (revokeMessages) { + args.emplace_back("revoke_messages", revokeMessages); + } return sendRequest("banChatMember", args).get("", false); } -bool Api::unbanChatMember(std::int64_t chatId, std::int64_t userId, bool onlyIfBanned) const { - vector args; +bool Api::unbanChatMember(boost::variant chatId, + std::int64_t userId, + bool onlyIfBanned) const { + std::vector args; args.reserve(3); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); - args.emplace_back("only_if_banned", onlyIfBanned); + if (onlyIfBanned) { + args.emplace_back("only_if_banned", onlyIfBanned); + } return sendRequest("unbanChatMember", args).get("", false); } -bool Api::restrictChatMember(std::int64_t chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, +bool Api::restrictChatMember(boost::variant chatId, + std::int64_t userId, + TgBot::ChatPermissions::Ptr permissions, std::uint64_t untilDate) const { - vector args; + std::vector args; args.reserve(4); + args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); @@ -1074,7 +1099,7 @@ bool Api::promoteChatMember(boost::variant cha bool canManageChat, bool canManageVideoChats, bool canRestrictMembers) const { - vector args; + std::vector args; args.reserve(13); args.emplace_back("chat_id", chatId); @@ -1116,8 +1141,10 @@ bool Api::promoteChatMember(boost::variant cha return sendRequest("promoteChatMember", args).get("", false); } -bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const { - vector args; +bool Api::setChatAdministratorCustomTitle(boost::variant chatId, + std::int64_t userId, + const std::string& customTitle) const { + std::vector args; args.reserve(3); args.emplace_back("chat_id", chatId); @@ -1127,9 +1154,9 @@ bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t user return sendRequest("setChatAdministratorCustomTitle", args).get("", false); } -bool Api::banChatSenderChat(std::int64_t chatId, - std::int64_t senderChatId) const { - vector args; +bool Api::banChatSenderChat(boost::variant chatId, + std::int64_t senderChatId) const { + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); @@ -1138,9 +1165,9 @@ bool Api::banChatSenderChat(std::int64_t chatId, return sendRequest("banChatSenderChat", args).get("", false); } -bool Api::unbanChatSenderChat(std::int64_t chatId, +bool Api::unbanChatSenderChat(boost::variant chatId, std::int64_t senderChatId) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); @@ -1149,27 +1176,32 @@ bool Api::unbanChatSenderChat(std::int64_t chatId, return sendRequest("unbanChatSenderChat", args).get("", false); } -bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const { - vector args; +bool Api::setChatPermissions(boost::variant chatId, + ChatPermissions::Ptr permissions) const { + std::vector args; args.reserve(2); + args.emplace_back("chat_id", chatId); args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); + return sendRequest("setChatPermissions", args).get("", false); } -string Api::exportChatInviteLink(std::int64_t chatId) const { - vector args; +std::string Api::exportChatInviteLink(boost::variant chatId) const { + std::vector args; args.reserve(1); + args.emplace_back("chat_id", chatId); + return sendRequest("exportChatInviteLink", args).get("", ""); } -ChatInviteLink::Ptr Api::createChatInviteLink(std::int64_t chatId, +ChatInviteLink::Ptr Api::createChatInviteLink(boost::variant chatId, std::int32_t expireDate, std::int32_t memberLimit, const std::string& name, bool createsJoinRequest) const { - vector args; + std::vector args; args.reserve(5); args.emplace_back("chat_id", chatId); @@ -1189,13 +1221,13 @@ ChatInviteLink::Ptr Api::createChatInviteLink(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("createChatInviteLink", args)); } -ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId, +ChatInviteLink::Ptr Api::editChatInviteLink(boost::variant chatId, const std::string& inviteLink, std::int32_t expireDate, std::int32_t memberLimit, const std::string& name, bool createsJoinRequest) const { - vector args; + std::vector args; args.reserve(6); args.emplace_back("chat_id", chatId); @@ -1218,7 +1250,7 @@ ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId, ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId, const std::string& inviteLink) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); @@ -1229,7 +1261,7 @@ ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId, bool Api::approveChatJoinRequest(std::int64_t chatId, std::int64_t userId) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); @@ -1240,7 +1272,7 @@ bool Api::approveChatJoinRequest(std::int64_t chatId, bool Api::declineChatJoinRequest(std::int64_t chatId, std::int64_t userId) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); @@ -1250,7 +1282,7 @@ bool Api::declineChatJoinRequest(std::int64_t chatId, } bool Api::setChatPhoto(std::int64_t chatId, const InputFile::Ptr photo) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName); @@ -1258,22 +1290,22 @@ bool Api::setChatPhoto(std::int64_t chatId, const InputFile::Ptr photo) const { } bool Api::deleteChatPhoto(std::int64_t chatId) const { - vector args; + std::vector args; args.reserve(1); args.emplace_back("chat_id", chatId); return sendRequest("deleteChatPhoto", args).get("", false); } -bool Api::setChatTitle(std::int64_t chatId, const string& title) const { - vector args; +bool Api::setChatTitle(std::int64_t chatId, const std::string& title) const { + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); args.emplace_back("title", title); return sendRequest("setChatTitle", args).get("", false); } -bool Api::setChatDescription(std::int64_t chatId, const string& description) const { - vector args; +bool Api::setChatDescription(std::int64_t chatId, const std::string& description) const { + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); args.emplace_back("description", description); @@ -1281,7 +1313,7 @@ bool Api::setChatDescription(std::int64_t chatId, const string& description) con } bool Api::pinChatMessage(std::int64_t chatId, std::int32_t messageId, bool disableNotification) const { - vector args; + std::vector args; args.reserve(3); args.emplace_back("chat_id", chatId); args.emplace_back("message_id", messageId); @@ -1292,7 +1324,7 @@ bool Api::pinChatMessage(std::int64_t chatId, std::int32_t messageId, bool disab } bool Api::unpinChatMessage(std::int64_t chatId, std::int32_t messageId) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); @@ -1302,7 +1334,7 @@ bool Api::unpinChatMessage(std::int64_t chatId, std::int32_t messageId) const { } bool Api::unpinAllChatMessages(std::int64_t chatId) const { - vector args; + std::vector args; args.reserve(1); args.emplace_back("chat_id", chatId); @@ -1311,14 +1343,14 @@ bool Api::unpinAllChatMessages(std::int64_t chatId) const { } bool Api::leaveChat(std::int64_t chatId) const { - vector args; + std::vector args; args.reserve(1); args.emplace_back("chat_id", chatId); return sendRequest("leaveChat", args).get("", false); } Chat::Ptr Api::getChat(std::int64_t chatId) const { - vector args; + std::vector args; args.reserve(1); args.emplace_back("chat_id", chatId); @@ -1326,15 +1358,15 @@ Chat::Ptr Api::getChat(std::int64_t chatId) const { return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args)); } -vector Api::getChatAdministrators(std::int64_t chatId) const { - vector args; +std::vector Api::getChatAdministrators(std::int64_t chatId) const { + std::vector args; args.reserve(1); args.emplace_back("chat_id", chatId); return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); } int32_t Api::getChatMemberCount(std::int64_t chatId) const { - vector args; + std::vector args; args.reserve(1); args.emplace_back("chat_id", chatId); @@ -1343,15 +1375,15 @@ int32_t Api::getChatMemberCount(std::int64_t chatId) const { } ChatMember::Ptr Api::getChatMember(std::int64_t chatId, std::int64_t userId) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); return _tgTypeParser.parseJsonAndGetChatMember(sendRequest("getChatMember", args)); } -bool Api::setChatStickerSet(std::int64_t chatId, const string& stickerSetName) const { - vector args; +bool Api::setChatStickerSet(std::int64_t chatId, const std::string& stickerSetName) const { + std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); args.emplace_back("sticker_set_name ", stickerSetName); @@ -1359,14 +1391,14 @@ bool Api::setChatStickerSet(std::int64_t chatId, const string& stickerSetName) c } bool Api::deleteChatStickerSet(std::int64_t chatId) const { - vector args; + std::vector args; args.reserve(1); args.emplace_back("chat_id", chatId); return sendRequest("deleteChatStickerSet", args).get("", false); } -bool Api::answerCallbackQuery(const string& callbackQueryId, const string& text, bool showAlert, const string& url, std::int32_t cacheTime) const { - vector args; +bool Api::answerCallbackQuery(const std::string& callbackQueryId, const std::string& text, bool showAlert, const std::string& url, std::int32_t cacheTime) const { + std::vector args; args.reserve(5); args.emplace_back("callback_query_id", callbackQueryId); if (!text.empty()) { @@ -1387,7 +1419,7 @@ bool Api::answerCallbackQuery(const string& callbackQueryId, const string& text, bool Api::setMyCommands(const std::vector& commands, BotCommandScope::Ptr scope, const std::string& languageCode) const { - vector args; + std::vector args; args.reserve(3); args.emplace_back("commands", _tgTypeParser.parseArray(&TgTypeParser::parseBotCommand, commands)); @@ -1403,7 +1435,7 @@ bool Api::setMyCommands(const std::vector& commands, bool Api::deleteMyCommands(BotCommandScope::Ptr scope, const std::string& languageCode) const { - vector args; + std::vector args; args.reserve(2); if (scope != nullptr) { @@ -1418,7 +1450,7 @@ bool Api::deleteMyCommands(BotCommandScope::Ptr scope, std::vector Api::getMyCommands(BotCommandScope::Ptr scope, const std::string& languageCode) const { - vector args; + std::vector args; args.reserve(2); ; if (scope != nullptr) { @@ -1433,7 +1465,7 @@ std::vector Api::getMyCommands(BotCommandScope::Ptr scope, bool Api::setChatMenuButton(std::int64_t chatId, MenuButton::Ptr menuButton) const { - vector args; + std::vector args; args.reserve(2); if (chatId != 0) { @@ -1447,7 +1479,7 @@ bool Api::setChatMenuButton(std::int64_t chatId, } MenuButton::Ptr Api::getChatMenuButton(std::int64_t chatId) const { - vector args; + std::vector args; args.reserve(1); if (chatId != 0) { @@ -1459,7 +1491,7 @@ MenuButton::Ptr Api::getChatMenuButton(std::int64_t chatId) const { bool Api::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights, bool forChannels) const { - vector args; + std::vector args; args.reserve(2); if (rights != nullptr) { @@ -1473,7 +1505,7 @@ bool Api::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights, } ChatAdministratorRights::Ptr Api::getMyDefaultAdministratorRights(bool forChannels) const { - vector args; + std::vector args; args.reserve(1); if (forChannels) { @@ -1491,7 +1523,7 @@ Message::Ptr Api::editMessageText(const std::string& text, bool disableWebPagePreview, GenericReply::Ptr replyMarkup, const std::vector& entities) const { - vector args; + std::vector args; args.reserve(8); if (chatId) { @@ -1517,7 +1549,7 @@ Message::Ptr Api::editMessageText(const std::string& text, args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - ptree p = sendRequest("editMessageText", args); + boost::property_tree::ptree p = sendRequest("editMessageText", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); } else { @@ -1532,7 +1564,7 @@ Message::Ptr Api::editMessageCaption(std::int64_t chatId, GenericReply::Ptr replyMarkup, const std::string& parseMode, const std::vector& captionEntities) const { - vector args; + std::vector args; args.reserve(7); if (chatId) { @@ -1557,7 +1589,7 @@ Message::Ptr Api::editMessageCaption(std::int64_t chatId, args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - ptree p = sendRequest("editMessageCaption", args); + boost::property_tree::ptree p = sendRequest("editMessageCaption", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); } else { @@ -1568,7 +1600,7 @@ Message::Ptr Api::editMessageCaption(std::int64_t chatId, Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId, GenericReply::Ptr replyMarkup) const { - vector args; + std::vector args; args.reserve(5); args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); if (chatId) { @@ -1583,7 +1615,7 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, s if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - ptree p = sendRequest("editMessageMedia", args); + boost::property_tree::ptree p = sendRequest("editMessageMedia", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); } else { @@ -1591,10 +1623,10 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, s } } -Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messageId, const string& inlineMessageId, +Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { - vector args; + std::vector args; args.reserve(4); if (chatId) { args.emplace_back("chat_id", chatId); @@ -1608,7 +1640,7 @@ Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messa if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } - ptree p = sendRequest("editMessageReplyMarkup", args); + boost::property_tree::ptree p = sendRequest("editMessageReplyMarkup", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); } else { @@ -1617,7 +1649,7 @@ Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messa } Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { - vector args; + std::vector args; args.reserve(3); args.emplace_back("chat_id", chatId); args.emplace_back("message_id", messageId); @@ -1638,7 +1670,7 @@ Message::Ptr Api::sendSticker(boost::variant c bool disableNotification, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(7); args.emplace_back("chat_id", chatId); @@ -1667,8 +1699,8 @@ Message::Ptr Api::sendSticker(boost::variant c return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendSticker", args)); } -StickerSet::Ptr Api::getStickerSet(const string& name) const { - vector args; +StickerSet::Ptr Api::getStickerSet(const std::string& name) const { + std::vector args; args.reserve(1); args.emplace_back("name", name); @@ -1676,19 +1708,19 @@ 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; +std::vector Api::getCustomEmojiStickers(const StringArrayPtr& customEmojiIds) const { + std::vector args; args.reserve(1); args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray([] (const std::string& customEmojiId) -> std::string { return "\"" + StringTools::urlEncode(customEmojiId) + "\""; - }, customEmojiIds)); + }, *customEmojiIds)); return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args)); } File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSticker) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("user_id", userId); args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName); @@ -1704,7 +1736,7 @@ bool Api::createNewStickerSet(std::int64_t userId, InputFile::Ptr tgsSticker, InputFile::Ptr webmSticker, const std::string& stickerType) const { - vector args; + std::vector args; args.reserve(10); args.emplace_back("user_id", userId); @@ -1740,7 +1772,7 @@ bool Api::addStickerToSet(std::int64_t userId, boost::variant pngSticker, InputFile::Ptr tgsSticker, InputFile::Ptr webmSticker) const { - vector args; + std::vector args; args.reserve(7); args.emplace_back("user_id", userId); @@ -1766,23 +1798,23 @@ bool Api::addStickerToSet(std::int64_t userId, return sendRequest("addStickerToSet", args).get("", false); } -bool Api::setStickerPositionInSet(const string& sticker, std::uint32_t position) const { - vector args; +bool Api::setStickerPositionInSet(const std::string& sticker, std::uint32_t position) const { + std::vector args; args.reserve(2); args.emplace_back("sticker", sticker); args.emplace_back("position", position); return sendRequest("setStickerPositionInSet", args).get("", false); } -bool Api::deleteStickerFromSet(const string& sticker) const { - vector args; +bool Api::deleteStickerFromSet(const std::string& sticker) const { + std::vector args; args.reserve(1); args.emplace_back("sticker", sticker); return sendRequest("deleteStickerFromSet", args).get("", false); } bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant thumb) const { - vector args; + std::vector args; args.reserve(3); args.emplace_back("name", name); @@ -1797,12 +1829,12 @@ bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, boost return sendRequest("setStickerSetThumb", args).get("", false); } -bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector& results, - std::int32_t cacheTime, bool isPersonal, const string& nextOffset, const string& switchPmText, const string& switchPmParameter) const { - vector args; +bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, + std::int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const { + std::vector args; args.reserve(7); args.emplace_back("inline_query_id", inlineQueryId); - string resultsJson = _tgTypeParser.parseArray(&TgTypeParser::parseInlineQueryResult, results); + std::string resultsJson = _tgTypeParser.parseArray(&TgTypeParser::parseInlineQueryResult, results); args.emplace_back("results", resultsJson); if (cacheTime) { args.emplace_back("cache_time", cacheTime); @@ -1824,7 +1856,7 @@ bool Api::answerInlineQuery(const string& inlineQueryId, const std::vector args; + std::vector args; args.reserve(2); args.emplace_back("web_app_query_id", webAppQueryId); @@ -1860,7 +1892,7 @@ Message::Ptr Api::sendInvoice(boost::variant c const std::vector& suggestedTipAmounts, const std::string& startParameter, bool protectContent) const { - vector args; + std::vector args; args.reserve(27); args.emplace_back("chat_id", chatId); @@ -1954,7 +1986,7 @@ std::string Api::createInvoiceLink(const std::string& title, bool sendPhoneNumberToProvider, bool sendEmailToProvider, bool isFlexible) const { - vector args; + std::vector args; args.reserve(20); args.emplace_back("title", title); @@ -2010,7 +2042,7 @@ std::string Api::createInvoiceLink(const std::string& title, } bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector& shippingOptions, const std::string& errorMessage) const { - vector args; + std::vector args; args.reserve(4); args.emplace_back("shipping_query_id", shippingQueryId); args.emplace_back("ok", ok); @@ -2024,7 +2056,7 @@ bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const } bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage) const { - vector args; + std::vector args; args.reserve(3); args.emplace_back("pre_checkout_query_id", preCheckoutQueryId); args.emplace_back("ok", ok); @@ -2035,7 +2067,7 @@ bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, } bool Api::setPassportDataErrors(std::int64_t userId, const std::vector& errors) const { - vector args; + std::vector args; args.reserve(2); args.emplace_back("user_id", userId); @@ -2051,7 +2083,7 @@ Message::Ptr Api::sendGame(std::int64_t chatId, bool disableNotification, bool allowSendingWithoutReply, bool protectContent) const { - vector args; + std::vector args; args.reserve(7); args.emplace_back("chat_id", chatId); @@ -2076,7 +2108,7 @@ Message::Ptr Api::sendGame(std::int64_t chatId, } Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool force, bool disableEditMessage, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const { - vector args; + std::vector args; args.reserve(7); args.emplace_back("user_id", userId); args.emplace_back("score", score); @@ -2098,11 +2130,11 @@ Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool for return _tgTypeParser.parseJsonAndGetMessage(sendRequest("setGameScore", args)); } -vector Api::getGameHighScores(std::int64_t userId, +std::vector Api::getGameHighScores(std::int64_t userId, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const { - vector args; + std::vector args; args.reserve(4); args.emplace_back("user_id", userId); @@ -2119,19 +2151,19 @@ vector Api::getGameHighScores(std::int64_t userId, return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args)); } -ptree Api::sendRequest(const string& method, const vector& args) const { - string url(_url); +boost::property_tree::ptree Api::sendRequest(const std::string& method, const std::vector& args) const { + std::string url(_url); url += "/bot"; url += _token; url += "/"; url += method; - string serverResponse = _httpClient.makeRequest(url, args); + std::string serverResponse = _httpClient.makeRequest(url, args); if (!serverResponse.compare(0, 6, "")) { throw TgException("tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token."); } - ptree result = _tgTypeParser.parseJson(serverResponse); + boost::property_tree::ptree result = _tgTypeParser.parseJson(serverResponse); try { if (result.get("ok", false)) { return result.get_child("result"); @@ -2139,7 +2171,7 @@ ptree Api::sendRequest(const string& method, const vector& args) con throw TgException(result.get("description", "")); } } catch (boost::property_tree::ptree_error& e) { - throw TgException("tgbot-cpp library can't parse json response. " + string(e.what())); + throw TgException("tgbot-cpp library can't parse json response. " + std::string(e.what())); } } } -- cgit v1.2.3 From 0d8cc750c06959fee17850646693312a9463fac4 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Tue, 20 Sep 2022 12:26:16 +0200 Subject: Update API methods --- src/Api.cpp | 186 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 139 insertions(+), 47 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 062dddf..ea9a550 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1072,7 +1072,7 @@ bool Api::unbanChatMember(boost::variant chatI bool Api::restrictChatMember(boost::variant chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, - std::uint64_t untilDate) const { + std::int64_t untilDate) const { std::vector args; args.reserve(4); @@ -1248,7 +1248,7 @@ ChatInviteLink::Ptr Api::editChatInviteLink(boost::variant chatId, const std::string& inviteLink) const { std::vector args; args.reserve(2); @@ -1259,7 +1259,7 @@ ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("revokeChatInviteLink", args)); } -bool Api::approveChatJoinRequest(std::int64_t chatId, +bool Api::approveChatJoinRequest(boost::variant chatId, std::int64_t userId) const { std::vector args; args.reserve(2); @@ -1270,7 +1270,7 @@ bool Api::approveChatJoinRequest(std::int64_t chatId, return sendRequest("approveChatJoinRequest", args).get("", false); } -bool Api::declineChatJoinRequest(std::int64_t chatId, +bool Api::declineChatJoinRequest(boost::variant chatId, std::int64_t userId) const { std::vector args; args.reserve(2); @@ -1281,59 +1281,79 @@ bool Api::declineChatJoinRequest(std::int64_t chatId, return sendRequest("declineChatJoinRequest", args).get("", false); } -bool Api::setChatPhoto(std::int64_t chatId, const InputFile::Ptr photo) const { +bool Api::setChatPhoto(boost::variant chatId, + const InputFile::Ptr photo) const { std::vector args; args.reserve(2); + args.emplace_back("chat_id", chatId); args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName); + return sendRequest("setChatPhoto", args).get("", false); } -bool Api::deleteChatPhoto(std::int64_t chatId) const { +bool Api::deleteChatPhoto(boost::variant chatId) const { std::vector args; args.reserve(1); + args.emplace_back("chat_id", chatId); + return sendRequest("deleteChatPhoto", args).get("", false); } -bool Api::setChatTitle(std::int64_t chatId, const std::string& title) const { +bool Api::setChatTitle(boost::variant chatId, + const std::string& title) const { std::vector args; args.reserve(2); + args.emplace_back("chat_id", chatId); args.emplace_back("title", title); + return sendRequest("setChatTitle", args).get("", false); } -bool Api::setChatDescription(std::int64_t chatId, const std::string& description) const { +bool Api::setChatDescription(boost::variant chatId, + const std::string& description) const { std::vector args; args.reserve(2); + args.emplace_back("chat_id", chatId); - args.emplace_back("description", description); + if (!description.empty()) { + args.emplace_back("description", description); + } + return sendRequest("setChatDescription", args).get("", false); } -bool Api::pinChatMessage(std::int64_t chatId, std::int32_t messageId, bool disableNotification) const { +bool Api::pinChatMessage(boost::variant chatId, + std::int32_t messageId, + bool disableNotification) const { std::vector args; args.reserve(3); + args.emplace_back("chat_id", chatId); args.emplace_back("message_id", messageId); if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } + return sendRequest("pinChatMessage", args).get("", false); } -bool Api::unpinChatMessage(std::int64_t chatId, std::int32_t messageId) const { +bool Api::unpinChatMessage(boost::variant chatId, + std::int32_t messageId) const { std::vector args; args.reserve(2); args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); + if (messageId != 0) { + args.emplace_back("message_id", messageId); + } return sendRequest("unpinChatMessage", args).get("", false); } -bool Api::unpinAllChatMessages(std::int64_t chatId) const { +bool Api::unpinAllChatMessages(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1342,14 +1362,16 @@ bool Api::unpinAllChatMessages(std::int64_t chatId) const { return sendRequest("unpinAllChatMessages", args).get("", false); } -bool Api::leaveChat(std::int64_t chatId) const { +bool Api::leaveChat(boost::variant chatId) const { std::vector args; args.reserve(1); + args.emplace_back("chat_id", chatId); + return sendRequest("leaveChat", args).get("", false); } -Chat::Ptr Api::getChat(std::int64_t chatId) const { +Chat::Ptr Api::getChat(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1358,14 +1380,16 @@ Chat::Ptr Api::getChat(std::int64_t chatId) const { return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args)); } -std::vector Api::getChatAdministrators(std::int64_t chatId) const { +std::vector Api::getChatAdministrators(boost::variant chatId) const { std::vector args; args.reserve(1); + args.emplace_back("chat_id", chatId); + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); } -int32_t Api::getChatMemberCount(std::int64_t chatId) const { +int32_t Api::getChatMemberCount(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1374,32 +1398,45 @@ int32_t Api::getChatMemberCount(std::int64_t chatId) const { return sendRequest("getChatMemberCount", args).get("", 0); } -ChatMember::Ptr Api::getChatMember(std::int64_t chatId, std::int64_t userId) const { +ChatMember::Ptr Api::getChatMember(boost::variant chatId, + std::int64_t userId) const { std::vector args; args.reserve(2); + args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); + return _tgTypeParser.parseJsonAndGetChatMember(sendRequest("getChatMember", args)); } -bool Api::setChatStickerSet(std::int64_t chatId, const std::string& stickerSetName) const { +bool Api::setChatStickerSet(boost::variant chatId, + const std::string& stickerSetName) const { std::vector args; args.reserve(2); + args.emplace_back("chat_id", chatId); args.emplace_back("sticker_set_name ", stickerSetName); + return sendRequest("setChatStickerSet", args).get("", false); } -bool Api::deleteChatStickerSet(std::int64_t chatId) const { +bool Api::deleteChatStickerSet(boost::variant chatId) const { std::vector args; args.reserve(1); + args.emplace_back("chat_id", chatId); + return sendRequest("deleteChatStickerSet", args).get("", false); } -bool Api::answerCallbackQuery(const std::string& callbackQueryId, const std::string& text, bool showAlert, const std::string& url, std::int32_t cacheTime) const { +bool Api::answerCallbackQuery(const std::string& callbackQueryId, + const std::string& text, + bool showAlert, + const std::string& url, + std::int32_t cacheTime) const { std::vector args; args.reserve(5); + args.emplace_back("callback_query_id", callbackQueryId); if (!text.empty()) { args.emplace_back("text", text); @@ -1413,6 +1450,7 @@ bool Api::answerCallbackQuery(const std::string& callbackQueryId, const std::str if (cacheTime) { args.emplace_back("cache_time", cacheTime); } + return sendRequest("answerCallbackQuery", args).get("", false); } @@ -1490,7 +1528,7 @@ MenuButton::Ptr Api::getChatMenuButton(std::int64_t chatId) const { } bool Api::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights, - bool forChannels) const { + bool forChannels) const { std::vector args; args.reserve(2); @@ -1516,7 +1554,7 @@ ChatAdministratorRights::Ptr Api::getMyDefaultAdministratorRights(bool forChanne } Message::Ptr Api::editMessageText(const std::string& text, - std::int64_t chatId, + boost::variant chatId, std::int32_t messageId, const std::string& inlineMessageId, const std::string& parseMode, @@ -1526,7 +1564,7 @@ Message::Ptr Api::editMessageText(const std::string& text, std::vector args; args.reserve(8); - if (chatId) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -1557,7 +1595,7 @@ Message::Ptr Api::editMessageText(const std::string& text, } } -Message::Ptr Api::editMessageCaption(std::int64_t chatId, +Message::Ptr Api::editMessageCaption(boost::variant chatId, std::int32_t messageId, const std::string& caption, const std::string& inlineMessageId, @@ -1567,7 +1605,7 @@ Message::Ptr Api::editMessageCaption(std::int64_t chatId, std::vector args; args.reserve(7); - if (chatId) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -1597,13 +1635,17 @@ Message::Ptr Api::editMessageCaption(std::int64_t chatId, } } -Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId, +Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, + boost::variant chatId, + std::int32_t messageId, + const std::string& inlineMessageId, GenericReply::Ptr replyMarkup) const { std::vector args; args.reserve(5); + args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); - if (chatId) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -1615,6 +1657,7 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, s if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } + boost::property_tree::ptree p = sendRequest("editMessageMedia", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); @@ -1623,12 +1666,15 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::int64_t chatId, s } } -Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId, +Message::Ptr Api::editMessageReplyMarkup(boost::variant chatId, + std::int32_t messageId, + const std::string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { std::vector args; args.reserve(4); - if (chatId) { + + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -1640,6 +1686,7 @@ Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messa if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } + boost::property_tree::ptree p = sendRequest("editMessageReplyMarkup", args); if (p.get_child_optional("message_id")) { return _tgTypeParser.parseJsonAndGetMessage(p); @@ -1648,19 +1695,30 @@ Message::Ptr Api::editMessageReplyMarkup(std::int64_t chatId, std::int32_t messa } } -Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { +Poll::Ptr Api::stopPoll(boost::variant chatId, + std::int64_t messageId, + const InlineKeyboardMarkup::Ptr replyMarkup) const { std::vector args; args.reserve(3); + args.emplace_back("chat_id", chatId); args.emplace_back("message_id", messageId); if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } + return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args)); } -void Api::deleteMessage(std::int64_t chatId, std::int32_t messageId) const { - sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) }); +bool Api::deleteMessage(boost::variant chatId, + std::int32_t messageId) const { + std::vector args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + + return sendRequest("deleteMessage", args).get("", false); } Message::Ptr Api::sendSticker(boost::variant chatId, @@ -1719,11 +1777,14 @@ std::vector Api::getCustomEmojiStickers(const StringArrayPtr& cust return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args)); } -File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSticker) const { +File::Ptr Api::uploadStickerFile(std::int64_t userId, + const InputFile::Ptr pngSticker) const { std::vector args; args.reserve(2); + args.emplace_back("user_id", userId); args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName); + return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); } @@ -1798,44 +1859,56 @@ bool Api::addStickerToSet(std::int64_t userId, return sendRequest("addStickerToSet", args).get("", false); } -bool Api::setStickerPositionInSet(const std::string& sticker, std::uint32_t position) const { +bool Api::setStickerPositionInSet(const std::string& sticker, + std::int32_t position) const { std::vector args; args.reserve(2); + args.emplace_back("sticker", sticker); args.emplace_back("position", position); + return sendRequest("setStickerPositionInSet", args).get("", false); } bool Api::deleteStickerFromSet(const std::string& sticker) const { std::vector args; args.reserve(1); + args.emplace_back("sticker", sticker); + return sendRequest("deleteStickerFromSet", args).get("", false); } -bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant thumb) const { +bool Api::setStickerSetThumb(const std::string& name, + std::int64_t userId, + boost::variant thumb) const { std::vector args; args.reserve(3); args.emplace_back("name", name); args.emplace_back("user_id", userId); - 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 */ { - args.emplace_back("thumb", boost::get(thumb)); + } else { // const std::string& + args.emplace_back("thumb", boost::get(thumb)); } return sendRequest("setStickerSetThumb", args).get("", false); } -bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector& results, - std::int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const { +bool Api::answerInlineQuery(const std::string& inlineQueryId, + const std::vector& results, + std::int32_t cacheTime, + bool isPersonal, + const std::string& nextOffset, + const std::string& switchPmText, + const std::string& switchPmParameter) const { std::vector args; args.reserve(7); + args.emplace_back("inline_query_id", inlineQueryId); - std::string resultsJson = _tgTypeParser.parseArray(&TgTypeParser::parseInlineQueryResult, results); - args.emplace_back("results", resultsJson); + args.emplace_back("results", _tgTypeParser.parseArray(&TgTypeParser::parseInlineQueryResult, results)); if (cacheTime) { args.emplace_back("cache_time", cacheTime); } @@ -1851,6 +1924,7 @@ bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector< if (!switchPmParameter.empty()) { args.emplace_back("switch_pm_parameter", switchPmParameter); } + return sendRequest("answerInlineQuery", args).get("", false); } @@ -2041,9 +2115,13 @@ std::string Api::createInvoiceLink(const std::string& title, return sendRequest("createInvoiceLink", args).get("", ""); } -bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const std::vector& shippingOptions, const std::string& errorMessage) const { +bool Api::answerShippingQuery(const std::string& shippingQueryId, + bool ok, + const std::vector& shippingOptions, + const std::string& errorMessage) const { std::vector args; args.reserve(4); + args.emplace_back("shipping_query_id", shippingQueryId); args.emplace_back("ok", ok); if (!shippingOptions.empty()) { @@ -2052,21 +2130,27 @@ bool Api::answerShippingQuery(const std::string& shippingQueryId, bool ok, const if (!errorMessage.empty()) { args.emplace_back("error_message", errorMessage); } + return sendRequest("answerShippingQuery", args).get("", false); } -bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, bool ok, const std::string& errorMessage) const { +bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, + bool ok, + const std::string& errorMessage) const { std::vector args; args.reserve(3); + args.emplace_back("pre_checkout_query_id", preCheckoutQueryId); args.emplace_back("ok", ok); if (!errorMessage.empty()) { args.emplace_back("error_message", errorMessage); } + return sendRequest("answerPreCheckoutQuery", args).get("", false); } -bool Api::setPassportDataErrors(std::int64_t userId, const std::vector& errors) const { +bool Api::setPassportDataErrors(std::int64_t userId, + const std::vector& errors) const { std::vector args; args.reserve(2); @@ -2107,9 +2191,16 @@ Message::Ptr Api::sendGame(std::int64_t chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendGame", args)); } -Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool force, bool disableEditMessage, std::int64_t chatId, std::int32_t messageId, const std::string& inlineMessageId) const { +Message::Ptr Api::setGameScore(std::int64_t userId, + std::int32_t score, + bool force, + bool disableEditMessage, + std::int64_t chatId, + std::int32_t messageId, + const std::string& inlineMessageId) const { std::vector args; args.reserve(7); + args.emplace_back("user_id", userId); args.emplace_back("score", score); if (force) { @@ -2127,6 +2218,7 @@ Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, bool for if (!inlineMessageId.empty()) { args.emplace_back("inline_message_id", inlineMessageId); } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("setGameScore", args)); } -- cgit v1.2.3 From f9e16bde59f57c3b6990c47e5082e3edeb527e4d Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:38:45 +0200 Subject: Add function to check if bot is blocked by user --- src/Api.cpp | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index ea9a550..875a79a 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1024,17 +1024,6 @@ File::Ptr Api::getFile(const std::string& fileId) const { return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args)); } -std::string Api::downloadFile(const std::string& filePath, - const std::vector& args) const { - std::string url(_url); - url += "/file/bot"; - url += _token; - url += "/"; - url += filePath; - - return _httpClient.makeRequest(url, args); -} - bool Api::banChatMember(boost::variant chatId, std::int64_t userId, std::int32_t untilDate, @@ -2243,6 +2232,34 @@ std::vector Api::getGameHighScores(std::int64_t userId, return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args)); } +std::string Api::downloadFile(const std::string& filePath, + const std::vector& args) const { + std::string url(_url); + url += "/file/bot"; + url += _token; + url += "/"; + url += filePath; + + return _httpClient.makeRequest(url, args); +} + +bool Api::blockedByUser(std::int64_t chatId) const { + bool isBotBlocked = false; + + try { + sendChatAction(chatId, "typing"); + + } catch (std::exception& e) { + std::string error = e.what(); + + if (error.compare("Forbidden: bot was blocked by the user") == 0) { + isBotBlocked = true; + } + } + + return isBotBlocked; +} + boost::property_tree::ptree Api::sendRequest(const std::string& method, const std::vector& args) const { std::string url(_url); url += "/bot"; -- cgit v1.2.3 From f9d24932cc960eeae32e049fc271fa6fa01327c3 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Tue, 20 Sep 2022 17:50:12 +0200 Subject: Fix #230 --- src/Api.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 875a79a..e13fa7c 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -880,7 +880,7 @@ Message::Ptr Api::sendContact(boost::variant c Message::Ptr Api::sendPoll(boost::variant chatId, const std::string& question, - const StringArrayPtr& options, + const std::vector& options, bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, @@ -903,8 +903,8 @@ Message::Ptr Api::sendPoll(boost::variant chat args.emplace_back("question", question); args.emplace_back("options", _tgTypeParser.parseArray( [](const std::string& option)->std::string { - return "\"" + StringTools::urlEncode(option) + "\""; - }, *options)); + return "\"" + option + "\""; + }, options)); if (!isAnonymous) { args.emplace_back("is_anonymous", isAnonymous); } @@ -1755,13 +1755,13 @@ StickerSet::Ptr Api::getStickerSet(const std::string& name) const { return _tgTypeParser.parseJsonAndGetStickerSet(sendRequest("getStickerSet", args)); } -std::vector Api::getCustomEmojiStickers(const StringArrayPtr& customEmojiIds) const { +std::vector Api::getCustomEmojiStickers(const std::vector& customEmojiIds) const { std::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 "\"" + customEmojiId + "\""; + }, customEmojiIds)); return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args)); } -- cgit v1.2.3 From d9615bbe41c830eb3941e3f6235d47b6a46e584d Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Wed, 5 Oct 2022 11:35:04 +0200 Subject: sendPoll: update default value (#234) --- src/Api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index e13fa7c..ed1f07a 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -914,7 +914,7 @@ Message::Ptr Api::sendPoll(boost::variant chat if (allowsMultipleAnswers) { args.emplace_back("allows_multiple_answers", allowsMultipleAnswers); } - if (correctOptionId != 0) { + if (correctOptionId != -1) { args.emplace_back("correct_option_id", correctOptionId); } if (!explanation.empty()) { -- cgit v1.2.3 From 1d238b70e2655e64b1cb1a51357a9eb0c753181d Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Wed, 5 Oct 2022 13:57:24 +0200 Subject: Escape poll options (#128) --- src/Api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index ed1f07a..7ceb75e 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -903,7 +903,7 @@ Message::Ptr Api::sendPoll(boost::variant chat args.emplace_back("question", question); args.emplace_back("options", _tgTypeParser.parseArray( [](const std::string& option)->std::string { - return "\"" + option + "\""; + return "\"" + StringTools::escapeJsonString(option) + "\""; }, options)); if (!isAnonymous) { args.emplace_back("is_anonymous", isAnonymous); @@ -1760,7 +1760,7 @@ std::vector Api::getCustomEmojiStickers(const std::vector([] (const std::string& customEmojiId) -> std::string { - return "\"" + customEmojiId + "\""; + return "\"" + StringTools::escapeJsonString(customEmojiId) + "\""; }, customEmojiIds)); return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args)); -- cgit v1.2.3 From 7abb2509b87ef1344da97ae734211715f291cfa2 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sun, 23 Oct 2022 16:08:28 +0200 Subject: Pass strings not as references with boost::variant (#237) --- src/Api.cpp | 220 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 110 insertions(+), 110 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 7ceb75e..9eefc09 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -107,7 +107,7 @@ bool Api::close() const { return sendRequest("close").get("", false); } -Message::Ptr Api::sendMessage(boost::variant chatId, +Message::Ptr Api::sendMessage(boost::variant chatId, const std::string& text, bool disableWebPagePreview, std::int32_t replyToMessageId, @@ -150,8 +150,8 @@ Message::Ptr Api::sendMessage(boost::variant c return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); } -Message::Ptr Api::forwardMessage(boost::variant chatId, - boost::variant fromChatId, +Message::Ptr Api::forwardMessage(boost::variant chatId, + boost::variant fromChatId, std::int32_t messageId, bool disableNotification, bool protectContent) const { @@ -171,8 +171,8 @@ Message::Ptr Api::forwardMessage(boost::variant chatId, - boost::variant fromChatId, +MessageId::Ptr Api::copyMessage(boost::variant chatId, + boost::variant fromChatId, std::int32_t messageId, const std::string& caption, const std::string& parseMode, @@ -216,8 +216,8 @@ MessageId::Ptr Api::copyMessage(boost::variant return _tgTypeParser.parseJsonAndGetMessageId(sendRequest("copyMessage", args)); } -Message::Ptr Api::sendPhoto(boost::variant 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, @@ -233,8 +233,8 @@ Message::Ptr Api::sendPhoto(boost::variant cha if (photo.which() == 0) { // InputFile::Ptr auto file = boost::get(photo); args.emplace_back("photo", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("photo", boost::get(photo)); + } else { // std::string + args.emplace_back("photo", boost::get(photo)); } if (!caption.empty()) { args.emplace_back("caption", caption); @@ -264,13 +264,13 @@ Message::Ptr Api::sendPhoto(boost::variant cha return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args)); } -Message::Ptr Api::sendAudio(boost::variant 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, @@ -285,8 +285,8 @@ Message::Ptr Api::sendAudio(boost::variant cha if (audio.which() == 0) { // InputFile::Ptr auto file = boost::get(audio); args.emplace_back("audio", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("audio", boost::get(audio)); + } else { // std::string + args.emplace_back("audio", boost::get(audio)); } if (!caption.empty()) { args.emplace_back("caption", caption); @@ -309,8 +309,8 @@ Message::Ptr Api::sendAudio(boost::variant cha if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - auto thumbStr = boost::get(thumb); + } else { // std::string + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -334,9 +334,9 @@ Message::Ptr Api::sendAudio(boost::variant cha return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args)); } -Message::Ptr Api::sendDocument(boost::variant 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, @@ -353,14 +353,14 @@ Message::Ptr Api::sendDocument(boost::variant if (document.which() == 0) { // InputFile::Ptr auto file = boost::get(document); args.emplace_back("document", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("document", boost::get(document)); + } else { // std::string + args.emplace_back("document", boost::get(document)); } if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - auto thumbStr = boost::get(thumb); + } else { // std::string + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -396,13 +396,13 @@ Message::Ptr Api::sendDocument(boost::variant return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDocument", args)); } -Message::Ptr Api::sendVideo(boost::variant 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, + boost::variant thumb, const std::string& caption , std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, @@ -418,8 +418,8 @@ Message::Ptr Api::sendVideo(boost::variant cha if (video.which() == 0) { // InputFile::Ptr auto file = boost::get(video); args.emplace_back("video", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("video", boost::get(video)); + } else { // std::string + args.emplace_back("video", boost::get(video)); } if (duration) { args.emplace_back("duration", duration); @@ -433,8 +433,8 @@ Message::Ptr Api::sendVideo(boost::variant cha if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - auto thumbStr = boost::get(thumb); + } else { // std::string + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -470,12 +470,12 @@ Message::Ptr Api::sendVideo(boost::variant cha return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); } -Message::Ptr Api::sendAnimation(boost::variant 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, @@ -491,8 +491,8 @@ Message::Ptr Api::sendAnimation(boost::variant if (animation.which() == 0) { // InputFile::Ptr auto file = boost::get(animation); args.emplace_back("animation", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("animation", boost::get(animation)); + } else { // std::string + args.emplace_back("animation", boost::get(animation)); } if (duration) { args.emplace_back("duration", duration); @@ -506,8 +506,8 @@ Message::Ptr Api::sendAnimation(boost::variant if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - auto thumbStr = boost::get(thumb); + } else { // std::string + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -540,8 +540,8 @@ Message::Ptr Api::sendAnimation(boost::variant return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); } -Message::Ptr Api::sendVoice(boost::variant 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, @@ -558,8 +558,8 @@ Message::Ptr Api::sendVoice(boost::variant cha if (voice.which() == 0) { // InputFile::Ptr auto file = boost::get(voice); args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("voice", boost::get(voice)); + } else { // std::string + args.emplace_back("voice", boost::get(voice)); } if (!caption.empty()) { args.emplace_back("caption", caption); @@ -592,13 +592,13 @@ Message::Ptr Api::sendVoice(boost::variant cha return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args)); } -Message::Ptr Api::sendVideoNote(boost::variant 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, bool protectContent) const { @@ -609,8 +609,8 @@ Message::Ptr Api::sendVideoNote(boost::variant if (videoNote.which() == 0) { // InputFile::Ptr auto file = boost::get(videoNote); args.emplace_back("video_note", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("video_note", boost::get(videoNote)); + } else { // std::string + args.emplace_back("video_note", boost::get(videoNote)); } if (duration) { args.emplace_back("duration", duration); @@ -621,8 +621,8 @@ Message::Ptr Api::sendVideoNote(boost::variant if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - auto thumbStr = boost::get(thumb); + } else { // std::string + auto thumbStr = boost::get(thumb); if (!thumbStr.empty()) { args.emplace_back("thumb", thumbStr); } @@ -646,7 +646,7 @@ Message::Ptr Api::sendVideoNote(boost::variant return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideoNote", args)); } -std::vector Api::sendMediaGroup(boost::variant chatId, +std::vector Api::sendMediaGroup(boost::variant chatId, const std::vector& media, bool disableNotification, std::int32_t replyToMessageId, @@ -673,7 +673,7 @@ std::vector Api::sendMediaGroup(boost::variant(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); } -Message::Ptr Api::sendLocation(boost::variant chatId, +Message::Ptr Api::sendLocation(boost::variant chatId, float latitude, float longitude, std::int32_t livePeriod, @@ -724,7 +724,7 @@ Message::Ptr Api::sendLocation(boost::variant Message::Ptr Api::editMessageLiveLocation(float latitude, float longitude, - boost::variant chatId, + boost::variant chatId, std::int32_t messageId, const std::string& inlineMessageId, InlineKeyboardMarkup::Ptr replyMarkup, @@ -734,7 +734,7 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, std::vector args; args.reserve(9); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -761,14 +761,14 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); } -Message::Ptr Api::stopMessageLiveLocation(boost::variant chatId, +Message::Ptr Api::stopMessageLiveLocation(boost::variant chatId, std::int32_t messageId, const std::string& inlineMessageId, InlineKeyboardMarkup::Ptr replyMarkup) const { std::vector args; args.reserve(4); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -784,7 +784,7 @@ Message::Ptr Api::stopMessageLiveLocation(boost::variant chatId, +Message::Ptr Api::sendVenue(boost::variant chatId, float latitude, float longitude, const std::string& title, @@ -837,7 +837,7 @@ Message::Ptr Api::sendVenue(boost::variant cha return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args)); } -Message::Ptr Api::sendContact(boost::variant chatId, +Message::Ptr Api::sendContact(boost::variant chatId, const std::string& phoneNumber, const std::string& firstName, const std::string& lastName , @@ -878,7 +878,7 @@ Message::Ptr Api::sendContact(boost::variant c return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendContact", args)); } -Message::Ptr Api::sendPoll(boost::variant chatId, +Message::Ptr Api::sendPoll(boost::variant chatId, const std::string& question, const std::vector& options, bool disableNotification, @@ -954,7 +954,7 @@ Message::Ptr Api::sendPoll(boost::variant chat return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); } -Message::Ptr Api::sendDice(boost::variant chatId, +Message::Ptr Api::sendDice(boost::variant chatId, bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, @@ -1024,7 +1024,7 @@ File::Ptr Api::getFile(const std::string& fileId) const { return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args)); } -bool Api::banChatMember(boost::variant chatId, +bool Api::banChatMember(boost::variant chatId, std::int64_t userId, std::int32_t untilDate, bool revokeMessages) const { @@ -1043,7 +1043,7 @@ bool Api::banChatMember(boost::variant chatId, return sendRequest("banChatMember", args).get("", false); } -bool Api::unbanChatMember(boost::variant chatId, +bool Api::unbanChatMember(boost::variant chatId, std::int64_t userId, bool onlyIfBanned) const { std::vector args; @@ -1058,7 +1058,7 @@ bool Api::unbanChatMember(boost::variant chatI return sendRequest("unbanChatMember", args).get("", false); } -bool Api::restrictChatMember(boost::variant chatId, +bool Api::restrictChatMember(boost::variant chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, std::int64_t untilDate) const { @@ -1075,7 +1075,7 @@ bool Api::restrictChatMember(boost::variant ch return sendRequest("restrictChatMember", args).get("", false); } -bool Api::promoteChatMember(boost::variant chatId, +bool Api::promoteChatMember(boost::variant chatId, std::int64_t userId, bool canChangeInfo, bool canPostMessages, @@ -1130,7 +1130,7 @@ bool Api::promoteChatMember(boost::variant cha return sendRequest("promoteChatMember", args).get("", false); } -bool Api::setChatAdministratorCustomTitle(boost::variant chatId, +bool Api::setChatAdministratorCustomTitle(boost::variant chatId, std::int64_t userId, const std::string& customTitle) const { std::vector args; @@ -1143,7 +1143,7 @@ bool Api::setChatAdministratorCustomTitle(boost::variant("", false); } -bool Api::banChatSenderChat(boost::variant chatId, +bool Api::banChatSenderChat(boost::variant chatId, std::int64_t senderChatId) const { std::vector args; args.reserve(2); @@ -1154,7 +1154,7 @@ bool Api::banChatSenderChat(boost::variant cha return sendRequest("banChatSenderChat", args).get("", false); } -bool Api::unbanChatSenderChat(boost::variant chatId, +bool Api::unbanChatSenderChat(boost::variant chatId, std::int64_t senderChatId) const { std::vector args; args.reserve(2); @@ -1165,7 +1165,7 @@ bool Api::unbanChatSenderChat(boost::variant c return sendRequest("unbanChatSenderChat", args).get("", false); } -bool Api::setChatPermissions(boost::variant chatId, +bool Api::setChatPermissions(boost::variant chatId, ChatPermissions::Ptr permissions) const { std::vector args; args.reserve(2); @@ -1176,7 +1176,7 @@ bool Api::setChatPermissions(boost::variant ch return sendRequest("setChatPermissions", args).get("", false); } -std::string Api::exportChatInviteLink(boost::variant chatId) const { +std::string Api::exportChatInviteLink(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1185,7 +1185,7 @@ std::string Api::exportChatInviteLink(boost::variant chatId, +ChatInviteLink::Ptr Api::createChatInviteLink(boost::variant chatId, std::int32_t expireDate, std::int32_t memberLimit, const std::string& name, @@ -1210,7 +1210,7 @@ ChatInviteLink::Ptr Api::createChatInviteLink(boost::variant chatId, +ChatInviteLink::Ptr Api::editChatInviteLink(boost::variant chatId, const std::string& inviteLink, std::int32_t expireDate, std::int32_t memberLimit, @@ -1237,7 +1237,7 @@ ChatInviteLink::Ptr Api::editChatInviteLink(boost::variant chatId, +ChatInviteLink::Ptr Api::revokeChatInviteLink(boost::variant chatId, const std::string& inviteLink) const { std::vector args; args.reserve(2); @@ -1248,7 +1248,7 @@ ChatInviteLink::Ptr Api::revokeChatInviteLink(boost::variant chatId, +bool Api::approveChatJoinRequest(boost::variant chatId, std::int64_t userId) const { std::vector args; args.reserve(2); @@ -1259,7 +1259,7 @@ bool Api::approveChatJoinRequest(boost::variant("", false); } -bool Api::declineChatJoinRequest(boost::variant chatId, +bool Api::declineChatJoinRequest(boost::variant chatId, std::int64_t userId) const { std::vector args; args.reserve(2); @@ -1270,7 +1270,7 @@ bool Api::declineChatJoinRequest(boost::variant("", false); } -bool Api::setChatPhoto(boost::variant chatId, +bool Api::setChatPhoto(boost::variant chatId, const InputFile::Ptr photo) const { std::vector args; args.reserve(2); @@ -1281,7 +1281,7 @@ bool Api::setChatPhoto(boost::variant chatId, return sendRequest("setChatPhoto", args).get("", false); } -bool Api::deleteChatPhoto(boost::variant chatId) const { +bool Api::deleteChatPhoto(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1290,7 +1290,7 @@ bool Api::deleteChatPhoto(boost::variant chatI return sendRequest("deleteChatPhoto", args).get("", false); } -bool Api::setChatTitle(boost::variant chatId, +bool Api::setChatTitle(boost::variant chatId, const std::string& title) const { std::vector args; args.reserve(2); @@ -1301,7 +1301,7 @@ bool Api::setChatTitle(boost::variant chatId, return sendRequest("setChatTitle", args).get("", false); } -bool Api::setChatDescription(boost::variant chatId, +bool Api::setChatDescription(boost::variant chatId, const std::string& description) const { std::vector args; args.reserve(2); @@ -1314,7 +1314,7 @@ bool Api::setChatDescription(boost::variant ch return sendRequest("setChatDescription", args).get("", false); } -bool Api::pinChatMessage(boost::variant chatId, +bool Api::pinChatMessage(boost::variant chatId, std::int32_t messageId, bool disableNotification) const { std::vector args; @@ -1329,7 +1329,7 @@ bool Api::pinChatMessage(boost::variant chatId return sendRequest("pinChatMessage", args).get("", false); } -bool Api::unpinChatMessage(boost::variant chatId, +bool Api::unpinChatMessage(boost::variant chatId, std::int32_t messageId) const { std::vector args; args.reserve(2); @@ -1342,7 +1342,7 @@ bool Api::unpinChatMessage(boost::variant chat return sendRequest("unpinChatMessage", args).get("", false); } -bool Api::unpinAllChatMessages(boost::variant chatId) const { +bool Api::unpinAllChatMessages(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1351,7 +1351,7 @@ bool Api::unpinAllChatMessages(boost::variant return sendRequest("unpinAllChatMessages", args).get("", false); } -bool Api::leaveChat(boost::variant chatId) const { +bool Api::leaveChat(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1360,7 +1360,7 @@ bool Api::leaveChat(boost::variant chatId) con return sendRequest("leaveChat", args).get("", false); } -Chat::Ptr Api::getChat(boost::variant chatId) const { +Chat::Ptr Api::getChat(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1369,7 +1369,7 @@ Chat::Ptr Api::getChat(boost::variant chatId) return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args)); } -std::vector Api::getChatAdministrators(boost::variant chatId) const { +std::vector Api::getChatAdministrators(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1378,7 +1378,7 @@ std::vector Api::getChatAdministrators(boost::variant(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); } -int32_t Api::getChatMemberCount(boost::variant chatId) const { +int32_t Api::getChatMemberCount(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1387,7 +1387,7 @@ int32_t Api::getChatMemberCount(boost::variant return sendRequest("getChatMemberCount", args).get("", 0); } -ChatMember::Ptr Api::getChatMember(boost::variant chatId, +ChatMember::Ptr Api::getChatMember(boost::variant chatId, std::int64_t userId) const { std::vector args; args.reserve(2); @@ -1398,7 +1398,7 @@ ChatMember::Ptr Api::getChatMember(boost::variant chatId, +bool Api::setChatStickerSet(boost::variant chatId, const std::string& stickerSetName) const { std::vector args; args.reserve(2); @@ -1409,7 +1409,7 @@ bool Api::setChatStickerSet(boost::variant cha return sendRequest("setChatStickerSet", args).get("", false); } -bool Api::deleteChatStickerSet(boost::variant chatId) const { +bool Api::deleteChatStickerSet(boost::variant chatId) const { std::vector args; args.reserve(1); @@ -1543,7 +1543,7 @@ ChatAdministratorRights::Ptr Api::getMyDefaultAdministratorRights(bool forChanne } Message::Ptr Api::editMessageText(const std::string& text, - boost::variant chatId, + boost::variant chatId, std::int32_t messageId, const std::string& inlineMessageId, const std::string& parseMode, @@ -1553,7 +1553,7 @@ Message::Ptr Api::editMessageText(const std::string& text, std::vector args; args.reserve(8); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -1584,7 +1584,7 @@ Message::Ptr Api::editMessageText(const std::string& text, } } -Message::Ptr Api::editMessageCaption(boost::variant chatId, +Message::Ptr Api::editMessageCaption(boost::variant chatId, std::int32_t messageId, const std::string& caption, const std::string& inlineMessageId, @@ -1594,7 +1594,7 @@ Message::Ptr Api::editMessageCaption(boost::variant args; args.reserve(7); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -1625,7 +1625,7 @@ Message::Ptr Api::editMessageCaption(boost::variant chatId, + boost::variant chatId, std::int32_t messageId, const std::string& inlineMessageId, GenericReply::Ptr replyMarkup) const { @@ -1634,7 +1634,7 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, args.reserve(5); args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -1655,7 +1655,7 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, } } -Message::Ptr Api::editMessageReplyMarkup(boost::variant chatId, +Message::Ptr Api::editMessageReplyMarkup(boost::variant chatId, std::int32_t messageId, const std::string& inlineMessageId, const GenericReply::Ptr replyMarkup) const { @@ -1663,7 +1663,7 @@ Message::Ptr Api::editMessageReplyMarkup(boost::variant args; args.reserve(4); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { + if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { args.emplace_back("chat_id", chatId); } if (messageId) { @@ -1684,7 +1684,7 @@ Message::Ptr Api::editMessageReplyMarkup(boost::variant chatId, +Poll::Ptr Api::stopPoll(boost::variant chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { std::vector args; @@ -1699,7 +1699,7 @@ Poll::Ptr Api::stopPoll(boost::variant chatId, return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args)); } -bool Api::deleteMessage(boost::variant chatId, +bool Api::deleteMessage(boost::variant chatId, std::int32_t messageId) const { std::vector args; args.reserve(2); @@ -1710,8 +1710,8 @@ bool Api::deleteMessage(boost::variant chatId, return sendRequest("deleteMessage", args).get("", false); } -Message::Ptr Api::sendSticker(boost::variant chatId, - boost::variant sticker, +Message::Ptr Api::sendSticker(boost::variant chatId, + boost::variant sticker, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, bool disableNotification, @@ -1724,8 +1724,8 @@ Message::Ptr Api::sendSticker(boost::variant c if (sticker.which() == 0) { // InputFile::Ptr auto file = boost::get(sticker); args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("sticker", boost::get(sticker)); + } else { // std::string + args.emplace_back("sticker", boost::get(sticker)); } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); @@ -1782,7 +1782,7 @@ bool Api::createNewStickerSet(std::int64_t userId, const std::string& title, const std::string& emojis, MaskPosition::Ptr maskPosition, - boost::variant pngSticker, + boost::variant pngSticker, InputFile::Ptr tgsSticker, InputFile::Ptr webmSticker, const std::string& stickerType) const { @@ -1795,8 +1795,8 @@ bool Api::createNewStickerSet(std::int64_t userId, if (pngSticker.which() == 0) { // InputFile::Ptr auto file = boost::get(pngSticker); args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("png_sticker", boost::get(pngSticker)); + } else { // std::string + args.emplace_back("png_sticker", boost::get(pngSticker)); } if (tgsSticker != nullptr) { args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName); @@ -1819,7 +1819,7 @@ bool Api::addStickerToSet(std::int64_t userId, const std::string& name, const std::string& emojis, MaskPosition::Ptr maskPosition, - boost::variant pngSticker, + boost::variant pngSticker, InputFile::Ptr tgsSticker, InputFile::Ptr webmSticker) const { std::vector args; @@ -1831,8 +1831,8 @@ bool Api::addStickerToSet(std::int64_t userId, if (pngSticker.which() == 0) { // InputFile::Ptr auto file = boost::get(pngSticker); args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("png_sticker", boost::get(pngSticker)); + } else { // std::string + args.emplace_back("png_sticker", boost::get(pngSticker)); } if (tgsSticker != nullptr) { args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName); @@ -1870,7 +1870,7 @@ bool Api::deleteStickerFromSet(const std::string& sticker) const { bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, - boost::variant thumb) const { + boost::variant thumb) const { std::vector args; args.reserve(3); @@ -1879,8 +1879,8 @@ bool Api::setStickerSetThumb(const std::string& name, if (thumb.which() == 0) { // InputFile::Ptr auto file = boost::get(thumb); args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); - } else { // const std::string& - args.emplace_back("thumb", boost::get(thumb)); + } else { // std::string + args.emplace_back("thumb", boost::get(thumb)); } return sendRequest("setStickerSetThumb", args).get("", false); @@ -1928,7 +1928,7 @@ SentWebAppMessage::Ptr Api::answerWebAppQuery(const std::string& webAppQueryId, return _tgTypeParser.parseJsonAndGetSentWebAppMessage(sendRequest("answerWebAppQuery", args)); } -Message::Ptr Api::sendInvoice(boost::variant chatId, +Message::Ptr Api::sendInvoice(boost::variant chatId, const std::string& title, const std::string& description, const std::string& payload, -- cgit v1.2.3