summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-09-04 13:45:21 +0200
committerllnulldisk <48621230+llnulldisk@users.noreply.github.com>2022-09-04 13:45:21 +0200
commitbfa7b0c67a3df3848eb7f9bccdf7c158ce4c9d07 (patch)
treee8976cfee6f7daf34ab511266fa38b649aec0dcc /src
parentc17ab6fb6574bdea6fc9011be0651dc74aa6a53e (diff)
Update to API 5.1
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp108
-rw-r--r--src/TgTypeParser.cpp140
2 files changed, 224 insertions, 24 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index 86d573b..a67aafb 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -852,15 +852,11 @@ Message::Ptr Api::sendDice(std::int64_t chatId,
if (!emoji.empty()) {
args.emplace_back("emoji", emoji);
}
- if (disableNotification) {
- args.emplace_back("disable_notification", disableNotification);
- }
+ args.emplace_back("disable_notification", disableNotification);
if (replyToMessageId != 0) {
args.emplace_back("reply_to_message_id", replyToMessageId);
}
- if (allowSendingWithoutReply) {
- args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply);
- }
+ args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply);
if (replyMarkup) {
args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup));
}
@@ -907,14 +903,18 @@ string Api::downloadFile(const string& filePath, const std::vector<HttpReqArg>&
return serverResponse;
}
-bool Api::kickChatMember(std::int64_t chatId, std::int64_t userId, std::uint64_t untilDate) const {
+bool Api::kickChatMember(std::int64_t chatId,
+ std::int64_t userId,
+ std::uint64_t untilDate,
+ bool revokeMessages) const {
vector<HttpReqArg> args;
- args.reserve(3);
+ args.reserve(4);
+
args.emplace_back("chat_id", chatId);
args.emplace_back("user_id", userId);
- if (untilDate) {
- args.emplace_back("until_date", untilDate);
- }
+ args.emplace_back("until_date", untilDate);
+ args.emplace_back("revoke_messages", revokeMessages);
+
return sendRequest("kickChatMember", args).get<bool>("", false);
}
@@ -943,20 +943,29 @@ bool Api::restrictChatMember(std::int64_t chatId, std::int64_t userId, TgBot::Ch
return sendRequest("restrictChatMember", args).get<bool>("", false);
}
-bool Api::promoteChatMember(std::int64_t chatId, std::int64_t userId, bool isAnonymous,
- bool canChangeInfo, bool canPostMessages, bool canEditMessages,
- bool canDeleteMessages, bool canInviteUsers, bool canRestrictMembers,
- bool canPinMessages, bool canPromoteMembers) const {
+bool Api::promoteChatMember(std::int64_t chatId,
+ std::int64_t userId,
+ bool isAnonymous,
+ bool canManageChat,
+ bool canPostMessages,
+ bool canEditMessages,
+ bool canDeleteMessages,
+ bool canManageVoiceChats,
+ bool canRestrictMembers,
+ bool canPromoteMembers,
+ bool canChangeInfo,
+ bool canInviteUsers,
+ bool canPinMessages) const {
vector<HttpReqArg> args;
- args.reserve(11);
+ args.reserve(13);
args.emplace_back("chat_id", chatId);
args.emplace_back("user_id", userId);
if (isAnonymous) {
args.emplace_back("is_anonymous", isAnonymous);
}
- if (canChangeInfo) {
- args.emplace_back("can_change_info", canChangeInfo);
+ if (canManageChat) {
+ args.emplace_back("can_manage_chat", canManageChat);
}
if (canPostMessages) {
args.emplace_back("can_post_messages", canPostMessages);
@@ -967,18 +976,24 @@ bool Api::promoteChatMember(std::int64_t chatId, std::int64_t userId, bool isAno
if (canDeleteMessages) {
args.emplace_back("can_delete_messages", canDeleteMessages);
}
- if (canInviteUsers) {
- args.emplace_back("can_invite_users", canInviteUsers);
+ if (canManageVoiceChats) {
+ args.emplace_back("can_manage_voice_chats", canManageVoiceChats);
}
if (canRestrictMembers) {
args.emplace_back("can_restrict_members", canRestrictMembers);
}
- if (canPinMessages) {
- args.emplace_back("can_pin_messages", canPinMessages);
- }
if (canPromoteMembers) {
args.emplace_back("can_promote_members", canPromoteMembers);
}
+ if (canChangeInfo) {
+ args.emplace_back("can_change_info", canChangeInfo);
+ }
+ if (canInviteUsers) {
+ args.emplace_back("can_invite_users", canInviteUsers);
+ }
+ if (canPinMessages) {
+ args.emplace_back("can_pin_messages", canPinMessages);
+ }
return sendRequest("promoteChatMember", args).get<bool>("", false);
}
@@ -1009,6 +1024,53 @@ string Api::exportChatInviteLink(std::int64_t chatId) const {
return sendRequest("exportChatInviteLink", args).get("", "");
}
+ChatInviteLink::Ptr Api::createChatInviteLink(std::int64_t chatId,
+ std::int32_t expireDate,
+ std::int32_t memberLimit) const {
+ vector<HttpReqArg> args;
+ args.reserve(3);
+
+ args.emplace_back("chat_id", chatId);
+ if (expireDate != 0) {
+ args.emplace_back("expire_date", expireDate);
+ }
+ if (memberLimit != 0) {
+ args.emplace_back("member_limit", memberLimit);
+ }
+
+ return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("createChatInviteLink", args));
+}
+
+ChatInviteLink::Ptr Api::editChatInviteLink(std::int64_t chatId,
+ std::string inviteLink,
+ std::int32_t expireDate,
+ std::int32_t memberLimit) const {
+ vector<HttpReqArg> args;
+ args.reserve(4);
+
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("invite_link", inviteLink);
+ if (expireDate != 0) {
+ args.emplace_back("expire_date", expireDate);
+ }
+ if (memberLimit != 0) {
+ args.emplace_back("member_limit", memberLimit);
+ }
+
+ return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("editChatInviteLink", args));
+}
+
+ChatInviteLink::Ptr Api::revokeChatInviteLink(std::int64_t chatId,
+ std::string inviteLink) const {
+ vector<HttpReqArg> args;
+ args.reserve(2);
+
+ args.emplace_back("chat_id", chatId);
+ args.emplace_back("invite_link", inviteLink);
+
+ return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("revokeChatInviteLink", args));
+}
+
bool Api::setChatPhoto(std::int64_t chatId, const InputFile::Ptr photo) const {
vector<HttpReqArg> args;
args.reserve(2);
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index 60a2c54..0491360 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -178,6 +178,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt
result->groupChatCreated = data.get<bool>("group_chat_created", false);
result->supergroupChatCreated = data.get<bool>("supergroup_chat_created", false);
result->channelChatCreated = data.get<bool>("channel_chat_created", false);
+ result->messageAutoDeleteTimerChanged = tryParseJson<MessageAutoDeleteTimerChanged>(&TgTypeParser::parseJsonAndGetMessageAutoDeleteTimerChanged, data, "message_auto_delete_timer_changed");
result->migrateToChatId = data.get<std::int64_t>("migrate_to_chat_id", 0);
result->migrateFromChatId = data.get<std::int64_t>("migrate_from_chat_id", 0);
result->pinnedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message");
@@ -186,7 +187,10 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt
result->connectedWebsite = data.get<std::string>("connected_website", "");
result->passportData = tryParseJson<PassportData>(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data");
result->passportData = tryParseJson<PassportData>(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data");
- result->proximityAlertTriggered = tryParseJson<ProximityAlertTriggered >(&TgTypeParser::parseJsonAndGetProximityAlertTriggered, data, "proximity_alert_triggered");
+ result->proximityAlertTriggered = tryParseJson<ProximityAlertTriggered>(&TgTypeParser::parseJsonAndGetProximityAlertTriggered, data, "proximity_alert_triggered");
+ result->voiceChatStarted = tryParseJson<VoiceChatStarted>(&TgTypeParser::parseJsonAndGetVoiceChatStarted, data, "voice_chat_started");
+ result->voiceChatEnded = tryParseJson<VoiceChatEnded>(&TgTypeParser::parseJsonAndGetVoiceChatEnded, data, "voice_chat_ended");
+ result->voiceChatParticipantsInvited = tryParseJson<VoiceChatParticipantsInvited>(&TgTypeParser::parseJsonAndGetVoiceChatParticipantsInvited, data, "voice_chat_participants_invited");
result->replyMarkup = tryParseJson<InlineKeyboardMarkup>(&TgTypeParser::parseJsonAndGetInlineKeyboardMarkup, data, "reply_markup");
result->automaticForward = data.get<bool>("is_automatic_forward", false);
return result;
@@ -240,6 +244,7 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "group_chat_created", object->groupChatCreated);
appendToJson(result, "supergroup_chat_created", object->supergroupChatCreated);
appendToJson(result, "channel_chat_created", object->channelChatCreated);
+ appendToJson(result, "message_auto_delete_timer_changed", parseMessageAutoDeleteTimerChanged(object->messageAutoDeleteTimerChanged));
appendToJson(result, "migrate_to_chat_id", object->migrateToChatId);
appendToJson(result, "migrate_from_chat_id", object->migrateFromChatId);
appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage));
@@ -248,6 +253,9 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const {
appendToJson(result, "connected_website", object->connectedWebsite);
appendToJson(result, "passport_data", parsePassportData(object->passportData));
appendToJson(result, "proximity_alert_triggered", parseProximityAlertTriggered(object->proximityAlertTriggered));
+ appendToJson(result, "voice_chat_started", parseVoiceChatStarted(object->voiceChatStarted));
+ appendToJson(result, "voice_chat_ended", parseVoiceChatEnded(object->voiceChatEnded));
+ appendToJson(result, "voice_chat_participants_invited", parseVoiceChatParticipantsInvited(object->voiceChatParticipantsInvited));
appendToJson(result, "reply_markup", parseInlineKeyboardMarkup(object->replyMarkup));
appendToJson(result, "is_automatic_forward", object->automaticForward);
removeLastComma(result);
@@ -887,6 +895,72 @@ std::string TgTypeParser::parseProximityAlertTriggered(const ProximityAlertTrigg
return result;
}
+MessageAutoDeleteTimerChanged::Ptr TgTypeParser::parseJsonAndGetMessageAutoDeleteTimerChanged(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<MessageAutoDeleteTimerChanged>());
+ result->messageAutoDeleteTime = data.get<std::int32_t>("message_auto_delete_time", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseMessageAutoDeleteTimerChanged(const MessageAutoDeleteTimerChanged::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "message_auto_delete_time", object->messageAutoDeleteTime);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+VoiceChatStarted::Ptr TgTypeParser::parseJsonAndGetVoiceChatStarted(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<VoiceChatStarted>());
+ return result;
+}
+
+std::string TgTypeParser::parseVoiceChatStarted(const VoiceChatStarted::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ return "{}";
+}
+
+VoiceChatEnded::Ptr TgTypeParser::parseJsonAndGetVoiceChatEnded(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<VoiceChatEnded>());
+ result->duration = data.get<std::int32_t>("duration", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseVoiceChatEnded(const VoiceChatEnded::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "duration", object->duration);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
+VoiceChatParticipantsInvited::Ptr TgTypeParser::parseJsonAndGetVoiceChatParticipantsInvited(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<VoiceChatParticipantsInvited>());
+ result->users = parseJsonAndGetArray<User>(&TgTypeParser::parseJsonAndGetUser, data, "users");
+ return result;
+}
+
+std::string TgTypeParser::parseVoiceChatParticipantsInvited(const VoiceChatParticipantsInvited::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "users", parseArray(&TgTypeParser::parseUser, object->users));
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<Update>());
result->updateId = data.get<std::int32_t>("update_id", 0);
@@ -901,6 +975,8 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptre
result->preCheckoutQuery = tryParseJson<PreCheckoutQuery>(&TgTypeParser::parseJsonAndGetPreCheckoutQuery, data, "pre_checkout_query");
result->poll = tryParseJson<Poll>(&TgTypeParser::parseJsonAndGetPoll, data, "poll");
result->pollAnswer = tryParseJson<PollAnswer>(&TgTypeParser::parseJsonAndGetPollAnswer, data, "poll_answer");
+ result->myChatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "my_chat_member");
+ result->chatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "chat_member");
return result;
}
@@ -922,6 +998,8 @@ std::string TgTypeParser::parseUpdate(const Update::Ptr& object) const {
appendToJson(result, "pre_checkout_query", parsePreCheckoutQuery(object->preCheckoutQuery));
appendToJson(result, "poll", parsePoll(object->poll));
appendToJson(result, "poll_answer", parsePollAnswer(object->pollAnswer));
+ appendToJson(result, "my_chat_member", parseChatMemberUpdated(object->myChatMember));
+ appendToJson(result, "chat_member", parseChatMemberUpdated(object->chatMember));
removeLastComma(result);
result += '}';
return result;
@@ -1267,9 +1345,11 @@ ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tr
result->customTitle = data.get<std::string>("custom_title", "");
result->isAnonymous = data.get<bool>("is_anonymous", false);
result->canBeEdited = data.get<bool>("can_be_edited", false);
+ result->canManageChat = data.get<bool>("can_manage_chat", false);
result->canPostMessages = data.get<bool>("can_post_messages", false);
result->canEditMessages = data.get<bool>("can_edit_messages", false);
result->canDeleteMessages = data.get<bool>("can_delete_messages", false);
+ result->canManageVoiceChats = data.get<bool>("can_manage_voice_chats", false);
result->canRestrictMembers = data.get<bool>("can_restrict_members", false);
result->canPromoteMembers = data.get<bool>("can_promote_members", false);
result->canChangeInfo = data.get<bool>("can_change_info", false);
@@ -1296,9 +1376,11 @@ std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const {
appendToJson(result, "custom_title", object->customTitle);
appendToJson(result, "is_anonymous", object->isAnonymous);
appendToJson(result, "can_be_edited", object->canBeEdited);
+ appendToJson(result, "can_manage_chat", object->canManageChat);
appendToJson(result, "can_post_messages", object->canPostMessages);
appendToJson(result, "can_edit_messages", object->canEditMessages);
appendToJson(result, "can_delete_messages", object->canDeleteMessages);
+ appendToJson(result, "can_manage_voice_chats", object->canManageVoiceChats);
appendToJson(result, "can_restrict_members", object->canRestrictMembers);
appendToJson(result, "can_promote_members", object->canPromoteMembers);
appendToJson(result, "can_change_info", object->canChangeInfo);
@@ -1316,6 +1398,34 @@ std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const {
return result;
}
+ChatMemberUpdated::Ptr TgTypeParser::parseJsonAndGetChatMemberUpdated(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ChatMemberUpdated>());
+ result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat");
+ result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from");
+ result->date = data.get<uint32_t>("date", 0);
+ result->oldChatMember = tryParseJson<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, data, "old_chat_member");
+ result->newChatMember = tryParseJson<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, data, "new_chat_member");
+ result->inviteLink = tryParseJson<ChatInviteLink>(&TgTypeParser::parseJsonAndGetChatInviteLink, data, "invite_link");
+ return result;
+}
+
+std::string TgTypeParser::parseChatMemberUpdated(const ChatMemberUpdated::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "chat", parseChat(object->chat));
+ appendToJson(result, "from", parseUser(object->from));
+ appendToJson(result, "date", object->date);
+ appendToJson(result, "old_chat_member", parseChatMember(object->oldChatMember));
+ appendToJson(result, "new_chat_member", parseChatMember(object->newChatMember));
+ appendToJson(result, "invite_link", parseChatInviteLink(object->inviteLink));
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
ChatPhoto::Ptr TgTypeParser::parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<ChatPhoto>());
result->smallFileId = data.get<std::string>("small_file_id", "");
@@ -1340,6 +1450,34 @@ std::string TgTypeParser::parseChatPhoto(const ChatPhoto::Ptr& object) const {
return result;
}
+ChatInviteLink::Ptr TgTypeParser::parseJsonAndGetChatInviteLink(const boost::property_tree::ptree& data) const {
+ auto result(std::make_shared<ChatInviteLink>());
+ result->inviteLink = data.get<std::string>("invite_link", "");
+ result->creator = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "creator");
+ result->isPrimary = data.get<bool>("is_primary", false);
+ result->isRevoked = data.get<bool>("is_revoked", false);
+ result->expireDate = data.get<std::int32_t>("expire_date", 0);
+ result->memberLimit = data.get<std::int32_t>("member_limit", 0);
+ return result;
+}
+
+std::string TgTypeParser::parseChatInviteLink(const ChatInviteLink::Ptr& object) const {
+ if (!object) {
+ return "";
+ }
+ std::string result;
+ result += '{';
+ appendToJson(result, "invite_link", object->inviteLink);
+ appendToJson(result, "creator", parseUser(object->creator));
+ appendToJson(result, "is_primary", object->isPrimary);
+ appendToJson(result, "is_revoked", object->isRevoked);
+ appendToJson(result, "expire_date", object->expireDate);
+ appendToJson(result, "member_limit", object->memberLimit);
+ removeLastComma(result);
+ result += '}';
+ return result;
+}
+
ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const {
auto result(std::make_shared<ResponseParameters>());
result->migrateToChatId = data.get<std::int64_t>("migrate_to_chat_id", 0);