summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--README.md2
-rw-r--r--include/tgbot/Api.h11
-rw-r--r--include/tgbot/TgTypeParser.h4
-rw-r--r--include/tgbot/types/Chat.h7
-rw-r--r--include/tgbot/types/ChatMember.h5
-rw-r--r--include/tgbot/types/ChatPermissions.h86
-rw-r--r--include/tgbot/types/Sticker.h5
-rw-r--r--include/tgbot/types/StickerSet.h5
-rw-r--r--src/Api.cpp29
-rw-r--r--src/TgTypeParser.cpp46
11 files changed, 177 insertions, 25 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e19b925..881ec0f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,7 +34,7 @@ set(SRC_LIST
src/tools/StringTools.cpp
src/types/InlineQueryResult.cpp
src/types/InputFile.cpp
- include/tgbot/types/Poll.h include/tgbot/types/PollOption.h include/tgbot/types/LoginUrl.h)
+ include/tgbot/types/Poll.h include/tgbot/types/PollOption.h include/tgbot/types/LoginUrl.h include/tgbot/types/ChatPermissions.h)
# libs
## threads
diff --git a/README.md b/README.md
index 6f3d3f4..0137f5e 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ Documentation is located [here](http://reo7sp.github.io/tgbot-cpp).
## State
- [x] Bot API 3.0 ~ 3.6
-- [x] Bot API 4.0 ~ 4.3 (Implemented all APIs except 'Telegram Passport')
+- [x] Bot API 4.0 ~ 4.4 (Implemented all APIs except 'Telegram Passport')
## Sample
diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h
index 184f3a1..4ce8dd7 100644
--- a/include/tgbot/Api.h
+++ b/include/tgbot/Api.h
@@ -679,8 +679,7 @@ public:
* @param canAddWebPagePreviews Optional. Pass True, if the user may add web page previews to their messages, implies can_send_media_messages.
* @return True on success
*/
- bool restrictChatMember(int64_t chatId, int32_t userId, uint64_t untilDate = 0, bool canSendMessages = false,
- bool canSendMediaMessages = false, bool canSendOtherMessages = false, bool canAddWebPagePreviews = false) const;
+ bool restrictChatMember(int64_t chatId, int32_t userId, ChatPermissions::Ptr permissions, uint64_t untilDate = 0) const;
/**
* @brief Use this method to promote or demote a user in a supergroup or a channel.
@@ -700,6 +699,14 @@ public:
bool canEditMessages = false, bool canDeleteMessages = false, bool canInviteUsers = false, bool canPinMessages = false, bool canPromoteMembers = false) const;
/**
+ * @brief Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success.
+ * @param chatId Unique identifier for the target chat of the target supergroup.
+ * @param permissions New default chat permissions.
+ * @return True on success
+ */
+ bool setChatPermissions(int64_t chatId, ChatPermissions::Ptr permissions) const;
+
+ /**
* @brief Use this method to generate a new invite link for a chat; any previously generated link is revoked.
* @param chatId Unique identifier for the target chat.
* @return The new invite link as String on success.
diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h
index a2cb660..aa0cd10 100644
--- a/include/tgbot/TgTypeParser.h
+++ b/include/tgbot/TgTypeParser.h
@@ -38,6 +38,7 @@
#include "tgbot/types/StickerSet.h"
#include "tgbot/types/Poll.h"
#include "tgbot/types/PollOption.h"
+#include "tgbot/types/ChatPermissions.h"
#include "tgbot/types/MaskPosition.h"
#include "tgbot/types/Video.h"
#include "tgbot/types/Voice.h"
@@ -153,6 +154,9 @@ namespace TgBot {
PollOption::Ptr parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const;
std::string parsePollOption(const PollOption::Ptr& object) const;
+ ChatPermissions::Ptr parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const;
+ std::string parseChatPermissions(const ChatPermissions::Ptr& object) const;
+
Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const;
std::string parseVideo(const Video::Ptr& object) const;
diff --git a/include/tgbot/types/Chat.h b/include/tgbot/types/Chat.h
index a402ebb..eb38ec7 100644
--- a/include/tgbot/types/Chat.h
+++ b/include/tgbot/types/Chat.h
@@ -27,6 +27,7 @@
#include <memory>
#include "tgbot/types/ChatPhoto.h"
+#include "tgbot/types/ChatPermissions.h"
namespace TgBot {
@@ -111,6 +112,12 @@ public:
std::shared_ptr<Message> pinnedMessage;
/**
+ * @brief Optional. Default chat member permissions, for groups and supergroups.
+ * Returned only in getChat.
+ */
+ ChatPermissions::Ptr permissions;
+
+ /**
* @brief Optional. For supergroups, name of group sticker set.
* Returned only in getChat.
*/
diff --git a/include/tgbot/types/ChatMember.h b/include/tgbot/types/ChatMember.h
index 79fff0e..f5e5acd 100644
--- a/include/tgbot/types/ChatMember.h
+++ b/include/tgbot/types/ChatMember.h
@@ -102,6 +102,11 @@ public:
bool canSendOtherMessages = false;
/**
+ * @brief Optional. Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages.
+ */
+ bool canSendPolls = false;
+
+ /**
* @brief Optional. Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages.
*/
bool canAddWebPagePreviews = false;
diff --git a/include/tgbot/types/ChatPermissions.h b/include/tgbot/types/ChatPermissions.h
new file mode 100644
index 0000000..8db32e6
--- /dev/null
+++ b/include/tgbot/types/ChatPermissions.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2019 Marcel Alexandru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef TGBOT_CPP_CHATPERMISSIONS_H
+#define TGBOT_CPP_CHATPERMISSIONS_H
+
+#include <memory>
+#include <string>
+
+
+namespace TgBot {
+
+ /**
+ * @brief This object describes actions that a non-administrator user is allowed to take in a chat.
+ * @ingroup types
+ */
+
+ class ChatPermissions {
+ public:
+ typedef std::shared_ptr<ChatPermissions> Ptr;
+
+ /**
+ * @brief Optional. True, if the user is allowed to send text messages, contacts, locations and venues.
+ */
+ bool canSendMessages = false;
+
+ /**
+ * @brief Optional. True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages.
+ */
+ bool canSendMediaMessages = false;
+
+ /**
+ * @brief Optional. True, if the user is allowed to send polls, implies can_send_messages.
+ */
+ bool canSendPolls = false;
+
+ /**
+ * @brief Optional. True, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages.
+ */
+ bool canSendOtherMessages = false;
+
+ /**
+ * @brief Optional. True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages.
+ */
+ bool canAddWebPagePreviews = false;
+
+ /**
+ * @brief Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups.
+ */
+ bool canChangeInfo = false;
+
+ /**
+ * @brief Optional. True, if the user is allowed to invite new users to the chat.
+ */
+ bool canInviteUsers = false;
+
+ /**
+ * @brief Optional. True, if the user is allowed to pin messages. Ignored in public supergroups.
+ */
+ bool canPinMessages = false;
+
+
+
+ };
+}
+
+#endif //TGBOT_CPP_CHATPERMISSIONS_H
diff --git a/include/tgbot/types/Sticker.h b/include/tgbot/types/Sticker.h
index 9fd200a..68fc574 100644
--- a/include/tgbot/types/Sticker.h
+++ b/include/tgbot/types/Sticker.h
@@ -57,6 +57,11 @@ public:
int32_t height;
/**
+ * @brief True, if the sticker is animated.
+ */
+ bool isAnimated = false;
+
+ /**
* @brief Optional. Optional. Sticker thumbnail in .webp or .jpg format.
*/
PhotoSize::Ptr thumb;
diff --git a/include/tgbot/types/StickerSet.h b/include/tgbot/types/StickerSet.h
index d08fd4a..deddf74 100644
--- a/include/tgbot/types/StickerSet.h
+++ b/include/tgbot/types/StickerSet.h
@@ -52,6 +52,11 @@ public:
std::string title;
/**
+ * @brief True, if the sticker set contains animated stickers.
+ */
+ bool isAnimated = false;
+
+ /**
* @brief True, if the sticker set contains masks.
*/
bool containsMasks = false;
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");