From b729f89033dca0cd2b9606060e735abfaf41c1f4 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Mon, 29 Aug 2022 18:46:44 +0200 Subject: Update to API 4.5 --- src/Api.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index ff39805..b1a2f69 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -45,7 +45,7 @@ Message::Ptr Api::sendMessage(std::int64_t chatId, const string& text, bool disa } return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); } - + Message::Ptr Api::sendMessage(const std::string &chatId, const string& text, bool disableWebPagePreview, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; args.reserve(7); @@ -67,7 +67,7 @@ Message::Ptr Api::sendMessage(const std::string &chatId, const string& text, boo args.emplace_back("parse_mode", parseMode); } 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 { vector args; @@ -1032,6 +1032,15 @@ bool Api::promoteChatMember(std::int64_t chatId, std::int64_t userId, bool canCh return sendRequest("promoteChatMember", args).get("", false); } +bool Api::setChatAdministratorCustomTitle(std::int64_t chatId, std::int64_t userId, const std::string& customTitle) const { + vector args; + args.reserve(3); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + args.emplace_back("custom_title", customTitle); + return sendRequest("setChatAdministratorCustomTitle", args).get("", false); +} + bool Api::setChatPermissions(std::int64_t chatId, ChatPermissions::Ptr permissions) const{ vector args; args.reserve(2); -- cgit v1.2.3 From ed5065b35911a6d7d3dff30bd80600cc593901a3 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Mon, 29 Aug 2022 21:30:37 +0200 Subject: Update to API 4.6 --- src/Api.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index b1a2f69..f1a1065 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1155,24 +1155,42 @@ 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::sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, bool disableNotification, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, const std::vector& options, bool disableNotification, std::int32_t replyToMessageId, + const GenericReply::Ptr replyMarkup, bool isAnonymous, const std::string& type, bool allowsMultipleAnswers, + std::int32_t correctOptionId, bool isClosed) const { vector args; - args.reserve(6); + args.reserve(11); args.emplace_back("chat_id", chatId); args.emplace_back("question", question); args.emplace_back("options", _tgTypeParser.parseArray([] (const std::string& option) -> std::string { return StringTools::urlEncode(option); }, options)); - if (disableNotification){ + if (!isAnonymous) { + args.emplace_back("is_anonymous", isAnonymous); + } + if (!type.empty()) { + args.emplace_back("type", type); + } + if (allowsMultipleAnswers) { + args.emplace_back("allows_multiple_answers", allowsMultipleAnswers); + } + if (correctOptionId != 0) { + args.emplace_back("correct_option_id", correctOptionId); + } + if (isClosed) { + args.emplace_back("is_closed", isClosed); + } + if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } - if (replyToMessageId != 0){ + if (replyToMessageId != 0) { args.emplace_back("reply_to_message_id", replyToMessageId); } - if (replyMarkup){ + if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); } + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); } -- cgit v1.2.3 From 76a362631705d9adcc2709e6d8f9b327112ae306 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Tue, 30 Aug 2022 00:25:15 +0200 Subject: Update to API 4.7 --- src/Api.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index f1a1065..22115c2 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -320,19 +320,28 @@ File::Ptr Api::uploadStickerFile(std::int64_t userId, const InputFile::Ptr pngSt return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); } -bool Api::createNewStickerSet(std::int64_t userId, const string& name, const string& title, boost::variant pngSticker, const string& emojis, bool containsMasks, MaskPosition::Ptr maskPosition) const { +bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, const std::string& emojis, + boost::variant pngSticker, boost::variant tgsSticker, + bool containsMasks, MaskPosition::Ptr maskPosition) const { vector args; - args.reserve(7); + args.reserve(8); 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 */) { 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)); } - args.emplace_back("emojis", emojis); + 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 (containsMasks) { args.emplace_back("contains_mask", containsMasks); } @@ -342,18 +351,27 @@ bool Api::createNewStickerSet(std::int64_t userId, const string& name, const str return sendRequest("createNewStickerSet", args).get("", false); } -bool Api::addStickerToSet(std::int64_t userId, const string& name, boost::variant pngSticker, const string& emojis, MaskPosition::Ptr maskPosition) const { +bool Api::addStickerToSet(std::int64_t userId, const std::string& name, const std::string& emojis, + boost::variant pngSticker, boost::variant tgsSticker, + MaskPosition::Ptr maskPosition) const { vector args; args.reserve(6); args.emplace_back("user_id", userId); args.emplace_back("name", name); + args.emplace_back("emojis", emojis); + 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)); } - args.emplace_back("emojis", emojis); + 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 (maskPosition != nullptr) { args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); } @@ -375,6 +393,20 @@ bool Api::deleteStickerFromSet(const string& sticker) const { return sendRequest("deleteStickerFromSet", args).get("", false); } +bool Api::setStickerSetThumb(const std::string& name, std::int64_t userId, boost::variant thumb) const { + vector args; + args.reserve(3); + args.emplace_back("name", name); + args.emplace_back("user_id", userId); + 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)); + } + return sendRequest("setStickerSetThumb", args).get("", false); +} + Message::Ptr Api::sendVideo(std::int64_t chatId, boost::variant video, bool supportsStreaming, std::int32_t duration, std::int32_t width, std::int32_t height, boost::variant thumb, const string &caption, std::int32_t replyToMessageId, const GenericReply::Ptr replyMarkup, const string& parseMode, bool disableNotification) const { vector args; args.reserve(12); @@ -1194,6 +1226,24 @@ Message::Ptr Api::sendPoll(std::int64_t chatId, const std::string& question, con return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); } +Message::Ptr Api::sendDice(std::int64_t chatId, bool disableNotification, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup) const { + vector args; + args.reserve(4); + args.emplace_back("chat_id", chatId); + + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (replyToMessageId != 0) { + args.emplace_back("reply_to_message_id", replyToMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + + return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args)); +} + Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { vector args; args.reserve(3); @@ -1206,7 +1256,6 @@ Poll::Ptr Api::stopPoll(std::int64_t chatId, std::int64_t messageId, const Inlin } bool Api::setMyCommands(const std::vector& commands) const { - vector args; args.reserve(5); @@ -1216,8 +1265,7 @@ bool Api::setMyCommands(const std::vector& commands) const { return sendRequest("setMyCommands",args).get("",false); } -std::vector Api::getMyCommands() const -{ +std::vector Api::getMyCommands() const { return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands")); } -- cgit v1.2.3