diff options
author | JellyBrick <shlee1503@naver.com> | 2018-05-28 03:45:31 +0900 |
---|---|---|
committer | JellyBrick <shlee1503@naver.com> | 2018-05-28 03:45:31 +0900 |
commit | 981737b20b0db4914c667195b6584d14e9473e3d (patch) | |
tree | b2a3aa0642c8360e0385c69717eb8f2cb86fbf24 /src/TgTypeParser.cpp | |
parent | b0134ff90ccd4203721fd8d32c1d1bacaea8b47f (diff) |
Bot API 3.5 update
Diffstat (limited to 'src/TgTypeParser.cpp')
-rw-r--r-- | src/TgTypeParser.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 702bc71..fcb7e0e 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -511,6 +511,67 @@ string TgTypeParser::parseUserProfilePhotos(const UserProfilePhotos::Ptr& object return result; } +InputMedia::Ptr TgTypeParser::parseJsonAndGetInputMedia(const ptree& data) const { + string type = data.get("type", ""); + if (type == "photo") { + auto result(make_shared<InputMediaPhoto>()); + result->media = data.get("media", ""); + result->caption = data.get("caption", ""); + result->parseMode = data.get("parse_mode", ""); + return result; + } + else if (type == "video") { + auto result(make_shared<InputMediaVideo>()); + result->media = data.get("media", ""); + result->caption = data.get("caption", ""); + result->parseMode = data.get("parse_mode", ""); + 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 { + return nullptr; + } +} + +string TgTypeParser::parseInputMedia(const InputMedia::Ptr& object) const { + if (!object) { + return ""; + } + string result; + result += '{'; + if (object->type == InputMedia::TYPE::PHOTO) { + appendToJson(result, "type", "photo"); + } + else { + appendToJson(result, "type", "video"); + } + appendToJson(result, "media", object->media); + if (object->caption) { + appendToJson(result, "caption", object->caption); + } + if (object->parseMode) { + appendToJson(result, "parse_mode", object->parseMode); + } + if (object->width) { + appendToJson(result, "width", object->width); + } + if (object->height) { + appendToJson(result, "height", object->height); + } + if (object->duration) { + appendToJson(result, "duration", object->duration); + } + if (object->supportsStreaming) { + appendToJson(result, "supports_streaming", object->supportsStreaming); + } + result.erase(result.length() - 1); + result += '}'; + return result; +} + File::Ptr TgTypeParser::parseJsonAndGetFile(const boost::property_tree::ptree& data) const { auto result(make_shared<File>()); result->fileId = data.get<string>("file_id"); |