diff options
author | nitanmarcel <nitan.marcel@protonmail.com> | 2019-11-20 21:04:11 +0200 |
---|---|---|
committer | nitanmarcel <nitan.marcel@protonmail.com> | 2019-11-20 21:04:11 +0200 |
commit | 084a6492103eff0d021562694c6869fdcce58261 (patch) | |
tree | bc02cd95b2541f969276e45adcfcb073299138b6 /src | |
parent | ae758af7e7e4257f33040fea82529aca4c92fe05 (diff) |
API 4.4
Diffstat (limited to 'src')
-rw-r--r-- | src/Api.cpp | 29 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 46 |
2 files changed, 54 insertions, 21 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index ae6ecee..ee8f36f 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -983,28 +983,17 @@ bool Api::unbanChatMember(int64_t chatId, int32_t userId) const { args.emplace_back("user_id", userId); return sendRequest("unbanChatMember", args).get<bool>("", false); } - -bool Api::restrictChatMember(int64_t chatId, int32_t userId, uint64_t untilDate, bool canSendMessages, - bool canSendMediaMessages, bool canSendOtherMessages, bool canAddWebPagePreviews) const { +bool Api::restrictChatMember(int64_t chatId, int32_t userId, TgBot::ChatPermissions::Ptr permissions, + uint64_t untilDate) const { vector<HttpReqArg> args; - args.reserve(7); + args.reserve(4); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); + args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); if (untilDate) { args.emplace_back("until_date", untilDate); } - if (canSendMessages) { - args.emplace_back("can_send_messages", canSendMessages); - } - if (canSendMediaMessages) { - args.emplace_back("can_send_media_messages", canSendMediaMessages); - } - if (canSendOtherMessages) { - args.emplace_back("can_send_other_messages", canSendOtherMessages); - } - if (canAddWebPagePreviews) { - args.emplace_back("can_add_web_page_previews", canAddWebPagePreviews); - } + return sendRequest("restrictChatMember", args).get<bool>("", false); } @@ -1038,6 +1027,14 @@ bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo, return sendRequest("promoteChatMember", args).get<bool>("", false); } +bool Api::setChatPermissions(int64_t chatId, ChatPermissions::Ptr permissions) const{ + vector<HttpReqArg> args; + args.reserve(2); + args.emplace_back("chat_id", chatId); + args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); + return sendRequest("setChatPermissions", args).get<bool>("", false); +} + string Api::exportChatInviteLink(int64_t chatId) const { vector<HttpReqArg> args; args.reserve(1); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 5206286..0a098f0 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -318,6 +318,7 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const ptree& data) const { result->fileId = data.get<string>("file_id"); result->width = data.get<int32_t>("width"); result->height = data.get<int32_t>("height"); + result->isAnimated = data.get<bool>("is_animated", false); result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); result->emoji = data.get("emoji", ""); result->setName = data.get("set_name", ""); @@ -335,6 +336,7 @@ string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { appendToJson(result, "file_id", object->fileId); appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); + appendToJson(result, "is_animated", object->isAnimated); appendToJson(result, "thumb", parsePhotoSize(object->thumb)); appendToJson(result, "emoji", object->emoji); appendToJson(result, "file_size", object->fileSize); @@ -348,6 +350,7 @@ StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const ptree& data) const result->name = data.get("name", ""); result->title = data.get("title", ""); result->containsMasks = data.get<bool>("contains_masks", false); + result->isAnimated = data.get<bool>("is_animated", false); result->stickers = parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "stickers"); return result; } @@ -360,6 +363,7 @@ string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const { result += '{'; appendToJson(result, "name", object->name); appendToJson(result, "title", object->title); + appendToJson(result, "is_animated", object->isAnimated); appendToJson(result, "contains_masks", object->containsMasks); appendToJson(result, "stickers", parseArray(&TgTypeParser::parseSticker, object->stickers)); removeLastComma(result); @@ -415,11 +419,11 @@ string TgTypeParser::parsePoll(const Poll::Ptr& object) const { return result; } - PollOption::Ptr TgTypeParser::parseJsonAndGetPollOption(const ptree& data) const { - auto result(make_shared<PollOption>()); - result->text = data.get("text", ""); - result->voter_count = data.get("voter_count", 0); - return result; +PollOption::Ptr TgTypeParser::parseJsonAndGetPollOption(const ptree& data) const { + auto result(make_shared<PollOption>()); + result->text = data.get("text", ""); + result->voter_count = data.get("voter_count", 0); + return result; } string TgTypeParser::parsePollOption(const PollOption::Ptr& object) const { @@ -435,6 +439,38 @@ string TgTypeParser::parsePollOption(const PollOption::Ptr& object) const { return result; } +ChatPermissions::Ptr TgTypeParser::parseJsonAndGetChatPermissions(const ptree& data) const { + auto result(make_shared<ChatPermissions>()); + result->canSendMessages = data.get<bool>("can_send_messages"); + result->canSendMediaMessages = data.get<bool>("can_send_media_messages"); + result->canSendPolls = data.get<bool>("can_send_polls"); + result->canSendOtherMessages = data.get<bool>("can_send_other_messages"); + result->canAddWebPagePreviews = data.get<bool>("can_add_web_page_previews"); + result->canChangeInfo = data.get<bool>("can_change_info"); + result->canInviteUsers = data.get<bool>("can_invite_users"); + result->canPinMessages = data.get<bool>("can_pin_messages"); + return result; +} + +string TgTypeParser::parseChatPermissions(const ChatPermissions::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + appendToJson(result, "can_send_messages", object->canSendMessages); + appendToJson(result, "can_send_media_messages", object->canSendMediaMessages); + appendToJson(result, "can_send_polls", object->canSendPolls); + appendToJson(result, "can_send_other_messages", object->canSendOtherMessages); + appendToJson(result, "can_add_web_page_previews", object->canAddWebPagePreviews); + appendToJson(result, "can_change_info", object->canChangeInfo); + appendToJson(result, "can_invite_users", object->canInviteUsers); + appendToJson(result, "can_pin_messages", object->canPinMessages); + removeLastComma(result); + result += '}'; + return result; +} + Video::Ptr TgTypeParser::parseJsonAndGetVideo(const ptree& data) const { auto result(make_shared<Video>()); result->fileId = data.get<string>("file_id"); |