diff options
author | JellyBrick <shlee1503@naver.com> | 2018-07-27 17:40:44 +0900 |
---|---|---|
committer | JellyBrick <shlee1503@naver.com> | 2018-07-27 17:40:44 +0900 |
commit | 941c97706cb5b81d5a2e44a827e8f6bf76a2c6bd (patch) | |
tree | ba87716d560a674d338c5d43f319b749ff4f46c4 /src | |
parent | 6c2dc4d2eb84e7ba98f73332ccf95ffa5a7adf3f (diff) |
Bot API 4.0 - Part 2
Diffstat (limited to 'src')
-rw-r--r-- | src/Api.cpp | 28 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 54 | ||||
-rw-r--r-- | src/net/HttpParser.cpp | 2 |
3 files changed, 77 insertions, 7 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index 85ba050..bd141d7 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -753,7 +753,7 @@ bool Api::deleteChatStickerSet(int64_t chatId) const { return sendRequest("deleteChatStickerSet", args).get<bool>("", false); } -Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { +Message::Ptr Api::sendVenue(int64_t chatId, float latitude, float longitude, const string& title, const string& address, const string& foursquareId, const string& foursquareType, bool disableNotification, int32_t replyToMessageId, const GenericReply::Ptr replyMarkup) const { vector<HttpReqArg> args; args.reserve(10); args.emplace_back("chat_id", chatId); @@ -962,6 +962,32 @@ Message::Ptr Api::editMessageReplyMarkup(int64_t chatId, int32_t messageId, cons } } +Message::Ptr Message::Ptr editMessageMedia(InputMedia::Ptr media, int64_t chatId, int32_t messageId, const std::string& inlineMessageId, + GenericReply::Ptr replyMarkup) const { + + vector<HttpReqArg> args; + args.reserve(5); + args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); + } + ptree p = sendRequest("editMessageCaption", args); + if (p.get_child_optional("message_id")) { + return _tgTypeParser.parseJsonAndGetMessage(p); + } else { + return nullptr; + } +} + ChatMember::Ptr Api::getChatMember(int64_t chatId, int32_t userId) const { vector<HttpReqArg> args; args.reserve(2); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 5a01aa6..1bbc38e 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -624,6 +624,7 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const result->media = data.get("media", ""); result->caption = data.get("caption", ""); result->parseMode = data.get("parse_mode", ""); + result->thumb = data.get("thumb", ""); return result; } else if (type == "video") { @@ -631,12 +632,40 @@ InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const result->media = data.get("media", ""); result->caption = data.get("caption", ""); result->parseMode = data.get("parse_mode", ""); + result->thumb = data.get("thumb", ""); result->width = data.get<int32_t>("width", 0); result->height = data.get<int32_t>("height", 0); result->duration = data.get<int32_t>("duration", 0); result->supportsStreaming = data.get<bool>("supports_streaming", false); return result; } + else if (type == "animation") { + auto result(make_shared<InputMediaAnimation>()); + result->media = data.get("media", ""); + result->caption = data.get("caption", ""); + result->parseMode = data.get("parse_mode", ""); + result->thumb = data.get("thumb", ""); + result->width = data.get<int32_t>("width", 0); + result->height = data.get<int32_t>("height", 0); + result->duration = data.get<int32_t>("duration", 0); + return result; + } else if (type == "document") { + auto result(make_shared<InputMediaDocument>()); + result->media = data.get("media", ""); + result->caption = data.get("caption", ""); + result->parseMode = data.get("parse_mode", ""); + result->thumb = data.get("thumb", ""); + return result; + } else if (type == "audio") { + auto result(make_shared<InputMediaAudio>()); + result->media = data.get("media", ""); + result->caption = data.get("caption", ""); + result->parseMode = data.get("parse_mode", ""); + result->thumb = data.get("thumb", ""); + result->duration = data.get<int32_t>("duration", 0); + result->title = data.get<int32_t>("title", 0); + result->performer = data.get<int32_t>("performer", 0); + } else { return nullptr; } @@ -648,15 +677,27 @@ string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const { } string result; result += '{'; - if (object->type == InputMedia::TYPE::PHOTO) { - appendToJson(result, "type", "photo"); - } - else { - appendToJson(result, "type", "video"); + switch(object->type) { + case InputMedia::TYPE::PHOTO: + appendToJson(result, "type", "photo"); + break; + case InputMedia::TYPE::VIDEO: + appendToJson(result, "type", "video"); + break; + case InputMedia::TYPE::ANIMATION: + appendToJson(result, "type", "animation"); + break; + case InputMedia::TYPE::DOCUMENT: + appendToJson(result, "type", "document"); + break; + case InputMedia::TYPE::AUDIO: + appendToJson(result, "type", "audio"); + break; } appendToJson(result, "media", object->media); appendToJson(result, "caption", object->caption); appendToJson(result, "parse_mode", object->parseMode); + args.emplace_back("thumb", boost::get<std::string>(object->thumb)); if (object->width) { appendToJson(result, "width", object->width); } @@ -666,6 +707,9 @@ string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const { if (object->duration) { appendToJson(result, "duration", object->duration); } + if (object->performer) { + appendToJson(result, "performer", object->performer); + } if (object->supportsStreaming) { appendToJson(result, "supports_streaming", object->supportsStreaming); } diff --git a/src/net/HttpParser.cpp b/src/net/HttpParser.cpp index 41dec14..c4f8215 100644 --- a/src/net/HttpParser.cpp +++ b/src/net/HttpParser.cpp @@ -100,7 +100,7 @@ string HttpParser::generateMultipartFormData(const vector<HttpReqArg>& args, con string HttpParser::generateMultipartBoundary(const vector<HttpReqArg>& args) const { string result; - srand((unsigned int) time(nullptr)); + srand((uint32_t) time(nullptr)); for (const HttpReqArg& item : args) { if (item.isFile) { while (result.empty() || item.value.find(result) != string::npos) { |