From eb1de0a6148c88510be63ac57f1c03fddb6cb395 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Tue, 30 Aug 2022 18:25:46 +0200 Subject: Rework Bot API 4.7 --- src/TgTypeParser.cpp | 224 +++++++++++++++++++++++++-------------------------- 1 file changed, 108 insertions(+), 116 deletions(-) (limited to 'src/TgTypeParser.cpp') diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 37dafb6..41cf642 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -10,8 +10,8 @@ namespace TgBot { Chat::Ptr TgTypeParser::parseJsonAndGetChat(const ptree& data) const { auto result(make_shared()); - result->id = data.get("id"); - string type = data.get("type"); + result->id = data.get("id", 0); + string type = data.get("type", ""); if (type == "private") { result->type = Chat::Type::Private; } else if (type == "group") { @@ -21,20 +21,18 @@ 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->allMembersAreAdministrators = data.get("all_members_are_administrators", false); + 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->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"); - 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); - return result; } @@ -58,7 +56,6 @@ string TgTypeParser::parseChat(const Chat::Ptr& object) const { appendToJson(result, "username", object->username); appendToJson(result, "first_name", object->firstName); appendToJson(result, "last_name", object->lastName); - appendToJson(result, "all_members_are_administrators", object->allMembersAreAdministrators); appendToJson(result, "photo", parseChatPhoto(object->photo)); appendToJson(result, "description", object->description); appendToJson(result, "invite_link", object->inviteLink); @@ -74,12 +71,12 @@ string TgTypeParser::parseChat(const Chat::Ptr& object) const { User::Ptr TgTypeParser::parseJsonAndGetUser(const ptree& data) const { auto result(make_shared()); - result->id = data.get("id"); + 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); @@ -108,9 +105,9 @@ string TgTypeParser::parseUser(const User::Ptr& object) const { MessageEntity::Ptr TgTypeParser::parseJsonAndGetMessageEntity(const ptree& data) const{ auto result(make_shared()); - result->type = data.get("type"); - result->offset = data.get("offset"); - result->length = data.get("length"); + 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", ""); @@ -136,21 +133,21 @@ string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) const Message::Ptr TgTypeParser::parseJsonAndGetMessage(const ptree& data) const { auto result(make_shared()); - result->messageId = data.get("message_id"); + result->messageId = data.get("message_id", 0); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); - result->date = data.get("date"); + 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->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->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->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->audio = tryParseJson