summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJellyBrick <shlee1503@naver.com>2018-05-27 16:35:52 +0900
committerJellyBrick <shlee1503@naver.com>2018-05-27 16:35:52 +0900
commit1deb50e9db6e1b668af8c993b449d59f001c8977 (patch)
treeb341aff55cbccf3d695dc967b12b1dc17b8271f6 /src
parentfbdbc4d5d3cd61086500d2406f3345da55627a56 (diff)
Bot API 3.1 update
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp116
-rw-r--r--src/TgTypeParser.cpp37
2 files changed, 142 insertions, 11 deletions
diff --git a/src/Api.cpp b/src/Api.cpp
index 5e39a9a..568ca71 100644
--- a/src/Api.cpp
+++ b/src/Api.cpp
@@ -609,7 +609,7 @@ vector<Update::Ptr> Api::getUpdates(int32_t offset, int32_t limit, int32_t timeo
if (timeout) {
args.push_back(HttpReqArg("timeout", timeout));
}
- if (allowedUpdates!=nullptr) {
+ if (allowedUpdates != nullptr) {
string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<std::string>(
[](const std::string &s)->std::string {
return s;
@@ -625,10 +625,10 @@ void Api::setWebhook(const string& url, const InputFile::Ptr certificate, int32_
args.push_back(HttpReqArg("url", url));
if (certificate != nullptr)
args.push_back(HttpReqArg("certificate", certificate->data, true, certificate->mimeType, certificate->fileName));
- if (maxConnection!=40)
+ if (maxConnection != 40)
args.push_back(HttpReqArg("max_connections", maxConnection));
- if (allowedUpdates!=nullptr)
+ if (allowedUpdates != nullptr)
{
string allowedUpdatesJson = TgTypeParser::getInstance().parseArray<std::string>(
[](const std::string &s)->std::string {
@@ -653,7 +653,7 @@ WebhookInfo::Ptr Api::getWebhookInfo() const
if (!p.get_child_optional("url"))
return nullptr;
- if (p.get<string>("url","")!=string(""))
+ if (p.get<string>("url","") != string(""))
{
return TgTypeParser::getInstance().parseJsonAndGetWebhookInfo(p);
}
@@ -664,7 +664,7 @@ WebhookInfo::Ptr Api::getWebhookInfo() const
}
bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector<InlineQueryResult::Ptr>& results,
- int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const {
+ int32_t cacheTime, bool isPersonal, const std::string& nextOffset, const std::string& switchPmText, const std::string& switchPmParameter) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("inline_query_id", inlineQueryId));
string resultsJson = TgTypeParser::getInstance().parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results);
@@ -687,10 +687,13 @@ bool Api::answerInlineQuery(const std::string& inlineQueryId, const std::vector<
return sendRequest("answerInlineQuery", args).get<bool>("", false);
}
-bool Api::kickChatMember(int64_t chatId, int32_t userId) const {
+bool Api::kickChatMember(int64_t chatId, int32_t userId, uint64_t untilDate) const {
vector<HttpReqArg> args;
args.push_back(HttpReqArg("chat_id", chatId));
args.push_back(HttpReqArg("user_id", userId));
+ if (untilDate) {
+ args.push_back(HttpReqArg("until_date", untilDate));
+ }
return sendRequest("kickChatMember", args).get<bool>("", false);
}
@@ -701,6 +704,107 @@ bool Api::unbanChatMember(int64_t chatId, int32_t userId) const {
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 {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ args.push_back(HttpReqArg("user_id", userId));
+ if (untilDate) {
+ args.push_back(HttpReqArg("until_date", untilDate));
+ }
+ if (canSendMessages) {
+ args.push_back(HttpReqArg("can_send_messages", canSendMessages));
+ }
+ if (canSendMediaMessages) {
+ args.push_back(HttpReqArg("can_send_media_messages", canSendMediaMessages));
+ }
+ if (canSendOtherMessages) {
+ args.push_back(HttpReqArg("can_send_other_messages", canSendOtherMessages));
+ }
+ if (canAddWebPagePreviews) {
+ args.push_back(HttpReqArg("can_add_web_page_previews", canAddWebPagePreviews));
+ }
+ return sendRequest("restrictChatMember", args).get<bool>("", false);
+}
+
+bool Api::promoteChatMember(int64_t chatId, int32_t userId, bool canChangeInfo, bool canPostMessages,
+ bool canEditMessages, bool canDeleteMessages, bool canInviteUsers, bool canPinMessages, bool canPromoteMembers) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ args.push_back(HttpReqArg("user_id", userId));
+ if (canChangeInfo) {
+ args.push_back(HttpReqArg("can_change_info", canChangeInfo));
+ }
+ if (canPostMessages) {
+ args.push_back(HttpReqArg("can_post_messages", canPostMessages));
+ }
+ if (canEditMessages) {
+ args.push_back(HttpReqArg("can_edit_messages", canEditMessages));
+ }
+ if (canDeleteMessages) {
+ args.push_back(HttpReqArg("can_delete_messages", canDeleteMessages));
+ }
+ if (canInviteUsers) {
+ args.push_back(HttpReqArg("can_invite_users", canInviteUsers));
+ }
+ if (canPinMessages) {
+ args.push_back(HttpReqArg("can_pin_messages", canPinMessages));
+ }
+ if (canPromoteMembers) {
+ args.push_back(HttpReqArg("can_promote_members", canPromoteMembers));
+ }
+ return sendRequest("promoteChatMember", args).get<bool>("", false);
+}
+
+std::string Api::exportChatInviteLink(int64_t chatId) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ return sendRequest("exportChatInviteLink", args).get("", "");
+}
+
+bool Api::setChatPhoto(int64_t chatId, InputFile::Ptr photo) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ args.push_back(HttpReqArg("photo", photo->data, true, photo->mimeType, photo->fileName));
+ return sendRequest("setChatPhoto", args).get<bool>("", false);
+}
+
+bool Api::deleteChatPhoto(int64_t chatId) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ return sendRequest("deleteChatPhoto", args).get<bool>("", false);
+}
+
+bool Api::setChatTitle(int64_t chatId, std::string title) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ args.push_back(HttpReqArg("title", title));
+ return sendRequest("setChatTitle", args).get<bool>("", false);
+}
+
+bool Api::setChatDescription(int64_t chatId, std::string description) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ args.push_back(HttpReqArg("description", description));
+ return sendRequest("setChatDescription", args).get<bool>("", false);
+}
+
+bool Api::pinChatMessage(int64_t chatId, int32_t messageId, bool disableNotification) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ args.push_back(HttpReqArg("description", description));
+ if (disableNotification) {
+ args.push_back(HttpReqArg("disable_notification", disableNotification));
+ }
+ return sendRequest("pinChatMessage", args).get<bool>("", false);
+}
+
+bool Api::unpinChatMessage(int64_t chatId) const {
+ vector<HttpReqArg> args;
+ args.push_back(HttpReqArg("chat_id", chatId));
+ return sendRequest("unpinChatMessage", args).get<bool>("", false);
+}
+
void Api::deleteMessage(int64_t chatId, int32_t messageId) const {
sendRequest("deleteMessage", { HttpReqArg("chat_id", chatId), HttpReqArg("message_id", messageId) });
}
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp
index c442600..9a48de5 100644
--- a/src/TgTypeParser.cpp
+++ b/src/TgTypeParser.cpp
@@ -50,6 +50,12 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const {
result->firstName = data.get<string>("first_name", "");
result->lastName = data.get("last_name", "");
result->allMembersAreAdministrators = data.get<bool>("all_members_are_administrators", false);
+ result->photo = tryParseJson<ChatPhoto>(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo");
+ result->description = data.get("description", "");
+ result->inviteLink = data.get("invite_link", "");
+ result->pinnedMessage = tryParseJson<ChatPhoto>(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message");
+ result->stickerSetName = data.get("sticker_set_name", "");
+ result->canSetStickerSet = data.get<bool>("can_set_sticker_set", false);
return result;
}
@@ -107,10 +113,10 @@ string TgTypeParser::parseUser(const User::Ptr& object) const {
MessageEntity::Ptr TgTypeParser::parseJsonAndGetEntity(const ptree& data) const{
auto result(make_shared<MessageEntity>());
- result->type=data.get<string>("type");
- result->offset=data.get<int32_t>("offset");
- result->length=data.get<int32_t>("length");
- result->url=data.get<string>("url", "");
+ result->type = data.get<string>("type");
+ result->offset = data.get<int32_t>("offset");
+ result->length = data.get<int32_t>("length");
+ result->url = data.get<string>("url", "");
result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user");
return result;
}
@@ -571,7 +577,21 @@ std::string TgTypeParser::parseForceReply(const ForceReply::Ptr& object) const {
ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const {
auto result(make_shared<ChatMember>());
result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user");
- result->status = data.get<string>("status");
+ result->status = data.get("status", "");
+ result->untilDate = data.get<uint64_t>("until_date", 0);
+ result->canBeEdited = data.get<bool>("can_be_edited", false);
+ result->canChangeInfo = data.get<bool>("can_change_info", 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->canInviteUsers = data.get<bool>("can_invite_users", false);
+ result->canRestrictMembers = data.get<bool>("can_restrict_members", false);
+ result->canPinMessages = data.get<bool>("can_pin_messages", false);
+ result->canPromoteMembers = data.get<bool>("can_promote_messages", false);
+ result->canSendMessages = data.get<bool>("can_send_messages", false);
+ result->canSendMediaMessages = data.get<bool>("can_send_media_messages", false);
+ result->canSendOtherMessages = data.get<bool>("can_send_other_messages", false);
+ result->canAddWebPagePreviews = data.get<bool>("can_add_web_page_previews", false);
return result;
}
@@ -588,6 +608,13 @@ std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const {
return result;
}
+ChatPhoto::Ptr TgTypeParser::parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const {
+ auto result(make_shared<ChatPhoto>());
+ result->smallFileId = data.get("small_file_id", "");
+ result->bigFileId = data.get("big_file_id", "");
+ return result;
+}
+
ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const {
auto result(make_shared<ResponseParameters>());
result->migrateToChatId = data.get<int32_t>("migrate_to_chat_id", 0);