From c17ab6fb6574bdea6fc9011be0651dc74aa6a53e Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sat, 3 Sep 2022 22:41:05 +0200 Subject: Update to API 5.0 --- src/TgTypeParser.cpp | 1927 +++++++++++++++++++++++++++++--------------------- 1 file changed, 1125 insertions(+), 802 deletions(-) (limited to 'src/TgTypeParser.cpp') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 89cdd4c..60a2c54 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -3,15 +3,12 @@ #include #include -using namespace std; -using namespace boost::property_tree; - namespace TgBot { -Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { - auto result(make_shared()); - result->id = data.get("id", 0); - string type = data.get("type", ""); +Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->id = data.get("id", 0); + std::string type = data.get("type", ""); if (type == "private") { result->type = Chat::Type::Private; } else if (type == "group") { @@ -21,26 +18,29 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { } else if (type == "channel") { result->type = Chat::Type::Channel; } - result->title = data.get("title", ""); - result->username = data.get("username", ""); - result->firstName = data.get("first_name", ""); - result->lastName = data.get("last_name", ""); + result->title = data.get("title", ""); + result->username = data.get("username", ""); + result->firstName = data.get("first_name", ""); + result->lastName = data.get("last_name", ""); result->photo = tryParseJson(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo"); - result->description = data.get("description", ""); - result->inviteLink = data.get("invite_link", ""); + result->bio = data.get("bio", ""); + result->description = data.get("description", ""); + result->inviteLink = data.get("invite_link", ""); result->pinnedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); result->permissions = tryParseJson(&TgTypeParser::parseJsonAndGetChatPermissions, data, "permissions"); - result->slowModeDelay = data.get("slow_mode_delay", 0); - result->stickerSetName = data.get("sticker_set_name", ""); + result->slowModeDelay = data.get("slow_mode_delay", 0); + result->stickerSetName = data.get("sticker_set_name", ""); result->canSetStickerSet = data.get("can_set_sticker_set", false); + result->linkedChatId = data.get("linked_chat_id", 0); + result->location = tryParseJson(&TgTypeParser::parseJsonAndGetChatLocation, data, "location"); return result; } -string TgTypeParser::parseChat(const Chat::Ptr& object) const { +std::string TgTypeParser::parseChat(const Chat::Ptr& object) const { if (!object) { return ""; } - string result; + std::string result; result += '{'; appendToJson(result, "id", object->id); if (object->type == Chat::Type::Private) { @@ -57,6 +57,7 @@ string TgTypeParser::parseChat(const Chat::Ptr& object) const { appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); appendToJson(result, "photo", parseChatPhoto(object->photo)); + appendToJson(result, "bio", object->bio); appendToJson(result, "description", object->description); appendToJson(result, "invite_link", object->inviteLink); appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage)); @@ -64,30 +65,32 @@ string TgTypeParser::parseChat(const Chat::Ptr& object) const { appendToJson(result, "slow_mode_delay", object->slowModeDelay); appendToJson(result, "sticker_set_name", object->stickerSetName); appendToJson(result, "can_set_sticker_set", object->canSetStickerSet); + appendToJson(result, "linked_chat_id", object->linkedChatId); + appendToJson(result, "location", parseChatLocation(object->location)); removeLastComma(result); result += '}'; return result; } -User::Ptr TgTypeParser::parseJsonAndGetUser(const ptree& data) const { - auto result(make_shared()); - result->id = data.get("id", 0); +User::Ptr TgTypeParser::parseJsonAndGetUser(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->id = data.get("id", 0); result->isBot = data.get("is_bot", false); - result->firstName = data.get("first_name", ""); - result->lastName = data.get("last_name", ""); - result->username = data.get("username", ""); - result->languageCode = data.get("language_code", ""); + result->firstName = data.get("first_name", ""); + result->lastName = data.get("last_name", ""); + result->username = data.get("username", ""); + result->languageCode = data.get("language_code", ""); result->canJoinGroups = data.get("can_join_groups", false); result->canReadAllGroupMessages = data.get("can_read_all_group_messages", false); result->supportsInlineQueries = data.get("supports_inline_queries", false); return result; } -string TgTypeParser::parseUser(const User::Ptr& object) const { +std::string TgTypeParser::parseUser(const User::Ptr& object) const { if (!object) { return ""; } - string result; + std::string result; result += '{'; appendToJson(result, "id", object->id); appendToJson(result, "is_bot", object->isBot); @@ -103,22 +106,22 @@ string TgTypeParser::parseUser(const User::Ptr& object) const { return result; } -MessageEntity::Ptr TgTypeParser::parseJsonAndGetMessageEntity(const ptree& data) const{ - auto result(make_shared()); - result->type = data.get("type", ""); - result->offset = data.get("offset", 0); - result->length = data.get("length", 0); - result->url = data.get("url", ""); +MessageEntity::Ptr TgTypeParser::parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const{ + auto result(std::make_shared()); + result->type = data.get("type", ""); + result->offset = data.get("offset", 0); + result->length = data.get("length", 0); + result->url = data.get("url", ""); result->user = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); - result->language = data.get("language", ""); + result->language = data.get("language", ""); return result; } -string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) const { +std::string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) const { if (!object) { return ""; } - string result; + std::string result; result += '{'; appendToJson(result, "type", object->type); appendToJson(result, "offset", object->offset); @@ -131,69 +134,73 @@ string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) const return result; } -Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { - auto result(make_shared()); - result->messageId = data.get("message_id", 0); +Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->messageId = data.get("message_id", 0); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); - result->date = data.get("date", 0); + result->senderChat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "sender_chat"); + result->date = data.get("date", 0); result->chat = parseJsonAndGetChat(data.find("chat")->second); result->forwardFrom = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "forward_from"); result->forwardFromChat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "forward_from_chat"); - result->forwardFromMessageId = data.get("forward_from_message_id", 0); - result->forwardSignature = data.get("forward_signature", ""); - result->forwardSenderName = data.get("forward_sender_name", ""); - result->forwardDate = data.get("forward_date", 0); + result->forwardFromMessageId = data.get("forward_from_message_id", 0); + result->forwardSignature = data.get("forward_signature", ""); + result->forwardSenderName = data.get("forward_sender_name", ""); + result->forwardDate = data.get("forward_date", 0); result->replyToMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message"); result->viaBot = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "via_bot"); - result->editDate = data.get("edit_date", 0); - result->mediaGroupId = data.get("media_group_id", ""); - result->authorSignature = data.get("author_signature", ""); - result->text = data.get("text", ""); + result->editDate = data.get("edit_date", 0); + result->mediaGroupId = data.get("media_group_id", ""); + result->authorSignature = data.get("author_signature", ""); + result->text = data.get("text", ""); result->entities = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageEntity, data, "entities"); - result->captionEntities = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageEntity, data, "caption_entities"); + result->animation = tryParseJson(&TgTypeParser::parseJsonAndGetAnimation, data, "animation"); result->audio = tryParseJson