diff options
author | Oleg Morozenkov <omorozenkov@gmail.com> | 2018-07-31 04:40:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-31 04:40:43 +0300 |
commit | 5a1bcfdddecaba039e458c957f79ecc60d12a5fb (patch) | |
tree | 17df84fbd12907fa3b668446eaebb5e0cd4b78d8 /src/TgTypeParser.cpp | |
parent | 90140927a052f55c633a976c6c404ac284d647a4 (diff) | |
parent | 6d1a96043c63f346b03df4c54d8200bc320ebe3e (diff) |
Merge pull request #78 from JellyBrick/master
Bot API 4.0
Diffstat (limited to 'src/TgTypeParser.cpp')
-rw-r--r-- | src/TgTypeParser.cpp | 120 |
1 files changed, 88 insertions, 32 deletions
diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index dbfb266..ad200b3 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -153,6 +153,7 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { result->captionEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities"); result->audio = tryParseJson<Audio>(&TgTypeParser::parseJsonAndGetAudio, data, "audio"); result->document = tryParseJson<Document>(&TgTypeParser::parseJsonAndGetDocument, data, "document"); + result->animation = tryParseJson<Animation>(&TgTypeParser::parseJsonAndGetAnimation, data, "animation"); result->game = tryParseJson<Game>(&TgTypeParser::parseJsonAndGetGame, data, "game"); result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo"); result->sticker = tryParseJson<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "sticker"); @@ -199,6 +200,7 @@ string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "text", object->text); appendToJson(result, "audio", parseAudio(object->audio)); appendToJson(result, "document", parseDocument(object->document)); + appendToJson(result, "animation", parseAnimation(object->animation)); appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo)); appendToJson(result, "sticker", parseSticker(object->sticker)); appendToJson(result, "video", parseVideo(object->video)); @@ -257,6 +259,7 @@ Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const ptree& data) const { result->title = data.get<string>("title", ""); result->mimeType = data.get("mime_type", ""); result->fileSize = data.get("file_size", 0); + result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); return result; } @@ -270,6 +273,7 @@ string TgTypeParser::parseAudio(const Audio::Ptr& object) const { appendToJson(result, "duration", object->duration); appendToJson(result, "mime_type", object->mimeType); appendToJson(result, "file_size", object->fileSize); + appendToJson(result, "thumb", parsePhotoSize(object->thumb)); removeLastComma(result); result += '}'; return result; @@ -517,6 +521,7 @@ Contact::Ptr TgTypeParser::parseJsonAndGetContact(const ptree& data) const { result->firstName = data.get<string>("first_name"); result->lastName = data.get("last_name", ""); result->userId = data.get("user_id", ""); + result->vcard = data.get("vcard", ""); return result; } @@ -530,6 +535,7 @@ string TgTypeParser::parseContact(const Contact::Ptr& object) const { appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); appendToJson(result, "user_id", object->userId); + appendToJson(result, "vcard", object->vcard); removeLastComma(result); result += '}'; return result; @@ -618,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") { @@ -625,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; } @@ -642,12 +677,23 @@ 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); @@ -660,6 +706,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); } @@ -1064,7 +1113,7 @@ InlineQueryResultCachedAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult std::string TgTypeParser::parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1084,7 +1133,7 @@ InlineQueryResultCachedDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryRes std::string TgTypeParser::parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1105,7 +1154,7 @@ InlineQueryResultCachedGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCa std::string TgTypeParser::parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1125,7 +1174,7 @@ InlineQueryResultCachedMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryRes std::string TgTypeParser::parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1146,7 +1195,7 @@ InlineQueryResultCachedPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult std::string TgTypeParser::parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1167,7 +1216,7 @@ InlineQueryResultCachedSticker::Ptr TgTypeParser::parseJsonAndGetInlineQueryResu std::string TgTypeParser::parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1187,7 +1236,7 @@ InlineQueryResultCachedVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult std::string TgTypeParser::parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1208,7 +1257,7 @@ InlineQueryResultCachedVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult std::string TgTypeParser::parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1232,7 +1281,7 @@ InlineQueryResultArticle::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultArti std::string TgTypeParser::parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1258,7 +1307,7 @@ InlineQueryResultAudio::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultAudio( std::string TgTypeParser::parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1277,6 +1326,7 @@ InlineQueryResultContact::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCont result->phoneNumber = data.get<string>("phone_number"); result->firstName = data.get<string>("first_name"); result->lastName = data.get<string>("last_name", ""); + result->vcard = data.get<string>("vcard", ""); result->thumbUrl = data.get<string>("thumb_url", ""); result->thumbWidth = data.get<int32_t>("thumb_width", 0); result->thumbHeight = data.get<int32_t>("thumb_height", 0); @@ -1285,7 +1335,7 @@ InlineQueryResultContact::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCont std::string TgTypeParser::parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1293,6 +1343,7 @@ std::string TgTypeParser::parseInlineQueryResultContact(const InlineQueryResultC appendToJson(result, "phone_number", object->phoneNumber); appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); + appendToJson(result, "vcard", object->vcard); appendToJson(result, "thumb_url", object->thumbUrl); appendToJson(result, "thumb_width", object->thumbWidth); appendToJson(result, "thumb_height", object->thumbHeight); @@ -1310,7 +1361,7 @@ InlineQueryResultGame::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGame(co std::string TgTypeParser::parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1334,7 +1385,7 @@ InlineQueryResultDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultDoc std::string TgTypeParser::parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1362,7 +1413,7 @@ InlineQueryResultLocation::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultLoc std::string TgTypeParser::parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1384,6 +1435,7 @@ InlineQueryResultVenue::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVenue( result->longitude = data.get<float>("longitude"); result->address = data.get<string>("address"); result->foursquareId = data.get<string>("foursquare_id", ""); + result->foursquareType = data.get<string>("foursquare_type", ""); result->thumbUrl = data.get<string>("thumb_url", ""); result->thumbWidth = data.get<int32_t>("thumb_width", 0); result->thumbHeight = data.get<int32_t>("thumb_height", 0); @@ -1392,7 +1444,7 @@ InlineQueryResultVenue::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVenue( std::string TgTypeParser::parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1401,6 +1453,7 @@ std::string TgTypeParser::parseInlineQueryResultVenue(const InlineQueryResultVen appendToJson(result, "longitude", object->longitude); appendToJson(result, "address", object->address); appendToJson(result, "foursquare_id", object->foursquareId); + appendToJson(result, "foursquare_type", object->foursquareType); appendToJson(result, "thumb_url", object->thumbUrl); appendToJson(result, "thumb_width", object->thumbWidth); appendToJson(result, "thumb_height", object->thumbHeight); @@ -1418,7 +1471,7 @@ InlineQueryResultVoice::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVoice( std::string TgTypeParser::parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1442,7 +1495,7 @@ InlineQueryResultPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultPhoto( std::string TgTypeParser::parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const{ if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1468,7 +1521,7 @@ InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(cons } std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1495,7 +1548,7 @@ InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpe std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResultMpeg4Gif::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1524,7 +1577,7 @@ InlineQueryResultVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVideo( std::string TgTypeParser::parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInlineQueryResult(), so I don't add // curly brackets to the result string. @@ -1751,7 +1804,7 @@ InputTextMessageContent::Ptr TgTypeParser::parseJsonAndGetInputTextMessageConten std::string TgTypeParser::parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInputMessageContent() string result; @@ -1772,7 +1825,7 @@ InputLocationMessageContent::Ptr TgTypeParser::parseJsonAndGetInputLocationMessa std::string TgTypeParser::parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInputMessageContent() string result; @@ -1790,12 +1843,13 @@ InputVenueMessageContent::Ptr TgTypeParser::parseJsonAndGetInputVenueMessageCont result->title = data.get<string>("title"); result->address = data.get<string>("address"); result->foursquareId = data.get<string>("foursquare_id", ""); + result->foursquareType = data.get<string>("foursquare_type", ""); return result; } std::string TgTypeParser::parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInputMessageContent() string result; @@ -1814,18 +1868,20 @@ InputContactMessageContent::Ptr TgTypeParser::parseJsonAndGetInputContactMessage result->phoneNumber = data.get<string>("phone_number"); result->firstName = data.get<string>("first_name"); result->lastName = data.get<string>("last_name", ""); + result->vcard = data.get<string>("vcard", ""); return result; } std::string TgTypeParser::parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const { if (!object){ - return " "; + return ""; } // This function will be called by parseInputMessageContent() string result; appendToJson(result, "phone_number", object->phoneNumber); appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); + appendToJson(result, "vcard", object->vcard); // The last comma will be erased by parseInputMessageContent(). return result; } @@ -1842,7 +1898,7 @@ Invoice::Ptr TgTypeParser::parseJsonAndGetInvoice(const boost::property_tree::pt std::string TgTypeParser::parseInvoice(const Invoice::Ptr& object) const { if (!object) { - return " "; + return ""; } string result; result += '{'; @@ -1884,7 +1940,7 @@ OrderInfo::Ptr TgTypeParser::parseJsonAndGetOrderInfo(const boost::property_tree string TgTypeParser::parseOrderInfo(const OrderInfo::Ptr& object) const { if (!object) { - return " "; + return ""; } std::string result; result += '{'; |