summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorllnulldisk <48621230+llnulldisk@users.noreply.github.com>2023-01-02 21:55:47 +0100
committerllnulldisk <48621230+llnulldisk@users.noreply.github.com>2023-01-02 21:55:47 +0100
commitc3ba72eb8ae63ef31688e3f4e4056b4f969abef4 (patch)
tree853cdc02e5941e8fcf21d8fbd997018dd5c0915b /src
parent2544005955722db8633bdac5d8e61aabd0756b70 (diff)
Update to Bot API 6.4
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp113
-rw-r--r--src/TgTypeParser.cpp90
2 files changed, 180 insertions, 23 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index dc4076f..54854f8 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -238,9 +238,10 @@ Message::Ptr Api::sendPhoto(boost::variant<std::int64_t, std::string> chatId,
const std::vector<MessageEntity::Ptr>& captionEntities,
bool allowSendingWithoutReply,
bool protectContent,
- std::int32_t messageThreadId) const {
+ std::int32_t messageThreadId,
+ bool hasSpoiler) const {
std::vector<HttpReqArg> args;
- args.reserve(11);
+ args.reserve(12);
args.emplace_back("chat_id", chatId);
if (messageThreadId != 0) {
@@ -261,19 +262,22 @@ Message::Ptr Api::sendPhoto(boost::variant<std::int64_t, std::string> chatId,
if (!captionEntities.empty()) {
args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities));
}
+ if (hasSpoiler) {
+ args.emplace_back("has_spoiler", hasSpoiler);
+ }
if (disableNotification) {
args.emplace_back("disable_notification", disableNotification);
}
if (protectContent) {
args.emplace_back("protect_content", protectContent);
}
- if (replyToMessageId) {
+ if (replyToMessageId != 0) {
args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (allowSendingWithoutReply) {
args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply);
}
- if (replyMarkup) {
+ if (replyMarkup != nullptr) {
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
@@ -435,9 +439,10 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, std::string> chatId,
const std::vector<MessageEntity::Ptr>& captionEntities,
bool allowSendingWithoutReply,
bool protectContent,
- std::int32_t messageThreadId) const {
+ std::int32_t messageThreadId,
+ bool hasSpoiler) const {
std::vector<HttpReqArg> args;
- args.reserve(16);
+ args.reserve(17);
args.emplace_back("chat_id", chatId);
if (messageThreadId != 0) {
@@ -449,13 +454,13 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, std::string> chatId,
} else { // std::string
args.emplace_back("video", boost::get<std::string>(video));
}
- if (duration) {
+ if (duration != 0) {
args.emplace_back("duration", duration);
}
- if (width) {
+ if (width != 0) {
args.emplace_back("width", width);
}
- if (height) {
+ if (height != 0) {
args.emplace_back("height", height);
}
if (thumb.which() == 0) { // InputFile::Ptr
@@ -476,6 +481,9 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, std::string> chatId,
if (!captionEntities.empty()) {
args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities));
}
+ if (hasSpoiler) {
+ args.emplace_back("has_spoiler", hasSpoiler);
+ }
if (supportsStreaming) {
args.emplace_back("supports_streaming", supportsStreaming);
}
@@ -485,13 +493,13 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, std::string> chatId,
if (protectContent) {
args.emplace_back("protect_content", protectContent);
}
- if (replyToMessageId) {
+ if (replyToMessageId != 0) {
args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (allowSendingWithoutReply) {
args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply);
}
- if (replyMarkup) {
+ if (replyMarkup != nullptr) {
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
@@ -512,9 +520,10 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, std::string> chatId
const std::vector<MessageEntity::Ptr>& captionEntities,
bool allowSendingWithoutReply,
bool protectContent,
- std::int32_t messageThreadId) const {
+ std::int32_t messageThreadId,
+ bool hasSpoiler ) const {
std::vector<HttpReqArg> args;
- args.reserve(15);
+ args.reserve(16);
args.emplace_back("chat_id", chatId);
if (messageThreadId != 0) {
@@ -526,13 +535,13 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, std::string> chatId
} else { // std::string
args.emplace_back("animation", boost::get<std::string>(animation));
}
- if (duration) {
+ if (duration != 0) {
args.emplace_back("duration", duration);
}
- if (width) {
+ if (width != 0) {
args.emplace_back("width", width);
}
- if (height) {
+ if (height != 0) {
args.emplace_back("height", height);
}
if (thumb.which() == 0) { // InputFile::Ptr
@@ -553,19 +562,22 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, std::string> chatId
if (!captionEntities.empty()) {
args.emplace_back("caption_entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, captionEntities));
}
+ if (hasSpoiler) {
+ args.emplace_back("has_spoiler", hasSpoiler);
+ }
if (disableNotification) {
args.emplace_back("disable_notification", disableNotification);
}
if (protectContent) {
args.emplace_back("protect_content", protectContent);
}
- if (replyToMessageId) {
+ if (replyToMessageId != 0) {
args.emplace_back("reply_to_message_id", replyToMessageId);
}
if (allowSendingWithoutReply) {
args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply);
}
- if (replyMarkup) {
+ if (replyMarkup != nullptr) {
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
@@ -1052,12 +1064,16 @@ Message::Ptr Api::sendDice(boost::variant<std::int64_t, std::string> chatId,
}
bool Api::sendChatAction(std::int64_t chatId,
- const std::string& action) const {
+ const std::string& action,
+ std::int32_t messageThreadId) const {
std::vector<HttpReqArg> args;
- args.reserve(2);
+ args.reserve(3);
args.emplace_back("chat_id", chatId);
args.emplace_back("action", action);
+ if (messageThreadId != 0) {
+ args.emplace_back("message_thread_id", messageThreadId);
+ }
return sendRequest("sendChatAction", args).get<bool>("", false);
}
@@ -1512,14 +1528,18 @@ ForumTopic::Ptr Api::createForumTopic(boost::variant<std::int64_t, std::string>
bool Api::editForumTopic(boost::variant<std::int64_t, std::string> chatId,
std::int32_t messageThreadId,
const std::string& name,
- const std::string& iconCustomEmojiId) const {
+ boost::variant<std::int8_t, std::string> iconCustomEmojiId) const {
std::vector<HttpReqArg> args;
args.reserve(4);
args.emplace_back("chat_id", chatId);
args.emplace_back("message_thread_id", messageThreadId);
- args.emplace_back("name", name);
- args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId);
+ if (!name.empty()) {
+ args.emplace_back("name", name);
+ }
+ if (iconCustomEmojiId.which() == 1) { // std::string
+ args.emplace_back("icon_custom_emoji_id", boost::get<std::string>(iconCustomEmojiId));
+ }
return sendRequest("editForumTopic", args).get<bool>("", false);
}
@@ -1568,6 +1588,53 @@ bool Api::unpinAllForumTopicMessages(boost::variant<std::int64_t, std::string> c
return sendRequest("unpinAllForumTopicMessages", args).get<bool>("", false);
}
+bool Api::editGeneralForumTopic(boost::variant<std::int64_t, std::string> chatId,
+ std::string name) const {
+ std::vector<HttpReqArg> args;
+ args.reserve(2);
+
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("name", name);
+
+ return sendRequest("editGeneralForumTopic", args).get<bool>("", false);
+}
+
+bool Api::closeGeneralForumTopic(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
+ args.reserve(1);
+
+ args.emplace_back("chat_id", chatId);
+
+ return sendRequest("closeGeneralForumTopic", args).get<bool>("", false);
+}
+
+bool Api::reopenGeneralForumTopic(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
+ args.reserve(1);
+
+ args.emplace_back("chat_id", chatId);
+
+ return sendRequest("reopenGeneralForumTopic", args).get<bool>("", false);
+}
+
+bool Api::hideGeneralForumTopic(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
+ args.reserve(1);
+
+ args.emplace_back("chat_id", chatId);
+
+ return sendRequest("hideGeneralForumTopic", args).get<bool>("", false);
+}
+
+bool Api::unhideGeneralForumTopic(boost::variant<std::int64_t, std::string> chatId) const {
+ std::vector<HttpReqArg> args;
+ args.reserve(1);
+
+ args.emplace_back("chat_id", chatId);
+
+ return sendRequest("unhideGeneralForumTopic", args).get<bool>("", false);
+}
+
bool Api::answerCallbackQuery(const std::string& callbackQueryId,
const std::string& text,
bool showAlert,
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index a31172f..24173c4 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -164,6 +164,8 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& d
result->slowModeDelay = data.get<std::int32_t>("slow_mode_delay", 0);
result->messageAutoDeleteTime = data.get<std::int32_t>("message_auto_delete_time", 0);
result->hasProtectedContent = data.get<bool>("has_protected_content", false);
+ result->hasAggressiveAntiSpamEnabled = data.get<bool>("has_aggressive_anti_spam_enabled", false);
+ result->hasHiddenMembers = data.get<bool>("has_hidden_members", false);
result->stickerSetName = data.get<std::string>("sticker_set_name", "");
result->canSetStickerSet = data.get<bool>("can_set_sticker_set", false);
result->linkedChatId = data.get<std::int64_t>("linked_chat_id", 0);
@@ -209,6 +211,8 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const {
appendToJson(result, "permissions", parseChatPermissions(object->permissions));
appendToJson(result, "slow_mode_delay", object->slowModeDelay);
appendToJson(result, "message_auto_delete_time", object->messageAutoDeleteTime);
+ appendToJson(result, "has_aggressive_anti_spam_enabled", object->hasAggressiveAntiSpamEnabled);
+ appendToJson(result, "has_hidden_members", object->hasHiddenMembers);
appendToJson(result, "has_protected_content", object->hasProtectedContent);
appendToJson(result, "sticker_set_name", object->stickerSetName);
appendToJson(result, "can_set_sticker_set", object->canSetStickerSet);
@@ -253,6 +257,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt
result->voice = tryParseJson<Voice>(&TgTypeParser::parseJsonAndGetVoice, data, "voice");
result->caption = data.get<std::string>("caption", "");
result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities");
+ result->hasMediaSpoiler = data.get<bool>("has_media_spoiler", false);
result->contact = tryParseJson<Contact>(&TgTypeParser::parseJsonAndGetContact, data, "contact");
result->dice = tryParseJson<Dice>(&TgTypeParser::parseJsonAndGetDice, data, "dice");
result->game = tryParseJson<Game>(&TgTypeParser::parseJsonAndGetGame, data, "game");
@@ -274,11 +279,15 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt
result->invoice = tryParseJson<Invoice>(&TgTypeParser::parseJsonAndGetInvoice, data, "invoice");
result->successfulPayment = tryParseJson<SuccessfulPayment>(&TgTypeParser::parseJsonAndGetSuccessfulPayment, data, "successful_payment");
result->connectedWebsite = data.get<std::string>("connected_website", "");
+ result->writeAccessAllowed = tryParseJson<WriteAccessAllowed>(&TgTypeParser::parseJsonAndGetWriteAccessAllowed, data, "write_access_allowed");
result->passportData = tryParseJson<PassportData>(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data");
result->proximityAlertTriggered = tryParseJson<ProximityAlertTriggered>(&TgTypeParser::parseJsonAndGetProximityAlertTriggered, data, "proximity_alert_triggered");
result->forumTopicCreated = tryParseJson<ForumTopicCreated>(&TgTypeParser::parseJsonAndGetForumTopicCreated, data, "forum_topic_created");
+ result->forumTopicEdited = tryParseJson<ForumTopicEdited>(&TgTypeParser::parseJsonAndGetForumTopicEdited, data, "forum_topic_edited");
result->forumTopicClosed = tryParseJson<ForumTopicClosed>(&TgTypeParser::parseJsonAndGetForumTopicClosed, data, "forum_topic_closed");
result->forumTopicReopened = tryParseJson<ForumTopicReopened>(&TgTypeParser::parseJsonAndGetForumTopicReopened, data, "forum_topic_reopened");
+ result->generalForumTopicHidden = tryParseJson<GeneralForumTopicHidden>(&TgTypeParser::parseJsonAndGetGeneralForumTopicHidden, data, "general_forum_topic_hidden");
+ result->generalForumTopicUnhidden = tryParseJson<GeneralForumTopicUnhidden>(&TgTypeParser::parseJsonAndGetGeneralForumTopicUnhidden, data, "general_forum_topic_unhidden");
result->videoChatScheduled = tryParseJson<VideoChatScheduled>(&TgTypeParser::parseJsonAndGetVideoChatScheduled, data, "video_chat_scheduled");
result->videoChatStarted = tryParseJson<VideoChatStarted>(&TgTypeParser::parseJsonAndGetVideoChatStarted, data, "video_chat_started");
result->videoChatEnded = tryParseJson<VideoChatEnded>(&TgTypeParser::parseJsonAndGetVideoChatEnded, data, "video_chat_ended");
@@ -326,6 +335,7 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "voice", parseVoice(object->voice));
appendToJson(result, "caption", object->caption);
appendToJson(result, "caption_entities", parseArray(&TgTypeParser::parseMessageEntity, object->captionEntities));
+ appendToJson(result, "has_media_spoiler", object->hasMediaSpoiler);
appendToJson(result, "contact", parseContact(object->contact));
appendToJson(result, "dice", parseDice(object->dice));
appendToJson(result, "game", parseGame(object->game));
@@ -347,11 +357,15 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "invoice", parseInvoice(object->invoice));
appendToJson(result, "successful_payment", parseSuccessfulPayment(object->successfulPayment));
appendToJson(result, "connected_website", object->connectedWebsite);
+ appendToJson(result, "write_access_allowed", parseWriteAccessAllowed(object->writeAccessAllowed));
appendToJson(result, "passport_data", parsePassportData(object->passportData));
appendToJson(result, "proximity_alert_triggered", parseProximityAlertTriggered(object->proximityAlertTriggered));
appendToJson(result, "forum_topic_created", parseForumTopicCreated(object->forumTopicCreated));
+ appendToJson(result, "forum_topic_edited", parseForumTopicEdited(object->forumTopicEdited));
appendToJson(result, "forum_topic_closed", parseForumTopicClosed(object->forumTopicClosed));
appendToJson(result, "forum_topic_reopened", parseForumTopicReopened(object->forumTopicReopened));
+ appendToJson(result, "general_forum_topic_hidden", parseGeneralForumTopicHidden(object->generalForumTopicHidden));
+ appendToJson(result, "general_forum_topic_unhidden", parseGeneralForumTopicUnhidden(object->generalForumTopicUnhidden));
appendToJson(result, "video_chat_scheduled", parseVideoChatScheduled(object->videoChatScheduled));
appendToJson(result, "video_chat_started", parseVideoChatStarted(object->videoChatStarted));
appendToJson(result, "video_chat_ended", parseVideoChatEnded(object->videoChatEnded));
@@ -981,6 +995,26 @@ std::string TgTypeParser::parseForumTopicClosed(const ForumTopicClosed::Ptr& obj
return result;
}
+ForumTopicEdited::Ptr TgTypeParser::parseJsonAndGetForumTopicEdited(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ForumTopicEdited>());
+ result->name = data.get<std::string>("name", "");
+ result->iconCustomEmojiId = data.get<std::string>("icon_custom_emoji_id", "");
+ return result;
+}
+
+std::string TgTypeParser::parseForumTopicEdited(const ForumTopicEdited::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "name", object->name);
+ appendToJson(result, "icon_custom_emoji_id", object->iconCustomEmojiId);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
ForumTopicReopened::Ptr TgTypeParser::parseJsonAndGetForumTopicReopened(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<ForumTopicReopened>());
return result;
@@ -997,6 +1031,54 @@ std::string TgTypeParser::parseForumTopicReopened(const ForumTopicReopened::Ptr&
return result;
}
+GeneralForumTopicHidden::Ptr TgTypeParser::parseJsonAndGetGeneralForumTopicHidden(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<GeneralForumTopicHidden>());
+ return result;
+}
+
+std::string TgTypeParser::parseGeneralForumTopicHidden(const GeneralForumTopicHidden::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ //removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+GeneralForumTopicUnhidden::Ptr TgTypeParser::parseJsonAndGetGeneralForumTopicUnhidden(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<GeneralForumTopicUnhidden>());
+ return result;
+}
+
+std::string TgTypeParser::parseGeneralForumTopicUnhidden(const GeneralForumTopicUnhidden::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ //removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+WriteAccessAllowed::Ptr TgTypeParser::parseJsonAndGetWriteAccessAllowed(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<WriteAccessAllowed>());
+ return result;
+}
+
+std::string TgTypeParser::parseWriteAccessAllowed(const WriteAccessAllowed::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ //removeLastComma(result);
+ result += '}';
+ return result;
+}
+
VideoChatScheduled::Ptr TgTypeParser::parseJsonAndGetVideoChatScheduled(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<VideoChatScheduled>());
result->startDate = data.get<std::int32_t>("start_date", 0);
@@ -1133,6 +1215,7 @@ ReplyKeyboardMarkup::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardMarkup(const
for (const auto& item : data.find("keyboard")->second) {
result->keyboard.push_back(parseJsonAndGetArray<KeyboardButton>(&TgTypeParser::parseJsonAndGetKeyboardButton, item.second));
}
+ result->isPersistent = data.get<bool>("is_persistent", false);
result->resizeKeyboard = data.get<bool>("resize_keyboard", false);
result->oneTimeKeyboard = data.get<bool>("one_time_keyboard", false);
result->inputFieldPlaceholder = data.get<std::string>("input_field_placeholder", "");
@@ -1159,6 +1242,7 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt
if (!object->keyboard.empty())
removeLastComma(result);
result += "],";
+ appendToJson(result, "is_persistent", object->isPersistent);
appendToJson(result, "resize_keyboard", object->resizeKeyboard);
appendToJson(result, "one_time_keyboard", object->oneTimeKeyboard);
appendToJson(result, "input_field_placeholder", object->inputFieldPlaceholder);
@@ -2186,6 +2270,7 @@ std::string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const {
InputMediaPhoto::Ptr TgTypeParser::parseJsonAndGetInputMediaPhoto(const boost::property_tree::ptree& data) const {
// NOTE: This function will be called by parseJsonAndGetInputMedia().
auto result(std::make_shared<InputMediaPhoto>());
+ result->hasSpoiler = data.get<bool>("has_spoiler", false);
return result;
}
@@ -2196,6 +2281,7 @@ std::string TgTypeParser::parseInputMediaPhoto(const InputMediaPhoto::Ptr& objec
// This function will be called by parseInputMedia(), so I don't add
// curly brackets to the result std::string.
std::string result;
+ appendToJson(result, "has_spoiler", object->hasSpoiler);
// The last comma will be erased by parseInputMedia().
return result;
}
@@ -2208,6 +2294,7 @@ InputMediaVideo::Ptr TgTypeParser::parseJsonAndGetInputMediaVideo(const boost::p
result->height = data.get<std::int32_t>("height", 0);
result->duration = data.get<std::int32_t>("duration", 0);
result->supportsStreaming = data.get<bool>("supports_streaming", false);
+ result->hasSpoiler = data.get<bool>("has_spoiler", false);
return result;
}
@@ -2223,6 +2310,7 @@ std::string TgTypeParser::parseInputMediaVideo(const InputMediaVideo::Ptr& objec
appendToJson(result, "height", object->height);
appendToJson(result, "duration", object->duration);
appendToJson(result, "supports_streaming", object->supportsStreaming);
+ appendToJson(result, "has_spoiler", object->hasSpoiler);
// The last comma will be erased by parseInputMedia().
return result;
}
@@ -2234,6 +2322,7 @@ InputMediaAnimation::Ptr TgTypeParser::parseJsonAndGetInputMediaAnimation(const
result->width = data.get<std::int32_t>("width", 0);
result->height = data.get<std::int32_t>("height", 0);
result->duration = data.get<std::int32_t>("duration", 0);
+ result->hasSpoiler = data.get<bool>("has_spoiler", false);
return result;
}
@@ -2248,6 +2337,7 @@ std::string TgTypeParser::parseInputMediaAnimation(const InputMediaAnimation::Pt
appendToJson(result, "width", object->width);
appendToJson(result, "height", object->height);
appendToJson(result, "duration", object->duration);
+ appendToJson(result, "has_spoiler", object->hasSpoiler);
// The last comma will be erased by parseInputMedia().
return result;
}