From 981737b20b0db4914c667195b6584d14e9473e3d Mon Sep 17 00:00:00 2001 From: JellyBrick Date: Mon, 28 May 2018 03:45:31 +0900 Subject: Bot API 3.5 update --- src/TgTypeParser.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/TgTypeParser.cpp') 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()); + 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()); + result->media = data.get("media", ""); + result->caption = data.get("caption", ""); + result->parseMode = data.get("parse_mode", ""); + result->width = data.get("width", 0); + result->height = data.get("height", 0); + result->duration = data.get("duration", 0); + result->supportsStreaming = data.get("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()); result->fileId = data.get("file_id"); -- cgit v1.2.3