From 12c56318a8c0e53cfcaa7d592654dc7a2c3e9daa Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Feb 2023 15:44:46 +0300 Subject: [PATCH 01/30] Update clang-format to 16.0.0. --- .clang-format | 82 +++++++++++++++++++++++++++++-------- telegram-bot-api/Client.cpp | 2 +- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/.clang-format b/.clang-format index 4e23f1d..8f0a588 100644 --- a/.clang-format +++ b/.clang-format @@ -4,15 +4,36 @@ Language: Cpp AccessModifierOffset: -1 AlignAfterOpenBracket: Align AlignArrayOfStructures: None -AlignConsecutiveMacros: None -AlignConsecutiveAssignments: None -AlignConsecutiveBitFields: None -AlignConsecutiveDeclarations: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + PadOperators: false AlignEscapedNewlines: Left AlignOperands: Align -AlignTrailingComments: true +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 AllowAllArgumentsOnNextLine: true -AllowAllConstructorInitializersOnNextLine: true AllowAllParametersOfDeclarationOnNextLine: true AllowShortBlocksOnASingleLine: Never AllowShortCaseLabelsOnASingleLine: false @@ -25,6 +46,8 @@ AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: Yes +# AttributeMacros: +# - __capability BinPackArguments: true BinPackParameters: true BitFieldColonSpacing: Both @@ -33,12 +56,12 @@ BraceWrapping: AfterClass: false AfterControlStatement: Never AfterEnum: false + AfterExternBlock: false AfterFunction: false AfterNamespace: false AfterObjCDeclaration: false AfterStruct: false AfterUnion: false - AfterExternBlock: false BeforeCatch: false BeforeElse: false BeforeLambdaBody: false @@ -47,24 +70,23 @@ BraceWrapping: SplitEmptyFunction: true SplitEmptyRecord: true SplitEmptyNamespace: true +BreakAfterAttributes: Never +# BreakAfterJavaFieldAnnotations: false +BreakArrays: true BreakBeforeBinaryOperators: None BreakBeforeBraces: Attach -BreakBeforeConceptDeclarations: true -BreakBeforeInheritanceComma: true # false -BreakInheritanceList: BeforeComma # BeforeColon +BreakBeforeConceptDeclarations: Always +BreakBeforeInlineASMColon: OnlyMultiline BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: true # false BreakConstructorInitializers: BeforeComma # BeforeColon -# BreakAfterJavaFieldAnnotations: false +BreakInheritanceList: BeforeComma # BeforeColon BreakStringLiterals: true ColumnLimit: 120 # 80 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: false -ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerIndentWidth: 4 ContinuationIndentWidth: 4 Cpp11BracedListStyle: true -DeriveLineEnding: true DerivePointerAlignment: true DisableFormat: false EmptyLineAfterAccessModifier: Never @@ -83,14 +105,21 @@ IndentCaseLabels: true IndentExternBlock: AfterExternBlock IndentGotoLabels: true IndentPPDirectives: None -IndentRequires: false +IndentRequiresClause: true IndentWidth: 2 IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false # InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + Decimal: 0 + Hex: 0 # JavaScriptQuotes: Leave # JavaScriptWrapImports: true KeepEmptyLinesAtTheStartOfBlocks: false LambdaBodyIndentation: Signature +LineEnding: DeriveLF MacroBlockBegin: '' MacroBlockEnd: '' MaxEmptyLinesToKeep: 1 @@ -100,23 +129,31 @@ NamespaceIndentation: None # ObjCBreakBeforeNestedBlockParam: true # ObjCSpaceAfterProperty: false # ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: NextLine PenaltyBreakAssignment: 2 PenaltyBreakBeforeFirstCallParameter: 1 PenaltyBreakComment: 300 PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 PenaltyBreakString: 1000 PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyIndentedWhitespace: 0 PenaltyReturnTypeOnItsOwnLine: 200 -PointerAlignment: Right +PointerAlignment: Right # Left PPIndentWidth: -1 +QualifierAlignment: Leave ReferenceAlignment: Pointer ReflowComments: false # true +RemoveBracesLLVM: false +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave ShortNamespaceLines: 0 # 1 SortIncludes: CaseInsensitive # CaseSensitive # SortJavaStaticImport: Before -SortUsingDeclarations: false # true +SortUsingDeclarations: Lexicographic # LexicographicNumeric SpaceAfterCStyleCast: false SpaceAfterLogicalNot: false SpaceAfterTemplateKeyword: true @@ -127,6 +164,16 @@ SpaceBeforeCpp11BracedList: false SpaceBeforeCtorInitializerColon: true SpaceBeforeInheritanceColon: true SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false SpaceBeforeRangeBasedForLoopColon: true SpaceBeforeSquareBrackets: false SpaceInEmptyBlock: false @@ -143,6 +190,5 @@ SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Auto TabWidth: 100 # 8 -UseCRLF: false UseTab: Never ... diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 8b62bf5..76ef68c 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -36,8 +36,8 @@ namespace telegram_bot_api { using td::Jsonable; -using td::JsonValueScope; using td::JsonValue; +using td::JsonValueScope; using td_api::make_object; using td_api::move_object_as; From 09c9db306a2fc61d403c65d2d7fcf0eafb951ef4 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Feb 2023 15:52:15 +0300 Subject: [PATCH 02/30] Fail flood-limited queries with a delay. --- telegram-bot-api/Client.cpp | 27 +++++++++++++++------------ telegram-bot-api/Client.h | 2 ++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 76ef68c..16b7ecf 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -4195,18 +4195,15 @@ void Client::send(PromisedQueryPtr query) { auto update_per_minute = static_cast(stat->get_minute_update_count(td::Time::now()) * 60); if (stat->get_active_request_count() > 500 + update_per_minute) { LOG(INFO) << "Fail a query, because there are too many active queries: " << *query; - flood_limited_query_count_++; - return query->set_retry_after_error(60); + return fail_query_flood_limit_exceeded(std::move(query)); } if (stat->get_active_file_upload_bytes() > (static_cast(1) << 32) && !query->files().empty()) { LOG(INFO) << "Fail a query, because the total size of active file uploads is too big: " << *query; - flood_limited_query_count_++; - return query->set_retry_after_error(60); + return fail_query_flood_limit_exceeded(std::move(query)); } if (stat->get_active_file_upload_count() > 100 + update_per_minute / 5 && !query->files().empty()) { LOG(INFO) << "Fail a query, because there are too many active file uploads: " << *query; - flood_limited_query_count_++; - return query->set_retry_after_error(60); + return fail_query_flood_limit_exceeded(std::move(query)); } } } @@ -7580,8 +7577,7 @@ td::Status Client::process_send_message_query(PromisedQueryPtr &query) { // fast path auto it = yet_unsent_message_count_.find(r_chat_id.ok()); if (it != yet_unsent_message_count_.end() && it->second >= MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) { - flood_limited_query_count_++; - query->set_retry_after_error(60); + fail_query_flood_limit_exceeded(std::move(query)); return Status::OK(); } } @@ -7889,8 +7885,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { PromisedQueryPtr query) mutable { auto &count = yet_unsent_message_count_[chat_id]; if (count >= MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) { - flood_limited_query_count_++; - return query->set_retry_after_error(60); + return fail_query_flood_limit_exceeded(std::move(query)); } auto message_count = input_message_contents.size(); count += static_cast(message_count); @@ -9527,8 +9522,7 @@ void Client::do_send_message(object_ptr input_messa int64 reply_to_message_id, PromisedQueryPtr query) mutable { auto &count = yet_unsent_message_count_[chat_id]; if (count >= MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) { - flood_limited_query_count_++; - return query->set_retry_after_error(60); + return fail_query_flood_limit_exceeded(std::move(query)); } count++; @@ -9616,6 +9610,15 @@ void Client::fail_query_closing(PromisedQueryPtr &&query) { } } +void Client::fail_query_flood_limit_exceeded(PromisedQueryPtr &&query) { + flood_limited_query_count_++; + td::create_actor( + "FailQueryFloodLimitExceededActor", 3.0, + td::PromiseCreator::lambda( + [query = std::move(query)](td::Result result) mutable { query->set_retry_after_error(60); })) + .release(); +} + Client::ClosingError Client::get_closing_error() { ClosingError result; result.retry_after = 0; diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 1925f87..5a0d620 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -618,6 +618,8 @@ class Client final : public WebhookActor::Callback { void fail_query_closing(PromisedQueryPtr &&query); + void fail_query_flood_limit_exceeded(PromisedQueryPtr &&query); + void fail_query_conflict(Slice message, PromisedQueryPtr &&query); struct ClosingError { From 0cf13d3bf40111136accb2be0712d70653296e6d Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Feb 2023 17:25:33 +0300 Subject: [PATCH 03/30] Update TDLib to 1.8.12. --- td | 2 +- telegram-bot-api/Client.cpp | 85 +++++++++++++++++-------------- telegram-bot-api/Client.h | 3 +- telegram-bot-api/HttpServer.h | 2 +- telegram-bot-api/WebhookActor.cpp | 2 +- 5 files changed, 52 insertions(+), 42 deletions(-) diff --git a/td b/td index 3179d35..6c53a61 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 3179d35694a28267a0b6273fc9b5bdce3b6b1235 +Subproject commit 6c53a61162e6ea4a753869ee248b8a9e926ffd5d diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 16b7ecf..373e44a 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -735,9 +735,9 @@ class Client::JsonChat final : public Jsonable { object("permissions", JsonChatPermissions(permissions)); } auto everyone_is_administrator = - permissions->can_send_messages_ && permissions->can_send_audios_ && permissions->can_send_documents_ && - permissions->can_send_photos_ && permissions->can_send_videos_ && permissions->can_send_video_notes_ && - permissions->can_send_voice_notes_ && permissions->can_send_polls_ && + permissions->can_send_basic_messages_ && permissions->can_send_audios_ && + permissions->can_send_documents_ && permissions->can_send_photos_ && permissions->can_send_videos_ && + permissions->can_send_video_notes_ && permissions->can_send_voice_notes_ && permissions->can_send_polls_ && permissions->can_send_other_messages_ && permissions->can_add_web_page_previews_ && permissions->can_change_info_ && permissions->can_invite_users_ && permissions->can_pin_messages_; object("all_members_are_administrators", td::JsonBool(everyone_is_administrator)); @@ -4190,7 +4190,7 @@ void Client::send(PromisedQueryPtr query) { if (!query->is_internal()) { query->set_stat_actor(stat_actor_); if (!parameters_->local_mode_ && !is_local_method(query->method()) && - td::Time::now() > parameters_->start_time_ + 10 * 60) { + td::Time::now() > parameters_->start_time_ + 60) { BotStatActor *stat = stat_actor_.get_actor_unsafe(); auto update_per_minute = static_cast(stat->get_minute_update_count(td::Time::now()) * 60); if (stat->get_active_request_count() > 500 + update_per_minute) { @@ -5999,7 +5999,7 @@ td::Result> Client::get_input_me td_api::object_ptr Client::get_message_send_options(bool disable_notification, bool protect_content) { - return make_object(disable_notification, false, protect_content, false, nullptr); + return make_object(disable_notification, false, protect_content, false, nullptr, 0); } td::Result>> Client::get_inline_query_results( @@ -6615,23 +6615,29 @@ td::Result> Client::get_mask_position(c return r_mask_position.move_as_ok(); } -td::Result>> Client::get_input_stickers(const Query *query) const { +td::Result>> Client::get_input_stickers( + const Query *query, object_ptr *sticker_format) const { auto emojis = query->arg("emojis"); auto sticker = get_input_file(query, "png_sticker"); - object_ptr sticker_format; object_ptr mask_position; if (sticker != nullptr) { - sticker_format = make_object(); + if (sticker_format != nullptr) { + *sticker_format = make_object(); + } TRY_RESULT_ASSIGN(mask_position, get_mask_position(query, "mask_position")); } else { sticker = get_input_file(query, "tgs_sticker", true); if (sticker != nullptr) { - sticker_format = make_object(); + if (sticker_format != nullptr) { + *sticker_format = make_object(); + } } else { sticker = get_input_file(query, "webm_sticker", true); if (sticker != nullptr) { - sticker_format = make_object(); + if (sticker_format != nullptr) { + *sticker_format = make_object(); + } } else { if (!query->arg("tgs_sticker").empty()) { return Status::Error(400, "Bad Request: animated sticker must be uploaded as an InputFile"); @@ -6645,8 +6651,8 @@ td::Result>> Client::get_inp } td::vector> stickers; - stickers.push_back(make_object(std::move(sticker), emojis.str(), std::move(sticker_format), - std::move(mask_position))); + stickers.push_back(make_object(std::move(sticker), emojis.str(), std::move(mask_position), + td::vector())); return std::move(stickers); } @@ -8207,19 +8213,22 @@ td::Status Client::process_answer_inline_query_query(PromisedQueryPtr &query) { int32 cache_time = get_integer_arg(query.get(), "cache_time", 300, 0, 24 * 60 * 60); auto next_offset = query->arg("next_offset"); auto switch_pm_text = query->arg("switch_pm_text"); - auto switch_pm_parameter = query->arg("switch_pm_parameter"); + object_ptr button; + if (!switch_pm_text.empty()) { + button = make_object( + switch_pm_text.str(), + make_object(query->arg("switch_pm_parameter").str())); + } TRY_RESULT(results, get_inline_query_results(query.get())); resolve_inline_query_results_bot_usernames( std::move(results), std::move(query), - [this, inline_query_id, is_personal, cache_time, next_offset = next_offset.str(), - switch_pm_text = switch_pm_text.str(), switch_pm_parameter = switch_pm_parameter.str()]( - td::vector> results, PromisedQueryPtr query) { - send_request( - make_object(inline_query_id, is_personal, std::move(results), cache_time, - next_offset, switch_pm_text, switch_pm_parameter), - td::make_unique(std::move(query))); + [this, inline_query_id, is_personal, cache_time, next_offset = next_offset.str(), button = std::move(button)]( + td::vector> results, PromisedQueryPtr query) mutable { + send_request(make_object(inline_query_id, is_personal, std::move(button), + std::move(results), cache_time, next_offset), + td::make_unique(std::move(query))); }); return Status::OK(); } @@ -8995,13 +9004,12 @@ td::Status Client::process_upload_sticker_file_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); auto png_sticker = get_input_file(query.get(), "png_sticker"); - check_user( - user_id, std::move(query), [this, user_id, png_sticker = std::move(png_sticker)](PromisedQueryPtr query) mutable { - send_request(make_object( - user_id, make_object(std::move(png_sticker), "", - make_object(), nullptr)), - td::make_unique(this, std::move(query))); - }); + check_user(user_id, std::move(query), + [this, user_id, png_sticker = std::move(png_sticker)](PromisedQueryPtr query) mutable { + send_request(make_object(user_id, make_object(), + std::move(png_sticker)), + td::make_unique(this, std::move(query))); + }); return Status::OK(); } @@ -9009,7 +9017,8 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) TRY_RESULT(user_id, get_user_id(query.get())); auto name = query->arg("name"); auto title = query->arg("title"); - TRY_RESULT(stickers, get_input_stickers(query.get())); + object_ptr sticker_format; + TRY_RESULT(stickers, get_input_stickers(query.get(), &sticker_format)); TRY_RESULT(sticker_type, get_sticker_type(query->arg("sticker_type"))); if (to_bool(query->arg("contains_masks"))) { @@ -9017,12 +9026,12 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) } check_user(user_id, std::move(query), - [this, user_id, title, name, sticker_type = std::move(sticker_type), - stickers = std::move(stickers)](PromisedQueryPtr query) mutable { - send_request( - make_object(user_id, title.str(), name.str(), std::move(sticker_type), - std::move(stickers), PSTRING() << "bot" << my_id_), - td::make_unique(this, false, std::move(query))); + [this, user_id, title, name, sticker_format = std::move(sticker_format), + sticker_type = std::move(sticker_type), stickers = std::move(stickers)](PromisedQueryPtr query) mutable { + send_request(make_object( + user_id, title.str(), name.str(), std::move(sticker_format), std::move(sticker_type), + false, std::move(stickers), PSTRING() << "bot" << my_id_), + td::make_unique(this, false, std::move(query))); }); return Status::OK(); } @@ -9030,13 +9039,13 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); auto name = query->arg("name"); - TRY_RESULT(stickers, get_input_stickers(query.get())); + TRY_RESULT(stickers, get_input_stickers(query.get(), nullptr)); CHECK(!stickers.empty()); check_user(user_id, std::move(query), [this, user_id, name, sticker = std::move(stickers[0])](PromisedQueryPtr query) mutable { send_request(make_object(user_id, name.str(), std::move(sticker)), - td::make_unique(this, false, std::move(query))); + td::make_unique(std::move(query))); }); return Status::OK(); } @@ -9048,7 +9057,7 @@ td::Status Client::process_set_sticker_set_thumb_query(PromisedQueryPtr &query) check_user(user_id, std::move(query), [this, user_id, name, thumbnail = std::move(thumbnail)](PromisedQueryPtr query) mutable { send_request(make_object(user_id, name.str(), std::move(thumbnail)), - td::make_unique(this, false, std::move(query))); + td::make_unique(std::move(query))); }); return Status::OK(); } @@ -10119,7 +10128,7 @@ void Client::json_store_permissions(td::JsonObjectScope &object, const td_api::c bool can_send_media_messages = permissions->can_send_audios_ || permissions->can_send_documents_ || permissions->can_send_photos_ || permissions->can_send_videos_ || permissions->can_send_video_notes_ || permissions->can_send_voice_notes_; - object("can_send_messages", td::JsonBool(permissions->can_send_messages_)); + object("can_send_messages", td::JsonBool(permissions->can_send_basic_messages_)); object("can_send_media_messages", td::JsonBool(can_send_media_messages)); object("can_send_audios", td::JsonBool(permissions->can_send_audios_)); object("can_send_documents", td::JsonBool(permissions->can_send_documents_)); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 5a0d620..5b1feb4 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -401,7 +401,8 @@ class Client final : public WebhookActor::Callback { static object_ptr mask_index_to_point(int32 index); - td::Result>> get_input_stickers(const Query *query) const; + td::Result>> get_input_stickers( + const Query *query, object_ptr *sticker_format) const; static td::Result get_passport_element_hash(Slice encoded_hash); diff --git a/telegram-bot-api/HttpServer.h b/telegram-bot-api/HttpServer.h index d5f0008..13a03c8 100644 --- a/telegram-bot-api/HttpServer.h +++ b/telegram-bot-api/HttpServer.h @@ -66,7 +66,7 @@ class HttpServer final : public td::TcpListener::Callback { scheduler_id--; } td::create_actor("HttpInboundConnection", td::BufferedFd(std::move(fd)), 0, - 20, 500, creator_(), scheduler_id) + 50, 500, creator_(), scheduler_id) .release(); } diff --git a/telegram-bot-api/WebhookActor.cpp b/telegram-bot-api/WebhookActor.cpp index e21e114..91b4e69 100644 --- a/telegram-bot-api/WebhookActor.cpp +++ b/telegram-bot-api/WebhookActor.cpp @@ -229,7 +229,7 @@ td::Status WebhookActor::create_connection(td::BufferedFd fd) { auto id = connections_.create(Connection()); auto *conn = connections_.get(id); conn->actor_id_ = td::create_actor( - PSLICE() << "Connect:" << id, std::move(fd), std::move(ssl_stream), 0, 20, 60, + PSLICE() << "Connect:" << id, std::move(fd), std::move(ssl_stream), 0, 50, 60, td::ActorShared(actor_id(this), id), slow_scheduler_id_); conn->ip_generation_ = ip_generation_; conn->event_id_ = {}; From 96e534bddceebe43324cf99a4aecf8660d2c5681 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 13:30:17 +0300 Subject: [PATCH 04/30] Rename "thumb" to "thumbnail". --- telegram-bot-api/Client.cpp | 99 ++++++++++++++++++++++--------------- telegram-bot-api/Client.h | 4 +- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 373e44a..b26d9cd 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -293,7 +293,8 @@ bool Client::init_methods() { methods_.emplace("uploadstickerfile", &Client::process_upload_sticker_file_query); methods_.emplace("createnewstickerset", &Client::process_create_new_sticker_set_query); methods_.emplace("addstickertoset", &Client::process_add_sticker_to_set_query); - methods_.emplace("setstickersetthumb", &Client::process_set_sticker_set_thumb_query); + methods_.emplace("setstickersetthumb", &Client::process_set_sticker_set_thumbnail_query); + methods_.emplace("setstickersetthumbnail", &Client::process_set_sticker_set_thumbnail_query); methods_.emplace("setstickerpositioninset", &Client::process_set_sticker_position_in_set_query); methods_.emplace("deletestickerfromset", &Client::process_delete_sticker_from_set_query); methods_.emplace("setpassportdataerrors", &Client::process_set_passport_data_errors_query); @@ -5879,10 +5880,13 @@ td_api::object_ptr Client::get_input_file(const Query *query, return nullptr; } -td_api::object_ptr Client::get_input_thumbnail(const Query *query, Slice field_name) const { - auto input_file = get_input_file(query, field_name, true); +td_api::object_ptr Client::get_input_thumbnail(const Query *query) const { + auto input_file = get_input_file(query, "thumbnail", true); if (input_file == nullptr) { - return nullptr; + input_file = get_input_file(query, "thumb", true); + if (input_file == nullptr) { + return nullptr; + } } return make_object(std::move(input_file), 0, 0); } @@ -6101,15 +6105,26 @@ td::Result> Client::get_inlin TRY_RESULT_ASSIGN(reply_markup, get_reply_markup(std::move(reply_markup_object))); } + auto thumbnail_url_field_name = Slice("thumbnail_url"); + auto thumbnail_width_field_name = Slice("thumbnail_width"); + auto thumbnail_height_field_name = Slice("thumbnail_height"); + if (!has_json_object_field(object, thumbnail_url_field_name) && + !has_json_object_field(object, thumbnail_width_field_name) && + !has_json_object_field(object, thumbnail_height_field_name)) { + thumbnail_url_field_name = Slice("thumb_url"); + thumbnail_width_field_name = Slice("thumb_width"); + thumbnail_height_field_name = Slice("thumb_height"); + } + TRY_RESULT(thumbnail_url, get_json_object_string_field(object, thumbnail_url_field_name)); + TRY_RESULT(thumbnail_width, get_json_object_int_field(object, thumbnail_width_field_name)); + TRY_RESULT(thumbnail_height, get_json_object_int_field(object, thumbnail_height_field_name)); + object_ptr result; if (type == "article") { TRY_RESULT(url, get_json_object_string_field(object, "url")); TRY_RESULT(hide_url, get_json_object_bool_field(object, "hide_url")); TRY_RESULT(title, get_json_object_string_field(object, "title", false)); TRY_RESULT(description, get_json_object_string_field(object, "description")); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url")); - TRY_RESULT(thumbnail_width, get_json_object_int_field(object, "thumb_width")); - TRY_RESULT(thumbnail_height, get_json_object_int_field(object, "thumb_height")); CHECK(input_message_content != nullptr); return make_object( @@ -6137,9 +6152,6 @@ td::Result> Client::get_inlin TRY_RESULT(first_name, get_json_object_string_field(object, "first_name", false)); TRY_RESULT(last_name, get_json_object_string_field(object, "last_name")); TRY_RESULT(vcard, get_json_object_string_field(object, "vcard")); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url")); - TRY_RESULT(thumbnail_width, get_json_object_int_field(object, "thumb_width")); - TRY_RESULT(thumbnail_height, get_json_object_int_field(object, "thumb_height")); if (input_message_content == nullptr) { input_message_content = make_object( @@ -6152,11 +6164,8 @@ td::Result> Client::get_inlin if (type == "document") { TRY_RESULT(title, get_json_object_string_field(object, "title", false)); TRY_RESULT(description, get_json_object_string_field(object, "description")); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url")); TRY_RESULT(document_url, get_json_object_string_field(object, "document_url")); TRY_RESULT(mime_type, get_json_object_string_field(object, "mime_type", document_url.empty())); - TRY_RESULT(thumbnail_width, get_json_object_int_field(object, "thumb_width")); - TRY_RESULT(thumbnail_height, get_json_object_int_field(object, "thumb_height")); if (document_url.empty()) { TRY_RESULT_ASSIGN(document_url, get_json_object_string_field(object, "document_file_id", false)); } @@ -6175,8 +6184,11 @@ td::Result> Client::get_inlin if (type == "gif") { TRY_RESULT(title, get_json_object_string_field(object, "title")); TRY_RESULT(gif_url, get_json_object_string_field(object, "gif_url")); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url", gif_url.empty())); - TRY_RESULT(thumbnail_mime_type, get_json_object_string_field(object, "thumb_mime_type", true)); + auto thumbnail_mime_type_field_name = Slice("thumbnail_mime_type"); + if (!has_json_object_field(object, thumbnail_mime_type_field_name)) { + thumbnail_mime_type_field_name = Slice("thumb_mime_type"); + } + TRY_RESULT(thumbnail_mime_type, get_json_object_string_field(object, thumbnail_mime_type_field_name)); TRY_RESULT(gif_duration, get_json_object_int_field(object, "gif_duration")); TRY_RESULT(gif_width, get_json_object_int_field(object, "gif_width")); TRY_RESULT(gif_height, get_json_object_int_field(object, "gif_height")); @@ -6200,9 +6212,6 @@ td::Result> Client::get_inlin TRY_RESULT(heading, get_json_object_int_field(object, "heading")); TRY_RESULT(proximity_alert_radius, get_json_object_int_field(object, "proximity_alert_radius")); TRY_RESULT(title, get_json_object_string_field(object, "title", false)); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url")); - TRY_RESULT(thumbnail_width, get_json_object_int_field(object, "thumb_width")); - TRY_RESULT(thumbnail_height, get_json_object_int_field(object, "thumb_height")); if (input_message_content == nullptr) { auto location = make_object(latitude, longitude, horizontal_accuracy); @@ -6216,8 +6225,11 @@ td::Result> Client::get_inlin if (type == "mpeg4_gif") { TRY_RESULT(title, get_json_object_string_field(object, "title")); TRY_RESULT(mpeg4_url, get_json_object_string_field(object, "mpeg4_url")); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url", mpeg4_url.empty())); - TRY_RESULT(thumbnail_mime_type, get_json_object_string_field(object, "thumb_mime_type", true)); + auto thumbnail_mime_type_field_name = Slice("thumbnail_mime_type"); + if (!has_json_object_field(object, thumbnail_mime_type_field_name)) { + thumbnail_mime_type_field_name = Slice("thumb_mime_type"); + } + TRY_RESULT(thumbnail_mime_type, get_json_object_string_field(object, thumbnail_mime_type_field_name)); TRY_RESULT(mpeg4_duration, get_json_object_int_field(object, "mpeg4_duration")); TRY_RESULT(mpeg4_width, get_json_object_int_field(object, "mpeg4_width")); TRY_RESULT(mpeg4_height, get_json_object_int_field(object, "mpeg4_height")); @@ -6237,7 +6249,6 @@ td::Result> Client::get_inlin TRY_RESULT(title, get_json_object_string_field(object, "title")); TRY_RESULT(description, get_json_object_string_field(object, "description")); TRY_RESULT(photo_url, get_json_object_string_field(object, "photo_url")); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url", photo_url.empty())); TRY_RESULT(photo_width, get_json_object_int_field(object, "photo_width")); TRY_RESULT(photo_height, get_json_object_int_field(object, "photo_height")); if (photo_url.empty()) { @@ -6271,9 +6282,6 @@ td::Result> Client::get_inlin TRY_RESULT(foursquare_type, get_json_object_string_field(object, "foursquare_type")); TRY_RESULT(google_place_id, get_json_object_string_field(object, "google_place_id")); TRY_RESULT(google_place_type, get_json_object_string_field(object, "google_place_type")); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url")); - TRY_RESULT(thumbnail_width, get_json_object_int_field(object, "thumb_width")); - TRY_RESULT(thumbnail_height, get_json_object_int_field(object, "thumb_height")); td::string provider; td::string venue_id; @@ -6304,7 +6312,6 @@ td::Result> Client::get_inlin TRY_RESULT(title, get_json_object_string_field(object, "title", false)); TRY_RESULT(description, get_json_object_string_field(object, "description")); TRY_RESULT(video_url, get_json_object_string_field(object, "video_url")); - TRY_RESULT(thumbnail_url, get_json_object_string_field(object, "thumb_url", video_url.empty())); TRY_RESULT(mime_type, get_json_object_string_field(object, "mime_type", video_url.empty())); TRY_RESULT(video_width, get_json_object_int_field(object, "video_width")); TRY_RESULT(video_height, get_json_object_int_field(object, "video_height")); @@ -7074,25 +7081,33 @@ td::Result> Client::get_input_me // TRY_RESULT(self_destruct_time, get_json_object_int_field(object, "self_destruct_time")); int32 self_destruct_time = 0; TRY_RESULT(has_spoiler, get_json_object_bool_field(object, "has_spoiler")); - TRY_RESULT(media, get_json_object_string_field(object, "media", true)); + TRY_RESULT(media, get_json_object_string_field(object, "media")); auto input_file = get_input_file(query, Slice(), media, false); if (input_file == nullptr) { return Status::Error("media not found"); } - TRY_RESULT(thumbnail, get_json_object_string_field(object, "thumb")); + TRY_RESULT(thumbnail, get_json_object_string_field(object, "thumbnail")); + if (thumbnail.empty()) { + TRY_RESULT_ASSIGN(thumbnail, get_json_object_string_field(object, "thumb")); + } + auto thumbnail_input_file = get_input_file(query, Slice(), thumbnail, true); + if (thumbnail_input_file == nullptr) { + thumbnail_input_file = get_input_file(query, "thumbnail", Slice(), true); + if (thumbnail_input_file == nullptr) { + thumbnail_input_file = get_input_file(query, "thumb", Slice(), true); + } + } object_ptr input_thumbnail; - auto thumbanil_input_file = get_input_file(query, thumbnail.empty() ? Slice("thumb") : Slice(), thumbnail, true); - if (thumbanil_input_file != nullptr) { - input_thumbnail = make_object(std::move(thumbanil_input_file), 0, 0); + if (thumbnail_input_file != nullptr) { + input_thumbnail = make_object(std::move(thumbnail_input_file), 0, 0); } TRY_RESULT(type, get_json_object_string_field(object, "type", false)); if (type == "photo") { - return make_object(std::move(input_file), std::move(input_thumbnail), - td::vector(), 0, 0, std::move(caption), self_destruct_time, - has_spoiler); + return make_object(std::move(input_file), nullptr, td::vector(), 0, 0, + std::move(caption), self_destruct_time, has_spoiler); } if (type == "video") { TRY_RESULT(width, get_json_object_int_field(object, "width")); @@ -7598,7 +7613,7 @@ td::Status Client::process_send_animation_query(PromisedQueryPtr &query) { if (animation == nullptr) { return Status::Error(400, "There is no animation in the request"); } - auto thumbnail = get_input_thumbnail(query.get(), "thumb"); + auto thumbnail = get_input_thumbnail(query.get()); int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); int32 width = get_integer_arg(query.get(), "width", 0, 0, MAX_LENGTH); int32 height = get_integer_arg(query.get(), "height", 0, 0, MAX_LENGTH); @@ -7616,7 +7631,7 @@ td::Status Client::process_send_audio_query(PromisedQueryPtr &query) { if (audio == nullptr) { return Status::Error(400, "There is no audio in the request"); } - auto thumbnail = get_input_thumbnail(query.get(), "thumb"); + auto thumbnail = get_input_thumbnail(query.get()); int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); auto title = query->arg("title").str(); auto performer = query->arg("performer").str(); @@ -7638,7 +7653,7 @@ td::Status Client::process_send_document_query(PromisedQueryPtr &query) { if (document == nullptr) { return Status::Error(400, "There is no document in the request"); } - auto thumbnail = get_input_thumbnail(query.get(), "thumb"); + auto thumbnail = get_input_thumbnail(query.get()); TRY_RESULT(caption, get_caption(query.get())); bool disable_content_type_detection = to_bool(query->arg("disable_content_type_detection")); do_send_message(make_object(std::move(document), std::move(thumbnail), @@ -7676,7 +7691,7 @@ td::Status Client::process_send_video_query(PromisedQueryPtr &query) { if (video == nullptr) { return Status::Error(400, "There is no video in the request"); } - auto thumbnail = get_input_thumbnail(query.get(), "thumb"); + auto thumbnail = get_input_thumbnail(query.get()); int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); int32 width = get_integer_arg(query.get(), "width", 0, 0, MAX_LENGTH); int32 height = get_integer_arg(query.get(), "height", 0, 0, MAX_LENGTH); @@ -7696,7 +7711,7 @@ td::Status Client::process_send_video_note_query(PromisedQueryPtr &query) { if (video_note == nullptr) { return Status::Error(400, "There is no video note in the request"); } - auto thumbnail = get_input_thumbnail(query.get(), "thumb"); + auto thumbnail = get_input_thumbnail(query.get()); int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); int32 length = get_integer_arg(query.get(), "length", 0, 0, MAX_LENGTH); do_send_message( @@ -9050,10 +9065,13 @@ td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) { return Status::OK(); } -td::Status Client::process_set_sticker_set_thumb_query(PromisedQueryPtr &query) { +td::Status Client::process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); auto name = query->arg("name"); - auto thumbnail = get_input_file(query.get(), "thumb"); + auto thumbnail = get_input_file(query.get(), "thumbnail"); + if (thumbnail == nullptr) { + thumbnail = get_input_file(query.get(), "thumb"); + } check_user(user_id, std::move(query), [this, user_id, name, thumbnail = std::move(thumbnail)](PromisedQueryPtr query) mutable { send_request(make_object(user_id, name.str(), std::move(thumbnail)), @@ -10074,6 +10092,7 @@ void Client::json_store_thumbnail(td::JsonObjectScope &object, const td_api::thu } CHECK(thumbnail->file_->id_ > 0); + object("thumbnail", JsonThumbnail(thumbnail, this)); object("thumb", JsonThumbnail(thumbnail, this)); } diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 5b1feb4..d010864 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -356,7 +356,7 @@ class Client final : public WebhookActor::Callback { object_ptr get_input_file(const Query *query, Slice field_name, Slice file_id, bool force_file) const; - object_ptr get_input_thumbnail(const Query *query, Slice field_name) const; + object_ptr get_input_thumbnail(const Query *query) const; td::Result> get_inline_query_result(const Query *query); @@ -569,7 +569,7 @@ class Client final : public WebhookActor::Callback { Status process_upload_sticker_file_query(PromisedQueryPtr &query); Status process_create_new_sticker_set_query(PromisedQueryPtr &query); Status process_add_sticker_to_set_query(PromisedQueryPtr &query); - Status process_set_sticker_set_thumb_query(PromisedQueryPtr &query); + Status process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query); Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); Status process_set_passport_data_errors_query(PromisedQueryPtr &query); From 3be3dfedf62568e23e3addcc4feea976f49c3203 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 13:37:27 +0300 Subject: [PATCH 05/30] Add "needs_repainting" parameter in createNewStickerSet. --- telegram-bot-api/Client.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index b26d9cd..0afbf90 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -9032,6 +9032,7 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) TRY_RESULT(user_id, get_user_id(query.get())); auto name = query->arg("name"); auto title = query->arg("title"); + auto needs_repainting = to_bool(query->arg("needs_repainting")); object_ptr sticker_format; TRY_RESULT(stickers, get_input_stickers(query.get(), &sticker_format)); @@ -9040,14 +9041,15 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) sticker_type = make_object(); } - check_user(user_id, std::move(query), - [this, user_id, title, name, sticker_format = std::move(sticker_format), - sticker_type = std::move(sticker_type), stickers = std::move(stickers)](PromisedQueryPtr query) mutable { - send_request(make_object( - user_id, title.str(), name.str(), std::move(sticker_format), std::move(sticker_type), - false, std::move(stickers), PSTRING() << "bot" << my_id_), - td::make_unique(this, false, std::move(query))); - }); + check_user( + user_id, std::move(query), + [this, user_id, title, name, sticker_format = std::move(sticker_format), sticker_type = std::move(sticker_type), + needs_repainting, stickers = std::move(stickers)](PromisedQueryPtr query) mutable { + send_request(make_object( + user_id, title.str(), name.str(), std::move(sticker_format), std::move(sticker_type), + needs_repainting, std::move(stickers), PSTRING() << "bot" << my_id_), + td::make_unique(this, false, std::move(query))); + }); return Status::OK(); } From 1da3d34299061e32cd28731bef183f9a67b3aed3 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 14:07:38 +0300 Subject: [PATCH 06/30] Add Sticker.needs_repainting. --- telegram-bot-api/Client.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 0afbf90..bf04948 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -1118,6 +1118,9 @@ class Client::JsonSticker final : public Jsonable { if (full_type->custom_emoji_id_ != 0) { object("custom_emoji_id", td::to_string(full_type->custom_emoji_id_)); } + if (full_type->needs_repainting_) { + object("needs_repainting", td::JsonBool(full_type->needs_repainting_)); + } break; } default: From d0b5abfc466a164869432d533927e541b2af66b4 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 14:26:42 +0300 Subject: [PATCH 07/30] Support InputSticker in addStickerToSet. --- telegram-bot-api/Client.cpp | 93 +++++++++++++++++++++++++++++++++++-- telegram-bot-api/Client.h | 8 ++++ 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index bf04948..2b00cfe 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -15,6 +15,7 @@ #include "td/utils/algorithm.h" #include "td/utils/base64.h" +#include "td/utils/emoji.h" #include "td/utils/filesystem.h" #include "td/utils/HttpUrl.h" #include "td/utils/JsonBuilder.h" @@ -6548,6 +6549,9 @@ td::Result> Client::get_chat td::Result> Client::get_mask_position(JsonValue &&value) { if (value.type() != JsonValue::Type::Object) { + if (value.type() == JsonValue::Type::Null) { + return nullptr; + } return Status::Error(400, "MaskPosition must be an Object"); } @@ -6625,6 +6629,90 @@ td::Result> Client::get_mask_position(c return r_mask_position.move_as_ok(); } +td::Result Client::get_sticker_emojis(JsonValue &&value) { + td::string result; + auto emoji_count = value.get_array().size(); + if (emoji_count == 0) { + return Status::Error(400, "emoji list must be non-empty"); + } + if (emoji_count > MAX_STICKER_EMOJI_COUNT) { + return Status::Error(400, "too many emoji specified"); + } + for (auto &emoji : value.get_array()) { + if (emoji.type() != JsonValue::Type::String) { + return Status::Error(400, "emoji must be a string"); + } + if (!td::is_emoji(emoji.get_string())) { + return Status::Error(400, "expected a Unicode emoji"); + } + result += emoji.get_string().str(); + } + return std::move(result); +} + +td::Result> Client::get_input_sticker(const Query *query, + JsonValue &&value) const { + if (value.type() != JsonValue::Type::Object) { + return Status::Error(400, "InputSticker must be an Object"); + } + + auto &object = value.get_object(); + + TRY_RESULT(sticker, get_json_object_string_field(object, "sticker")); + auto input_file = get_input_file(query, Slice(), sticker, false); + if (input_file == nullptr) { + return Status::Error("sticker not found"); + } + TRY_RESULT(emoji_list, get_json_object_field(object, "emoji_list", JsonValue::Type::Array, false)); + TRY_RESULT(emojis, get_sticker_emojis(std::move(emoji_list))); + TRY_RESULT(mask_position, get_mask_position(get_json_object_field_force(object, "mask_position"))); + return make_object(std::move(input_file), emojis, std::move(mask_position), + td::vector()); +} + +td::Result> Client::get_input_sticker(const Query *query) const { + if (query->has_arg("sticker") || query->file("sticker") != nullptr) { + auto sticker = query->arg("sticker"); + LOG(INFO) << "Parsing JSON object: " << sticker; + auto r_value = json_decode(sticker); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return Status::Error(400, "Can't parse sticker JSON object"); + } + + auto r_sticker = get_input_sticker(query, r_value.move_as_ok()); + if (r_sticker.is_error()) { + return Status::Error(400, PSLICE() << "Can't parse sticker: " << r_sticker.error().message()); + } + return r_sticker.move_as_ok(); + } + + auto emojis = query->arg("emojis"); + + auto sticker = get_input_file(query, "png_sticker"); + object_ptr mask_position; + if (sticker != nullptr) { + TRY_RESULT_ASSIGN(mask_position, get_mask_position(query, "mask_position")); + } else { + sticker = get_input_file(query, "tgs_sticker", true); + if (sticker == nullptr) { + sticker = get_input_file(query, "webm_sticker", true); + if (sticker == nullptr) { + if (!query->arg("tgs_sticker").empty()) { + return Status::Error(400, "Bad Request: animated sticker must be uploaded as an InputFile"); + } + if (!query->arg("webm_sticker").empty()) { + return Status::Error(400, "Bad Request: video sticker must be uploaded as an InputFile"); + } + return Status::Error(400, "Bad Request: there is no sticker file in the request"); + } + } + } + + return make_object(std::move(sticker), emojis.str(), std::move(mask_position), + td::vector()); +} + td::Result>> Client::get_input_stickers( const Query *query, object_ptr *sticker_format) const { auto emojis = query->arg("emojis"); @@ -9059,11 +9147,10 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); auto name = query->arg("name"); - TRY_RESULT(stickers, get_input_stickers(query.get(), nullptr)); - CHECK(!stickers.empty()); + TRY_RESULT(sticker, get_input_sticker(query.get())); check_user(user_id, std::move(query), - [this, user_id, name, sticker = std::move(stickers[0])](PromisedQueryPtr query) mutable { + [this, user_id, name, sticker = std::move(sticker)](PromisedQueryPtr query) mutable { send_request(make_object(user_id, name.str(), std::move(sticker)), td::make_unique(std::move(query))); }); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index d010864..86ae0b4 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -86,6 +86,8 @@ class Client final : public WebhookActor::Callback { static constexpr int32 MAX_LENGTH = 10000; // max width or height static constexpr int32 MAX_DURATION = 24 * 60 * 60; + static constexpr std::size_t MAX_STICKER_EMOJI_COUNT = 20; + class JsonEmptyObject; class JsonFile; class JsonDatedFile; @@ -401,6 +403,12 @@ class Client final : public WebhookActor::Callback { static object_ptr mask_index_to_point(int32 index); + static td::Result get_sticker_emojis(td::JsonValue &&value); + + td::Result> get_input_sticker(const Query *query) const; + + td::Result> get_input_sticker(const Query *query, td::JsonValue &&value) const; + td::Result>> get_input_stickers( const Query *query, object_ptr *sticker_format) const; From a1d7c768bbcf9db193b51673743d7a2d8507bf9c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 16:34:10 +0300 Subject: [PATCH 08/30] Aloow to specify up to 50 stickers in createNewStickerSet. --- telegram-bot-api/Client.cpp | 60 ++++++++++++++++++++++++++++++------- telegram-bot-api/Client.h | 4 ++- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 2b00cfe..a2c6788 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -6650,6 +6650,19 @@ td::Result Client::get_sticker_emojis(JsonValue &&value) { return std::move(result); } +td::Result> Client::get_sticker_format(Slice sticker_format) { + if (sticker_format == "static") { + return make_object(); + } + if (sticker_format == "animated") { + return make_object(); + } + if (sticker_format == "video") { + return make_object(); + } + return Status::Error(400, "Invalid sticker format specified"); +} + td::Result> Client::get_input_sticker(const Query *query, JsonValue &&value) const { if (value.type() != JsonValue::Type::Object) { @@ -6714,28 +6727,53 @@ td::Result> Client::get_input_sticker(c } td::Result>> Client::get_input_stickers( - const Query *query, object_ptr *sticker_format) const { + const Query *query, object_ptr &sticker_format) const { + if (query->has_arg("stickers")) { + TRY_RESULT_ASSIGN(sticker_format, get_sticker_format(query->arg("sticker_format"))); + auto stickers = query->arg("stickers"); + LOG(INFO) << "Parsing JSON object: " << stickers; + auto r_value = json_decode(stickers); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return Status::Error(400, "Can't parse stickers JSON object"); + } + auto value = r_value.move_as_ok(); + + if (value.type() != JsonValue::Type::Array) { + return Status::Error(400, "Expected an Array of InputSticker"); + } + + constexpr std::size_t MAX_STICKER_COUNT = 50; + if (value.get_array().size() > MAX_STICKER_COUNT) { + return Status::Error(400, "Too many stickers specified"); + } + + td::vector> input_stickers; + for (auto &input_sticker : value.get_array()) { + auto r_input_sticker = get_input_sticker(query, std::move(input_sticker)); + if (r_input_sticker.is_error()) { + return Status::Error(400, PSLICE() << "Can't parse InputSticker: " << r_input_sticker.error().message()); + } + input_stickers.push_back(r_input_sticker.move_as_ok()); + } + return std::move(input_stickers); + } + auto emojis = query->arg("emojis"); auto sticker = get_input_file(query, "png_sticker"); object_ptr mask_position; if (sticker != nullptr) { - if (sticker_format != nullptr) { - *sticker_format = make_object(); - } + sticker_format = make_object(); TRY_RESULT_ASSIGN(mask_position, get_mask_position(query, "mask_position")); } else { sticker = get_input_file(query, "tgs_sticker", true); if (sticker != nullptr) { - if (sticker_format != nullptr) { - *sticker_format = make_object(); - } + sticker_format = make_object(); } else { sticker = get_input_file(query, "webm_sticker", true); if (sticker != nullptr) { - if (sticker_format != nullptr) { - *sticker_format = make_object(); - } + sticker_format = make_object(); } else { if (!query->arg("tgs_sticker").empty()) { return Status::Error(400, "Bad Request: animated sticker must be uploaded as an InputFile"); @@ -9125,7 +9163,7 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) auto title = query->arg("title"); auto needs_repainting = to_bool(query->arg("needs_repainting")); object_ptr sticker_format; - TRY_RESULT(stickers, get_input_stickers(query.get(), &sticker_format)); + TRY_RESULT(stickers, get_input_stickers(query.get(), sticker_format)); TRY_RESULT(sticker_type, get_sticker_type(query->arg("sticker_type"))); if (to_bool(query->arg("contains_masks"))) { diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 86ae0b4..efe8f9e 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -405,12 +405,14 @@ class Client final : public WebhookActor::Callback { static td::Result get_sticker_emojis(td::JsonValue &&value); + static td::Result> get_sticker_format(Slice sticker_format); + td::Result> get_input_sticker(const Query *query) const; td::Result> get_input_sticker(const Query *query, td::JsonValue &&value) const; td::Result>> get_input_stickers( - const Query *query, object_ptr *sticker_format) const; + const Query *query, object_ptr &sticker_format) const; static td::Result get_passport_element_hash(Slice encoded_hash); From d3898d9b7f67ccecaf057e80e6725377696af0b9 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 16:46:05 +0300 Subject: [PATCH 09/30] Allow to preupload animated and video stickers. --- telegram-bot-api/Client.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index a2c6788..ef6b549 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -9146,13 +9146,22 @@ td::Status Client::process_get_custom_emoji_stickers_query(PromisedQueryPtr &que td::Status Client::process_upload_sticker_file_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); - auto png_sticker = get_input_file(query.get(), "png_sticker"); + object_ptr sticker_format; + td_api::object_ptr sticker; + if (query->has_arg("sticker") || query->file("sticker") != nullptr) { + TRY_RESULT_ASSIGN(sticker_format, get_sticker_format(query->arg("sticker_format"))); + sticker = get_input_file(query.get(), "sticker", true); + } else { + sticker_format = make_object(); + sticker = get_input_file(query.get(), "png_sticker", true); + } check_user(user_id, std::move(query), - [this, user_id, png_sticker = std::move(png_sticker)](PromisedQueryPtr query) mutable { - send_request(make_object(user_id, make_object(), - std::move(png_sticker)), - td::make_unique(this, std::move(query))); + [this, user_id, sticker_format = std::move(sticker_format), + sticker = std::move(sticker)](PromisedQueryPtr query) mutable { + send_request( + make_object(user_id, std::move(sticker_format), std::move(sticker)), + td::make_unique(this, std::move(query))); }); return Status::OK(); } From 84e6f5fa1d0646978d9aa75676aa4d887b018c7f Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 17:13:19 +0300 Subject: [PATCH 10/30] Support keywords in InputSticker. --- telegram-bot-api/Client.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index ef6b549..a699d4a 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -6679,8 +6679,18 @@ td::Result> Client::get_input_sticker(c TRY_RESULT(emoji_list, get_json_object_field(object, "emoji_list", JsonValue::Type::Array, false)); TRY_RESULT(emojis, get_sticker_emojis(std::move(emoji_list))); TRY_RESULT(mask_position, get_mask_position(get_json_object_field_force(object, "mask_position"))); + td::vector input_keywords; + if (has_json_object_field(object, "keywords")) { + TRY_RESULT(keywords, get_json_object_field(object, "keywords", JsonValue::Type::Array, false)); + for (auto &keyword : keywords.get_array()) { + if (keyword.type() != JsonValue::Type::String) { + return Status::Error(400, "keyword must be a string"); + } + input_keywords.push_back(keyword.get_string().str()); + } + } return make_object(std::move(input_file), emojis, std::move(mask_position), - td::vector()); + std::move(input_keywords)); } td::Result> Client::get_input_sticker(const Query *query) const { From 0c7a7236eb9a0e4177edd8351623988c783ce130 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 17:26:31 +0300 Subject: [PATCH 11/30] Add setCustomEmojiStickerSetThumbnail. --- telegram-bot-api/Client.cpp | 9 +++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 10 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index a699d4a..eab2cf8 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -296,6 +296,7 @@ bool Client::init_methods() { methods_.emplace("addstickertoset", &Client::process_add_sticker_to_set_query); methods_.emplace("setstickersetthumb", &Client::process_set_sticker_set_thumbnail_query); methods_.emplace("setstickersetthumbnail", &Client::process_set_sticker_set_thumbnail_query); + methods_.emplace("setcustomemojistickersetthumbnail", &Client::process_set_custom_emoji_sticker_set_thumbnail_query); methods_.emplace("setstickerpositioninset", &Client::process_set_sticker_position_in_set_query); methods_.emplace("deletestickerfromset", &Client::process_delete_sticker_from_set_query); methods_.emplace("setpassportdataerrors", &Client::process_set_passport_data_errors_query); @@ -9229,6 +9230,14 @@ td::Status Client::process_set_sticker_set_thumbnail_query(PromisedQueryPtr &que return Status::OK(); } +td::Status Client::process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query) { + auto name = query->arg("name"); + auto custom_emoji_id = td::to_integer(query->arg("custom_emoji_id")); + send_request(make_object(name.str(), custom_emoji_id), + td::make_unique(std::move(query))); + return Status::OK(); +} + td::Status Client::process_set_sticker_position_in_set_query(PromisedQueryPtr &query) { auto file_id = trim(query->arg("sticker")); if (file_id.empty()) { diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index efe8f9e..f177c4e 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -580,6 +580,7 @@ class Client final : public WebhookActor::Callback { Status process_create_new_sticker_set_query(PromisedQueryPtr &query); Status process_add_sticker_to_set_query(PromisedQueryPtr &query); Status process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query); + Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query); Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); Status process_set_passport_data_errors_query(PromisedQueryPtr &query); From 401894a53bff2865afcdd3178b723551c3f81df2 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 17:30:50 +0300 Subject: [PATCH 12/30] Add setStickerSetTitle. --- telegram-bot-api/Client.cpp | 9 +++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 10 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index eab2cf8..a5873df 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -294,6 +294,7 @@ bool Client::init_methods() { methods_.emplace("uploadstickerfile", &Client::process_upload_sticker_file_query); methods_.emplace("createnewstickerset", &Client::process_create_new_sticker_set_query); methods_.emplace("addstickertoset", &Client::process_add_sticker_to_set_query); + methods_.emplace("setstickersettitle", &Client::process_set_sticker_set_title_query); methods_.emplace("setstickersetthumb", &Client::process_set_sticker_set_thumbnail_query); methods_.emplace("setstickersetthumbnail", &Client::process_set_sticker_set_thumbnail_query); methods_.emplace("setcustomemojistickersetthumbnail", &Client::process_set_custom_emoji_sticker_set_thumbnail_query); @@ -9215,6 +9216,14 @@ td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) { return Status::OK(); } +td::Status Client::process_set_sticker_set_title_query(PromisedQueryPtr &query) { + auto name = query->arg("name"); + auto title = query->arg("title"); + send_request(make_object(name.str(), title.str()), + td::make_unique(std::move(query))); + return Status::OK(); +} + td::Status Client::process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); auto name = query->arg("name"); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index f177c4e..99f2d5e 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -579,6 +579,7 @@ class Client final : public WebhookActor::Callback { Status process_upload_sticker_file_query(PromisedQueryPtr &query); Status process_create_new_sticker_set_query(PromisedQueryPtr &query); Status process_add_sticker_to_set_query(PromisedQueryPtr &query); + Status process_set_sticker_set_title_query(PromisedQueryPtr &query); Status process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query); Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query); Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); From bb5f3651b2372680082757d64a2804cc35259566 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 17:40:32 +0300 Subject: [PATCH 13/30] Add Client::get_sticker_input_file. --- telegram-bot-api/Client.cpp | 25 +++++++++++++------------ telegram-bot-api/Client.h | 2 ++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index a5873df..dc185bb 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -6804,6 +6804,14 @@ td::Result>> Client::get_inp return std::move(stickers); } +td::Result> Client::get_sticker_input_file(const Query *query) { + auto file_id = trim(query->arg("sticker")); + if (file_id.empty()) { + return Status::Error(400, "Sticker is not specified"); + } + return make_object(file_id.str()); +} + td::Result Client::get_passport_element_hash(Slice encoded_hash) { if (!td::is_base64(encoded_hash)) { return Status::Error(400, "hash isn't a valid base64-encoded string"); @@ -9248,25 +9256,18 @@ td::Status Client::process_set_custom_emoji_sticker_set_thumbnail_query(Promised } td::Status Client::process_set_sticker_position_in_set_query(PromisedQueryPtr &query) { - auto file_id = trim(query->arg("sticker")); - if (file_id.empty()) { - return Status::Error(400, "Sticker is not specified"); - } + TRY_RESULT(input_file, get_sticker_input_file(query.get())); int32 position = get_integer_arg(query.get(), "position", -1); - send_request( - make_object(make_object(file_id.str()), position), - td::make_unique(std::move(query))); + send_request(make_object(std::move(input_file), position), + td::make_unique(std::move(query))); return Status::OK(); } td::Status Client::process_delete_sticker_from_set_query(PromisedQueryPtr &query) { - auto file_id = trim(query->arg("sticker")); - if (file_id.empty()) { - return Status::Error(400, "Sticker is not specified"); - } + TRY_RESULT(input_file, get_sticker_input_file(query.get())); - send_request(make_object(make_object(file_id.str())), + send_request(make_object(std::move(input_file)), td::make_unique(std::move(query))); return Status::OK(); } diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 99f2d5e..e9b24eb 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -414,6 +414,8 @@ class Client final : public WebhookActor::Callback { td::Result>> get_input_stickers( const Query *query, object_ptr &sticker_format) const; + static td::Result> get_sticker_input_file(const Query *query); + static td::Result get_passport_element_hash(Slice encoded_hash); static td::Result> get_passport_element_error_source( From c48dfe5d4dd646c445f5a6ee2ae1214909d03786 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 17:43:08 +0300 Subject: [PATCH 14/30] Add setStickerEmojiList. --- telegram-bot-api/Client.cpp | 29 +++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index dc185bb..47d0d11 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -300,6 +300,7 @@ bool Client::init_methods() { methods_.emplace("setcustomemojistickersetthumbnail", &Client::process_set_custom_emoji_sticker_set_thumbnail_query); methods_.emplace("setstickerpositioninset", &Client::process_set_sticker_position_in_set_query); methods_.emplace("deletestickerfromset", &Client::process_delete_sticker_from_set_query); + methods_.emplace("setstickeremojilist", &Client::process_set_sticker_emoji_list_query); methods_.emplace("setpassportdataerrors", &Client::process_set_passport_data_errors_query); methods_.emplace("sendcustomrequest", &Client::process_send_custom_request_query); methods_.emplace("answercustomquery", &Client::process_answer_custom_query_query); @@ -6632,6 +6633,10 @@ td::Result> Client::get_mask_position(c } td::Result Client::get_sticker_emojis(JsonValue &&value) { + if (value.type() != JsonValue::Type::Array) { + return Status::Error(400, "expected an Array of string"); + } + td::string result; auto emoji_count = value.get_array().size(); if (emoji_count == 0) { @@ -6652,6 +6657,21 @@ td::Result Client::get_sticker_emojis(JsonValue &&value) { return std::move(result); } +td::Result Client::get_sticker_emojis(td::MutableSlice emoji_list) { + LOG(INFO) << "Parsing JSON object: " << emoji_list; + auto r_value = json_decode(emoji_list); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return Status::Error(400, "Can't parse emoji list JSON array"); + } + + auto r_emojis = get_sticker_emojis(r_value.move_as_ok()); + if (r_emojis.is_error()) { + return Status::Error(400, PSLICE() << "Can't parse emoji list: " << r_emojis.error().message()); + } + return r_emojis.move_as_ok(); +} + td::Result> Client::get_sticker_format(Slice sticker_format) { if (sticker_format == "static") { return make_object(); @@ -9272,6 +9292,15 @@ td::Status Client::process_delete_sticker_from_set_query(PromisedQueryPtr &query return Status::OK(); } +td::Status Client::process_set_sticker_emoji_list_query(PromisedQueryPtr &query) { + TRY_RESULT(input_file, get_sticker_input_file(query.get())); + TRY_RESULT(emojis, get_sticker_emojis(query->arg("emoji_list"))); + + send_request(make_object(std::move(input_file), emojis), + td::make_unique(std::move(query))); + return Status::OK(); +} + td::Status Client::process_set_passport_data_errors_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); TRY_RESULT(passport_element_errors, get_passport_element_errors(query.get())); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index e9b24eb..c3eadd7 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -405,6 +405,8 @@ class Client final : public WebhookActor::Callback { static td::Result get_sticker_emojis(td::JsonValue &&value); + static td::Result get_sticker_emojis(td::MutableSlice emoji_list); + static td::Result> get_sticker_format(Slice sticker_format); td::Result> get_input_sticker(const Query *query) const; @@ -586,6 +588,7 @@ class Client final : public WebhookActor::Callback { Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query); Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); + Status process_set_sticker_emoji_list_query(PromisedQueryPtr &query); Status process_set_passport_data_errors_query(PromisedQueryPtr &query); Status process_send_custom_request_query(PromisedQueryPtr &query); Status process_answer_custom_query_query(PromisedQueryPtr &query); From 116e7aab247f5b3cd46f048aae1a07865f443993 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 17:54:59 +0300 Subject: [PATCH 15/30] Add setStickerKeywords. --- telegram-bot-api/Client.cpp | 28 ++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 29 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 47d0d11..42e1a72 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -301,6 +301,7 @@ bool Client::init_methods() { methods_.emplace("setstickerpositioninset", &Client::process_set_sticker_position_in_set_query); methods_.emplace("deletestickerfromset", &Client::process_delete_sticker_from_set_query); methods_.emplace("setstickeremojilist", &Client::process_set_sticker_emoji_list_query); + methods_.emplace("setstickerkeywords", &Client::process_set_sticker_keywords_query); methods_.emplace("setpassportdataerrors", &Client::process_set_passport_data_errors_query); methods_.emplace("sendcustomrequest", &Client::process_send_custom_request_query); methods_.emplace("answercustomquery", &Client::process_answer_custom_query_query); @@ -9301,6 +9302,33 @@ td::Status Client::process_set_sticker_emoji_list_query(PromisedQueryPtr &query) return Status::OK(); } +td::Status Client::process_set_sticker_keywords_query(PromisedQueryPtr &query) { + TRY_RESULT(input_file, get_sticker_input_file(query.get())); + td::vector input_keywords; + if (query->has_arg("keywords")) { + auto r_value = json_decode(query->arg("keywords")); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return Status::Error(400, "Can't parse keywords JSON object"); + } + auto value = r_value.move_as_ok(); + + if (value.type() != JsonValue::Type::Array) { + return Status::Error(400, "Field \"keywords\" must be an Array"); + } + for (auto &keyword : value.get_array()) { + if (keyword.type() != JsonValue::Type::String) { + return Status::Error(400, "keyword must be a string"); + } + input_keywords.push_back(keyword.get_string().str()); + } + } + + send_request(make_object(std::move(input_file), std::move(input_keywords)), + td::make_unique(std::move(query))); + return Status::OK(); +} + td::Status Client::process_set_passport_data_errors_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); TRY_RESULT(passport_element_errors, get_passport_element_errors(query.get())); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index c3eadd7..b623bfb 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -589,6 +589,7 @@ class Client final : public WebhookActor::Callback { Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); Status process_set_sticker_emoji_list_query(PromisedQueryPtr &query); + Status process_set_sticker_keywords_query(PromisedQueryPtr &query); Status process_set_passport_data_errors_query(PromisedQueryPtr &query); Status process_send_custom_request_query(PromisedQueryPtr &query); Status process_answer_custom_query_query(PromisedQueryPtr &query); From 64591671fce25c7ebfd56a5d9ddc3fc726b80a35 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 18:04:47 +0300 Subject: [PATCH 16/30] Add getStickerMaskPosition. --- telegram-bot-api/Client.cpp | 10 ++++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 11 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 42e1a72..aacfecc 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -302,6 +302,7 @@ bool Client::init_methods() { methods_.emplace("deletestickerfromset", &Client::process_delete_sticker_from_set_query); methods_.emplace("setstickeremojilist", &Client::process_set_sticker_emoji_list_query); methods_.emplace("setstickerkeywords", &Client::process_set_sticker_keywords_query); + methods_.emplace("setstickermaskposition", &Client::process_set_sticker_mask_position_query); methods_.emplace("setpassportdataerrors", &Client::process_set_passport_data_errors_query); methods_.emplace("sendcustomrequest", &Client::process_send_custom_request_query); methods_.emplace("answercustomquery", &Client::process_answer_custom_query_query); @@ -9329,6 +9330,15 @@ td::Status Client::process_set_sticker_keywords_query(PromisedQueryPtr &query) { return Status::OK(); } +td::Status Client::process_set_sticker_mask_position_query(PromisedQueryPtr &query) { + TRY_RESULT(input_file, get_sticker_input_file(query.get())); + TRY_RESULT(mask_position, get_mask_position(query.get(), "mask_position")); + + send_request(make_object(std::move(input_file), std::move(mask_position)), + td::make_unique(std::move(query))); + return Status::OK(); +} + td::Status Client::process_set_passport_data_errors_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); TRY_RESULT(passport_element_errors, get_passport_element_errors(query.get())); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index b623bfb..1876251 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -590,6 +590,7 @@ class Client final : public WebhookActor::Callback { Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); Status process_set_sticker_emoji_list_query(PromisedQueryPtr &query); Status process_set_sticker_keywords_query(PromisedQueryPtr &query); + Status process_set_sticker_mask_position_query(PromisedQueryPtr &query); Status process_set_passport_data_errors_query(PromisedQueryPtr &query); Status process_send_custom_request_query(PromisedQueryPtr &query); Status process_answer_custom_query_query(PromisedQueryPtr &query); From b38ce2a79d9890eec38d76233eed519631c81b1e Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 16 Feb 2023 16:27:58 +0300 Subject: [PATCH 17/30] Add deleteStickerSet. --- telegram-bot-api/Client.cpp | 8 ++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 9 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index aacfecc..32771a3 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -298,6 +298,7 @@ bool Client::init_methods() { methods_.emplace("setstickersetthumb", &Client::process_set_sticker_set_thumbnail_query); methods_.emplace("setstickersetthumbnail", &Client::process_set_sticker_set_thumbnail_query); methods_.emplace("setcustomemojistickersetthumbnail", &Client::process_set_custom_emoji_sticker_set_thumbnail_query); + methods_.emplace("deletestickerset", &Client::process_delete_sticker_set_query); methods_.emplace("setstickerpositioninset", &Client::process_set_sticker_position_in_set_query); methods_.emplace("deletestickerfromset", &Client::process_delete_sticker_from_set_query); methods_.emplace("setstickeremojilist", &Client::process_set_sticker_emoji_list_query); @@ -9277,6 +9278,13 @@ td::Status Client::process_set_custom_emoji_sticker_set_thumbnail_query(Promised return Status::OK(); } +td::Status Client::process_delete_sticker_set_query(PromisedQueryPtr &query) { + auto name = query->arg("name"); + send_request(make_object(name.str()), + td::make_unique(std::move(query))); + return Status::OK(); +} + td::Status Client::process_set_sticker_position_in_set_query(PromisedQueryPtr &query) { TRY_RESULT(input_file, get_sticker_input_file(query.get())); int32 position = get_integer_arg(query.get(), "position", -1); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 1876251..ecf07b5 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -586,6 +586,7 @@ class Client final : public WebhookActor::Callback { Status process_set_sticker_set_title_query(PromisedQueryPtr &query); Status process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query); Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query); + Status process_delete_sticker_set_query(PromisedQueryPtr &query); Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); Status process_set_sticker_emoji_list_query(PromisedQueryPtr &query); From f24dca312fc657e9aacc47343f0f1779a96d2b13 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Feb 2023 19:40:25 +0300 Subject: [PATCH 18/30] Remove using for td::Status and td::Slice. --- telegram-bot-api/Client.cpp | 810 ++++++++++++++++++------------------ telegram-bot-api/Client.h | 294 +++++++------ 2 files changed, 556 insertions(+), 548 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 32771a3..5fc8a3f 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -43,8 +43,8 @@ using td::JsonValueScope; using td_api::make_object; using td_api::move_object_as; -int Client::get_retry_after_time(Slice error_message) { - Slice prefix = "Too Many Requests: retry after "; +int Client::get_retry_after_time(td::Slice error_message) { + td::Slice prefix = "Too Many Requests: retry after "; if (begins_with(error_message, prefix)) { auto r_retry_after = td::to_integer_safe(error_message.substr(prefix.size())); if (r_retry_after.is_ok() && r_retry_after.ok() > 0) { @@ -54,8 +54,8 @@ int Client::get_retry_after_time(Slice error_message) { return 0; } -void Client::fail_query_with_error(PromisedQueryPtr query, int32 error_code, Slice error_message, - Slice default_message) { +void Client::fail_query_with_error(PromisedQueryPtr query, int32 error_code, td::Slice error_message, + td::Slice default_message) { if (error_code == 429) { auto retry_after_time = get_retry_after_time(error_message); if (retry_after_time > 0) { @@ -65,7 +65,7 @@ void Client::fail_query_with_error(PromisedQueryPtr query, int32 error_code, Sli return fail_query(500, error_message, std::move(query)); } int32 real_error_code = error_code; - Slice real_error_message = error_message; + td::Slice real_error_message = error_message; if (error_code < 400 || error_code == 404) { if (error_code < 200) { LOG(ERROR) << "Receive error \"" << real_error_message << "\" with code " << error_code << " from " << *query; @@ -91,7 +91,7 @@ void Client::fail_query_with_error(PromisedQueryPtr query, int32 error_code, Sli error_message = default_message; } if (error_message == "MESSAGE_NOT_MODIFIED") { - error_message = Slice( + error_message = td::Slice( "message is not modified: specified new message content and reply markup are exactly the same as a current " "content and reply markup of the message"); } else if (error_message == "WC_CONVERT_URL_INVALID" || error_message == "EXTERNAL_URL_INVALID") { @@ -103,53 +103,53 @@ void Client::fail_query_with_error(PromisedQueryPtr query, int32 error_code, Sli } else if (error_message == "MEDIA_GROUPED_INVALID") { error_message = "Can't use the media of the specified type in the album"; } else if (error_message == "REPLY_MARKUP_TOO_LONG") { - error_message = Slice("reply markup is too long"); + error_message = td::Slice("reply markup is too long"); } else if (error_message == "INPUT_USER_DEACTIVATED") { error_code = 403; - error_message = Slice("Forbidden: user is deactivated"); + error_message = td::Slice("Forbidden: user is deactivated"); } else if (error_message == "USER_IS_BLOCKED") { error_code = 403; - error_message = Slice("bot was blocked by the user"); + error_message = td::Slice("bot was blocked by the user"); } else if (error_message == "USER_ADMIN_INVALID") { error_code = 400; - error_message = Slice("user is an administrator of the chat"); + error_message = td::Slice("user is an administrator of the chat"); } else if (error_message == "File generation failed") { error_code = 400; - error_message = Slice("can't upload file by URL"); + error_message = td::Slice("can't upload file by URL"); } else if (error_message == "CHAT_ABOUT_NOT_MODIFIED") { error_code = 400; - error_message = Slice("chat description is not modified"); + error_message = td::Slice("chat description is not modified"); } else if (error_message == "PACK_SHORT_NAME_INVALID") { error_code = 400; - error_message = Slice("invalid sticker set name is specified"); + error_message = td::Slice("invalid sticker set name is specified"); } else if (error_message == "PACK_SHORT_NAME_OCCUPIED") { error_code = 400; - error_message = Slice("sticker set name is already occupied"); + error_message = td::Slice("sticker set name is already occupied"); } else if (error_message == "STICKER_EMOJI_INVALID") { error_code = 400; - error_message = Slice("invalid sticker emojis"); + error_message = td::Slice("invalid sticker emojis"); } else if (error_message == "QUERY_ID_INVALID") { error_code = 400; - error_message = Slice("query is too old and response timeout expired or query ID is invalid"); + error_message = td::Slice("query is too old and response timeout expired or query ID is invalid"); } else if (error_message == "MESSAGE_DELETE_FORBIDDEN") { error_code = 400; - error_message = Slice("message can't be deleted"); + error_message = td::Slice("message can't be deleted"); } } - Slice prefix; + td::Slice prefix; switch (error_code) { case 400: - prefix = Slice("Bad Request"); + prefix = td::Slice("Bad Request"); break; case 401: - prefix = Slice("Unauthorized"); + prefix = td::Slice("Unauthorized"); break; case 403: - prefix = Slice("Forbidden"); + prefix = td::Slice("Forbidden"); break; case 500: - prefix = Slice("Internal Server Error"); - if (real_error_message != Slice("Request aborted")) { + prefix = td::Slice("Internal Server Error"); + if (real_error_message != td::Slice("Request aborted")) { LOG(ERROR) << "Receive Internal Server Error \"" << real_error_message << "\" from " << *query; } break; @@ -178,7 +178,8 @@ void Client::fail_query_with_error(PromisedQueryPtr query, int32 error_code, Sli } } -void Client::fail_query_with_error(PromisedQueryPtr &&query, object_ptr error, Slice default_message) { +void Client::fail_query_with_error(PromisedQueryPtr &&query, object_ptr error, + td::Slice default_message) { fail_query_with_error(std::move(query), error->code_, error->message_, default_message); } @@ -315,7 +316,7 @@ bool Client::init_methods() { return true; } -bool Client::is_local_method(Slice method) { +bool Client::is_local_method(td::Slice method) { return method == "close" || method == "logout" || method == "getme" || method == "getupdates" || method == "setwebhook" || method == "deletewebhook" || method == "getwebhookinfo"; } @@ -707,7 +708,7 @@ class Client::JsonChat final : public Jsonable { if (is_full_) { if (!user_info->active_usernames.empty()) { object("active_usernames", td::json_array(user_info->active_usernames, - [](Slice username) { return td::JsonString(username); })); + [](td::Slice username) { return td::JsonString(username); })); } if (user_info->emoji_status_custom_emoji_id != 0) { object("emoji_status_custom_emoji_id", td::to_string(user_info->emoji_status_custom_emoji_id)); @@ -772,7 +773,7 @@ class Client::JsonChat final : public Jsonable { if (is_full_) { if (!supergroup_info->active_usernames.empty()) { object("active_usernames", td::json_array(supergroup_info->active_usernames, - [](Slice username) { return td::JsonString(username); })); + [](td::Slice username) { return td::JsonString(username); })); } if (!supergroup_info->description.empty()) { object("description", supergroup_info->description); @@ -3286,7 +3287,7 @@ class Client::TdOnResolveBotUsernameCallback final : public TdQueryCallback { template class Client::TdOnCheckMessageCallback final : public TdQueryCallback { public: - TdOnCheckMessageCallback(Client *client, int64 chat_id, int64 message_id, bool allow_empty, Slice message_type, + TdOnCheckMessageCallback(Client *client, int64 chat_id, int64 message_id, bool allow_empty, td::Slice message_type, PromisedQueryPtr query, OnSuccess on_success) : client_(client) , chat_id_(chat_id) @@ -3321,7 +3322,7 @@ class Client::TdOnCheckMessageCallback final : public TdQueryCallback { int64 chat_id_; int64 message_id_; bool allow_empty_; - Slice message_type_; + td::Slice message_type_; PromisedQueryPtr query_; OnSuccess on_success_; }; @@ -3425,7 +3426,7 @@ class Client::TdOnDownloadFileCallback final : public TdQueryCallback { void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); - return client_->on_file_download(file_id_, Status::Error(error->code_, error->message_)); + return client_->on_file_download(file_id_, td::Status::Error(error->code_, error->message_)); } CHECK(result->get_id() == td_api::file::ID); if (client_->is_file_being_downloaded(file_id_)) { // if download is yet not finished @@ -3993,7 +3994,7 @@ class Client::TdOnGetStickerSetPromiseCallback final : public TdQueryCallback { void on_result(object_ptr result) final { if (result->get_id() == td_api::error::ID) { auto error = move_object_as(result); - return promise_.set_error(Status::Error(error->code_, error->message_)); + return promise_.set_error(td::Status::Error(error->code_, error->message_)); } CHECK(result->get_id() == td_api::stickerSet::ID); @@ -4074,7 +4075,7 @@ void Client::close() { } } -void Client::log_out(int32 error_code, Slice error_message) { +void Client::log_out(int32 error_code, td::Slice error_message) { LOG(WARNING) << "Logging out due to error " << error_code << ": " << error_message; if (error_message == "API_ID_INVALID") { is_api_id_invalid_ = true; @@ -4446,7 +4447,8 @@ void Client::check_chat_access(int64 chat_id, AccessRights access_rights, const } template -void Client::check_chat(Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success) { +void Client::check_chat(td::Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, + OnSuccess on_success) { if (chat_id_str.empty()) { return fail_query(400, "Bad Request: chat_id is empty", std::move(query)); } @@ -4468,7 +4470,7 @@ void Client::check_chat(Slice chat_id_str, AccessRights access_rights, PromisedQ } template -void Client::check_chat_no_fail(Slice chat_id_str, PromisedQueryPtr query, OnSuccess on_success) { +void Client::check_chat_no_fail(td::Slice chat_id_str, PromisedQueryPtr query, OnSuccess on_success) { if (chat_id_str.empty()) { return fail_query(400, "Bad Request: sender_chat_id is empty", std::move(query)); } @@ -4560,8 +4562,8 @@ bool Client::have_message_access(int64 chat_id) const { } template -void Client::check_message(Slice chat_id_str, int64 message_id, bool allow_empty, AccessRights access_rights, - Slice message_type, PromisedQueryPtr query, OnSuccess on_success) { +void Client::check_message(td::Slice chat_id_str, int64 message_id, bool allow_empty, AccessRights access_rights, + td::Slice message_type, PromisedQueryPtr query, OnSuccess on_success) { check_chat(chat_id_str, access_rights, std::move(query), [this, message_id, allow_empty, message_type, on_success = std::move(on_success)]( int64 chat_id, PromisedQueryPtr query) mutable { @@ -4780,7 +4782,7 @@ void Client::on_update_file(object_ptr file) { send_request(make_object(file_id, false), td::make_unique()); } - return on_file_download(file_id, Status::Error(400, "Bad Request: file is too big")); + return on_file_download(file_id, td::Status::Error(400, "Bad Request: file is too big")); } if (file->local_->is_downloading_completed_) { return on_file_download(file_id, std::move(file)); @@ -4789,10 +4791,10 @@ void Client::on_update_file(object_ptr file) { // also includes all 5xx and 429 errors if (closing_ || logging_out_) { auto error = get_closing_error(); - return on_file_download(file_id, Status::Error(error.code, error.message)); + return on_file_download(file_id, td::Status::Error(error.code, error.message)); } - auto error = Status::Error(400, "Bad Request: wrong file_id or the file is temporarily unavailable"); + auto error = td::Status::Error(400, "Bad Request: wrong file_id or the file is temporarily unavailable"); return on_file_download(file_id, std::move(error)); } } @@ -4935,7 +4937,7 @@ void Client::on_update(object_ptr result) { case td_api::updateMessageSendFailed::ID: { auto update = move_object_as(result); on_message_send_failed(update->message_->chat_id_, update->old_message_id_, update->message_->id_, - Status::Error(update->error_code_, update->error_message_)); + td::Status::Error(update->error_code_, update->error_message_)); break; } case td_api::updateMessageContent::ID: { @@ -5443,12 +5445,12 @@ td::Result> Client::get_keyboard_butt return make_object(button.get_string().str(), nullptr); } - return Status::Error(400, "KeyboardButton must be a String or an Object"); + return td::Status::Error(400, "KeyboardButton must be a String or an Object"); } td::Result> Client::get_inline_keyboard_button(JsonValue &button) { if (button.type() != JsonValue::Type::Object) { - return Status::Error(400, "InlineKeyboardButton must be an Object"); + return td::Status::Error(400, "InlineKeyboardButton must be an Object"); } auto &object = button.get_object(); @@ -5506,15 +5508,15 @@ td::Result> Client::get_inline_ bot_username = bot_username.substr(1); } if (bot_username.empty()) { - return Status::Error(400, "LoginUrl bot username is invalid"); + return td::Status::Error(400, "LoginUrl bot username is invalid"); } for (auto c : bot_username) { if (c != '_' && !td::is_alnum(c)) { - return Status::Error(400, "LoginUrl bot username is invalid"); + return td::Status::Error(400, "LoginUrl bot username is invalid"); } } if (cur_temp_bot_user_id_ >= 100000) { - return Status::Error(400, "Too many different LoginUrl bot usernames"); + return td::Status::Error(400, "Too many different LoginUrl bot usernames"); } auto &user_id = bot_user_ids_[bot_username]; if (user_id == 0) { @@ -5540,7 +5542,7 @@ td::Result> Client::get_inline_ return make_object(text, make_object(url)); } - return Status::Error(400, "Text buttons are unallowed in the inline keyboard"); + return td::Status::Error(400, "Text buttons are unallowed in the inline keyboard"); } td::Result> Client::get_reply_markup(const Query *query) { @@ -5553,7 +5555,7 @@ td::Result> Client::get_reply_markup(con auto r_value = json_decode(reply_markup); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse reply keyboard markup JSON object"); + return td::Status::Error(400, "Can't parse reply keyboard markup JSON object"); } return get_reply_markup(r_value.move_as_ok()); @@ -5562,7 +5564,7 @@ td::Result> Client::get_reply_markup(con td::Result> Client::get_reply_markup(JsonValue &&value) { td::vector>> rows; td::vector>> inline_rows; - Slice input_field_placeholder; + td::Slice input_field_placeholder; bool resize_keyboard = false; bool is_persistent = false; bool one_time = false; @@ -5571,23 +5573,23 @@ td::Result> Client::get_reply_markup(Jso bool force_reply = false; if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "Object expected as reply markup"); + return td::Status::Error(400, "Object expected as reply markup"); } for (auto &field_value : value.get_object()) { if (field_value.first == "keyboard") { auto keyboard = std::move(field_value.second); if (keyboard.type() != JsonValue::Type::Array) { - return Status::Error(400, "Field \"keyboard\" of the ReplyKeyboardMarkup must be an Array"); + return td::Status::Error(400, "Field \"keyboard\" of the ReplyKeyboardMarkup must be an Array"); } for (auto &row : keyboard.get_array()) { td::vector> new_row; if (row.type() != JsonValue::Type::Array) { - return Status::Error(400, "Field \"keyboard\" of the ReplyKeyboardMarkup must be an Array of Arrays"); + return td::Status::Error(400, "Field \"keyboard\" of the ReplyKeyboardMarkup must be an Array of Arrays"); } for (auto &button : row.get_array()) { auto r_button = get_keyboard_button(button); if (r_button.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse keyboard button: " << r_button.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse keyboard button: " << r_button.error().message()); } new_row.push_back(r_button.move_as_ok()); } @@ -5597,17 +5599,19 @@ td::Result> Client::get_reply_markup(Jso } else if (field_value.first == "inline_keyboard") { auto inline_keyboard = std::move(field_value.second); if (inline_keyboard.type() != JsonValue::Type::Array) { - return Status::Error(400, "Field \"inline_keyboard\" of the InlineKeyboardMarkup must be an Array"); + return td::Status::Error(400, "Field \"inline_keyboard\" of the InlineKeyboardMarkup must be an Array"); } for (auto &inline_row : inline_keyboard.get_array()) { td::vector> new_inline_row; if (inline_row.type() != JsonValue::Type::Array) { - return Status::Error(400, "Field \"inline_keyboard\" of the InlineKeyboardMarkup must be an Array of Arrays"); + return td::Status::Error(400, + "Field \"inline_keyboard\" of the InlineKeyboardMarkup must be an Array of Arrays"); } for (auto &button : inline_row.get_array()) { auto r_button = get_inline_keyboard_button(button); if (r_button.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse inline keyboard button: " << r_button.error().message()); + return td::Status::Error(400, PSLICE() + << "Can't parse inline keyboard button: " << r_button.error().message()); } new_inline_row.push_back(r_button.move_as_ok()); } @@ -5616,37 +5620,41 @@ td::Result> Client::get_reply_markup(Jso } } else if (field_value.first == "resize_keyboard") { if (field_value.second.type() != JsonValue::Type::Boolean) { - return Status::Error(400, "Field \"resize_keyboard\" of the ReplyKeyboardMarkup must be of the type Boolean"); + return td::Status::Error(400, + "Field \"resize_keyboard\" of the ReplyKeyboardMarkup must be of the type Boolean"); } resize_keyboard = field_value.second.get_boolean(); } else if (field_value.first == "is_persistent") { if (field_value.second.type() != JsonValue::Type::Boolean) { - return Status::Error(400, "Field \"is_persistent\" of the ReplyKeyboardMarkup must be of the type Boolean"); + return td::Status::Error(400, "Field \"is_persistent\" of the ReplyKeyboardMarkup must be of the type Boolean"); } is_persistent = field_value.second.get_boolean(); } else if (field_value.first == "one_time_keyboard") { if (field_value.second.type() != JsonValue::Type::Boolean) { - return Status::Error(400, "Field \"one_time_keyboard\" of the ReplyKeyboardMarkup must be of the type Boolean"); + return td::Status::Error(400, + "Field \"one_time_keyboard\" of the ReplyKeyboardMarkup must be of the type Boolean"); } one_time = field_value.second.get_boolean(); } else if (field_value.first == "hide_keyboard" || field_value.first == "remove_keyboard") { if (field_value.second.type() != JsonValue::Type::Boolean) { - return Status::Error(400, "Field \"remove_keyboard\" of the ReplyKeyboardRemove must be of the type Boolean"); + return td::Status::Error(400, + "Field \"remove_keyboard\" of the ReplyKeyboardRemove must be of the type Boolean"); } remove = field_value.second.get_boolean(); } else if (field_value.first == "personal_keyboard" || field_value.first == "selective") { if (field_value.second.type() != JsonValue::Type::Boolean) { - return Status::Error(400, "Field \"selective\" of the reply markup must be of the type Boolean"); + return td::Status::Error(400, "Field \"selective\" of the reply markup must be of the type Boolean"); } is_personal = field_value.second.get_boolean(); } else if (field_value.first == "force_reply_keyboard" || field_value.first == "force_reply") { if (field_value.second.type() != JsonValue::Type::Boolean) { - return Status::Error(400, "Field \"force_reply\" of the reply markup must be of the type Boolean"); + return td::Status::Error(400, "Field \"force_reply\" of the reply markup must be of the type Boolean"); } force_reply = field_value.second.get_boolean(); } else if (field_value.first == "input_field_placeholder") { if (field_value.second.type() != JsonValue::Type::String) { - return Status::Error(400, "Field \"input_field_placeholder\" of the reply markup must be of the type String"); + return td::Status::Error(400, + "Field \"input_field_placeholder\" of the reply markup must be of the type String"); } input_field_placeholder = field_value.second.get_string(); } @@ -5672,47 +5680,47 @@ td::Result> Client::get_reply_markup(Jso td::Result> Client::get_labeled_price_part(JsonValue &value) { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "LabeledPrice must be an Object"); + return td::Status::Error(400, "LabeledPrice must be an Object"); } auto &object = value.get_object(); TRY_RESULT(label, get_json_object_string_field(object, "label", false)); if (label.empty()) { - return Status::Error(400, "LabeledPrice label must be non-empty"); + return td::Status::Error(400, "LabeledPrice label must be non-empty"); } TRY_RESULT(amount, get_json_object_field(object, "amount", JsonValue::Type::Null, false)); - Slice number; + td::Slice number; if (amount.type() == JsonValue::Type::Number) { number = amount.get_number(); } else if (amount.type() == JsonValue::Type::String) { number = amount.get_string(); } else { - return Status::Error(400, "Field \"amount\" must be of type Number or String"); + return td::Status::Error(400, "Field \"amount\" must be of type Number or String"); } auto parsed_amount = td::to_integer_safe(number); if (parsed_amount.is_error()) { - return Status::Error(400, "Can't parse \"amount\" as Number"); + return td::Status::Error(400, "Can't parse \"amount\" as Number"); } return make_object(label, parsed_amount.ok()); } td::Result>> Client::get_labeled_price_parts(JsonValue &value) { if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of labeled prices"); + return td::Status::Error(400, "Expected an Array of labeled prices"); } td::vector> prices; for (auto &price : value.get_array()) { auto r_labeled_price = get_labeled_price_part(price); if (r_labeled_price.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse labeled price: " << r_labeled_price.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse labeled price: " << r_labeled_price.error().message()); } prices.push_back(r_labeled_price.move_as_ok()); } if (prices.empty()) { - return Status::Error(400, "There must be at least one price"); + return td::Status::Error(400, "There must be at least one price"); } return std::move(prices); @@ -5720,22 +5728,22 @@ td::Result>> Client::get td::Result> Client::get_suggested_tip_amounts(JsonValue &value) { if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of suggested tip amounts"); + return td::Status::Error(400, "Expected an Array of suggested tip amounts"); } td::vector suggested_tip_amounts; for (auto &amount : value.get_array()) { - Slice number; + td::Slice number; if (amount.type() == JsonValue::Type::Number) { number = amount.get_number(); } else if (amount.type() == JsonValue::Type::String) { number = amount.get_string(); } else { - return Status::Error(400, "Suggested tip amount must be of type Number or String"); + return td::Status::Error(400, "Suggested tip amount must be of type Number or String"); } auto parsed_amount = td::to_integer_safe(number); if (parsed_amount.is_error()) { - return Status::Error(400, "Can't parse suggested tip amount as Number"); + return td::Status::Error(400, "Can't parse suggested tip amount as Number"); } suggested_tip_amounts.push_back(parsed_amount.ok()); } @@ -5744,26 +5752,26 @@ td::Result> Client::get_suggested_tip_amounts(JsonValue &v td::Result> Client::get_shipping_option(JsonValue &option) { if (option.type() != JsonValue::Type::Object) { - return Status::Error(400, "ShippingOption must be an Object"); + return td::Status::Error(400, "ShippingOption must be an Object"); } auto &object = option.get_object(); TRY_RESULT(id, get_json_object_string_field(object, "id", false)); if (id.empty()) { - return Status::Error(400, "ShippingOption identifier must be non-empty"); + return td::Status::Error(400, "ShippingOption identifier must be non-empty"); } TRY_RESULT(title, get_json_object_string_field(object, "title", false)); if (title.empty()) { - return Status::Error(400, "ShippingOption title must be non-empty"); + return td::Status::Error(400, "ShippingOption title must be non-empty"); } TRY_RESULT(prices_json, get_json_object_field(object, "prices", JsonValue::Type::Array, false)); auto r_prices = get_labeled_price_parts(prices_json); if (r_prices.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse shipping option prices: " << r_prices.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse shipping option prices: " << r_prices.error().message()); } return make_object(id, title, r_prices.move_as_ok()); @@ -5776,7 +5784,7 @@ td::Result>> Client::get_s auto r_value = json_decode(shipping_options); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse shipping options JSON object"); + return td::Status::Error(400, "Can't parse shipping options JSON object"); } return get_shipping_options(r_value.move_as_ok()); @@ -5784,19 +5792,19 @@ td::Result>> Client::get_s td::Result>> Client::get_shipping_options(JsonValue &&value) { if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of shipping options"); + return td::Status::Error(400, "Expected an Array of shipping options"); } td::vector> options; for (auto &option : value.get_array()) { auto r_shipping_option = get_shipping_option(option); if (r_shipping_option.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse shipping option: " << r_shipping_option.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse shipping option: " << r_shipping_option.error().message()); } options.push_back(r_shipping_option.move_as_ok()); } if (options.empty()) { - return Status::Error(400, "There must be at least one shipping option"); + return td::Status::Error(400, "There must be at least one shipping option"); } return std::move(options); @@ -5844,12 +5852,12 @@ td_api::object_ptr Client::get_chat_action(const Query *quer return nullptr; } -td_api::object_ptr Client::get_input_file(const Query *query, Slice field_name, +td_api::object_ptr Client::get_input_file(const Query *query, td::Slice field_name, bool force_file) const { return get_input_file(query, field_name, query->arg(field_name), force_file); } -td::string Client::get_local_file_path(Slice file_uri) { +td::string Client::get_local_file_path(td::Slice file_uri) { if (td::begins_with(file_uri, "/")) { file_uri.remove_prefix(td::begins_with(file_uri, "/localhost") ? 10 : 1); } @@ -5864,16 +5872,16 @@ td::string Client::get_local_file_path(Slice file_uri) { return result; } -td_api::object_ptr Client::get_input_file(const Query *query, Slice field_name, Slice file_id, - bool force_file) const { +td_api::object_ptr Client::get_input_file(const Query *query, td::Slice field_name, + td::Slice file_id, bool force_file) const { if (!file_id.empty()) { if (parameters_->local_mode_) { - Slice file_protocol{"file:/"}; + td::Slice file_protocol{"file:/"}; if (td::begins_with(file_id, file_protocol)) { return make_object(get_local_file_path(file_id.substr(file_protocol.size()))); } } - Slice attach_protocol{"attach://"}; + td::Slice attach_protocol{"attach://"}; if (td::begins_with(file_id, attach_protocol)) { field_name = file_id.substr(attach_protocol.size()); } else { @@ -5970,7 +5978,7 @@ td::Result> Client::get_input_me TRY_RESULT(description, get_json_object_string_field(object, "description", false)); TRY_RESULT(payload, get_json_object_string_field(object, "payload", false)); if (!td::check_utf8(payload)) { - return Status::Error(400, "InputInvoiceMessageContent payload must be encoded in UTF-8"); + return td::Status::Error(400, "InputInvoiceMessageContent payload must be encoded in UTF-8"); } TRY_RESULT(provider_token, get_json_object_string_field(object, "provider_token", false)); TRY_RESULT(currency, get_json_object_string_field(object, "currency", false)); @@ -6006,7 +6014,7 @@ td::Result> Client::get_input_me } if (is_input_message_content_required) { - return Status::Error(400, "Input message content is not specified"); + return td::Status::Error(400, "Input message content is not specified"); } return nullptr; } @@ -6026,8 +6034,8 @@ td::Result>> Clien LOG(INFO) << "Parsing JSON object: " << results_encoded; auto r_values = json_decode(results_encoded); if (r_values.is_error()) { - return Status::Error(400, - PSLICE() << "Can't parse JSON encoded inline query results: " << r_values.error().message()); + return td::Status::Error( + 400, PSLICE() << "Can't parse JSON encoded inline query results: " << r_values.error().message()); } return get_inline_query_results(r_values.move_as_ok()); @@ -6039,15 +6047,15 @@ td::Result>> Clien return td::vector>(); } if (values.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of inline query results"); + return td::Status::Error(400, "Expected an Array of inline query results"); } td::vector> inline_query_results; for (auto &value : values.get_array()) { auto r_inline_query_result = get_inline_query_result(std::move(value)); if (r_inline_query_result.is_error()) { - return Status::Error(400, - PSLICE() << "Can't parse inline query result: " << r_inline_query_result.error().message()); + return td::Status::Error( + 400, PSLICE() << "Can't parse inline query result: " << r_inline_query_result.error().message()); } inline_query_results.push_back(r_inline_query_result.move_as_ok()); } @@ -6058,14 +6066,14 @@ td::Result>> Clien td::Result> Client::get_inline_query_result(const Query *query) { auto result_encoded = query->arg("result"); if (result_encoded.empty()) { - return Status::Error(400, "Result isn't specified"); + return td::Status::Error(400, "Result isn't specified"); } LOG(INFO) << "Parsing JSON object: " << result_encoded; auto r_value = json_decode(result_encoded); if (r_value.is_error()) { - return Status::Error(400, - PSLICE() << "Can't parse JSON encoded web view query results " << r_value.error().message()); + return td::Status::Error( + 400, PSLICE() << "Can't parse JSON encoded web view query results " << r_value.error().message()); } return get_inline_query_result(r_value.move_as_ok()); @@ -6073,7 +6081,7 @@ td::Result> Client::get_inlin td::Result> Client::get_inline_query_result(td::JsonValue &&value) { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "Inline query result must be an object"); + return td::Status::Error(400, "Inline query result must be an object"); } auto &object = value.get_object(); @@ -6115,15 +6123,15 @@ td::Result> Client::get_inlin TRY_RESULT_ASSIGN(reply_markup, get_reply_markup(std::move(reply_markup_object))); } - auto thumbnail_url_field_name = Slice("thumbnail_url"); - auto thumbnail_width_field_name = Slice("thumbnail_width"); - auto thumbnail_height_field_name = Slice("thumbnail_height"); + auto thumbnail_url_field_name = td::Slice("thumbnail_url"); + auto thumbnail_width_field_name = td::Slice("thumbnail_width"); + auto thumbnail_height_field_name = td::Slice("thumbnail_height"); if (!has_json_object_field(object, thumbnail_url_field_name) && !has_json_object_field(object, thumbnail_width_field_name) && !has_json_object_field(object, thumbnail_height_field_name)) { - thumbnail_url_field_name = Slice("thumb_url"); - thumbnail_width_field_name = Slice("thumb_width"); - thumbnail_height_field_name = Slice("thumb_height"); + thumbnail_url_field_name = td::Slice("thumb_url"); + thumbnail_width_field_name = td::Slice("thumb_width"); + thumbnail_height_field_name = td::Slice("thumb_height"); } TRY_RESULT(thumbnail_url, get_json_object_string_field(object, thumbnail_url_field_name)); TRY_RESULT(thumbnail_width, get_json_object_int_field(object, thumbnail_width_field_name)); @@ -6194,9 +6202,9 @@ td::Result> Client::get_inlin if (type == "gif") { TRY_RESULT(title, get_json_object_string_field(object, "title")); TRY_RESULT(gif_url, get_json_object_string_field(object, "gif_url")); - auto thumbnail_mime_type_field_name = Slice("thumbnail_mime_type"); + auto thumbnail_mime_type_field_name = td::Slice("thumbnail_mime_type"); if (!has_json_object_field(object, thumbnail_mime_type_field_name)) { - thumbnail_mime_type_field_name = Slice("thumb_mime_type"); + thumbnail_mime_type_field_name = td::Slice("thumb_mime_type"); } TRY_RESULT(thumbnail_mime_type, get_json_object_string_field(object, thumbnail_mime_type_field_name)); TRY_RESULT(gif_duration, get_json_object_int_field(object, "gif_duration")); @@ -6235,9 +6243,9 @@ td::Result> Client::get_inlin if (type == "mpeg4_gif") { TRY_RESULT(title, get_json_object_string_field(object, "title")); TRY_RESULT(mpeg4_url, get_json_object_string_field(object, "mpeg4_url")); - auto thumbnail_mime_type_field_name = Slice("thumbnail_mime_type"); + auto thumbnail_mime_type_field_name = td::Slice("thumbnail_mime_type"); if (!has_json_object_field(object, thumbnail_mime_type_field_name)) { - thumbnail_mime_type_field_name = Slice("thumb_mime_type"); + thumbnail_mime_type_field_name = td::Slice("thumb_mime_type"); } TRY_RESULT(thumbnail_mime_type, get_json_object_string_field(object, thumbnail_mime_type_field_name)); TRY_RESULT(mpeg4_duration, get_json_object_int_field(object, "mpeg4_duration")); @@ -6355,12 +6363,12 @@ td::Result> Client::get_inlin id, title, voice_note_url, voice_note_duration, std::move(reply_markup), std::move(input_message_content)); } - return Status::Error(400, PSLICE() << "type \"" << type << "\" is unsupported for the inline query result"); + return td::Status::Error(400, PSLICE() << "type \"" << type << "\" is unsupported for the inline query result"); } td::Result Client::get_bot_command_scope(JsonValue &&value) { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "BotCommandScope must be an Object"); + return td::Status::Error(400, "BotCommandScope must be an Object"); } auto &object = value.get_object(); @@ -6379,12 +6387,12 @@ td::Result Client::get_bot_command_scope(JsonValue &&va return BotCommandScope(make_object()); } if (type != "chat" && type != "chat_administrators" && type != "chat_member") { - return Status::Error(400, "Unsupported type specified"); + return td::Status::Error(400, "Unsupported type specified"); } TRY_RESULT(chat_id, get_json_object_string_field(object, "chat_id", false)); if (chat_id.empty()) { - return Status::Error(400, "Empty chat_id specified"); + return td::Status::Error(400, "Empty chat_id specified"); } if (type == "chat") { return BotCommandScope(make_object(0), std::move(chat_id)); @@ -6395,7 +6403,7 @@ td::Result Client::get_bot_command_scope(JsonValue &&va TRY_RESULT(user_id, get_json_object_long_field(object, "user_id", false)); if (user_id <= 0) { - return Status::Error(400, "Invalid user_id specified"); + return td::Status::Error(400, "Invalid user_id specified"); } CHECK(type == "chat_member"); return BotCommandScope(make_object(0, user_id), std::move(chat_id), user_id); @@ -6411,19 +6419,19 @@ td::Result Client::get_bot_command_scope(const Query *q auto r_value = json_decode(scope); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse BotCommandScope JSON object"); + return td::Status::Error(400, "Can't parse BotCommandScope JSON object"); } auto r_scope = get_bot_command_scope(r_value.move_as_ok()); if (r_scope.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse BotCommandScope: " << r_scope.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse BotCommandScope: " << r_scope.error().message()); } return r_scope.move_as_ok(); } td::Result> Client::get_bot_command(JsonValue &&value) { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "expected an Object"); + return td::Status::Error(400, "expected an Object"); } auto &object = value.get_object(); @@ -6443,19 +6451,19 @@ td::Result>> Client::get_bot_c auto r_value = json_decode(commands); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse commands JSON object"); + return td::Status::Error(400, "Can't parse commands JSON object"); } auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of BotCommand"); + return td::Status::Error(400, "Expected an Array of BotCommand"); } td::vector> bot_commands; for (auto &command : value.get_array()) { auto r_bot_command = get_bot_command(std::move(command)); if (r_bot_command.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse BotCommand: " << r_bot_command.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse BotCommand: " << r_bot_command.error().message()); } bot_commands.push_back(r_bot_command.move_as_ok()); } @@ -6464,7 +6472,7 @@ td::Result>> Client::get_bot_c td::Result> Client::get_bot_menu_button(JsonValue &&value) { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "MenuButton must be an Object"); + return td::Status::Error(400, "MenuButton must be an Object"); } auto &object = value.get_object(); @@ -6484,7 +6492,7 @@ td::Result> Client::get_bot_menu_butto return td_api::make_object(text, url); } - return Status::Error(400, "MenuButton has unsupported type"); + return td::Status::Error(400, "MenuButton has unsupported type"); } td::Result> Client::get_bot_menu_button(const Query *query) { @@ -6497,12 +6505,12 @@ td::Result> Client::get_bot_menu_butto auto r_value = json_decode(menu_button); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse menu button JSON object"); + return td::Status::Error(400, "Can't parse menu button JSON object"); } auto r_menu_button = get_bot_menu_button(r_value.move_as_ok()); if (r_menu_button.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse menu button: " << r_menu_button.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse menu button: " << r_menu_button.error().message()); } return r_menu_button.move_as_ok(); } @@ -6510,7 +6518,7 @@ td::Result> Client::get_bot_menu_butto td::Result> Client::get_chat_administrator_rights( JsonValue &&value) { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "ChatAdministratorRights must be an Object"); + return td::Status::Error(400, "ChatAdministratorRights must be an Object"); } auto &object = value.get_object(); @@ -6543,12 +6551,12 @@ td::Result> Client::get_chat auto r_value = json_decode(rights); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse ChatAdministratorRights JSON object"); + return td::Status::Error(400, "Can't parse ChatAdministratorRights JSON object"); } auto r_rights = get_chat_administrator_rights(r_value.move_as_ok()); if (r_rights.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse ChatAdministratorRights: " << r_rights.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse ChatAdministratorRights: " << r_rights.error().message()); } return r_rights.move_as_ok(); } @@ -6558,7 +6566,7 @@ td::Result> Client::get_mask_position(J if (value.type() == JsonValue::Type::Null) { return nullptr; } - return Status::Error(400, "MaskPosition must be an Object"); + return td::Status::Error(400, "MaskPosition must be an Object"); } auto &object = value.get_object(); @@ -6572,7 +6580,7 @@ td::Result> Client::get_mask_position(J } } if (point == MASK_POINTS_SIZE) { - return Status::Error(400, "Wrong point specified in MaskPosition"); + return td::Status::Error(400, "Wrong point specified in MaskPosition"); } TRY_RESULT(x_shift, get_json_object_double_field(object, "x_shift", false)); @@ -6615,7 +6623,8 @@ td_api::object_ptr Client::mask_index_to_point(int32 index) { } } -td::Result> Client::get_mask_position(const Query *query, Slice field_name) { +td::Result> Client::get_mask_position(const Query *query, + td::Slice field_name) { auto mask_position = query->arg(field_name); if (mask_position.empty()) { return nullptr; @@ -6625,35 +6634,35 @@ td::Result> Client::get_mask_position(c auto r_value = json_decode(mask_position); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse mask position JSON object"); + return td::Status::Error(400, "Can't parse mask position JSON object"); } auto r_mask_position = get_mask_position(r_value.move_as_ok()); if (r_mask_position.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse mask position: " << r_mask_position.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse mask position: " << r_mask_position.error().message()); } return r_mask_position.move_as_ok(); } td::Result Client::get_sticker_emojis(JsonValue &&value) { if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "expected an Array of string"); + return td::Status::Error(400, "expected an Array of string"); } td::string result; auto emoji_count = value.get_array().size(); if (emoji_count == 0) { - return Status::Error(400, "emoji list must be non-empty"); + return td::Status::Error(400, "emoji list must be non-empty"); } if (emoji_count > MAX_STICKER_EMOJI_COUNT) { - return Status::Error(400, "too many emoji specified"); + return td::Status::Error(400, "too many emoji specified"); } for (auto &emoji : value.get_array()) { if (emoji.type() != JsonValue::Type::String) { - return Status::Error(400, "emoji must be a string"); + return td::Status::Error(400, "emoji must be a string"); } if (!td::is_emoji(emoji.get_string())) { - return Status::Error(400, "expected a Unicode emoji"); + return td::Status::Error(400, "expected a Unicode emoji"); } result += emoji.get_string().str(); } @@ -6665,17 +6674,17 @@ td::Result Client::get_sticker_emojis(td::MutableSlice emoji_list) { auto r_value = json_decode(emoji_list); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse emoji list JSON array"); + return td::Status::Error(400, "Can't parse emoji list JSON array"); } auto r_emojis = get_sticker_emojis(r_value.move_as_ok()); if (r_emojis.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse emoji list: " << r_emojis.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse emoji list: " << r_emojis.error().message()); } return r_emojis.move_as_ok(); } -td::Result> Client::get_sticker_format(Slice sticker_format) { +td::Result> Client::get_sticker_format(td::Slice sticker_format) { if (sticker_format == "static") { return make_object(); } @@ -6685,21 +6694,21 @@ td::Result> Client::get_sticker_format if (sticker_format == "video") { return make_object(); } - return Status::Error(400, "Invalid sticker format specified"); + return td::Status::Error(400, "Invalid sticker format specified"); } td::Result> Client::get_input_sticker(const Query *query, JsonValue &&value) const { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "InputSticker must be an Object"); + return td::Status::Error(400, "InputSticker must be an Object"); } auto &object = value.get_object(); TRY_RESULT(sticker, get_json_object_string_field(object, "sticker")); - auto input_file = get_input_file(query, Slice(), sticker, false); + auto input_file = get_input_file(query, td::Slice(), sticker, false); if (input_file == nullptr) { - return Status::Error("sticker not found"); + return td::Status::Error("sticker not found"); } TRY_RESULT(emoji_list, get_json_object_field(object, "emoji_list", JsonValue::Type::Array, false)); TRY_RESULT(emojis, get_sticker_emojis(std::move(emoji_list))); @@ -6709,7 +6718,7 @@ td::Result> Client::get_input_sticker(c TRY_RESULT(keywords, get_json_object_field(object, "keywords", JsonValue::Type::Array, false)); for (auto &keyword : keywords.get_array()) { if (keyword.type() != JsonValue::Type::String) { - return Status::Error(400, "keyword must be a string"); + return td::Status::Error(400, "keyword must be a string"); } input_keywords.push_back(keyword.get_string().str()); } @@ -6725,12 +6734,12 @@ td::Result> Client::get_input_sticker(c auto r_value = json_decode(sticker); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse sticker JSON object"); + return td::Status::Error(400, "Can't parse sticker JSON object"); } auto r_sticker = get_input_sticker(query, r_value.move_as_ok()); if (r_sticker.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse sticker: " << r_sticker.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse sticker: " << r_sticker.error().message()); } return r_sticker.move_as_ok(); } @@ -6747,12 +6756,12 @@ td::Result> Client::get_input_sticker(c sticker = get_input_file(query, "webm_sticker", true); if (sticker == nullptr) { if (!query->arg("tgs_sticker").empty()) { - return Status::Error(400, "Bad Request: animated sticker must be uploaded as an InputFile"); + return td::Status::Error(400, "Bad Request: animated sticker must be uploaded as an InputFile"); } if (!query->arg("webm_sticker").empty()) { - return Status::Error(400, "Bad Request: video sticker must be uploaded as an InputFile"); + return td::Status::Error(400, "Bad Request: video sticker must be uploaded as an InputFile"); } - return Status::Error(400, "Bad Request: there is no sticker file in the request"); + return td::Status::Error(400, "Bad Request: there is no sticker file in the request"); } } } @@ -6770,24 +6779,24 @@ td::Result>> Client::get_inp auto r_value = json_decode(stickers); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse stickers JSON object"); + return td::Status::Error(400, "Can't parse stickers JSON object"); } auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of InputSticker"); + return td::Status::Error(400, "Expected an Array of InputSticker"); } constexpr std::size_t MAX_STICKER_COUNT = 50; if (value.get_array().size() > MAX_STICKER_COUNT) { - return Status::Error(400, "Too many stickers specified"); + return td::Status::Error(400, "Too many stickers specified"); } td::vector> input_stickers; for (auto &input_sticker : value.get_array()) { auto r_input_sticker = get_input_sticker(query, std::move(input_sticker)); if (r_input_sticker.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse InputSticker: " << r_input_sticker.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse InputSticker: " << r_input_sticker.error().message()); } input_stickers.push_back(r_input_sticker.move_as_ok()); } @@ -6811,12 +6820,12 @@ td::Result>> Client::get_inp sticker_format = make_object(); } else { if (!query->arg("tgs_sticker").empty()) { - return Status::Error(400, "Bad Request: animated sticker must be uploaded as an InputFile"); + return td::Status::Error(400, "Bad Request: animated sticker must be uploaded as an InputFile"); } if (!query->arg("webm_sticker").empty()) { - return Status::Error(400, "Bad Request: video sticker must be uploaded as an InputFile"); + return td::Status::Error(400, "Bad Request: video sticker must be uploaded as an InputFile"); } - return Status::Error(400, "Bad Request: there is no sticker file in the request"); + return td::Status::Error(400, "Bad Request: there is no sticker file in the request"); } } } @@ -6830,14 +6839,14 @@ td::Result>> Client::get_inp td::Result> Client::get_sticker_input_file(const Query *query) { auto file_id = trim(query->arg("sticker")); if (file_id.empty()) { - return Status::Error(400, "Sticker is not specified"); + return td::Status::Error(400, "Sticker is not specified"); } return make_object(file_id.str()); } -td::Result Client::get_passport_element_hash(Slice encoded_hash) { +td::Result Client::get_passport_element_hash(td::Slice encoded_hash) { if (!td::is_base64(encoded_hash)) { - return Status::Error(400, "hash isn't a valid base64-encoded string"); + return td::Status::Error(400, "hash isn't a valid base64-encoded string"); } return td::base64_decode(encoded_hash).move_as_ok(); } @@ -6886,7 +6895,7 @@ td::Result> Client:: TRY_RESULT(file_hashes, get_json_object_field(object, "file_hashes", JsonValue::Type::Array, false)); for (auto &input_hash : file_hashes.get_array()) { if (input_hash.type() != JsonValue::Type::String) { - return Status::Error(400, "hash must be a string"); + return td::Status::Error(400, "hash must be a string"); } TRY_RESULT(hash, get_passport_element_hash(input_hash.get_string())); input_hashes.push_back(std::move(hash)); @@ -6899,13 +6908,13 @@ td::Result> Client:: } UNREACHABLE(); } - return Status::Error(400, "wrong source specified"); + return td::Status::Error(400, "wrong source specified"); } td::Result> Client::get_passport_element_error( JsonValue &&value) { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "expected an Object"); + return td::Status::Error(400, "expected an Object"); } auto &object = value.get_object(); @@ -6913,7 +6922,7 @@ td::Result> Client::get_pa TRY_RESULT(input_type, get_json_object_string_field(object, "type", false)); auto type = get_passport_element_type(input_type); if (type == nullptr) { - return Status::Error(400, "wrong Telegram Passport element type specified"); + return td::Status::Error(400, "wrong Telegram Passport element type specified"); } TRY_RESULT(message, get_json_object_string_field(object, "message", false)); TRY_RESULT(source, get_passport_element_error_source(object)); @@ -6928,26 +6937,26 @@ td::Result>> Cl auto r_value = json_decode(input_errors); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse errors JSON object"); + return td::Status::Error(400, "Can't parse errors JSON object"); } auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of PassportElementError"); + return td::Status::Error(400, "Expected an Array of PassportElementError"); } td::vector> errors; for (auto &input_error : value.get_array()) { auto r_error = get_passport_element_error(std::move(input_error)); if (r_error.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse PassportElementError: " << r_error.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse PassportElementError: " << r_error.error().message()); } errors.push_back(r_error.move_as_ok()); } return std::move(errors); } -JsonValue Client::get_input_entities(const Query *query, Slice field_name) { +JsonValue Client::get_input_entities(const Query *query, td::Slice field_name) { auto entities = query->arg(field_name); if (!entities.empty()) { auto r_value = json_decode(entities); @@ -6969,7 +6978,7 @@ td::Result> Client::get_caption(const td::Result> Client::get_text_entity_type(td::JsonObject &object) { TRY_RESULT(type, get_json_object_string_field(object, "type", false)); if (type.empty()) { - return Status::Error("Type is not specified"); + return td::Status::Error("Type is not specified"); } if (type == "bold") { @@ -7016,12 +7025,12 @@ td::Result> Client::get_text_entity_t return nullptr; } - return Status::Error("Unsupported type specified"); + return td::Status::Error("Unsupported type specified"); } td::Result> Client::get_text_entity(JsonValue &&value) { if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "expected an Object"); + return td::Status::Error(400, "expected an Object"); } auto &object = value.get_object(); @@ -7048,13 +7057,13 @@ td::Result> Client::get_formatted_text } else if (parse_mode == "html") { text_parse_mode = make_object(); } else { - return Status::Error(400, "Unsupported parse_mode"); + return td::Status::Error(400, "Unsupported parse_mode"); } auto parsed_text = execute(make_object(text, std::move(text_parse_mode))); if (parsed_text->get_id() == td_api::error::ID) { auto error = move_object_as(parsed_text); - return Status::Error(error->code_, error->message_); + return td::Status::Error(error->code_, error->message_); } CHECK(parsed_text->get_id() == td_api::formattedText::ID); @@ -7066,7 +7075,7 @@ td::Result> Client::get_formatted_text for (auto &input_entity : input_entities.get_array()) { auto r_entity = get_text_entity(std::move(input_entity)); if (r_entity.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse MessageEntity: " << r_entity.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse MessageEntity: " << r_entity.error().message()); } if (r_entity.ok() == nullptr) { continue; @@ -7088,7 +7097,7 @@ td::Result> Client::get_input_messa td::string parse_mode, JsonValue &&input_entities) { if (text.empty()) { - return Status::Error(400, "Message text is empty"); + return td::Status::Error(400, "Message text is empty"); } TRY_RESULT(formatted_text, get_formatted_text(std::move(text), std::move(parse_mode), std::move(input_entities))); @@ -7099,11 +7108,11 @@ td::Result> Client::get_input_messa td::Result> Client::get_location(const Query *query) { auto latitude = trim(query->arg("latitude")); if (latitude.empty()) { - return Status::Error(400, "Bad Request: latitude is empty"); + return td::Status::Error(400, "Bad Request: latitude is empty"); } auto longitude = trim(query->arg("longitude")); if (longitude.empty()) { - return Status::Error(400, "Bad Request: longitude is empty"); + return td::Status::Error(400, "Bad Request: longitude is empty"); } auto horizontal_accuracy = trim(query->arg("horizontal_accuracy")); @@ -7134,12 +7143,12 @@ td::Result> Client::get_chat_permiss auto r_value = json_decode(query->arg("permissions")); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse permissions JSON object"); + return td::Status::Error(400, "Can't parse permissions JSON object"); } auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "Object expected as permissions"); + return td::Status::Error(400, "Object expected as permissions"); } auto &object = value.get_object(); @@ -7178,11 +7187,11 @@ td::Result> Client::get_chat_permiss can_send_messages = true; } } - return Status::OK(); + return td::Status::OK(); }(); if (status.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse chat permissions: " << status.message()); + return td::Status::Error(400, PSLICE() << "Can't parse chat permissions: " << status.message()); } if ((can_send_other_messages || can_add_web_page_previews) && !use_independent_chat_permissions) { @@ -7241,7 +7250,7 @@ td::Result> Client::get_input_me JsonValue &&input_media, bool for_album) const { if (input_media.type() != JsonValue::Type::Object) { - return Status::Error("expected an Object"); + return td::Status::Error("expected an Object"); } auto &object = input_media.get_object(); @@ -7255,20 +7264,20 @@ td::Result> Client::get_input_me TRY_RESULT(has_spoiler, get_json_object_bool_field(object, "has_spoiler")); TRY_RESULT(media, get_json_object_string_field(object, "media")); - auto input_file = get_input_file(query, Slice(), media, false); + auto input_file = get_input_file(query, td::Slice(), media, false); if (input_file == nullptr) { - return Status::Error("media not found"); + return td::Status::Error("media not found"); } TRY_RESULT(thumbnail, get_json_object_string_field(object, "thumbnail")); if (thumbnail.empty()) { TRY_RESULT_ASSIGN(thumbnail, get_json_object_string_field(object, "thumb")); } - auto thumbnail_input_file = get_input_file(query, Slice(), thumbnail, true); + auto thumbnail_input_file = get_input_file(query, td::Slice(), thumbnail, true); if (thumbnail_input_file == nullptr) { - thumbnail_input_file = get_input_file(query, "thumbnail", Slice(), true); + thumbnail_input_file = get_input_file(query, "thumbnail", td::Slice(), true); if (thumbnail_input_file == nullptr) { - thumbnail_input_file = get_input_file(query, "thumb", Slice(), true); + thumbnail_input_file = get_input_file(query, "thumb", td::Slice(), true); } } object_ptr input_thumbnail; @@ -7295,7 +7304,7 @@ td::Result> Client::get_input_me std::move(caption), self_destruct_time, has_spoiler); } if (for_album && type == "animation") { - return Status::Error(PSLICE() << "type \"" << type << "\" can't be used in sendMediaGroup"); + return td::Status::Error(PSLICE() << "type \"" << type << "\" can't be used in sendMediaGroup"); } if (type == "animation") { TRY_RESULT(width, get_json_object_int_field(object, "width")); @@ -7322,36 +7331,36 @@ td::Result> Client::get_input_me disable_content_type_detection || for_album, std::move(caption)); } - return Status::Error(PSLICE() << "type \"" << type << "\" is unsupported"); + return td::Status::Error(PSLICE() << "type \"" << type << "\" is unsupported"); } td::Result> Client::get_input_media(const Query *query, - Slice field_name) const { + td::Slice field_name) const { TRY_RESULT(media, get_required_string_arg(query, field_name)); LOG(INFO) << "Parsing JSON object: " << media; auto r_value = json_decode(media); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse input media JSON object"); + return td::Status::Error(400, "Can't parse input media JSON object"); } auto r_input_message_content = get_input_media(query, r_value.move_as_ok(), false); if (r_input_message_content.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse InputMedia: " << r_input_message_content.error().message()); + return td::Status::Error(400, PSLICE() << "Can't parse InputMedia: " << r_input_message_content.error().message()); } return r_input_message_content.move_as_ok(); } td::Result>> Client::get_input_message_contents( - const Query *query, Slice field_name) const { + const Query *query, td::Slice field_name) const { TRY_RESULT(media, get_required_string_arg(query, field_name)); LOG(INFO) << "Parsing JSON object: " << media; auto r_value = json_decode(media); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse media JSON object"); + return td::Status::Error(400, "Can't parse media JSON object"); } return get_input_message_contents(query, r_value.move_as_ok()); @@ -7360,14 +7369,15 @@ td::Result>> Client:: td::Result>> Client::get_input_message_contents( const Query *query, JsonValue &&value) const { if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of InputMedia"); + return td::Status::Error(400, "Expected an Array of InputMedia"); } td::vector> contents; for (auto &input_media : value.get_array()) { auto r_input_message_content = get_input_media(query, std::move(input_media), true); if (r_input_message_content.is_error()) { - return Status::Error(400, PSLICE() << "Can't parse InputMedia: " << r_input_message_content.error().message()); + return td::Status::Error(400, PSLICE() + << "Can't parse InputMedia: " << r_input_message_content.error().message()); } contents.push_back(r_input_message_content.move_as_ok()); } @@ -7380,7 +7390,7 @@ td::Result> Client::get_input_me TRY_RESULT(description, get_required_string_arg(query, "description")); TRY_RESULT(payload, get_required_string_arg(query, "payload")); if (!td::check_utf8(payload.str())) { - return Status::Error(400, "The payload must be encoded in UTF-8"); + return td::Status::Error(400, "The payload must be encoded in UTF-8"); } TRY_RESULT(provider_token, get_required_string_arg(query, "provider_token")); auto provider_data = query->arg("provider_data"); @@ -7390,7 +7400,7 @@ td::Result> Client::get_input_me TRY_RESULT(labeled_price_parts, get_required_string_arg(query, "prices")); auto r_labeled_price_parts_value = json_decode(labeled_price_parts); if (r_labeled_price_parts_value.is_error()) { - return Status::Error(400, "Can't parse prices JSON object"); + return td::Status::Error(400, "Can't parse prices JSON object"); } TRY_RESULT(prices, get_labeled_price_parts(r_labeled_price_parts_value.ok_ref())); @@ -7402,7 +7412,7 @@ td::Result> Client::get_input_me if (!max_tip_amount_str.empty()) { auto r_max_tip_amount = td::to_integer_safe(max_tip_amount_str); if (r_max_tip_amount.is_error()) { - return Status::Error(400, "Can't parse \"max_tip_amount\" as Number"); + return td::Status::Error(400, "Can't parse \"max_tip_amount\" as Number"); } max_tip_amount = r_max_tip_amount.ok(); } @@ -7411,7 +7421,7 @@ td::Result> Client::get_input_me if (!suggested_tip_amounts_str.empty()) { auto r_suggested_tip_amounts_value = json_decode(suggested_tip_amounts_str); if (r_suggested_tip_amounts_value.is_error()) { - return Status::Error(400, "Can't parse suggested_tip_amounts JSON object"); + return td::Status::Error(400, "Can't parse suggested_tip_amounts JSON object"); } TRY_RESULT_ASSIGN(suggested_tip_amounts, get_suggested_tip_amounts(r_suggested_tip_amounts_value.ok_ref())); @@ -7451,40 +7461,40 @@ td::Result> Client::get_poll_options(const Query *query) auto r_value = json_decode(input_options); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse options JSON object"); + return td::Status::Error(400, "Can't parse options JSON object"); } auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of String as options"); + return td::Status::Error(400, "Expected an Array of String as options"); } td::vector options; for (auto &input_option : value.get_array()) { if (input_option.type() != JsonValue::Type::String) { - return Status::Error(400, "Expected an option to be of type String"); + return td::Status::Error(400, "Expected an option to be of type String"); } options.push_back(input_option.get_string().str()); } return std::move(options); } -td::int32 Client::get_integer_arg(const Query *query, Slice field_name, int32 default_value, int32 min_value, +td::int32 Client::get_integer_arg(const Query *query, td::Slice field_name, int32 default_value, int32 min_value, int32 max_value) { auto s_arg = query->arg(field_name); auto value = s_arg.empty() ? default_value : td::to_integer(s_arg); return td::clamp(value, min_value, max_value); } -td::Result Client::get_required_string_arg(const Query *query, Slice field_name) { +td::Result Client::get_required_string_arg(const Query *query, td::Slice field_name) { auto s_arg = query->arg(field_name); if (s_arg.empty()) { - return Status::Error(400, PSLICE() << "Parameter \"" << field_name << "\" is required"); + return td::Status::Error(400, PSLICE() << "Parameter \"" << field_name << "\" is required"); } return s_arg; } -td::int64 Client::get_message_id(const Query *query, Slice field_name) { +td::int64 Client::get_message_id(const Query *query, td::Slice field_name) { auto s_arg = query->arg(field_name); if (s_arg.empty()) { return 0; @@ -7498,18 +7508,18 @@ td::int64 Client::get_message_id(const Query *query, Slice field_name) { return as_tdlib_message_id(arg); } -td::Result Client::get_inline_message_id(const Query *query, Slice field_name) { +td::Result Client::get_inline_message_id(const Query *query, td::Slice field_name) { auto s_arg = query->arg(field_name); if (s_arg.empty()) { - return Status::Error(400, "Message identifier is not specified"); + return td::Status::Error(400, "Message identifier is not specified"); } return s_arg; } -td::Result Client::get_user_id(const Query *query, Slice field_name) { +td::Result Client::get_user_id(const Query *query, td::Slice field_name) { int64 user_id = td::max(td::to_integer(query->arg(field_name)), static_cast(0)); if (user_id == 0) { - return Status::Error(400, PSLICE() << "Invalid " << field_name << " specified"); + return td::Status::Error(400, PSLICE() << "Invalid " << field_name << " specified"); } return user_id; } @@ -7589,7 +7599,7 @@ void Client::on_message_send_succeeded(object_ptr &&message, in } } -void Client::on_message_send_failed(int64 chat_id, int64 old_message_id, int64 new_message_id, Status result) { +void Client::on_message_send_failed(int64 chat_id, int64 old_message_id, int64 new_message_id, td::Status result) { auto error = make_object(result.code(), result.message().str()); auto query_id = extract_yet_unsent_message_query_id(chat_id, old_message_id, nullptr); @@ -7660,7 +7670,7 @@ void Client::on_cmd(PromisedQueryPtr query) { td::Status Client::process_get_me_query(PromisedQueryPtr &query) { answer_query(JsonUser(my_id_, this, true), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_my_commands_query(PromisedQueryPtr &query) { @@ -7672,7 +7682,7 @@ td::Status Client::process_get_my_commands_query(PromisedQueryPtr &query) { send_request(make_object(std::move(scope), language_code), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_my_commands_query(PromisedQueryPtr &query) { @@ -7687,7 +7697,7 @@ td::Status Client::process_set_my_commands_query(PromisedQueryPtr &query) { send_request(make_object(std::move(scope), language_code, std::move(bot_commands)), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_delete_my_commands_query(PromisedQueryPtr &query) { @@ -7699,14 +7709,14 @@ td::Status Client::process_delete_my_commands_query(PromisedQueryPtr &query) { send_request(make_object(std::move(scope), language_code), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_my_default_administrator_rights_query(PromisedQueryPtr &query) { bool for_channels = to_bool(query->arg("for_channels")); send_request(make_object(my_id_), td::make_unique(for_channels, std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_my_default_administrator_rights_query(PromisedQueryPtr &query) { @@ -7720,7 +7730,7 @@ td::Status Client::process_set_my_default_administrator_rights_query(PromisedQue send_request(make_object(std::move(rights)), td::make_unique(std::move(query))); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_chat_menu_button_query(PromisedQueryPtr &query) { @@ -7733,7 +7743,7 @@ td::Status Client::process_get_chat_menu_button_query(PromisedQueryPtr &query) { } else { send_request(make_object(0), td::make_unique(std::move(query))); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_chat_menu_button_query(PromisedQueryPtr &query) { @@ -7749,7 +7759,7 @@ td::Status Client::process_set_chat_menu_button_query(PromisedQueryPtr &query) { send_request(make_object(0, std::move(menu_button)), td::make_unique(std::move(query))); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_user_profile_photos_query(PromisedQueryPtr &query) { @@ -7761,7 +7771,7 @@ td::Status Client::process_get_user_profile_photos_query(PromisedQueryPtr &query send_request(make_object(user_id, offset, limit), td::make_unique(this, std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_message_query(PromisedQueryPtr &query) { @@ -7771,19 +7781,19 @@ td::Status Client::process_send_message_query(PromisedQueryPtr &query) { auto it = yet_unsent_message_count_.find(r_chat_id.ok()); if (it != yet_unsent_message_count_.end() && it->second >= MAX_CONCURRENTLY_SENT_CHAT_MESSAGES) { fail_query_flood_limit_exceeded(std::move(query)); - return Status::OK(); + return td::Status::OK(); } } TRY_RESULT(input_message_text, get_input_message_text(query.get())); do_send_message(std::move(input_message_text), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_animation_query(PromisedQueryPtr &query) { auto animation = get_input_file(query.get(), "animation"); if (animation == nullptr) { - return Status::Error(400, "There is no animation in the request"); + return td::Status::Error(400, "There is no animation in the request"); } auto thumbnail = get_input_thumbnail(query.get()); int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); @@ -7795,13 +7805,13 @@ td::Status Client::process_send_animation_query(PromisedQueryPtr &query) { make_object(std::move(animation), std::move(thumbnail), td::vector(), duration, width, height, std::move(caption), has_spoiler), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_audio_query(PromisedQueryPtr &query) { auto audio = get_input_file(query.get(), "audio"); if (audio == nullptr) { - return Status::Error(400, "There is no audio in the request"); + return td::Status::Error(400, "There is no audio in the request"); } auto thumbnail = get_input_thumbnail(query.get()); int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); @@ -7811,19 +7821,19 @@ td::Status Client::process_send_audio_query(PromisedQueryPtr &query) { do_send_message(make_object(std::move(audio), std::move(thumbnail), duration, title, performer, std::move(caption)), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_dice_query(PromisedQueryPtr &query) { auto emoji = query->arg("emoji"); do_send_message(make_object(emoji.str(), false), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_document_query(PromisedQueryPtr &query) { auto document = get_input_file(query.get(), "document"); if (document == nullptr) { - return Status::Error(400, "There is no document in the request"); + return td::Status::Error(400, "There is no document in the request"); } auto thumbnail = get_input_thumbnail(query.get()); TRY_RESULT(caption, get_caption(query.get())); @@ -7831,13 +7841,13 @@ td::Status Client::process_send_document_query(PromisedQueryPtr &query) { do_send_message(make_object(std::move(document), std::move(thumbnail), disable_content_type_detection, std::move(caption)), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_photo_query(PromisedQueryPtr &query) { auto photo = get_input_file(query.get(), "photo"); if (photo == nullptr) { - return Status::Error(400, "There is no photo in the request"); + return td::Status::Error(400, "There is no photo in the request"); } TRY_RESULT(caption, get_caption(query.get())); auto self_destruct_time = 0; @@ -7845,23 +7855,23 @@ td::Status Client::process_send_photo_query(PromisedQueryPtr &query) { do_send_message(make_object(std::move(photo), nullptr, td::vector(), 0, 0, std::move(caption), self_destruct_time, has_spoiler), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_sticker_query(PromisedQueryPtr &query) { auto sticker = get_input_file(query.get(), "sticker"); if (sticker == nullptr) { - return Status::Error(400, "There is no sticker in the request"); + return td::Status::Error(400, "There is no sticker in the request"); } do_send_message(make_object(std::move(sticker), nullptr, 0, 0, td::string()), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_video_query(PromisedQueryPtr &query) { auto video = get_input_file(query.get(), "video"); if (video == nullptr) { - return Status::Error(400, "There is no video in the request"); + return td::Status::Error(400, "There is no video in the request"); } auto thumbnail = get_input_thumbnail(query.get()); int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); @@ -7875,13 +7885,13 @@ td::Status Client::process_send_video_query(PromisedQueryPtr &query) { duration, width, height, supports_streaming, std::move(caption), self_destruct_time, has_spoiler), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_video_note_query(PromisedQueryPtr &query) { auto video_note = get_input_file(query.get(), "video_note"); if (video_note == nullptr) { - return Status::Error(400, "There is no video note in the request"); + return td::Status::Error(400, "There is no video note in the request"); } auto thumbnail = get_input_thumbnail(query.get()); int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); @@ -7889,31 +7899,31 @@ td::Status Client::process_send_video_note_query(PromisedQueryPtr &query) { do_send_message( make_object(std::move(video_note), std::move(thumbnail), duration, length), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_voice_query(PromisedQueryPtr &query) { auto voice_note = get_input_file(query.get(), "voice"); if (voice_note == nullptr) { - return Status::Error(400, "There is no voice in the request"); + return td::Status::Error(400, "There is no voice in the request"); } int32 duration = get_integer_arg(query.get(), "duration", 0, 0, MAX_DURATION); TRY_RESULT(caption, get_caption(query.get())); do_send_message(make_object(std::move(voice_note), duration, "", std::move(caption)), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_game_query(PromisedQueryPtr &query) { TRY_RESULT(game_short_name, get_required_string_arg(query.get(), "game_short_name")); do_send_message(make_object(my_id_, game_short_name.str()), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_invoice_query(PromisedQueryPtr &query) { TRY_RESULT(input_message_invoice, get_input_message_invoice(query.get())); do_send_message(std::move(input_message_invoice), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_location_query(PromisedQueryPtr &query) { @@ -7925,7 +7935,7 @@ td::Status Client::process_send_location_query(PromisedQueryPtr &query) { do_send_message( make_object(std::move(location), live_period, heading, proximity_alert_radius), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_venue_query(PromisedQueryPtr &query) { @@ -7955,7 +7965,7 @@ td::Status Client::process_send_venue_query(PromisedQueryPtr &query) { do_send_message(make_object(make_object( std::move(location), title.str(), address.str(), provider, venue_id, venue_type)), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_contact_query(PromisedQueryPtr &query) { @@ -7966,7 +7976,7 @@ td::Status Client::process_send_contact_query(PromisedQueryPtr &query) { do_send_message(make_object(make_object( phone_number.str(), first_name.str(), last_name.str(), vcard.str(), 0)), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_poll_query(PromisedQueryPtr &query) { @@ -7989,7 +7999,7 @@ td::Status Client::process_send_poll_query(PromisedQueryPtr &query) { } else if (type.empty() || type == "regular") { poll_type = make_object(to_bool(query->arg("allows_multiple_answers"))); } else { - return Status::Error(400, "Unsupported poll type specified"); + return td::Status::Error(400, "Unsupported poll type specified"); } int32 open_period = get_integer_arg(query.get(), "open_period", 0, 0, 10 * 60); int32 close_date = get_integer_arg(query.get(), "close_date", 0); @@ -7997,7 +8007,7 @@ td::Status Client::process_send_poll_query(PromisedQueryPtr &query) { do_send_message(make_object(question.str(), std::move(options), is_anonymous, std::move(poll_type), open_period, close_date, is_closed), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_stop_poll_query(PromisedQueryPtr &query) { @@ -8017,7 +8027,7 @@ td::Status Client::process_stop_poll_query(PromisedQueryPtr &query) { td::make_unique(this, chat_id, message_id, std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_copy_message_query(PromisedQueryPtr &query) { @@ -8036,7 +8046,7 @@ td::Status Client::process_copy_message_query(PromisedQueryPtr &query) { do_send_message(make_object(from_chat_id, message_id, false, std::move(options)), std::move(query)); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_forward_message_query(PromisedQueryPtr &query) { @@ -8048,7 +8058,7 @@ td::Status Client::process_forward_message_query(PromisedQueryPtr &query) { do_send_message(make_object(from_chat_id, message_id, false, nullptr), std::move(query)); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { @@ -8095,7 +8105,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { check_message(chat_id, reply_to_message_id, reply_to_message_id <= 0 || allow_sending_without_reply, AccessRights::Write, "replied message", std::move(query), std::move(on_success)); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_chat_action_query(PromisedQueryPtr &query) { @@ -8103,7 +8113,7 @@ td::Status Client::process_send_chat_action_query(PromisedQueryPtr &query) { auto message_thread_id = get_message_id(query.get(), "message_thread_id"); object_ptr action = get_chat_action(query.get()); if (action == nullptr) { - return Status::Error(400, "Wrong parameter action in request"); + return td::Status::Error(400, "Wrong parameter action in request"); } check_chat(chat_id, AccessRights::Write, std::move(query), @@ -8111,7 +8121,7 @@ td::Status Client::process_send_chat_action_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, message_thread_id, std::move(action)), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_edit_message_text_query(PromisedQueryPtr &query) { @@ -8145,7 +8155,7 @@ td::Status Client::process_edit_message_text_query(PromisedQueryPtr &query) { }); }); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_edit_message_live_location_query(PromisedQueryPtr &query) { @@ -8186,7 +8196,7 @@ td::Status Client::process_edit_message_live_location_query(PromisedQueryPtr &qu }); }); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_edit_message_media_query(PromisedQueryPtr &query) { @@ -8220,7 +8230,7 @@ td::Status Client::process_edit_message_media_query(PromisedQueryPtr &query) { }); }); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_edit_message_caption_query(PromisedQueryPtr &query) { @@ -8253,7 +8263,7 @@ td::Status Client::process_edit_message_caption_query(PromisedQueryPtr &query) { }); }); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_edit_message_reply_markup_query(PromisedQueryPtr &query) { @@ -8284,7 +8294,7 @@ td::Status Client::process_edit_message_reply_markup_query(PromisedQueryPtr &que }); }); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_delete_message_query(PromisedQueryPtr &query) { @@ -8292,11 +8302,11 @@ td::Status Client::process_delete_message_query(PromisedQueryPtr &query) { auto message_id = get_message_id(query.get()); if (chat_id.empty()) { - return Status::Error(400, "Chat identifier is not specified"); + return td::Status::Error(400, "Chat identifier is not specified"); } if (message_id == 0) { - return Status::Error(400, "Message identifier is not specified"); + return td::Status::Error(400, "Message identifier is not specified"); } check_message(chat_id, message_id, false, AccessRights::Write, "message to delete", std::move(query), @@ -8304,14 +8314,14 @@ td::Status Client::process_delete_message_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, td::vector{message_id}, true), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_create_invoice_link_query(PromisedQueryPtr &query) { TRY_RESULT(input_message_invoice, get_input_message_invoice(query.get())); send_request(make_object(std::move(input_message_invoice)), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_game_score_query(PromisedQueryPtr &query) { @@ -8348,7 +8358,7 @@ td::Status Client::process_set_game_score_query(PromisedQueryPtr &query) { }); }); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_game_high_scores_query(PromisedQueryPtr &query) { @@ -8373,7 +8383,7 @@ td::Status Client::process_get_game_high_scores_query(PromisedQueryPtr &query) { }); }); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_answer_web_app_query_query(PromisedQueryPtr &query) { @@ -8391,7 +8401,7 @@ td::Status Client::process_answer_web_app_query_query(PromisedQueryPtr &query) { send_request(make_object(web_app_query_id, std::move(results[0])), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_answer_inline_query_query(PromisedQueryPtr &query) { @@ -8417,7 +8427,7 @@ td::Status Client::process_answer_inline_query_query(PromisedQueryPtr &query) { std::move(results), cache_time, next_offset), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_answer_callback_query_query(PromisedQueryPtr &query) { @@ -8429,7 +8439,7 @@ td::Status Client::process_answer_callback_query_query(PromisedQueryPtr &query) send_request(make_object(callback_query_id, text, show_alert, url, cache_time), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_answer_shipping_query_query(PromisedQueryPtr &query) { @@ -8445,7 +8455,7 @@ td::Status Client::process_answer_shipping_query_query(PromisedQueryPtr &query) send_request( make_object(shipping_query_id, std::move(shipping_options), error_message.str()), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_answer_pre_checkout_query_query(PromisedQueryPtr &query) { @@ -8458,7 +8468,7 @@ td::Status Client::process_answer_pre_checkout_query_query(PromisedQueryPtr &que send_request(make_object(pre_checkout_query_id, error_message.str()), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_export_chat_invite_link_query(PromisedQueryPtr &query) { @@ -8468,7 +8478,7 @@ td::Status Client::process_export_chat_invite_link_query(PromisedQueryPtr &query send_request(make_object(chat_id), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_create_chat_invite_link_query(PromisedQueryPtr &query) { @@ -8485,7 +8495,7 @@ td::Status Client::process_create_chat_invite_link_query(PromisedQueryPtr &query creates_join_request), td::make_unique(this, std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_edit_chat_invite_link_query(PromisedQueryPtr &query) { @@ -8503,7 +8513,7 @@ td::Status Client::process_edit_chat_invite_link_query(PromisedQueryPtr &query) member_limit, creates_join_request), td::make_unique(this, std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_revoke_chat_invite_link_query(PromisedQueryPtr &query) { @@ -8515,7 +8525,7 @@ td::Status Client::process_revoke_chat_invite_link_query(PromisedQueryPtr &query send_request(make_object(chat_id, invite_link), td::make_unique(this, std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_chat_query(PromisedQueryPtr &query) { @@ -8539,7 +8549,7 @@ td::Status Client::process_get_chat_query(PromisedQueryPtr &query) { UNREACHABLE(); } }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_chat_photo_query(PromisedQueryPtr &query) { @@ -8547,9 +8557,9 @@ td::Status Client::process_set_chat_photo_query(PromisedQueryPtr &query) { auto photo = get_input_file(query.get(), "photo", true); if (photo == nullptr) { if (query->arg("photo").empty()) { - return Status::Error(400, "There is no photo in the request"); + return td::Status::Error(400, "There is no photo in the request"); } - return Status::Error(400, "Photo must be uploaded as an InputFile"); + return td::Status::Error(400, "Photo must be uploaded as an InputFile"); } check_chat(chat_id, AccessRights::Write, std::move(query), @@ -8558,7 +8568,7 @@ td::Status Client::process_set_chat_photo_query(PromisedQueryPtr &query) { chat_id, make_object(std::move(photo))), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_delete_chat_photo_query(PromisedQueryPtr &query) { @@ -8568,7 +8578,7 @@ td::Status Client::process_delete_chat_photo_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, nullptr), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_chat_title_query(PromisedQueryPtr &query) { @@ -8580,7 +8590,7 @@ td::Status Client::process_set_chat_title_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, title), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_chat_permissions_query(PromisedQueryPtr &query) { @@ -8595,7 +8605,7 @@ td::Status Client::process_set_chat_permissions_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, std::move(permissions)), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_chat_description_query(PromisedQueryPtr &query) { @@ -8607,7 +8617,7 @@ td::Status Client::process_set_chat_description_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, description), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_pin_chat_message_query(PromisedQueryPtr &query) { @@ -8620,7 +8630,7 @@ td::Status Client::process_pin_chat_message_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, message_id, disable_notification, false), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_unpin_chat_message_query(PromisedQueryPtr &query) { @@ -8639,7 +8649,7 @@ td::Status Client::process_unpin_chat_message_query(PromisedQueryPtr &query) { td::make_unique(std::move(query))); }); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_unpin_all_chat_messages_query(PromisedQueryPtr &query) { @@ -8649,7 +8659,7 @@ td::Status Client::process_unpin_all_chat_messages_query(PromisedQueryPtr &query send_request(make_object(chat_id), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_chat_sticker_set_query(PromisedQueryPtr &query) { @@ -8672,7 +8682,7 @@ td::Status Client::process_set_chat_sticker_set_query(PromisedQueryPtr &query) { td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_delete_chat_sticker_set_query(PromisedQueryPtr &query) { @@ -8689,13 +8699,13 @@ td::Status Client::process_delete_chat_sticker_set_query(PromisedQueryPtr &query send_request(make_object(chat_info->supergroup_id, 0), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_forum_topic_icon_stickers_query(PromisedQueryPtr &query) { send_request(make_object(), td::make_unique(this, std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_create_forum_topic_query(PromisedQueryPtr &query) { @@ -8710,7 +8720,7 @@ td::Status Client::process_create_forum_topic_query(PromisedQueryPtr &query) { chat_id, name, make_object(icon_color, icon_custom_emoji_id)), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_edit_forum_topic_query(PromisedQueryPtr &query) { @@ -8727,7 +8737,7 @@ td::Status Client::process_edit_forum_topic_query(PromisedQueryPtr &query) { edit_icon_custom_emoji_id, icon_custom_emoji_id), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_close_forum_topic_query(PromisedQueryPtr &query) { @@ -8739,7 +8749,7 @@ td::Status Client::process_close_forum_topic_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, message_thread_id, true), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_reopen_forum_topic_query(PromisedQueryPtr &query) { @@ -8751,7 +8761,7 @@ td::Status Client::process_reopen_forum_topic_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, message_thread_id, false), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_delete_forum_topic_query(PromisedQueryPtr &query) { @@ -8763,7 +8773,7 @@ td::Status Client::process_delete_forum_topic_query(PromisedQueryPtr &query) { send_request(make_object(chat_id, message_thread_id), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_unpin_all_forum_topic_messages_query(PromisedQueryPtr &query) { @@ -8775,7 +8785,7 @@ td::Status Client::process_unpin_all_forum_topic_messages_query(PromisedQueryPtr send_request(make_object(chat_id, message_thread_id), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_edit_general_forum_topic_query(PromisedQueryPtr &query) { @@ -8787,7 +8797,7 @@ td::Status Client::process_edit_general_forum_topic_query(PromisedQueryPtr &quer send_request(make_object(chat_id, GENERAL_MESSAGE_THREAD_ID, name, false, 0), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_close_general_forum_topic_query(PromisedQueryPtr &query) { @@ -8797,7 +8807,7 @@ td::Status Client::process_close_general_forum_topic_query(PromisedQueryPtr &que send_request(make_object(chat_id, GENERAL_MESSAGE_THREAD_ID, true), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_reopen_general_forum_topic_query(PromisedQueryPtr &query) { @@ -8807,7 +8817,7 @@ td::Status Client::process_reopen_general_forum_topic_query(PromisedQueryPtr &qu send_request(make_object(chat_id, GENERAL_MESSAGE_THREAD_ID, false), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_hide_general_forum_topic_query(PromisedQueryPtr &query) { @@ -8817,7 +8827,7 @@ td::Status Client::process_hide_general_forum_topic_query(PromisedQueryPtr &quer send_request(make_object(chat_id, true), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_unhide_general_forum_topic_query(PromisedQueryPtr &query) { @@ -8827,7 +8837,7 @@ td::Status Client::process_unhide_general_forum_topic_query(PromisedQueryPtr &qu send_request(make_object(chat_id, false), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_chat_member_query(PromisedQueryPtr &query) { @@ -8842,7 +8852,7 @@ td::Status Client::process_get_chat_member_query(PromisedQueryPtr &query) { answer_query(JsonChatMember(chat_member.get(), chat_type, this), std::move(query)); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_chat_administrators_query(PromisedQueryPtr &query) { @@ -8867,7 +8877,7 @@ td::Status Client::process_get_chat_administrators_query(PromisedQueryPtr &query UNREACHABLE(); } }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_chat_member_count_query(PromisedQueryPtr &query) { @@ -8892,7 +8902,7 @@ td::Status Client::process_get_chat_member_count_query(PromisedQueryPtr &query) UNREACHABLE(); } }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_leave_chat_query(PromisedQueryPtr &query) { @@ -8901,7 +8911,7 @@ td::Status Client::process_leave_chat_query(PromisedQueryPtr &query) { check_chat(chat_id, AccessRights::Read, std::move(query), [this](int64 chat_id, PromisedQueryPtr query) { send_request(make_object(chat_id), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_promote_chat_member_query(PromisedQueryPtr &query) { @@ -8950,7 +8960,7 @@ td::Status Client::process_promote_chat_member_query(PromisedQueryPtr &query) { td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_chat_administrator_custom_title_query(PromisedQueryPtr &query) { @@ -8983,7 +8993,7 @@ td::Status Client::process_set_chat_administrator_custom_title_query(PromisedQue td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_ban_chat_member_query(PromisedQueryPtr &query) { @@ -9002,7 +9012,7 @@ td::Status Client::process_ban_chat_member_query(PromisedQueryPtr &query) { td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_restrict_chat_member_query(PromisedQueryPtr &query) { @@ -9042,7 +9052,7 @@ td::Status Client::process_restrict_chat_member_query(PromisedQueryPtr &query) { td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_unban_chat_member_query(PromisedQueryPtr &query) { @@ -9081,7 +9091,7 @@ td::Status Client::process_unban_chat_member_query(PromisedQueryPtr &query) { }); } }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_ban_chat_sender_chat_query(PromisedQueryPtr &query) { @@ -9099,7 +9109,7 @@ td::Status Client::process_ban_chat_sender_chat_query(PromisedQueryPtr &query) { td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_unban_chat_sender_chat_query(PromisedQueryPtr &query) { @@ -9116,7 +9126,7 @@ td::Status Client::process_unban_chat_sender_chat_query(PromisedQueryPtr &query) td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_approve_chat_join_request_query(PromisedQueryPtr &query) { @@ -9129,7 +9139,7 @@ td::Status Client::process_approve_chat_join_request_query(PromisedQueryPtr &que td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_decline_chat_join_request_query(PromisedQueryPtr &query) { @@ -9142,7 +9152,7 @@ td::Status Client::process_decline_chat_join_request_query(PromisedQueryPtr &que td::make_unique(std::move(query))); }); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_sticker_set_query(PromisedQueryPtr &query) { @@ -9154,7 +9164,7 @@ td::Status Client::process_get_sticker_set_query(PromisedQueryPtr &query) { send_request(make_object(name.str()), td::make_unique(this, true, std::move(query))); } - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_custom_emoji_stickers_query(PromisedQueryPtr &query) { @@ -9163,28 +9173,28 @@ td::Status Client::process_get_custom_emoji_stickers_query(PromisedQueryPtr &que LOG(INFO) << "Parsing JSON object: " << custom_emoji_ids_json; auto r_value = json_decode(custom_emoji_ids_json); if (r_value.is_error()) { - return Status::Error(400, "Can't parse custom emoji identifiers JSON object"); + return td::Status::Error(400, "Can't parse custom emoji identifiers JSON object"); } auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Expected an Array of custom emoji identifiers"); + return td::Status::Error(400, "Expected an Array of custom emoji identifiers"); } td::vector custom_emoji_ids; for (auto &custom_emoji_id : value.get_array()) { if (custom_emoji_id.type() != JsonValue::Type::String) { - return Status::Error(400, "Custom emoji identifier must be of type String"); + return td::Status::Error(400, "Custom emoji identifier must be of type String"); } auto parsed_id = td::to_integer_safe(custom_emoji_id.get_string()); if (parsed_id.is_error()) { - return Status::Error(400, "Invalid custom emoji identifier specified"); + return td::Status::Error(400, "Invalid custom emoji identifier specified"); } custom_emoji_ids.push_back(parsed_id.ok()); } send_request(make_object(std::move(custom_emoji_ids)), td::make_unique(this, std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_upload_sticker_file_query(PromisedQueryPtr &query) { @@ -9206,7 +9216,7 @@ td::Status Client::process_upload_sticker_file_query(PromisedQueryPtr &query) { make_object(user_id, std::move(sticker_format), std::move(sticker)), td::make_unique(this, std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) { @@ -9231,7 +9241,7 @@ td::Status Client::process_create_new_sticker_set_query(PromisedQueryPtr &query) needs_repainting, std::move(stickers), PSTRING() << "bot" << my_id_), td::make_unique(this, false, std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) { @@ -9244,7 +9254,7 @@ td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) { send_request(make_object(user_id, name.str(), std::move(sticker)), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_sticker_set_title_query(PromisedQueryPtr &query) { @@ -9252,7 +9262,7 @@ td::Status Client::process_set_sticker_set_title_query(PromisedQueryPtr &query) auto title = query->arg("title"); send_request(make_object(name.str(), title.str()), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query) { @@ -9267,7 +9277,7 @@ td::Status Client::process_set_sticker_set_thumbnail_query(PromisedQueryPtr &que send_request(make_object(user_id, name.str(), std::move(thumbnail)), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query) { @@ -9275,14 +9285,14 @@ td::Status Client::process_set_custom_emoji_sticker_set_thumbnail_query(Promised auto custom_emoji_id = td::to_integer(query->arg("custom_emoji_id")); send_request(make_object(name.str(), custom_emoji_id), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_delete_sticker_set_query(PromisedQueryPtr &query) { auto name = query->arg("name"); send_request(make_object(name.str()), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_sticker_position_in_set_query(PromisedQueryPtr &query) { @@ -9291,7 +9301,7 @@ td::Status Client::process_set_sticker_position_in_set_query(PromisedQueryPtr &q send_request(make_object(std::move(input_file), position), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_delete_sticker_from_set_query(PromisedQueryPtr &query) { @@ -9299,7 +9309,7 @@ td::Status Client::process_delete_sticker_from_set_query(PromisedQueryPtr &query send_request(make_object(std::move(input_file)), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_sticker_emoji_list_query(PromisedQueryPtr &query) { @@ -9308,7 +9318,7 @@ td::Status Client::process_set_sticker_emoji_list_query(PromisedQueryPtr &query) send_request(make_object(std::move(input_file), emojis), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_sticker_keywords_query(PromisedQueryPtr &query) { @@ -9318,16 +9328,16 @@ td::Status Client::process_set_sticker_keywords_query(PromisedQueryPtr &query) { auto r_value = json_decode(query->arg("keywords")); if (r_value.is_error()) { LOG(INFO) << "Can't parse JSON object: " << r_value.error(); - return Status::Error(400, "Can't parse keywords JSON object"); + return td::Status::Error(400, "Can't parse keywords JSON object"); } auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Array) { - return Status::Error(400, "Field \"keywords\" must be an Array"); + return td::Status::Error(400, "Field \"keywords\" must be an Array"); } for (auto &keyword : value.get_array()) { if (keyword.type() != JsonValue::Type::String) { - return Status::Error(400, "keyword must be a string"); + return td::Status::Error(400, "keyword must be a string"); } input_keywords.push_back(keyword.get_string().str()); } @@ -9335,7 +9345,7 @@ td::Status Client::process_set_sticker_keywords_query(PromisedQueryPtr &query) { send_request(make_object(std::move(input_file), std::move(input_keywords)), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_sticker_mask_position_query(PromisedQueryPtr &query) { @@ -9344,7 +9354,7 @@ td::Status Client::process_set_sticker_mask_position_query(PromisedQueryPtr &que send_request(make_object(std::move(input_file), std::move(mask_position)), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_passport_data_errors_query(PromisedQueryPtr &query) { @@ -9356,7 +9366,7 @@ td::Status Client::process_set_passport_data_errors_query(PromisedQueryPtr &quer send_request(make_object(user_id, std::move(errors)), td::make_unique(std::move(query))); }); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_send_custom_request_query(PromisedQueryPtr &query) { @@ -9364,7 +9374,7 @@ td::Status Client::process_send_custom_request_query(PromisedQueryPtr &query) { auto parameters = query->arg("parameters"); send_request(make_object(method.str(), parameters.str()), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_answer_custom_query_query(PromisedQueryPtr &query) { @@ -9372,7 +9382,7 @@ td::Status Client::process_answer_custom_query_query(PromisedQueryPtr &query) { auto data = query->arg("data"); send_request(make_object(custom_query_id, data.str()), td::make_unique(std::move(query))); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_updates_query(PromisedQueryPtr &query) { @@ -9380,7 +9390,7 @@ td::Status Client::process_get_updates_query(PromisedQueryPtr &query) { fail_query_conflict( "Conflict: can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first", std::move(query)); - return Status::OK(); + return td::Status::OK(); } int32 offset = get_integer_arg(query.get(), "offset", 0); int32 limit = get_integer_arg(query.get(), "limit", 100, 1, 100); @@ -9398,11 +9408,11 @@ td::Status Client::process_get_updates_query(PromisedQueryPtr &query) { previous_get_updates_offset_ = offset; previous_get_updates_start_time_ = now; do_get_updates(offset, limit, timeout, std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_set_webhook_query(PromisedQueryPtr &query) { - Slice new_url; + td::Slice new_url; if (query->method() == "setwebhook") { new_url = query->arg("url"); } @@ -9411,7 +9421,7 @@ td::Status Client::process_set_webhook_query(PromisedQueryPtr &query) { if (!new_url.empty() && !query->is_internal()) { if (now < next_allowed_set_webhook_time_) { query->set_retry_after_error(1); - return Status::OK(); + return td::Status::OK(); } next_allowed_set_webhook_time_ = now + 1; } @@ -9423,16 +9433,16 @@ td::Status Client::process_set_webhook_query(PromisedQueryPtr &query) { : (get_webhook_certificate(query.get()) != nullptr || (query->is_internal() && query->arg("certificate") == "previous")); int32 new_max_connections = new_url.empty() ? 0 : get_webhook_max_connections(query.get()); - Slice new_ip_address = new_url.empty() ? Slice() : query->arg("ip_address"); + td::Slice new_ip_address = new_url.empty() ? td::Slice() : query->arg("ip_address"); bool new_fix_ip_address = new_url.empty() ? false : get_webhook_fix_ip_address(query.get()); - Slice new_secret_token = new_url.empty() ? Slice() : query->arg("secret_token"); + td::Slice new_secret_token = new_url.empty() ? td::Slice() : query->arg("secret_token"); bool drop_pending_updates = to_bool(query->arg("drop_pending_updates")); if (webhook_set_query_) { // already updating webhook. Cancel previous request fail_query_conflict("Conflict: terminated by other setWebhook", std::move(webhook_set_query_)); } else if (active_webhook_set_query_) { query->set_retry_after_error(1); - return Status::OK(); + return td::Status::OK(); } else if (webhook_url_ == new_url && !has_webhook_certificate_ && !new_has_certificate && new_max_connections == webhook_max_connections_ && new_fix_ip_address == webhook_fix_ip_address_ && new_secret_token == webhook_secret_token_ && @@ -9444,8 +9454,8 @@ td::Status Client::process_set_webhook_query(PromisedQueryPtr &query) { LOG(WARNING) << "Webhook is not modified: \"" << new_url << '"'; } answer_query(td::JsonTrue(), std::move(query), - new_url.empty() ? Slice("Webhook is already deleted") : Slice("Webhook is already set")); - return Status::OK(); + new_url.empty() ? td::Slice("Webhook is already deleted") : td::Slice("Webhook is already set")); + return td::Status::OK(); } if (now > next_set_webhook_logging_time_ || webhook_url_ != new_url) { @@ -9469,16 +9479,16 @@ td::Status Client::process_set_webhook_query(PromisedQueryPtr &query) { webhook_query_type_ = WebhookQueryType::Cancel; CHECK(!active_webhook_set_query_); webhook_set_query_ = std::move(query); - return Status::OK(); + return td::Status::OK(); } do_set_webhook(std::move(query), false); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_webhook_info_query(PromisedQueryPtr &query) { update_last_synchronization_error_date(); answer_query(JsonWebhookInfo(this), std::move(query)); - return Status::OK(); + return td::Status::OK(); } td::Status Client::process_get_file_query(PromisedQueryPtr &query) { @@ -9486,7 +9496,7 @@ td::Status Client::process_get_file_query(PromisedQueryPtr &query) { check_remote_file_id(file_id, std::move(query), [this](object_ptr file, PromisedQueryPtr query) { do_get_file(std::move(file), std::move(query)); }); - return Status::OK(); + return td::Status::OK(); } void Client::do_get_file(object_ptr file, PromisedQueryPtr query) { @@ -9573,7 +9583,7 @@ void Client::webhook_success() { } } -void Client::webhook_error(Status status) { +void Client::webhook_error(td::Status status) { CHECK(status.is_error()); last_webhook_error_date_ = get_unix_time(); last_webhook_error_ = std::move(status); @@ -9588,7 +9598,7 @@ void Client::webhook_error(Status status) { } } -void Client::webhook_closed(Status status) { +void Client::webhook_closed(td::Status status) { if (has_webhook_certificate_) { td::Scheduler::instance()->run_on_scheduler(SharedData::get_database_scheduler_id(), [actor_id = actor_id(this), path = get_webhook_certificate_path(), @@ -9602,7 +9612,7 @@ void Client::webhook_closed(Status status) { on_webhook_closed(std::move(status)); } -void Client::on_webhook_closed(Status status) { +void Client::on_webhook_closed(td::Status status) { LOG(WARNING) << "Webhook closed: " << status << ", webhook_query_type = " << (webhook_query_type_ == WebhookQueryType::Verify ? "verify" : "change"); webhook_id_.release(); @@ -9614,7 +9624,7 @@ void Client::on_webhook_closed(Status status) { webhook_secret_token_ = td::string(); webhook_set_time_ = td::Time::now(); last_webhook_error_date_ = 0; - last_webhook_error_ = Status::OK(); + last_webhook_error_ = td::Status::OK(); parameters_->shared_data_->webhook_db_->erase(bot_token_with_dc_); if (webhook_set_query_) { @@ -9627,7 +9637,7 @@ void Client::on_webhook_closed(Status status) { } void Client::hangup_shared() { - webhook_closed(Status::Error("Unknown")); + webhook_closed(td::Status::Error("Unknown")); } td::string Client::get_webhook_certificate_path() const { @@ -9638,7 +9648,7 @@ const td::HttpFile *Client::get_webhook_certificate(const Query *query) const { auto file = query->file("certificate"); if (file == nullptr) { auto attach_name = query->arg("certificate"); - Slice attach_protocol{"attach://"}; + td::Slice attach_protocol{"attach://"}; if (td::begins_with(attach_name, attach_protocol)) { file = query->file(attach_name.substr(attach_protocol.size())); } @@ -9667,7 +9677,7 @@ void Client::do_set_webhook(PromisedQueryPtr query, bool was_deleted) { if (to_bool(query->arg("drop_pending_updates"))) { clear_tqueue(); } - Slice new_url; + td::Slice new_url; if (query->method() == "setwebhook") { new_url = query->arg("url"); } @@ -9716,11 +9726,11 @@ void Client::do_set_webhook(PromisedQueryPtr query, bool was_deleted) { finish_set_webhook(std::move(query)); } else { answer_query(td::JsonTrue(), std::move(query), - was_deleted ? Slice("Webhook was deleted") : Slice("Webhook is already deleted")); + was_deleted ? td::Slice("Webhook was deleted") : td::Slice("Webhook is already deleted")); } } -void Client::on_webhook_certificate_copied(Status status) { +void Client::on_webhook_certificate_copied(td::Status status) { CHECK(active_webhook_set_query_); if (status.is_error()) { return fail_query(500, "Internal Server Error: failed to save certificate", std::move(active_webhook_set_query_)); @@ -9736,7 +9746,7 @@ void Client::finish_set_webhook(PromisedQueryPtr query) { if (logging_out_ || closing_) { return fail_query_closing(std::move(query)); } - Slice new_url = query->arg("url"); + td::Slice new_url = query->arg("url"); CHECK(!new_url.empty()); webhook_url_ = new_url.str(); webhook_set_time_ = td::Time::now(); @@ -9745,7 +9755,7 @@ void Client::finish_set_webhook(PromisedQueryPtr query) { webhook_ip_address_ = query->arg("ip_address").str(); webhook_fix_ip_address_ = get_webhook_fix_ip_address(query.get()); last_webhook_error_date_ = 0; - last_webhook_error_ = Status::OK(); + last_webhook_error_ = td::Status::OK(); update_allowed_update_types(query.get()); @@ -9845,18 +9855,18 @@ void Client::on_sent_message(object_ptr &&message, int64 query_ void Client::abort_long_poll(bool from_set_webhook) { if (long_poll_query_) { - Slice message; + td::Slice message; if (from_set_webhook) { - message = Slice("Conflict: terminated by setWebhook request"); + message = td::Slice("Conflict: terminated by setWebhook request"); } else { - message = - Slice("Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"); + message = td::Slice( + "Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"); } fail_query_conflict(message, std::move(long_poll_query_)); } } -void Client::fail_query_conflict(Slice message, PromisedQueryPtr &&query) { +void Client::fail_query_conflict(td::Slice message, PromisedQueryPtr &&query) { auto now = td::Time::now_cached(); if (now >= next_get_updates_conflict_time_) { fail_query(409, message, std::move(query)); @@ -9895,7 +9905,7 @@ Client::ClosingError Client::get_closing_error() { if (logging_out_) { if (is_api_id_invalid_) { result.code = 401; - result.message = Slice("Unauthorized: invalid api-id/api-hash"); + result.message = td::Slice("Unauthorized: invalid api-id/api-hash"); } else if (next_authorization_time_ > 0.0) { result.code = 429; result.retry_after = td::max(static_cast(next_authorization_time_ - td::Time::now()), 0) + 1; @@ -9906,15 +9916,15 @@ Client::ClosingError Client::get_closing_error() { result.message = retry_after_error_message; } else if (clear_tqueue_) { result.code = 400; - result.message = Slice("Logged out"); + result.message = td::Slice("Logged out"); } else { result.code = 401; - result.message = Slice("Unauthorized"); + result.message = td::Slice("Unauthorized"); } } else { CHECK(closing_); result.code = 500; - result.message = Slice("Internal Server Error: restart"); + result.message = td::Slice("Internal Server Error: restart"); } return result; } @@ -10321,7 +10331,7 @@ void Client::json_store_file(td::JsonObjectScope &object, const td_api::file *fi object("file_path", td::JsonRawString(file->local_->path_)); } } else { - Slice relative_path = td::PathView::relative(file->local_->path_, dir_, true); + td::Slice relative_path = td::PathView::relative(file->local_->path_, dir_, true); if (!relative_path.empty() && file->local_->downloaded_size_ <= MAX_DOWNLOAD_FILE_SIZE) { object("file_path", relative_path); } @@ -10407,43 +10417,43 @@ void Client::json_store_permissions(td::JsonObjectScope &object, const td_api::c object("can_manage_topics", td::JsonBool(permissions->can_manage_topics_)); } -Client::Slice Client::get_update_type_name(UpdateType update_type) { +td::Slice Client::get_update_type_name(UpdateType update_type) { switch (update_type) { case UpdateType::Message: - return Slice("message"); + return td::Slice("message"); case UpdateType::EditedMessage: - return Slice("edited_message"); + return td::Slice("edited_message"); case UpdateType::ChannelPost: - return Slice("channel_post"); + return td::Slice("channel_post"); case UpdateType::EditedChannelPost: - return Slice("edited_channel_post"); + return td::Slice("edited_channel_post"); case UpdateType::InlineQuery: - return Slice("inline_query"); + return td::Slice("inline_query"); case UpdateType::ChosenInlineResult: - return Slice("chosen_inline_result"); + return td::Slice("chosen_inline_result"); case UpdateType::CallbackQuery: - return Slice("callback_query"); + return td::Slice("callback_query"); case UpdateType::CustomEvent: - return Slice("custom_event"); + return td::Slice("custom_event"); case UpdateType::CustomQuery: - return Slice("custom_query"); + return td::Slice("custom_query"); case UpdateType::ShippingQuery: - return Slice("shipping_query"); + return td::Slice("shipping_query"); case UpdateType::PreCheckoutQuery: - return Slice("pre_checkout_query"); + return td::Slice("pre_checkout_query"); case UpdateType::Poll: - return Slice("poll"); + return td::Slice("poll"); case UpdateType::PollAnswer: - return Slice("poll_answer"); + return td::Slice("poll_answer"); case UpdateType::MyChatMember: - return Slice("my_chat_member"); + return td::Slice("my_chat_member"); case UpdateType::ChatMember: - return Slice("chat_member"); + return td::Slice("chat_member"); case UpdateType::ChatJoinRequest: - return Slice("chat_join_request"); + return td::Slice("chat_join_request"); default: UNREACHABLE(); - return Slice(); + return td::Slice(); } } @@ -10931,18 +10941,18 @@ td::Slice Client::get_sticker_type(const object_ptr &type) CHECK(type != nullptr); switch (type->get_id()) { case td_api::stickerTypeRegular::ID: - return Slice("regular"); + return td::Slice("regular"); case td_api::stickerTypeMask::ID: - return Slice("mask"); + return td::Slice("mask"); case td_api::stickerTypeCustomEmoji::ID: - return Slice("custom_emoji"); + return td::Slice("custom_emoji"); default: UNREACHABLE(); - return Slice(); + return td::Slice(); } } -td::Result> Client::get_sticker_type(Slice type) { +td::Result> Client::get_sticker_type(td::Slice type) { if (type.empty() || type == "regular") { return make_object(); } @@ -10952,7 +10962,7 @@ td::Result> Client::get_sticker_type(Sli if (type == "custom_emoji") { return make_object(); } - return Status::Error(400, "Unsupported sticker type specified"); + return td::Status::Error(400, "Unsupported sticker type specified"); } td::CSlice Client::get_callback_data(const object_ptr &type) { @@ -11213,17 +11223,17 @@ td::unique_ptr Client::delete_message(int64 chat_id, int64 auto chat_info = get_chat(chat_id); CHECK(chat_info != nullptr); - Status error = - Status::Error(500, "Internal Server Error: sent message was immediately deleted and can't be returned"); + td::Status error = + td::Status::Error(500, "Internal Server Error: sent message was immediately deleted and can't be returned"); if (chat_info->type == ChatInfo::Type::Supergroup) { auto supergroup_info = get_supergroup_info(chat_info->supergroup_id); CHECK(supergroup_info != nullptr); if (supergroup_info->status->get_id() == td_api::chatMemberStatusBanned::ID || supergroup_info->status->get_id() == td_api::chatMemberStatusLeft::ID) { if (supergroup_info->is_supergroup) { - error = Status::Error(403, "Forbidden: bot is not a member of the supergroup chat"); + error = td::Status::Error(403, "Forbidden: bot is not a member of the supergroup chat"); } else { - error = Status::Error(403, "Forbidden: bot is not a member of the channel chat"); + error = td::Status::Error(403, "Forbidden: bot is not a member of the channel chat"); } } } @@ -11467,7 +11477,7 @@ td::string Client::get_passport_element_type(int32 id) { } } -td_api::object_ptr Client::get_passport_element_type(Slice type) { +td_api::object_ptr Client::get_passport_element_type(td::Slice type) { if (type == "personal_details") { return make_object(); } @@ -11536,9 +11546,9 @@ td::int64 Client::get_basic_group_chat_id(int64 basic_group_id) { constexpr Client::int64 Client::GENERAL_MESSAGE_THREAD_ID; constexpr Client::int64 Client::GREAT_MINDS_SET_ID; -constexpr Client::Slice Client::GREAT_MINDS_SET_NAME; +constexpr td::Slice Client::GREAT_MINDS_SET_NAME; -constexpr Client::Slice Client::MASK_POINTS[MASK_POINTS_SIZE]; +constexpr td::Slice Client::MASK_POINTS[MASK_POINTS_SIZE]; td::FlatHashMap Client::methods_; diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index ecf07b5..df98b5e 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -60,9 +60,6 @@ class Client final : public WebhookActor::Callback { using int32 = td::int32; using int64 = td::int64; - using Slice = td::Slice; - using Status = td::Status; - template using object_ptr = td_api::object_ptr; @@ -78,10 +75,10 @@ class Client final : public WebhookActor::Callback { static constexpr std::size_t MIN_PENDING_UPDATES_WARNING = 200; static constexpr int64 GREAT_MINDS_SET_ID = 1842540969984001; - static constexpr Slice GREAT_MINDS_SET_NAME = "TelegramGreatMinds"; + static constexpr td::Slice GREAT_MINDS_SET_NAME = "TelegramGreatMinds"; static constexpr int32 MASK_POINTS_SIZE = 4; - static constexpr Slice MASK_POINTS[MASK_POINTS_SIZE] = {"forehead", "eyes", "mouth", "chin"}; + static constexpr td::Slice MASK_POINTS[MASK_POINTS_SIZE] = {"forehead", "eyes", "mouth", "chin"}; static constexpr int32 MAX_LENGTH = 10000; // max width or height static constexpr int32 MAX_DURATION = 24 * 60 * 60; @@ -273,10 +270,10 @@ class Client final : public WebhookActor::Callback { OnSuccess on_success) const; template - void check_chat(Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success); + void check_chat(td::Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success); template - void check_chat_no_fail(Slice chat_id_str, PromisedQueryPtr query, OnSuccess on_success); + void check_chat_no_fail(td::Slice chat_id_str, PromisedQueryPtr query, OnSuccess on_success); template void check_bot_command_scope(BotCommandScope &&scope, PromisedQueryPtr query, OnSuccess on_success); @@ -285,8 +282,8 @@ class Client final : public WebhookActor::Callback { void check_remote_file_id(td::string file_id, PromisedQueryPtr query, OnSuccess on_success); template - void check_message(Slice chat_id_str, int64 message_id, bool allow_empty, AccessRights access_rights, - Slice message_type, PromisedQueryPtr query, OnSuccess on_success); + void check_message(td::Slice chat_id_str, int64 message_id, bool allow_empty, AccessRights access_rights, + td::Slice message_type, PromisedQueryPtr query, OnSuccess on_success); template void check_message_thread(int64 chat_id, int64 message_thread_id, int64 reply_to_message_id, PromisedQueryPtr query, @@ -313,7 +310,7 @@ class Client final : public WebhookActor::Callback { void on_result(td::uint64 id, object_ptr result); void on_update_authorization_state(); - void log_out(int32 error_code, Slice error_message); + void log_out(int32 error_code, td::Slice error_message); void on_closed(); void finish_closing(); @@ -351,11 +348,11 @@ class Client final : public WebhookActor::Callback { static object_ptr get_chat_action(const Query *query); - static td::string get_local_file_path(Slice file_uri); + static td::string get_local_file_path(td::Slice file_uri); - object_ptr get_input_file(const Query *query, Slice field_name, bool force_file = false) const; + object_ptr get_input_file(const Query *query, td::Slice field_name, bool force_file = false) const; - object_ptr get_input_file(const Query *query, Slice field_name, Slice file_id, + object_ptr get_input_file(const Query *query, td::Slice field_name, td::Slice file_id, bool force_file) const; object_ptr get_input_thumbnail(const Query *query) const; @@ -395,7 +392,7 @@ class Client final : public WebhookActor::Callback { static td::Result> get_chat_administrator_rights(const Query *query); - static td::Result> get_mask_position(const Query *query, Slice field_name); + static td::Result> get_mask_position(const Query *query, td::Slice field_name); static td::Result> get_mask_position(td::JsonValue &&value); @@ -407,7 +404,7 @@ class Client final : public WebhookActor::Callback { static td::Result get_sticker_emojis(td::MutableSlice emoji_list); - static td::Result> get_sticker_format(Slice sticker_format); + static td::Result> get_sticker_format(td::Slice sticker_format); td::Result> get_input_sticker(const Query *query) const; @@ -418,7 +415,7 @@ class Client final : public WebhookActor::Callback { static td::Result> get_sticker_input_file(const Query *query); - static td::Result get_passport_element_hash(Slice encoded_hash); + static td::Result get_passport_element_hash(td::Slice encoded_hash); static td::Result> get_passport_element_error_source( td::JsonObject &object); @@ -428,7 +425,7 @@ class Client final : public WebhookActor::Callback { static td::Result>> get_passport_element_errors( const Query *query); - static td::JsonValue get_input_entities(const Query *query, Slice field_name); + static td::JsonValue get_input_entities(const Query *query, td::Slice field_name); static td::Result> get_caption(const Query *query); @@ -454,10 +451,10 @@ class Client final : public WebhookActor::Callback { td::Result> get_input_media(const Query *query, td::JsonValue &&input_media, bool for_album) const; - td::Result> get_input_media(const Query *query, Slice field_name) const; + td::Result> get_input_media(const Query *query, td::Slice field_name) const; - td::Result>> get_input_message_contents(const Query *query, - Slice field_name) const; + td::Result>> get_input_message_contents( + const Query *query, td::Slice field_name) const; td::Result>> get_input_message_contents( const Query *query, td::JsonValue &&value) const; @@ -469,152 +466,153 @@ class Client final : public WebhookActor::Callback { static td::Result> get_poll_options(const Query *query); - static int32 get_integer_arg(const Query *query, Slice field_name, int32 default_value, + static int32 get_integer_arg(const Query *query, td::Slice field_name, int32 default_value, int32 min_value = std::numeric_limits::min(), int32 max_value = std::numeric_limits::max()); - static td::Result get_required_string_arg(const Query *query, Slice field_name); + static td::Result get_required_string_arg(const Query *query, td::Slice field_name); - static int64 get_message_id(const Query *query, Slice field_name = Slice("message_id")); + static int64 get_message_id(const Query *query, td::Slice field_name = td::Slice("message_id")); - static td::Result get_inline_message_id(const Query *query, Slice field_name = Slice("inline_message_id")); + static td::Result get_inline_message_id(const Query *query, + td::Slice field_name = td::Slice("inline_message_id")); - static td::Result get_user_id(const Query *query, Slice field_name = Slice("user_id")); + static td::Result get_user_id(const Query *query, td::Slice field_name = td::Slice("user_id")); void decrease_yet_unsent_message_count(int64 chat_id, int32 count); int64 extract_yet_unsent_message_query_id(int64 chat_id, int64 message_id, bool *is_reply_to_message_deleted); void on_message_send_succeeded(object_ptr &&message, int64 old_message_id); - void on_message_send_failed(int64 chat_id, int64 old_message_id, int64 new_message_id, Status result); + void on_message_send_failed(int64 chat_id, int64 old_message_id, int64 new_message_id, td::Status result); static bool init_methods(); - static bool is_local_method(Slice method); + static bool is_local_method(td::Slice method); void on_cmd(PromisedQueryPtr query); - Status process_get_me_query(PromisedQueryPtr &query); - Status process_get_my_commands_query(PromisedQueryPtr &query); - Status process_set_my_commands_query(PromisedQueryPtr &query); - Status process_delete_my_commands_query(PromisedQueryPtr &query); - Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query); - Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query); - Status process_get_chat_menu_button_query(PromisedQueryPtr &query); - Status process_set_chat_menu_button_query(PromisedQueryPtr &query); - Status process_get_user_profile_photos_query(PromisedQueryPtr &query); - Status process_send_message_query(PromisedQueryPtr &query); - Status process_send_animation_query(PromisedQueryPtr &query); - Status process_send_audio_query(PromisedQueryPtr &query); - Status process_send_dice_query(PromisedQueryPtr &query); - Status process_send_document_query(PromisedQueryPtr &query); - Status process_send_photo_query(PromisedQueryPtr &query); - Status process_send_sticker_query(PromisedQueryPtr &query); - Status process_send_video_query(PromisedQueryPtr &query); - Status process_send_video_note_query(PromisedQueryPtr &query); - Status process_send_voice_query(PromisedQueryPtr &query); - Status process_send_game_query(PromisedQueryPtr &query); - Status process_send_invoice_query(PromisedQueryPtr &query); - Status process_send_location_query(PromisedQueryPtr &query); - Status process_send_venue_query(PromisedQueryPtr &query); - Status process_send_contact_query(PromisedQueryPtr &query); - Status process_send_poll_query(PromisedQueryPtr &query); - Status process_stop_poll_query(PromisedQueryPtr &query); - Status process_copy_message_query(PromisedQueryPtr &query); - Status process_forward_message_query(PromisedQueryPtr &query); - Status process_send_media_group_query(PromisedQueryPtr &query); - Status process_send_chat_action_query(PromisedQueryPtr &query); - Status process_edit_message_text_query(PromisedQueryPtr &query); - Status process_edit_message_live_location_query(PromisedQueryPtr &query); - Status process_edit_message_media_query(PromisedQueryPtr &query); - Status process_edit_message_caption_query(PromisedQueryPtr &query); - Status process_edit_message_reply_markup_query(PromisedQueryPtr &query); - Status process_delete_message_query(PromisedQueryPtr &query); - Status process_create_invoice_link_query(PromisedQueryPtr &query); - Status process_set_game_score_query(PromisedQueryPtr &query); - Status process_get_game_high_scores_query(PromisedQueryPtr &query); - Status process_answer_web_app_query_query(PromisedQueryPtr &query); - Status process_answer_inline_query_query(PromisedQueryPtr &query); - Status process_answer_callback_query_query(PromisedQueryPtr &query); - Status process_answer_shipping_query_query(PromisedQueryPtr &query); - Status process_answer_pre_checkout_query_query(PromisedQueryPtr &query); - Status process_export_chat_invite_link_query(PromisedQueryPtr &query); - Status process_create_chat_invite_link_query(PromisedQueryPtr &query); - Status process_edit_chat_invite_link_query(PromisedQueryPtr &query); - Status process_revoke_chat_invite_link_query(PromisedQueryPtr &query); - Status process_get_chat_query(PromisedQueryPtr &query); - Status process_set_chat_photo_query(PromisedQueryPtr &query); - Status process_delete_chat_photo_query(PromisedQueryPtr &query); - Status process_set_chat_title_query(PromisedQueryPtr &query); - Status process_set_chat_permissions_query(PromisedQueryPtr &query); - Status process_set_chat_description_query(PromisedQueryPtr &query); - Status process_pin_chat_message_query(PromisedQueryPtr &query); - Status process_unpin_chat_message_query(PromisedQueryPtr &query); - Status process_unpin_all_chat_messages_query(PromisedQueryPtr &query); - Status process_set_chat_sticker_set_query(PromisedQueryPtr &query); - Status process_delete_chat_sticker_set_query(PromisedQueryPtr &query); - Status process_get_forum_topic_icon_stickers_query(PromisedQueryPtr &query); - Status process_create_forum_topic_query(PromisedQueryPtr &query); - Status process_edit_forum_topic_query(PromisedQueryPtr &query); - Status process_close_forum_topic_query(PromisedQueryPtr &query); - Status process_reopen_forum_topic_query(PromisedQueryPtr &query); - Status process_delete_forum_topic_query(PromisedQueryPtr &query); - Status process_unpin_all_forum_topic_messages_query(PromisedQueryPtr &query); - Status process_edit_general_forum_topic_query(PromisedQueryPtr &query); - Status process_close_general_forum_topic_query(PromisedQueryPtr &query); - Status process_reopen_general_forum_topic_query(PromisedQueryPtr &query); - Status process_hide_general_forum_topic_query(PromisedQueryPtr &query); - Status process_unhide_general_forum_topic_query(PromisedQueryPtr &query); - Status process_get_chat_member_query(PromisedQueryPtr &query); - Status process_get_chat_administrators_query(PromisedQueryPtr &query); - Status process_get_chat_member_count_query(PromisedQueryPtr &query); - Status process_leave_chat_query(PromisedQueryPtr &query); - Status process_promote_chat_member_query(PromisedQueryPtr &query); - Status process_set_chat_administrator_custom_title_query(PromisedQueryPtr &query); - Status process_ban_chat_member_query(PromisedQueryPtr &query); - Status process_restrict_chat_member_query(PromisedQueryPtr &query); - Status process_unban_chat_member_query(PromisedQueryPtr &query); - Status process_ban_chat_sender_chat_query(PromisedQueryPtr &query); - Status process_unban_chat_sender_chat_query(PromisedQueryPtr &query); - Status process_approve_chat_join_request_query(PromisedQueryPtr &query); - Status process_decline_chat_join_request_query(PromisedQueryPtr &query); - Status process_get_sticker_set_query(PromisedQueryPtr &query); - Status process_get_custom_emoji_stickers_query(PromisedQueryPtr &query); - Status process_upload_sticker_file_query(PromisedQueryPtr &query); - Status process_create_new_sticker_set_query(PromisedQueryPtr &query); - Status process_add_sticker_to_set_query(PromisedQueryPtr &query); - Status process_set_sticker_set_title_query(PromisedQueryPtr &query); - Status process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query); - Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query); - Status process_delete_sticker_set_query(PromisedQueryPtr &query); - Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); - Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); - Status process_set_sticker_emoji_list_query(PromisedQueryPtr &query); - Status process_set_sticker_keywords_query(PromisedQueryPtr &query); - Status process_set_sticker_mask_position_query(PromisedQueryPtr &query); - Status process_set_passport_data_errors_query(PromisedQueryPtr &query); - Status process_send_custom_request_query(PromisedQueryPtr &query); - Status process_answer_custom_query_query(PromisedQueryPtr &query); - Status process_get_updates_query(PromisedQueryPtr &query); - Status process_set_webhook_query(PromisedQueryPtr &query); - Status process_get_webhook_info_query(PromisedQueryPtr &query); - Status process_get_file_query(PromisedQueryPtr &query); + td::Status process_get_me_query(PromisedQueryPtr &query); + td::Status process_get_my_commands_query(PromisedQueryPtr &query); + td::Status process_set_my_commands_query(PromisedQueryPtr &query); + td::Status process_delete_my_commands_query(PromisedQueryPtr &query); + td::Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query); + td::Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query); + td::Status process_get_chat_menu_button_query(PromisedQueryPtr &query); + td::Status process_set_chat_menu_button_query(PromisedQueryPtr &query); + td::Status process_get_user_profile_photos_query(PromisedQueryPtr &query); + td::Status process_send_message_query(PromisedQueryPtr &query); + td::Status process_send_animation_query(PromisedQueryPtr &query); + td::Status process_send_audio_query(PromisedQueryPtr &query); + td::Status process_send_dice_query(PromisedQueryPtr &query); + td::Status process_send_document_query(PromisedQueryPtr &query); + td::Status process_send_photo_query(PromisedQueryPtr &query); + td::Status process_send_sticker_query(PromisedQueryPtr &query); + td::Status process_send_video_query(PromisedQueryPtr &query); + td::Status process_send_video_note_query(PromisedQueryPtr &query); + td::Status process_send_voice_query(PromisedQueryPtr &query); + td::Status process_send_game_query(PromisedQueryPtr &query); + td::Status process_send_invoice_query(PromisedQueryPtr &query); + td::Status process_send_location_query(PromisedQueryPtr &query); + td::Status process_send_venue_query(PromisedQueryPtr &query); + td::Status process_send_contact_query(PromisedQueryPtr &query); + td::Status process_send_poll_query(PromisedQueryPtr &query); + td::Status process_stop_poll_query(PromisedQueryPtr &query); + td::Status process_copy_message_query(PromisedQueryPtr &query); + td::Status process_forward_message_query(PromisedQueryPtr &query); + td::Status process_send_media_group_query(PromisedQueryPtr &query); + td::Status process_send_chat_action_query(PromisedQueryPtr &query); + td::Status process_edit_message_text_query(PromisedQueryPtr &query); + td::Status process_edit_message_live_location_query(PromisedQueryPtr &query); + td::Status process_edit_message_media_query(PromisedQueryPtr &query); + td::Status process_edit_message_caption_query(PromisedQueryPtr &query); + td::Status process_edit_message_reply_markup_query(PromisedQueryPtr &query); + td::Status process_delete_message_query(PromisedQueryPtr &query); + td::Status process_create_invoice_link_query(PromisedQueryPtr &query); + td::Status process_set_game_score_query(PromisedQueryPtr &query); + td::Status process_get_game_high_scores_query(PromisedQueryPtr &query); + td::Status process_answer_web_app_query_query(PromisedQueryPtr &query); + td::Status process_answer_inline_query_query(PromisedQueryPtr &query); + td::Status process_answer_callback_query_query(PromisedQueryPtr &query); + td::Status process_answer_shipping_query_query(PromisedQueryPtr &query); + td::Status process_answer_pre_checkout_query_query(PromisedQueryPtr &query); + td::Status process_export_chat_invite_link_query(PromisedQueryPtr &query); + td::Status process_create_chat_invite_link_query(PromisedQueryPtr &query); + td::Status process_edit_chat_invite_link_query(PromisedQueryPtr &query); + td::Status process_revoke_chat_invite_link_query(PromisedQueryPtr &query); + td::Status process_get_chat_query(PromisedQueryPtr &query); + td::Status process_set_chat_photo_query(PromisedQueryPtr &query); + td::Status process_delete_chat_photo_query(PromisedQueryPtr &query); + td::Status process_set_chat_title_query(PromisedQueryPtr &query); + td::Status process_set_chat_permissions_query(PromisedQueryPtr &query); + td::Status process_set_chat_description_query(PromisedQueryPtr &query); + td::Status process_pin_chat_message_query(PromisedQueryPtr &query); + td::Status process_unpin_chat_message_query(PromisedQueryPtr &query); + td::Status process_unpin_all_chat_messages_query(PromisedQueryPtr &query); + td::Status process_set_chat_sticker_set_query(PromisedQueryPtr &query); + td::Status process_delete_chat_sticker_set_query(PromisedQueryPtr &query); + td::Status process_get_forum_topic_icon_stickers_query(PromisedQueryPtr &query); + td::Status process_create_forum_topic_query(PromisedQueryPtr &query); + td::Status process_edit_forum_topic_query(PromisedQueryPtr &query); + td::Status process_close_forum_topic_query(PromisedQueryPtr &query); + td::Status process_reopen_forum_topic_query(PromisedQueryPtr &query); + td::Status process_delete_forum_topic_query(PromisedQueryPtr &query); + td::Status process_unpin_all_forum_topic_messages_query(PromisedQueryPtr &query); + td::Status process_edit_general_forum_topic_query(PromisedQueryPtr &query); + td::Status process_close_general_forum_topic_query(PromisedQueryPtr &query); + td::Status process_reopen_general_forum_topic_query(PromisedQueryPtr &query); + td::Status process_hide_general_forum_topic_query(PromisedQueryPtr &query); + td::Status process_unhide_general_forum_topic_query(PromisedQueryPtr &query); + td::Status process_get_chat_member_query(PromisedQueryPtr &query); + td::Status process_get_chat_administrators_query(PromisedQueryPtr &query); + td::Status process_get_chat_member_count_query(PromisedQueryPtr &query); + td::Status process_leave_chat_query(PromisedQueryPtr &query); + td::Status process_promote_chat_member_query(PromisedQueryPtr &query); + td::Status process_set_chat_administrator_custom_title_query(PromisedQueryPtr &query); + td::Status process_ban_chat_member_query(PromisedQueryPtr &query); + td::Status process_restrict_chat_member_query(PromisedQueryPtr &query); + td::Status process_unban_chat_member_query(PromisedQueryPtr &query); + td::Status process_ban_chat_sender_chat_query(PromisedQueryPtr &query); + td::Status process_unban_chat_sender_chat_query(PromisedQueryPtr &query); + td::Status process_approve_chat_join_request_query(PromisedQueryPtr &query); + td::Status process_decline_chat_join_request_query(PromisedQueryPtr &query); + td::Status process_get_sticker_set_query(PromisedQueryPtr &query); + td::Status process_get_custom_emoji_stickers_query(PromisedQueryPtr &query); + td::Status process_upload_sticker_file_query(PromisedQueryPtr &query); + td::Status process_create_new_sticker_set_query(PromisedQueryPtr &query); + td::Status process_add_sticker_to_set_query(PromisedQueryPtr &query); + td::Status process_set_sticker_set_title_query(PromisedQueryPtr &query); + td::Status process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query); + td::Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query); + td::Status process_delete_sticker_set_query(PromisedQueryPtr &query); + td::Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); + td::Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); + td::Status process_set_sticker_emoji_list_query(PromisedQueryPtr &query); + td::Status process_set_sticker_keywords_query(PromisedQueryPtr &query); + td::Status process_set_sticker_mask_position_query(PromisedQueryPtr &query); + td::Status process_set_passport_data_errors_query(PromisedQueryPtr &query); + td::Status process_send_custom_request_query(PromisedQueryPtr &query); + td::Status process_answer_custom_query_query(PromisedQueryPtr &query); + td::Status process_get_updates_query(PromisedQueryPtr &query); + td::Status process_set_webhook_query(PromisedQueryPtr &query); + td::Status process_get_webhook_info_query(PromisedQueryPtr &query); + td::Status process_get_file_query(PromisedQueryPtr &query); void webhook_verified(td::string cached_ip_address) final; void webhook_success() final; - void webhook_error(Status status) final; - void webhook_closed(Status status) final; + void webhook_error(td::Status status) final; + void webhook_closed(td::Status status) final; void hangup_shared() final; const td::HttpFile *get_webhook_certificate(const Query *query) const; int32 get_webhook_max_connections(const Query *query) const; static bool get_webhook_fix_ip_address(const Query *query); void do_set_webhook(PromisedQueryPtr query, bool was_deleted); - void on_webhook_certificate_copied(Status status); + void on_webhook_certificate_copied(td::Status status); void finish_set_webhook(PromisedQueryPtr query); void save_webhook() const; td::string get_webhook_certificate_path() const; - void on_webhook_closed(Status status); + void on_webhook_closed(td::Status status); void do_send_message(object_ptr input_message_content, PromisedQueryPtr query); @@ -641,22 +639,22 @@ class Client final : public WebhookActor::Callback { void fail_query_flood_limit_exceeded(PromisedQueryPtr &&query); - void fail_query_conflict(Slice message, PromisedQueryPtr &&query); + void fail_query_conflict(td::Slice message, PromisedQueryPtr &&query); struct ClosingError { int code; int retry_after; - Slice message; + td::Slice message; }; ClosingError get_closing_error(); - static int get_retry_after_time(Slice error_message); + static int get_retry_after_time(td::Slice error_message); - static void fail_query_with_error(PromisedQueryPtr query, int32 error_code, Slice error_message, - Slice default_message = Slice()); + static void fail_query_with_error(PromisedQueryPtr query, int32 error_code, td::Slice error_message, + td::Slice default_message = td::Slice()); static void fail_query_with_error(PromisedQueryPtr &&query, object_ptr error, - Slice default_message = Slice()); + td::Slice default_message = td::Slice()); class JsonUpdates; void do_get_updates(int32 offset, int32 limit, int32 timeout, PromisedQueryPtr query); @@ -810,9 +808,9 @@ class Client final : public WebhookActor::Callback { void set_message_reply_to_message_id(MessageInfo *message_info, int64 reply_to_message_id); - static Slice get_sticker_type(const object_ptr &type); + static td::Slice get_sticker_type(const object_ptr &type); - static td::Result> get_sticker_type(Slice type); + static td::Result> get_sticker_type(td::Slice type); static td::CSlice get_callback_data(const object_ptr &type); @@ -944,7 +942,7 @@ class Client final : public WebhookActor::Callback { Size }; - static Slice get_update_type_name(UpdateType update_type); + static td::Slice get_update_type_name(UpdateType update_type); static td::uint32 get_allowed_update_types(td::MutableSlice allowed_updates, bool is_internal); @@ -966,7 +964,7 @@ class Client final : public WebhookActor::Callback { static td::string get_passport_element_type(int32 id); - static object_ptr get_passport_element_type(Slice type); + static object_ptr get_passport_element_type(td::Slice type); bool have_message_access(int64 chat_id) const; @@ -1001,7 +999,7 @@ class Client final : public WebhookActor::Callback { int64 channel_bot_user_id_ = 0; int64 service_notifications_user_id_ = 0; - static td::FlatHashMap methods_; + static td::FlatHashMap methods_; td::WaitFreeHashMap, FullMessageIdHash> messages_; td::WaitFreeHashMap> users_; @@ -1110,7 +1108,7 @@ class Client final : public WebhookActor::Callback { bool webhook_fix_ip_address_ = false; td::string webhook_secret_token_; int32 last_webhook_error_date_ = 0; - Status last_webhook_error_; + td::Status last_webhook_error_; double next_allowed_set_webhook_time_ = 0; double next_set_webhook_logging_time_ = 0; double next_webhook_is_not_modified_warning_time_ = 0; From b81073cb1a020f60c2970bc3e2818c4d108da299 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Feb 2023 19:47:23 +0300 Subject: [PATCH 19/30] Remove using of td::Json*. --- telegram-bot-api/Client.cpp | 547 ++++++++++++++++++------------------ 1 file changed, 271 insertions(+), 276 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 5fc8a3f..61e357c 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -36,10 +36,6 @@ namespace telegram_bot_api { -using td::Jsonable; -using td::JsonValue; -using td::JsonValueScope; - using td_api::make_object; using td_api::move_object_as; @@ -321,19 +317,19 @@ bool Client::is_local_method(td::Slice method) { method == "setwebhook" || method == "deletewebhook" || method == "getwebhookinfo"; } -class Client::JsonEmptyObject final : public Jsonable { +class Client::JsonEmptyObject final : public td::Jsonable { public: - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); } }; -class Client::JsonFile final : public Jsonable { +class Client::JsonFile final : public td::Jsonable { public: JsonFile(const td_api::file *file, const Client *client, bool with_path) : file_(file), client_(client), with_path_(with_path) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); client_->json_store_file(object, file_, with_path_); } @@ -344,11 +340,11 @@ class Client::JsonFile final : public Jsonable { bool with_path_; }; -class Client::JsonDatedFile final : public Jsonable { +class Client::JsonDatedFile final : public td::Jsonable { public: JsonDatedFile(const td_api::datedFile *file, const Client *client) : file_(file), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); client_->json_store_file(object, file_->file_.get()); object("file_date", file_->date_); @@ -359,12 +355,12 @@ class Client::JsonDatedFile final : public Jsonable { const Client *client_; }; -class Client::JsonDatedFiles final : public Jsonable { +class Client::JsonDatedFiles final : public td::Jsonable { public: JsonDatedFiles(const td::vector> &files, const Client *client) : files_(files), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &file : files_) { array << JsonDatedFile(file.get(), client_); @@ -376,12 +372,12 @@ class Client::JsonDatedFiles final : public Jsonable { const Client *client_; }; -class Client::JsonUser final : public Jsonable { +class Client::JsonUser final : public td::Jsonable { public: JsonUser(int64 user_id, const Client *client, bool full_bot_info = false) : user_id_(user_id), client_(client), full_bot_info_(full_bot_info) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); auto user_info = client_->get_user_info(user_id_); object("id", user_id_); @@ -416,11 +412,11 @@ class Client::JsonUser final : public Jsonable { bool full_bot_info_; }; -class Client::JsonUsers final : public Jsonable { +class Client::JsonUsers final : public td::Jsonable { public: JsonUsers(const td::vector &user_ids, const Client *client) : user_ids_(user_ids), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &user_id : user_ids_) { array << JsonUser(user_id, client_); @@ -432,11 +428,11 @@ class Client::JsonUsers final : public Jsonable { const Client *client_; }; -class Client::JsonEntity final : public Jsonable { +class Client::JsonEntity final : public td::Jsonable { public: JsonEntity(const td_api::textEntity *entity, const Client *client) : entity_(entity), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("offset", entity_->offset_); object("length", entity_->length_); @@ -520,12 +516,12 @@ class Client::JsonEntity final : public Jsonable { const Client *client_; }; -class Client::JsonVectorEntities final : public Jsonable { +class Client::JsonVectorEntities final : public td::Jsonable { public: JsonVectorEntities(const td::vector> &entities, const Client *client) : entities_(entities), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &entity : entities_) { auto entity_type = entity->type_->get_id(); @@ -541,7 +537,7 @@ class Client::JsonVectorEntities final : public Jsonable { const Client *client_; }; -class Client::JsonLocation final : public Jsonable { +class Client::JsonLocation final : public td::Jsonable { public: explicit JsonLocation(const td_api::location *location, double expires_in = 0.0, int32 live_period = 0, int32 heading = 0, int32 proximity_alert_radius = 0) @@ -551,7 +547,7 @@ class Client::JsonLocation final : public Jsonable { , heading_(heading) , proximity_alert_radius_(proximity_alert_radius) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("latitude", location_->latitude_); object("longitude", location_->longitude_); @@ -577,11 +573,11 @@ class Client::JsonLocation final : public Jsonable { int32 proximity_alert_radius_; }; -class Client::JsonChatPermissions final : public Jsonable { +class Client::JsonChatPermissions final : public td::Jsonable { public: explicit JsonChatPermissions(const td_api::chatPermissions *chat_permissions) : chat_permissions_(chat_permissions) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); Client::json_store_permissions(object, chat_permissions_); } @@ -590,11 +586,11 @@ class Client::JsonChatPermissions final : public Jsonable { const td_api::chatPermissions *chat_permissions_; }; -class Client::JsonChatPhotoInfo final : public Jsonable { +class Client::JsonChatPhotoInfo final : public td::Jsonable { public: explicit JsonChatPhotoInfo(const td_api::chatPhotoInfo *chat_photo) : chat_photo_(chat_photo) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("small_file_id", chat_photo_->small_->remote_->id_); object("small_file_unique_id", chat_photo_->small_->remote_->unique_id_); @@ -606,11 +602,11 @@ class Client::JsonChatPhotoInfo final : public Jsonable { const td_api::chatPhotoInfo *chat_photo_; }; -class Client::JsonChatLocation final : public Jsonable { +class Client::JsonChatLocation final : public td::Jsonable { public: explicit JsonChatLocation(const td_api::chatLocation *chat_location) : chat_location_(chat_location) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("location", JsonLocation(chat_location_->location_.get())); object("address", chat_location_->address_); @@ -620,12 +616,12 @@ class Client::JsonChatLocation final : public Jsonable { const td_api::chatLocation *chat_location_; }; -class Client::JsonChatInviteLink final : public Jsonable { +class Client::JsonChatInviteLink final : public td::Jsonable { public: JsonChatInviteLink(const td_api::chatInviteLink *chat_invite_link, const Client *client) : chat_invite_link_(chat_invite_link), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("invite_link", chat_invite_link_->invite_link_); if (!chat_invite_link_->name_.empty()) { @@ -651,12 +647,12 @@ class Client::JsonChatInviteLink final : public Jsonable { const Client *client_; }; -class Client::JsonMessage final : public Jsonable { +class Client::JsonMessage final : public td::Jsonable { public: JsonMessage(const MessageInfo *message, bool need_reply, const td::string &source, const Client *client) : message_(message), need_reply_(need_reply), source_(source), client_(client) { } - void store(JsonValueScope *scope) const; + void store(td::JsonValueScope *scope) const; private: const MessageInfo *message_; @@ -682,12 +678,12 @@ class Client::JsonMessage final : public Jsonable { } }; -class Client::JsonChat final : public Jsonable { +class Client::JsonChat final : public td::Jsonable { public: JsonChat(int64 chat_id, bool is_full, const Client *client, int64 pinned_message_id = -1) : chat_id_(chat_id), is_full_(is_full), client_(client), pinned_message_id_(pinned_message_id) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto chat_info = client_->get_chat(chat_id_); CHECK(chat_info != nullptr); auto object = scope->enter_object(); @@ -879,12 +875,12 @@ class Client::JsonChat final : public Jsonable { int64 pinned_message_id_; }; -class Client::JsonMessageSender final : public Jsonable { +class Client::JsonMessageSender final : public td::Jsonable { public: JsonMessageSender(const td_api::MessageSender *sender_id, const Client *client) : sender_id_(sender_id), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { CHECK(sender_id_ != nullptr); switch (sender_id_->get_id()) { case td_api::messageSenderUser::ID: { @@ -907,11 +903,11 @@ class Client::JsonMessageSender final : public Jsonable { const Client *client_; }; -class Client::JsonMessages final : public Jsonable { +class Client::JsonMessages final : public td::Jsonable { public: explicit JsonMessages(const td::vector &messages) : messages_(messages) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &message : messages_) { array << td::JsonRaw(message); @@ -922,12 +918,12 @@ class Client::JsonMessages final : public Jsonable { const td::vector &messages_; }; -class Client::JsonAnimation final : public Jsonable { +class Client::JsonAnimation final : public td::Jsonable { public: JsonAnimation(const td_api::animation *animation, bool as_document, const Client *client) : animation_(animation), as_document_(as_document), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); if (!animation_->file_name_.empty()) { object("file_name", animation_->file_name_); @@ -950,11 +946,11 @@ class Client::JsonAnimation final : public Jsonable { const Client *client_; }; -class Client::JsonAudio final : public Jsonable { +class Client::JsonAudio final : public td::Jsonable { public: JsonAudio(const td_api::audio *audio, const Client *client) : audio_(audio), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("duration", audio_->duration_); if (!audio_->file_name_.empty()) { @@ -978,11 +974,11 @@ class Client::JsonAudio final : public Jsonable { const Client *client_; }; -class Client::JsonDocument final : public Jsonable { +class Client::JsonDocument final : public td::Jsonable { public: JsonDocument(const td_api::document *document, const Client *client) : document_(document), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); if (!document_->file_name_.empty()) { object("file_name", document_->file_name_); @@ -999,11 +995,11 @@ class Client::JsonDocument final : public Jsonable { const Client *client_; }; -class Client::JsonPhotoSize final : public Jsonable { +class Client::JsonPhotoSize final : public td::Jsonable { public: JsonPhotoSize(const td_api::photoSize *photo_size, const Client *client) : photo_size_(photo_size), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); client_->json_store_file(object, photo_size_->photo_.get()); object("width", photo_size_->width_); @@ -1015,11 +1011,11 @@ class Client::JsonPhotoSize final : public Jsonable { const Client *client_; }; -class Client::JsonThumbnail final : public Jsonable { +class Client::JsonThumbnail final : public td::Jsonable { public: JsonThumbnail(const td_api::thumbnail *thumbnail, const Client *client) : thumbnail_(thumbnail), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); client_->json_store_file(object, thumbnail_->file_.get()); object("width", thumbnail_->width_); @@ -1031,11 +1027,11 @@ class Client::JsonThumbnail final : public Jsonable { const Client *client_; }; -class Client::JsonPhoto final : public Jsonable { +class Client::JsonPhoto final : public td::Jsonable { public: JsonPhoto(const td_api::photo *photo, const Client *client) : photo_(photo), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &photo_size : photo_->sizes_) { if (photo_size->type_ != "i" && photo_size->type_ != "t" && !photo_size->photo_->remote_->id_.empty()) { @@ -1049,11 +1045,11 @@ class Client::JsonPhoto final : public Jsonable { const Client *client_; }; -class Client::JsonChatPhoto final : public Jsonable { +class Client::JsonChatPhoto final : public td::Jsonable { public: JsonChatPhoto(const td_api::chatPhoto *photo, const Client *client) : photo_(photo), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &photo_size : photo_->sizes_) { if (photo_size->type_ != "i" && photo_size->type_ != "t" && !photo_size->photo_->remote_->id_.empty()) { @@ -1067,11 +1063,11 @@ class Client::JsonChatPhoto final : public Jsonable { const Client *client_; }; -class Client::JsonMaskPosition final : public Jsonable { +class Client::JsonMaskPosition final : public td::Jsonable { public: explicit JsonMaskPosition(const td_api::maskPosition *mask_position) : mask_position_(mask_position) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("point", Client::MASK_POINTS[Client::mask_point_to_index(mask_position_->point_)]); object("x_shift", mask_position_->x_shift_); @@ -1083,11 +1079,11 @@ class Client::JsonMaskPosition final : public Jsonable { const td_api::maskPosition *mask_position_; }; -class Client::JsonSticker final : public Jsonable { +class Client::JsonSticker final : public td::Jsonable { public: JsonSticker(const td_api::sticker *sticker, const Client *client) : sticker_(sticker), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("width", sticker_->width_); object("height", sticker_->height_); @@ -1145,12 +1141,12 @@ class Client::JsonSticker final : public Jsonable { const Client *client_; }; -class Client::JsonStickers final : public Jsonable { +class Client::JsonStickers final : public td::Jsonable { public: JsonStickers(const td::vector> &stickers, const Client *client) : stickers_(stickers), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &sticker : stickers_) { array << JsonSticker(sticker.get(), client_); @@ -1162,11 +1158,11 @@ class Client::JsonStickers final : public Jsonable { const Client *client_; }; -class Client::JsonVideo final : public Jsonable { +class Client::JsonVideo final : public td::Jsonable { public: JsonVideo(const td_api::video *video, const Client *client) : video_(video), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("duration", video_->duration_); object("width", video_->width_); @@ -1186,11 +1182,11 @@ class Client::JsonVideo final : public Jsonable { const Client *client_; }; -class Client::JsonVideoNote final : public Jsonable { +class Client::JsonVideoNote final : public td::Jsonable { public: JsonVideoNote(const td_api::videoNote *video_note, const Client *client) : video_note_(video_note), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("duration", video_note_->duration_); object("length", video_note_->length_); @@ -1203,11 +1199,11 @@ class Client::JsonVideoNote final : public Jsonable { const Client *client_; }; -class Client::JsonVoiceNote final : public Jsonable { +class Client::JsonVoiceNote final : public td::Jsonable { public: JsonVoiceNote(const td_api::voiceNote *voice_note, const Client *client) : voice_note_(voice_note), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("duration", voice_note_->duration_); if (!voice_note_->mime_type_.empty()) { @@ -1221,11 +1217,11 @@ class Client::JsonVoiceNote final : public Jsonable { const Client *client_; }; -class Client::JsonVenue final : public Jsonable { +class Client::JsonVenue final : public td::Jsonable { public: explicit JsonVenue(const td_api::venue *venue) : venue_(venue) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("location", JsonLocation(venue_->location_.get())); object("title", venue_->title_); @@ -1252,11 +1248,11 @@ class Client::JsonVenue final : public Jsonable { const td_api::venue *venue_; }; -class Client::JsonContact final : public Jsonable { +class Client::JsonContact final : public td::Jsonable { public: explicit JsonContact(const td_api::contact *contact) : contact_(contact) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("phone_number", contact_->phone_number_); object("first_name", contact_->first_name_); @@ -1275,11 +1271,11 @@ class Client::JsonContact final : public Jsonable { const td_api::contact *contact_; }; -class Client::JsonDice final : public Jsonable { +class Client::JsonDice final : public td::Jsonable { public: JsonDice(const td::string &emoji, int32 value) : emoji_(emoji), value_(value) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("emoji", emoji_); object("value", value_); @@ -1290,11 +1286,11 @@ class Client::JsonDice final : public Jsonable { int32 value_; }; -class Client::JsonGame final : public Jsonable { +class Client::JsonGame final : public td::Jsonable { public: JsonGame(const td_api::game *game, const Client *client) : game_(game), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("title", game_->title_); if (!game_->text_->text_.empty()) { @@ -1316,11 +1312,11 @@ class Client::JsonGame final : public Jsonable { const Client *client_; }; -class Client::JsonInvoice final : public Jsonable { +class Client::JsonInvoice final : public td::Jsonable { public: explicit JsonInvoice(const td_api::messageInvoice *invoice) : invoice_(invoice) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("title", invoice_->title_); object("description", invoice_->description_->text_); @@ -1337,11 +1333,11 @@ class Client::JsonInvoice final : public Jsonable { const td_api::messageInvoice *invoice_; }; -class Client::JsonPollOption final : public Jsonable { +class Client::JsonPollOption final : public td::Jsonable { public: explicit JsonPollOption(const td_api::pollOption *option) : option_(option) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("text", option_->text_); object("voter_count", option_->voter_count_); @@ -1352,11 +1348,11 @@ class Client::JsonPollOption final : public Jsonable { const td_api::pollOption *option_; }; -class Client::JsonPoll final : public Jsonable { +class Client::JsonPoll final : public td::Jsonable { public: JsonPoll(const td_api::poll *poll, const Client *client) : poll_(poll), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("id", td::to_string(poll_->id_)); object("question", poll_->question_); @@ -1399,12 +1395,12 @@ class Client::JsonPoll final : public Jsonable { const Client *client_; }; -class Client::JsonPollAnswer final : public Jsonable { +class Client::JsonPollAnswer final : public td::Jsonable { public: JsonPollAnswer(const td_api::updatePollAnswer *poll_answer, const Client *client) : poll_answer_(poll_answer), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("poll_id", td::to_string(poll_answer_->poll_id_)); object("user", JsonUser(poll_answer_->user_id_, client_)); @@ -1416,12 +1412,12 @@ class Client::JsonPollAnswer final : public Jsonable { const Client *client_; }; -class Client::JsonForumTopicCreated final : public Jsonable { +class Client::JsonForumTopicCreated final : public td::Jsonable { public: explicit JsonForumTopicCreated(const td_api::messageForumTopicCreated *forum_topic_created) : forum_topic_created_(forum_topic_created) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("name", forum_topic_created_->name_); object("icon_color", forum_topic_created_->icon_->color_); @@ -1434,12 +1430,12 @@ class Client::JsonForumTopicCreated final : public Jsonable { const td_api::messageForumTopicCreated *forum_topic_created_; }; -class Client::JsonForumTopicEdited final : public Jsonable { +class Client::JsonForumTopicEdited final : public td::Jsonable { public: explicit JsonForumTopicEdited(const td_api::messageForumTopicEdited *forum_topic_edited) : forum_topic_edited_(forum_topic_edited) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); if (!forum_topic_edited_->name_.empty()) { object("name", forum_topic_edited_->name_); @@ -1455,11 +1451,11 @@ class Client::JsonForumTopicEdited final : public Jsonable { const td_api::messageForumTopicEdited *forum_topic_edited_; }; -class Client::JsonForumTopicInfo final : public Jsonable { +class Client::JsonForumTopicInfo final : public td::Jsonable { public: explicit JsonForumTopicInfo(const td_api::forumTopicInfo *forum_topic_info) : forum_topic_info_(forum_topic_info) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("message_thread_id", as_client_message_id(forum_topic_info_->message_thread_id_)); object("name", forum_topic_info_->name_); @@ -1473,11 +1469,11 @@ class Client::JsonForumTopicInfo final : public Jsonable { const td_api::forumTopicInfo *forum_topic_info_; }; -class Client::JsonAddress final : public Jsonable { +class Client::JsonAddress final : public td::Jsonable { public: explicit JsonAddress(const td_api::address *address) : address_(address) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("country_code", address_->country_code_); object("state", address_->state_); @@ -1491,11 +1487,11 @@ class Client::JsonAddress final : public Jsonable { const td_api::address *address_; }; -class Client::JsonOrderInfo final : public Jsonable { +class Client::JsonOrderInfo final : public td::Jsonable { public: explicit JsonOrderInfo(const td_api::orderInfo *order_info) : order_info_(order_info) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); if (!order_info_->name_.empty()) { object("name", order_info_->name_); @@ -1515,12 +1511,12 @@ class Client::JsonOrderInfo final : public Jsonable { const td_api::orderInfo *order_info_; }; -class Client::JsonSuccessfulPaymentBot final : public Jsonable { +class Client::JsonSuccessfulPaymentBot final : public td::Jsonable { public: explicit JsonSuccessfulPaymentBot(const td_api::messagePaymentSuccessfulBot *successful_payment) : successful_payment_(successful_payment) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("currency", successful_payment_->currency_); object("total_amount", successful_payment_->total_amount_); @@ -1545,12 +1541,12 @@ class Client::JsonSuccessfulPaymentBot final : public Jsonable { const td_api::messagePaymentSuccessfulBot *successful_payment_; }; -class Client::JsonEncryptedPassportElement final : public Jsonable { +class Client::JsonEncryptedPassportElement final : public td::Jsonable { public: JsonEncryptedPassportElement(const td_api::encryptedPassportElement *element, const Client *client) : element_(element), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); auto id = element_->type_->get_id(); object("type", Client::get_passport_element_type(id)); @@ -1612,11 +1608,11 @@ class Client::JsonEncryptedPassportElement final : public Jsonable { const Client *client_; }; -class Client::JsonEncryptedCredentials final : public Jsonable { +class Client::JsonEncryptedCredentials final : public td::Jsonable { public: explicit JsonEncryptedCredentials(const td_api::encryptedCredentials *credentials) : credentials_(credentials) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("data", td::base64_encode(credentials_->data_)); object("hash", td::base64_encode(credentials_->hash_)); @@ -1627,12 +1623,12 @@ class Client::JsonEncryptedCredentials final : public Jsonable { const td_api::encryptedCredentials *credentials_; }; -class Client::JsonPassportData final : public Jsonable { +class Client::JsonPassportData final : public td::Jsonable { public: JsonPassportData(const td_api::messagePassportDataReceived *passport_data, const Client *client) : passport_data_(passport_data), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("data", td::json_array(passport_data_->elements_, [client = client_](auto &element) { return JsonEncryptedPassportElement(element.get(), client); @@ -1645,11 +1641,11 @@ class Client::JsonPassportData final : public Jsonable { const Client *client_; }; -class Client::JsonWebAppData final : public Jsonable { +class Client::JsonWebAppData final : public td::Jsonable { public: explicit JsonWebAppData(const td_api::messageWebAppDataReceived *web_app_data) : web_app_data_(web_app_data) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("button_text", web_app_data_->button_text_); object("data", web_app_data_->data_); @@ -1659,13 +1655,13 @@ class Client::JsonWebAppData final : public Jsonable { const td_api::messageWebAppDataReceived *web_app_data_; }; -class Client::JsonProximityAlertTriggered final : public Jsonable { +class Client::JsonProximityAlertTriggered final : public td::Jsonable { public: JsonProximityAlertTriggered(const td_api::messageProximityAlertTriggered *proximity_alert_triggered, const Client *client) : proximity_alert_triggered_(proximity_alert_triggered), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("traveler", JsonMessageSender(proximity_alert_triggered_->traveler_id_.get(), client_)); object("watcher", JsonMessageSender(proximity_alert_triggered_->watcher_id_.get(), client_)); @@ -1677,12 +1673,12 @@ class Client::JsonProximityAlertTriggered final : public Jsonable { const Client *client_; }; -class Client::JsonVideoChatScheduled final : public Jsonable { +class Client::JsonVideoChatScheduled final : public td::Jsonable { public: explicit JsonVideoChatScheduled(const td_api::messageVideoChatScheduled *video_chat_scheduled) : video_chat_scheduled_(video_chat_scheduled) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("start_date", video_chat_scheduled_->start_date_); } @@ -1691,12 +1687,12 @@ class Client::JsonVideoChatScheduled final : public Jsonable { const td_api::messageVideoChatScheduled *video_chat_scheduled_; }; -class Client::JsonVideoChatEnded final : public Jsonable { +class Client::JsonVideoChatEnded final : public td::Jsonable { public: explicit JsonVideoChatEnded(const td_api::messageVideoChatEnded *video_chat_ended) : video_chat_ended_(video_chat_ended) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("duration", video_chat_ended_->duration_); } @@ -1705,13 +1701,13 @@ class Client::JsonVideoChatEnded final : public Jsonable { const td_api::messageVideoChatEnded *video_chat_ended_; }; -class Client::JsonInviteVideoChatParticipants final : public Jsonable { +class Client::JsonInviteVideoChatParticipants final : public td::Jsonable { public: JsonInviteVideoChatParticipants(const td_api::messageInviteVideoChatParticipants *invite_video_chat_participants, const Client *client) : invite_video_chat_participants_(invite_video_chat_participants), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("users", JsonUsers(invite_video_chat_participants_->user_ids_, client_)); } @@ -1721,13 +1717,13 @@ class Client::JsonInviteVideoChatParticipants final : public Jsonable { const Client *client_; }; -class Client::JsonChatSetMessageAutoDeleteTime final : public Jsonable { +class Client::JsonChatSetMessageAutoDeleteTime final : public td::Jsonable { public: explicit JsonChatSetMessageAutoDeleteTime( const td_api::messageChatSetMessageAutoDeleteTime *chat_set_message_auto_delete_time) : chat_set_message_auto_delete_time_(chat_set_message_auto_delete_time) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("message_auto_delete_time", chat_set_message_auto_delete_time_->message_auto_delete_time_); } @@ -1736,11 +1732,11 @@ class Client::JsonChatSetMessageAutoDeleteTime final : public Jsonable { const td_api::messageChatSetMessageAutoDeleteTime *chat_set_message_auto_delete_time_; }; -class Client::JsonUserShared final : public Jsonable { +class Client::JsonUserShared final : public td::Jsonable { public: explicit JsonUserShared(const td_api::messageUserShared *user_shared) : user_shared_(user_shared) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("user_id", user_shared_->user_id_); object("request_id", user_shared_->button_id_); @@ -1750,11 +1746,11 @@ class Client::JsonUserShared final : public Jsonable { const td_api::messageUserShared *user_shared_; }; -class Client::JsonChatShared final : public Jsonable { +class Client::JsonChatShared final : public td::Jsonable { public: explicit JsonChatShared(const td_api::messageChatShared *chat_shared) : chat_shared_(chat_shared) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("chat_id", chat_shared_->chat_id_); object("request_id", chat_shared_->button_id_); @@ -1764,11 +1760,11 @@ class Client::JsonChatShared final : public Jsonable { const td_api::messageChatShared *chat_shared_; }; -class Client::JsonWebAppInfo final : public Jsonable { +class Client::JsonWebAppInfo final : public td::Jsonable { public: explicit JsonWebAppInfo(const td::string &url) : url_(url) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("url", url_); } @@ -1777,11 +1773,11 @@ class Client::JsonWebAppInfo final : public Jsonable { const td::string &url_; }; -class Client::JsonInlineKeyboardButton final : public Jsonable { +class Client::JsonInlineKeyboardButton final : public td::Jsonable { public: explicit JsonInlineKeyboardButton(const td_api::inlineKeyboardButton *button) : button_(button) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("text", button_->text_); switch (button_->type_->get_id()) { @@ -1840,12 +1836,12 @@ class Client::JsonInlineKeyboardButton final : public Jsonable { const td_api::inlineKeyboardButton *button_; }; -class Client::JsonInlineKeyboard final : public Jsonable { +class Client::JsonInlineKeyboard final : public td::Jsonable { public: explicit JsonInlineKeyboard(const td_api::replyMarkupInlineKeyboard *inline_keyboard) : inline_keyboard_(inline_keyboard) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &row : inline_keyboard_->rows_) { array << td::json_array(row, [](auto &button) { return JsonInlineKeyboardButton(button.get()); }); @@ -1856,11 +1852,11 @@ class Client::JsonInlineKeyboard final : public Jsonable { const td_api::replyMarkupInlineKeyboard *inline_keyboard_; }; -class Client::JsonReplyMarkup final : public Jsonable { +class Client::JsonReplyMarkup final : public td::Jsonable { public: explicit JsonReplyMarkup(const td_api::ReplyMarkup *reply_markup) : reply_markup_(reply_markup) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { CHECK(reply_markup_->get_id() == td_api::replyMarkupInlineKeyboard::ID); auto object = scope->enter_object(); object("inline_keyboard", @@ -1871,7 +1867,7 @@ class Client::JsonReplyMarkup final : public Jsonable { const td_api::ReplyMarkup *reply_markup_; }; -void Client::JsonMessage::store(JsonValueScope *scope) const { +void Client::JsonMessage::store(td::JsonValueScope *scope) const { CHECK(message_ != nullptr); auto object = scope->enter_object(); object("message_id", as_client_message_id(message_->id)); @@ -2265,12 +2261,12 @@ void Client::JsonMessage::store(JsonValueScope *scope) const { } } -class Client::JsonDeletedMessage final : public Jsonable { +class Client::JsonDeletedMessage final : public td::Jsonable { public: JsonDeletedMessage(int64 chat_id, int64 message_id, const Client *client) : chat_id_(chat_id), message_id_(message_id), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("message_id", as_client_message_id(message_id_)); object("chat", JsonChat(chat_id_, false, client_)); @@ -2283,11 +2279,11 @@ class Client::JsonDeletedMessage final : public Jsonable { const Client *client_; }; -class Client::JsonMessageId final : public Jsonable { +class Client::JsonMessageId final : public td::Jsonable { public: explicit JsonMessageId(int64 message_id) : message_id_(message_id) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("message_id", as_client_message_id(message_id_)); } @@ -2296,7 +2292,7 @@ class Client::JsonMessageId final : public Jsonable { int64 message_id_; }; -class Client::JsonInlineQuery final : public Jsonable { +class Client::JsonInlineQuery final : public td::Jsonable { public: JsonInlineQuery(int64 inline_query_id, int64 sender_user_id, const td_api::location *user_location, const td_api::ChatType *chat_type, const td::string &query, const td::string &offset, @@ -2310,7 +2306,7 @@ class Client::JsonInlineQuery final : public Jsonable { , client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("id", td::to_string(inline_query_id_)); object("from", JsonUser(sender_user_id_, client_)); @@ -2362,7 +2358,7 @@ class Client::JsonInlineQuery final : public Jsonable { const Client *client_; }; -class Client::JsonChosenInlineResult final : public Jsonable { +class Client::JsonChosenInlineResult final : public td::Jsonable { public: JsonChosenInlineResult(int64 sender_user_id, const td_api::location *user_location, const td::string &query, const td::string &result_id, const td::string &inline_message_id, const Client *client) @@ -2374,7 +2370,7 @@ class Client::JsonChosenInlineResult final : public Jsonable { , client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("from", JsonUser(sender_user_id_, client_)); if (user_location_ != nullptr) { @@ -2396,7 +2392,7 @@ class Client::JsonChosenInlineResult final : public Jsonable { const Client *client_; }; -class Client::JsonCallbackQuery final : public Jsonable { +class Client::JsonCallbackQuery final : public td::Jsonable { public: JsonCallbackQuery(int64 callback_query_id, int64 sender_user_id, int64 chat_id, int64 message_id, const MessageInfo *message_info, int64 chat_instance, td_api::CallbackQueryPayload *payload, @@ -2411,7 +2407,7 @@ class Client::JsonCallbackQuery final : public Jsonable { , client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("id", td::to_string(callback_query_id_)); object("from", JsonUser(sender_user_id_, client_)); @@ -2435,7 +2431,7 @@ class Client::JsonCallbackQuery final : public Jsonable { const Client *client_; }; -class Client::JsonInlineCallbackQuery final : public Jsonable { +class Client::JsonInlineCallbackQuery final : public td::Jsonable { public: JsonInlineCallbackQuery(int64 callback_query_id, int64 sender_user_id, const td::string &inline_message_id, int64 chat_instance, td_api::CallbackQueryPayload *payload, const Client *client) @@ -2447,7 +2443,7 @@ class Client::JsonInlineCallbackQuery final : public Jsonable { , client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("id", td::to_string(callback_query_id_)); object("from", JsonUser(sender_user_id_, client_)); @@ -2465,13 +2461,13 @@ class Client::JsonInlineCallbackQuery final : public Jsonable { const Client *client_; }; -class Client::JsonShippingQuery final : public Jsonable { +class Client::JsonShippingQuery final : public td::Jsonable { public: JsonShippingQuery(const td_api::updateNewShippingQuery *query, const Client *client) : query_(query), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("id", td::to_string(query_->id_)); object("from", JsonUser(query_->sender_user_id_, client_)); @@ -2489,13 +2485,13 @@ class Client::JsonShippingQuery final : public Jsonable { const Client *client_; }; -class Client::JsonPreCheckoutQuery final : public Jsonable { +class Client::JsonPreCheckoutQuery final : public td::Jsonable { public: JsonPreCheckoutQuery(const td_api::updateNewPreCheckoutQuery *query, const Client *client) : query_(query), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("id", td::to_string(query_->id_)); object("from", JsonUser(query_->sender_user_id_, client_)); @@ -2520,12 +2516,12 @@ class Client::JsonPreCheckoutQuery final : public Jsonable { const Client *client_; }; -class Client::JsonCustomJson final : public Jsonable { +class Client::JsonCustomJson final : public td::Jsonable { public: explicit JsonCustomJson(const td::string &json) : json_(json) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { *scope << td::JsonRaw(json_); } @@ -2533,11 +2529,11 @@ class Client::JsonCustomJson final : public Jsonable { const td::string &json_; }; -class Client::JsonBotCommand final : public Jsonable { +class Client::JsonBotCommand final : public td::Jsonable { public: explicit JsonBotCommand(const td_api::botCommand *command) : command_(command) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("command", command_->command_); object("description", command_->description_); @@ -2547,11 +2543,11 @@ class Client::JsonBotCommand final : public Jsonable { const td_api::botCommand *command_; }; -class Client::JsonBotMenuButton final : public Jsonable { +class Client::JsonBotMenuButton final : public td::Jsonable { public: explicit JsonBotMenuButton(const td_api::botMenuButton *menu_button) : menu_button_(menu_button) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); if (menu_button_->text_.empty()) { object("type", menu_button_->url_.empty() ? "commands" : "default"); @@ -2566,13 +2562,13 @@ class Client::JsonBotMenuButton final : public Jsonable { const td_api::botMenuButton *menu_button_; }; -class Client::JsonChatAdministratorRights final : public Jsonable { +class Client::JsonChatAdministratorRights final : public td::Jsonable { public: JsonChatAdministratorRights(const td_api::chatAdministratorRights *rights, Client::ChatType chat_type) : rights_(rights), chat_type_(chat_type) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); td_api::chatAdministratorRights empty_rights; Client::json_store_administrator_rights(object, rights_ == nullptr ? &empty_rights : rights_, chat_type_); @@ -2583,11 +2579,11 @@ class Client::JsonChatAdministratorRights final : public Jsonable { Client::ChatType chat_type_; }; -class Client::JsonChatPhotos final : public Jsonable { +class Client::JsonChatPhotos final : public td::Jsonable { public: JsonChatPhotos(const td_api::chatPhotos *photos, const Client *client) : photos_(photos), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("total_count", photos_->total_count_); object("photos", td::json_array(photos_->photos_, @@ -2599,13 +2595,13 @@ class Client::JsonChatPhotos final : public Jsonable { const Client *client_; }; -class Client::JsonChatMember final : public Jsonable { +class Client::JsonChatMember final : public td::Jsonable { public: JsonChatMember(const td_api::chatMember *member, Client::ChatType chat_type, const Client *client) : member_(member), chat_type_(chat_type), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); CHECK(member_->member_id_ != nullptr); switch (member_->member_id_->get_id()) { @@ -2668,13 +2664,13 @@ class Client::JsonChatMember final : public Jsonable { const Client *client_; }; -class Client::JsonChatMembers final : public Jsonable { +class Client::JsonChatMembers final : public td::Jsonable { public: JsonChatMembers(const td::vector> &members, Client::ChatType chat_type, bool administrators_only, const Client *client) : members_(members), chat_type_(chat_type), administrators_only_(administrators_only), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (auto &member : members_) { CHECK(member != nullptr); @@ -2705,12 +2701,12 @@ class Client::JsonChatMembers final : public Jsonable { const Client *client_; }; -class Client::JsonChatMemberUpdated final : public Jsonable { +class Client::JsonChatMemberUpdated final : public td::Jsonable { public: JsonChatMemberUpdated(const td_api::updateChatMember *update, const Client *client) : update_(update), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("chat", JsonChat(update_->chat_id_, false, client_)); object("from", JsonUser(update_->actor_user_id_, client_)); @@ -2728,12 +2724,12 @@ class Client::JsonChatMemberUpdated final : public Jsonable { const Client *client_; }; -class Client::JsonChatJoinRequest final : public Jsonable { +class Client::JsonChatJoinRequest final : public td::Jsonable { public: JsonChatJoinRequest(const td_api::updateNewChatJoinRequest *update, const Client *client) : update_(update), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("chat", JsonChat(update_->chat_id_, false, client_)); object("from", JsonUser(update_->request_->user_id_, client_)); @@ -2752,12 +2748,12 @@ class Client::JsonChatJoinRequest final : public Jsonable { const Client *client_; }; -class Client::JsonGameHighScore final : public Jsonable { +class Client::JsonGameHighScore final : public td::Jsonable { public: JsonGameHighScore(const td_api::gameHighScore *score, const Client *client) : score_(score), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); object("position", score_->position_); object("user", JsonUser(score_->user_id_, client_)); @@ -2769,11 +2765,11 @@ class Client::JsonGameHighScore final : public Jsonable { const Client *client_; }; -class Client::JsonUpdateTypes final : public Jsonable { +class Client::JsonUpdateTypes final : public td::Jsonable { public: explicit JsonUpdateTypes(td::uint32 update_types) : update_types_(update_types) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); for (int32 i = 0; i < static_cast(UpdateType::Size); i++) { if (((update_types_ >> i) & 1) != 0) { @@ -2789,11 +2785,11 @@ class Client::JsonUpdateTypes final : public Jsonable { td::uint32 update_types_; }; -class Client::JsonWebhookInfo final : public Jsonable { +class Client::JsonWebhookInfo final : public td::Jsonable { public: explicit JsonWebhookInfo(const Client *client) : client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); td::CSlice url = client_->webhook_url_; if (td::check_utf8(url)) { @@ -2830,12 +2826,12 @@ class Client::JsonWebhookInfo final : public Jsonable { const Client *client_; }; -class Client::JsonStickerSet final : public Jsonable { +class Client::JsonStickerSet final : public td::Jsonable { public: JsonStickerSet(const td_api::stickerSet *sticker_set, const Client *client) : sticker_set_(sticker_set), client_(client) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); if (sticker_set_->id_ == Client::GREAT_MINDS_SET_ID) { object("name", GREAT_MINDS_SET_NAME); @@ -2863,11 +2859,11 @@ class Client::JsonStickerSet final : public Jsonable { const Client *client_; }; -class Client::JsonSentWebAppMessage final : public Jsonable { +class Client::JsonSentWebAppMessage final : public td::Jsonable { public: explicit JsonSentWebAppMessage(const td_api::sentWebAppMessage *message) : message_(message) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto object = scope->enter_object(); if (!message_->inline_message_id_.empty()) { object("inline_message_id", message_->inline_message_id_); @@ -5357,8 +5353,8 @@ bool Client::to_bool(td::MutableSlice value) { return value == "true" || value == "yes" || value == "1"; } -td::Result> Client::get_keyboard_button(JsonValue &button) { - if (button.type() == JsonValue::Type::Object) { +td::Result> Client::get_keyboard_button(td::JsonValue &button) { + if (button.type() == td::JsonValue::Type::Object) { auto &object = button.get_object(); TRY_RESULT(text, get_json_object_string_field(object, "text", false)); @@ -5377,7 +5373,7 @@ td::Result> Client::get_keyboard_butt if (has_json_object_field(object, "request_poll")) { bool force_regular = false; bool force_quiz = false; - TRY_RESULT(request_poll, get_json_object_field(object, "request_poll", JsonValue::Type::Object, false)); + TRY_RESULT(request_poll, get_json_object_field(object, "request_poll", td::JsonValue::Type::Object, false)); auto &request_poll_object = request_poll.get_object(); if (has_json_object_field(request_poll_object, "type")) { TRY_RESULT(type, get_json_object_string_field(request_poll_object, "type")); @@ -5392,14 +5388,14 @@ td::Result> Client::get_keyboard_butt } if (has_json_object_field(object, "web_app")) { - TRY_RESULT(web_app, get_json_object_field(object, "web_app", JsonValue::Type::Object, false)); + TRY_RESULT(web_app, get_json_object_field(object, "web_app", td::JsonValue::Type::Object, false)); auto &web_app_object = web_app.get_object(); TRY_RESULT(url, get_json_object_string_field(web_app_object, "url", false)); return make_object(text, make_object(url)); } if (has_json_object_field(object, "request_user")) { - TRY_RESULT(request_user, get_json_object_field(object, "request_user", JsonValue::Type::Object, false)); + TRY_RESULT(request_user, get_json_object_field(object, "request_user", td::JsonValue::Type::Object, false)); auto &request_user_object = request_user.get_object(); TRY_RESULT(id, get_json_object_int_field(request_user_object, "request_id", false)); auto restrict_user_is_bot = has_json_object_field(request_user_object, "user_is_bot"); @@ -5412,7 +5408,7 @@ td::Result> Client::get_keyboard_butt } if (has_json_object_field(object, "request_chat")) { - TRY_RESULT(request_chat, get_json_object_field(object, "request_chat", JsonValue::Type::Object, false)); + TRY_RESULT(request_chat, get_json_object_field(object, "request_chat", td::JsonValue::Type::Object, false)); auto &request_chat_object = request_chat.get_object(); TRY_RESULT(id, get_json_object_int_field(request_chat_object, "request_id", false)); TRY_RESULT(chat_is_channel, get_json_object_bool_field(request_chat_object, "chat_is_channel")); @@ -5441,15 +5437,15 @@ td::Result> Client::get_keyboard_butt return make_object(text, nullptr); } - if (button.type() == JsonValue::Type::String) { + if (button.type() == td::JsonValue::Type::String) { return make_object(button.get_string().str(), nullptr); } return td::Status::Error(400, "KeyboardButton must be a String or an Object"); } -td::Result> Client::get_inline_keyboard_button(JsonValue &button) { - if (button.type() != JsonValue::Type::Object) { +td::Result> Client::get_inline_keyboard_button(td::JsonValue &button) { + if (button.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "InlineKeyboardButton must be an Object"); } @@ -5492,8 +5488,8 @@ td::Result> Client::get_inline_ } if (has_json_object_field(object, "login_url")) { - TRY_RESULT(login_url, get_json_object_field(object, "login_url", JsonValue::Type::Object, false)); - CHECK(login_url.type() == JsonValue::Type::Object); + TRY_RESULT(login_url, get_json_object_field(object, "login_url", td::JsonValue::Type::Object, false)); + CHECK(login_url.type() == td::JsonValue::Type::Object); auto &login_url_object = login_url.get_object(); TRY_RESULT(url, get_json_object_string_field(login_url_object, "url", false)); TRY_RESULT(bot_username, get_json_object_string_field(login_url_object, "bot_username")); @@ -5536,7 +5532,7 @@ td::Result> Client::get_inline_ } if (has_json_object_field(object, "web_app")) { - TRY_RESULT(web_app, get_json_object_field(object, "web_app", JsonValue::Type::Object, false)); + TRY_RESULT(web_app, get_json_object_field(object, "web_app", td::JsonValue::Type::Object, false)); auto &web_app_object = web_app.get_object(); TRY_RESULT(url, get_json_object_string_field(web_app_object, "url", false)); return make_object(text, make_object(url)); @@ -5561,7 +5557,7 @@ td::Result> Client::get_reply_markup(con return get_reply_markup(r_value.move_as_ok()); } -td::Result> Client::get_reply_markup(JsonValue &&value) { +td::Result> Client::get_reply_markup(td::JsonValue &&value) { td::vector>> rows; td::vector>> inline_rows; td::Slice input_field_placeholder; @@ -5572,18 +5568,18 @@ td::Result> Client::get_reply_markup(Jso bool is_personal = false; bool force_reply = false; - if (value.type() != JsonValue::Type::Object) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "Object expected as reply markup"); } for (auto &field_value : value.get_object()) { if (field_value.first == "keyboard") { auto keyboard = std::move(field_value.second); - if (keyboard.type() != JsonValue::Type::Array) { + if (keyboard.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Field \"keyboard\" of the ReplyKeyboardMarkup must be an Array"); } for (auto &row : keyboard.get_array()) { td::vector> new_row; - if (row.type() != JsonValue::Type::Array) { + if (row.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Field \"keyboard\" of the ReplyKeyboardMarkup must be an Array of Arrays"); } for (auto &button : row.get_array()) { @@ -5598,12 +5594,12 @@ td::Result> Client::get_reply_markup(Jso } } else if (field_value.first == "inline_keyboard") { auto inline_keyboard = std::move(field_value.second); - if (inline_keyboard.type() != JsonValue::Type::Array) { + if (inline_keyboard.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Field \"inline_keyboard\" of the InlineKeyboardMarkup must be an Array"); } for (auto &inline_row : inline_keyboard.get_array()) { td::vector> new_inline_row; - if (inline_row.type() != JsonValue::Type::Array) { + if (inline_row.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Field \"inline_keyboard\" of the InlineKeyboardMarkup must be an Array of Arrays"); } @@ -5619,40 +5615,40 @@ td::Result> Client::get_reply_markup(Jso inline_rows.push_back(std::move(new_inline_row)); } } else if (field_value.first == "resize_keyboard") { - if (field_value.second.type() != JsonValue::Type::Boolean) { + if (field_value.second.type() != td::JsonValue::Type::Boolean) { return td::Status::Error(400, "Field \"resize_keyboard\" of the ReplyKeyboardMarkup must be of the type Boolean"); } resize_keyboard = field_value.second.get_boolean(); } else if (field_value.first == "is_persistent") { - if (field_value.second.type() != JsonValue::Type::Boolean) { + if (field_value.second.type() != td::JsonValue::Type::Boolean) { return td::Status::Error(400, "Field \"is_persistent\" of the ReplyKeyboardMarkup must be of the type Boolean"); } is_persistent = field_value.second.get_boolean(); } else if (field_value.first == "one_time_keyboard") { - if (field_value.second.type() != JsonValue::Type::Boolean) { + if (field_value.second.type() != td::JsonValue::Type::Boolean) { return td::Status::Error(400, "Field \"one_time_keyboard\" of the ReplyKeyboardMarkup must be of the type Boolean"); } one_time = field_value.second.get_boolean(); } else if (field_value.first == "hide_keyboard" || field_value.first == "remove_keyboard") { - if (field_value.second.type() != JsonValue::Type::Boolean) { + if (field_value.second.type() != td::JsonValue::Type::Boolean) { return td::Status::Error(400, "Field \"remove_keyboard\" of the ReplyKeyboardRemove must be of the type Boolean"); } remove = field_value.second.get_boolean(); } else if (field_value.first == "personal_keyboard" || field_value.first == "selective") { - if (field_value.second.type() != JsonValue::Type::Boolean) { + if (field_value.second.type() != td::JsonValue::Type::Boolean) { return td::Status::Error(400, "Field \"selective\" of the reply markup must be of the type Boolean"); } is_personal = field_value.second.get_boolean(); } else if (field_value.first == "force_reply_keyboard" || field_value.first == "force_reply") { - if (field_value.second.type() != JsonValue::Type::Boolean) { + if (field_value.second.type() != td::JsonValue::Type::Boolean) { return td::Status::Error(400, "Field \"force_reply\" of the reply markup must be of the type Boolean"); } force_reply = field_value.second.get_boolean(); } else if (field_value.first == "input_field_placeholder") { - if (field_value.second.type() != JsonValue::Type::String) { + if (field_value.second.type() != td::JsonValue::Type::String) { return td::Status::Error(400, "Field \"input_field_placeholder\" of the reply markup must be of the type String"); } @@ -5678,8 +5674,8 @@ td::Result> Client::get_reply_markup(Jso return std::move(result); } -td::Result> Client::get_labeled_price_part(JsonValue &value) { - if (value.type() != JsonValue::Type::Object) { +td::Result> Client::get_labeled_price_part(td::JsonValue &value) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "LabeledPrice must be an Object"); } @@ -5690,11 +5686,11 @@ td::Result> Client::get_labeled_pri return td::Status::Error(400, "LabeledPrice label must be non-empty"); } - TRY_RESULT(amount, get_json_object_field(object, "amount", JsonValue::Type::Null, false)); + TRY_RESULT(amount, get_json_object_field(object, "amount", td::JsonValue::Type::Null, false)); td::Slice number; - if (amount.type() == JsonValue::Type::Number) { + if (amount.type() == td::JsonValue::Type::Number) { number = amount.get_number(); - } else if (amount.type() == JsonValue::Type::String) { + } else if (amount.type() == td::JsonValue::Type::String) { number = amount.get_string(); } else { return td::Status::Error(400, "Field \"amount\" must be of type Number or String"); @@ -5706,8 +5702,9 @@ td::Result> Client::get_labeled_pri return make_object(label, parsed_amount.ok()); } -td::Result>> Client::get_labeled_price_parts(JsonValue &value) { - if (value.type() != JsonValue::Type::Array) { +td::Result>> Client::get_labeled_price_parts( + td::JsonValue &value) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of labeled prices"); } @@ -5726,17 +5723,17 @@ td::Result>> Client::get return std::move(prices); } -td::Result> Client::get_suggested_tip_amounts(JsonValue &value) { - if (value.type() != JsonValue::Type::Array) { +td::Result> Client::get_suggested_tip_amounts(td::JsonValue &value) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of suggested tip amounts"); } td::vector suggested_tip_amounts; for (auto &amount : value.get_array()) { td::Slice number; - if (amount.type() == JsonValue::Type::Number) { + if (amount.type() == td::JsonValue::Type::Number) { number = amount.get_number(); - } else if (amount.type() == JsonValue::Type::String) { + } else if (amount.type() == td::JsonValue::Type::String) { number = amount.get_string(); } else { return td::Status::Error(400, "Suggested tip amount must be of type Number or String"); @@ -5750,8 +5747,8 @@ td::Result> Client::get_suggested_tip_amounts(JsonValue &v return std::move(suggested_tip_amounts); } -td::Result> Client::get_shipping_option(JsonValue &option) { - if (option.type() != JsonValue::Type::Object) { +td::Result> Client::get_shipping_option(td::JsonValue &option) { + if (option.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "ShippingOption must be an Object"); } @@ -5767,7 +5764,7 @@ td::Result> Client::get_shipping_opti return td::Status::Error(400, "ShippingOption title must be non-empty"); } - TRY_RESULT(prices_json, get_json_object_field(object, "prices", JsonValue::Type::Array, false)); + TRY_RESULT(prices_json, get_json_object_field(object, "prices", td::JsonValue::Type::Array, false)); auto r_prices = get_labeled_price_parts(prices_json); if (r_prices.is_error()) { @@ -5790,8 +5787,8 @@ td::Result>> Client::get_s return get_shipping_options(r_value.move_as_ok()); } -td::Result>> Client::get_shipping_options(JsonValue &&value) { - if (value.type() != JsonValue::Type::Array) { +td::Result>> Client::get_shipping_options(td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of shipping options"); } @@ -5910,8 +5907,8 @@ td_api::object_ptr Client::get_input_thumbnail(const Que } td::Result> Client::get_input_message_content( - JsonValue &input_message_content, bool is_input_message_content_required) { - CHECK(input_message_content.type() == JsonValue::Type::Object); + td::JsonValue &input_message_content, bool is_input_message_content_required) { + CHECK(input_message_content.type() == td::JsonValue::Type::Object); auto &object = input_message_content.get_object(); TRY_RESULT(message_text, get_json_object_string_field(object, "message_text")); @@ -5982,14 +5979,14 @@ td::Result> Client::get_input_me } TRY_RESULT(provider_token, get_json_object_string_field(object, "provider_token", false)); TRY_RESULT(currency, get_json_object_string_field(object, "currency", false)); - TRY_RESULT(prices_object, get_json_object_field(object, "prices", JsonValue::Type::Array, false)); + TRY_RESULT(prices_object, get_json_object_field(object, "prices", td::JsonValue::Type::Array, false)); TRY_RESULT(prices, get_labeled_price_parts(prices_object)); TRY_RESULT(provider_data, get_json_object_string_field(object, "provider_data")); TRY_RESULT(max_tip_amount, get_json_object_long_field(object, "max_tip_amount")); td::vector suggested_tip_amounts; TRY_RESULT(suggested_tip_amounts_array, - get_json_object_field(object, "suggested_tip_amounts", JsonValue::Type::Array)); - if (suggested_tip_amounts_array.type() == JsonValue::Type::Array) { + get_json_object_field(object, "suggested_tip_amounts", td::JsonValue::Type::Array)); + if (suggested_tip_amounts_array.type() == td::JsonValue::Type::Array) { TRY_RESULT_ASSIGN(suggested_tip_amounts, get_suggested_tip_amounts(suggested_tip_amounts_array)); } TRY_RESULT(photo_url, get_json_object_string_field(object, "photo_url")); @@ -6043,10 +6040,10 @@ td::Result>> Clien td::Result>> Client::get_inline_query_results( td::JsonValue &&values) { - if (values.type() == JsonValue::Type::Null) { + if (values.type() == td::JsonValue::Type::Null) { return td::vector>(); } - if (values.type() != JsonValue::Type::Array) { + if (values.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of inline query results"); } @@ -6080,7 +6077,7 @@ td::Result> Client::get_inlin } td::Result> Client::get_inline_query_result(td::JsonValue &&value) { - if (value.type() != JsonValue::Type::Object) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "Inline query result must be an object"); } @@ -6095,8 +6092,8 @@ td::Result> Client::get_inlin object_ptr input_message_content; TRY_RESULT(input_message_content_obj, - get_json_object_field(object, "input_message_content", JsonValue::Type::Object)); - if (input_message_content_obj.type() == JsonValue::Type::Null) { + get_json_object_field(object, "input_message_content", td::JsonValue::Type::Object)); + if (input_message_content_obj.type() == td::JsonValue::Type::Null) { TRY_RESULT(message_text, get_json_object_string_field(object, "message_text", !is_input_message_content_required)); TRY_RESULT(disable_web_page_preview, get_json_object_bool_field(object, "disable_web_page_preview")); TRY_RESULT(parse_mode, get_json_object_string_field(object, "parse_mode")); @@ -6117,9 +6114,9 @@ td::Result> Client::get_inlin auto entities = get_json_object_field_force(object, "caption_entities"); TRY_RESULT(caption, get_formatted_text(std::move(input_caption), std::move(parse_mode), std::move(entities))); - TRY_RESULT(reply_markup_object, get_json_object_field(object, "reply_markup", JsonValue::Type::Object)); + TRY_RESULT(reply_markup_object, get_json_object_field(object, "reply_markup", td::JsonValue::Type::Object)); object_ptr reply_markup; - if (reply_markup_object.type() != JsonValue::Type::Null) { + if (reply_markup_object.type() != td::JsonValue::Type::Null) { TRY_RESULT_ASSIGN(reply_markup, get_reply_markup(std::move(reply_markup_object))); } @@ -6366,8 +6363,8 @@ td::Result> Client::get_inlin return td::Status::Error(400, PSLICE() << "type \"" << type << "\" is unsupported for the inline query result"); } -td::Result Client::get_bot_command_scope(JsonValue &&value) { - if (value.type() != JsonValue::Type::Object) { +td::Result Client::get_bot_command_scope(td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "BotCommandScope must be an Object"); } @@ -6429,8 +6426,8 @@ td::Result Client::get_bot_command_scope(const Query *q return r_scope.move_as_ok(); } -td::Result> Client::get_bot_command(JsonValue &&value) { - if (value.type() != JsonValue::Type::Object) { +td::Result> Client::get_bot_command(td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "expected an Object"); } @@ -6455,7 +6452,7 @@ td::Result>> Client::get_bot_c } auto value = r_value.move_as_ok(); - if (value.type() != JsonValue::Type::Array) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of BotCommand"); } @@ -6470,8 +6467,8 @@ td::Result>> Client::get_bot_c return std::move(bot_commands); } -td::Result> Client::get_bot_menu_button(JsonValue &&value) { - if (value.type() != JsonValue::Type::Object) { +td::Result> Client::get_bot_menu_button(td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "MenuButton must be an Object"); } @@ -6486,7 +6483,7 @@ td::Result> Client::get_bot_menu_butto } if (type == "web_app") { TRY_RESULT(text, get_json_object_string_field(object, "text", false)); - TRY_RESULT(web_app, get_json_object_field(object, "web_app", JsonValue::Type::Object, false)); + TRY_RESULT(web_app, get_json_object_field(object, "web_app", td::JsonValue::Type::Object, false)); auto &web_app_object = web_app.get_object(); TRY_RESULT(url, get_json_object_string_field(web_app_object, "url", false)); return td_api::make_object(text, url); @@ -6516,8 +6513,8 @@ td::Result> Client::get_bot_menu_butto } td::Result> Client::get_chat_administrator_rights( - JsonValue &&value) { - if (value.type() != JsonValue::Type::Object) { + td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "ChatAdministratorRights must be an Object"); } @@ -6561,9 +6558,9 @@ td::Result> Client::get_chat return r_rights.move_as_ok(); } -td::Result> Client::get_mask_position(JsonValue &&value) { - if (value.type() != JsonValue::Type::Object) { - if (value.type() == JsonValue::Type::Null) { +td::Result> Client::get_mask_position(td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Object) { + if (value.type() == td::JsonValue::Type::Null) { return nullptr; } return td::Status::Error(400, "MaskPosition must be an Object"); @@ -6644,8 +6641,8 @@ td::Result> Client::get_mask_position(c return r_mask_position.move_as_ok(); } -td::Result Client::get_sticker_emojis(JsonValue &&value) { - if (value.type() != JsonValue::Type::Array) { +td::Result Client::get_sticker_emojis(td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "expected an Array of string"); } @@ -6658,7 +6655,7 @@ td::Result Client::get_sticker_emojis(JsonValue &&value) { return td::Status::Error(400, "too many emoji specified"); } for (auto &emoji : value.get_array()) { - if (emoji.type() != JsonValue::Type::String) { + if (emoji.type() != td::JsonValue::Type::String) { return td::Status::Error(400, "emoji must be a string"); } if (!td::is_emoji(emoji.get_string())) { @@ -6698,8 +6695,8 @@ td::Result> Client::get_sticker_format } td::Result> Client::get_input_sticker(const Query *query, - JsonValue &&value) const { - if (value.type() != JsonValue::Type::Object) { + td::JsonValue &&value) const { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "InputSticker must be an Object"); } @@ -6710,14 +6707,14 @@ td::Result> Client::get_input_sticker(c if (input_file == nullptr) { return td::Status::Error("sticker not found"); } - TRY_RESULT(emoji_list, get_json_object_field(object, "emoji_list", JsonValue::Type::Array, false)); + TRY_RESULT(emoji_list, get_json_object_field(object, "emoji_list", td::JsonValue::Type::Array, false)); TRY_RESULT(emojis, get_sticker_emojis(std::move(emoji_list))); TRY_RESULT(mask_position, get_mask_position(get_json_object_field_force(object, "mask_position"))); td::vector input_keywords; if (has_json_object_field(object, "keywords")) { - TRY_RESULT(keywords, get_json_object_field(object, "keywords", JsonValue::Type::Array, false)); + TRY_RESULT(keywords, get_json_object_field(object, "keywords", td::JsonValue::Type::Array, false)); for (auto &keyword : keywords.get_array()) { - if (keyword.type() != JsonValue::Type::String) { + if (keyword.type() != td::JsonValue::Type::String) { return td::Status::Error(400, "keyword must be a string"); } input_keywords.push_back(keyword.get_string().str()); @@ -6783,7 +6780,7 @@ td::Result>> Client::get_inp } auto value = r_value.move_as_ok(); - if (value.type() != JsonValue::Type::Array) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of InputSticker"); } @@ -6892,9 +6889,9 @@ td::Result> Client:: } if (source == "files" || source == "translation_files") { td::vector input_hashes; - TRY_RESULT(file_hashes, get_json_object_field(object, "file_hashes", JsonValue::Type::Array, false)); + TRY_RESULT(file_hashes, get_json_object_field(object, "file_hashes", td::JsonValue::Type::Array, false)); for (auto &input_hash : file_hashes.get_array()) { - if (input_hash.type() != JsonValue::Type::String) { + if (input_hash.type() != td::JsonValue::Type::String) { return td::Status::Error(400, "hash must be a string"); } TRY_RESULT(hash, get_passport_element_hash(input_hash.get_string())); @@ -6912,8 +6909,8 @@ td::Result> Client:: } td::Result> Client::get_passport_element_error( - JsonValue &&value) { - if (value.type() != JsonValue::Type::Object) { + td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "expected an Object"); } @@ -6941,7 +6938,7 @@ td::Result>> Cl } auto value = r_value.move_as_ok(); - if (value.type() != JsonValue::Type::Array) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of PassportElementError"); } @@ -6956,7 +6953,7 @@ td::Result>> Cl return std::move(errors); } -JsonValue Client::get_input_entities(const Query *query, td::Slice field_name) { +td::JsonValue Client::get_input_entities(const Query *query, td::Slice field_name) { auto entities = query->arg(field_name); if (!entities.empty()) { auto r_value = json_decode(entities); @@ -6967,7 +6964,7 @@ JsonValue Client::get_input_entities(const Query *query, td::Slice field_name) { LOG(INFO) << "Can't parse entities JSON object: " << r_value.error(); } - return JsonValue(); + return td::JsonValue(); } td::Result> Client::get_caption(const Query *query) { @@ -7011,8 +7008,8 @@ td::Result> Client::get_text_entity_t return make_object(url); } if (type == "text_mention") { - TRY_RESULT(user, get_json_object_field(object, "user", JsonValue::Type::Object, false)); - CHECK(user.type() == JsonValue::Type::Object); + TRY_RESULT(user, get_json_object_field(object, "user", td::JsonValue::Type::Object, false)); + CHECK(user.type() == td::JsonValue::Type::Object); TRY_RESULT(user_id, get_json_object_long_field(user.get_object(), "id", false)); return make_object(user_id); } @@ -7028,8 +7025,8 @@ td::Result> Client::get_text_entity_t return td::Status::Error("Unsupported type specified"); } -td::Result> Client::get_text_entity(JsonValue &&value) { - if (value.type() != JsonValue::Type::Object) { +td::Result> Client::get_text_entity(td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "expected an Object"); } @@ -7046,7 +7043,7 @@ td::Result> Client::get_text_entity(JsonV } td::Result> Client::get_formatted_text(td::string text, td::string parse_mode, - JsonValue &&input_entities) { + td::JsonValue &&input_entities) { td::to_lower_inplace(parse_mode); if (!text.empty() && !parse_mode.empty() && parse_mode != "none") { object_ptr text_parse_mode; @@ -7071,7 +7068,7 @@ td::Result> Client::get_formatted_text } td::vector> entities; - if (input_entities.type() == JsonValue::Type::Array) { + if (input_entities.type() == td::JsonValue::Type::Array) { for (auto &input_entity : input_entities.get_array()) { auto r_entity = get_text_entity(std::move(input_entity)); if (r_entity.is_error()) { @@ -7092,10 +7089,8 @@ td::Result> Client::get_input_messa query->arg("parse_mode").str(), get_input_entities(query, "entities")); } -td::Result> Client::get_input_message_text(td::string text, - bool disable_web_page_preview, - td::string parse_mode, - JsonValue &&input_entities) { +td::Result> Client::get_input_message_text( + td::string text, bool disable_web_page_preview, td::string parse_mode, td::JsonValue &&input_entities) { if (text.empty()) { return td::Status::Error(400, "Message text is empty"); } @@ -7147,7 +7142,7 @@ td::Result> Client::get_chat_permiss } auto value = r_value.move_as_ok(); - if (value.type() != JsonValue::Type::Object) { + if (value.type() != td::JsonValue::Type::Object) { return td::Status::Error(400, "Object expected as permissions"); } auto &object = value.get_object(); @@ -7247,9 +7242,9 @@ td::Result> Client::get_chat_permiss } td::Result> Client::get_input_media(const Query *query, - JsonValue &&input_media, + td::JsonValue &&input_media, bool for_album) const { - if (input_media.type() != JsonValue::Type::Object) { + if (input_media.type() != td::JsonValue::Type::Object) { return td::Status::Error("expected an Object"); } @@ -7367,8 +7362,8 @@ td::Result>> Client:: } td::Result>> Client::get_input_message_contents( - const Query *query, JsonValue &&value) const { - if (value.type() != JsonValue::Type::Array) { + const Query *query, td::JsonValue &&value) const { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of InputMedia"); } @@ -7465,13 +7460,13 @@ td::Result> Client::get_poll_options(const Query *query) } auto value = r_value.move_as_ok(); - if (value.type() != JsonValue::Type::Array) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of String as options"); } td::vector options; for (auto &input_option : value.get_array()) { - if (input_option.type() != JsonValue::Type::String) { + if (input_option.type() != td::JsonValue::Type::String) { return td::Status::Error(400, "Expected an option to be of type String"); } options.push_back(input_option.get_string().str()); @@ -9176,13 +9171,13 @@ td::Status Client::process_get_custom_emoji_stickers_query(PromisedQueryPtr &que return td::Status::Error(400, "Can't parse custom emoji identifiers JSON object"); } auto value = r_value.move_as_ok(); - if (value.type() != JsonValue::Type::Array) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Expected an Array of custom emoji identifiers"); } td::vector custom_emoji_ids; for (auto &custom_emoji_id : value.get_array()) { - if (custom_emoji_id.type() != JsonValue::Type::String) { + if (custom_emoji_id.type() != td::JsonValue::Type::String) { return td::Status::Error(400, "Custom emoji identifier must be of type String"); } auto parsed_id = td::to_integer_safe(custom_emoji_id.get_string()); @@ -9332,11 +9327,11 @@ td::Status Client::process_set_sticker_keywords_query(PromisedQueryPtr &query) { } auto value = r_value.move_as_ok(); - if (value.type() != JsonValue::Type::Array) { + if (value.type() != td::JsonValue::Type::Array) { return td::Status::Error(400, "Field \"keywords\" must be an Array"); } for (auto &keyword : value.get_array()) { - if (keyword.type() != JsonValue::Type::String) { + if (keyword.type() != td::JsonValue::Type::String) { return td::Status::Error(400, "keyword must be a string"); } input_keywords.push_back(keyword.get_string().str()); @@ -9929,11 +9924,11 @@ Client::ClosingError Client::get_closing_error() { return result; } -class Client::JsonUpdates final : public Jsonable { +class Client::JsonUpdates final : public td::Jsonable { public: explicit JsonUpdates(td::Span updates) : updates_(updates) { } - void store(JsonValueScope *scope) const { + void store(td::JsonValueScope *scope) const { auto array = scope->enter_array(); int left_len = 1 << 22; for (auto &update : updates_) { @@ -10471,8 +10466,8 @@ td::uint32 Client::get_allowed_update_types(td::MutableSlice allowed_updates, bo td::uint32 result = 0; auto value = r_value.move_as_ok(); - if (value.type() != JsonValue::Type::Array) { - if (value.type() == JsonValue::Type::Number && is_internal) { + if (value.type() != td::JsonValue::Type::Array) { + if (value.type() == td::JsonValue::Type::Number && is_internal) { auto r_number = td::to_integer_safe(value.get_number()); if (r_number.is_ok() && r_number.ok() > 0) { return r_number.ok(); @@ -10481,7 +10476,7 @@ td::uint32 Client::get_allowed_update_types(td::MutableSlice allowed_updates, bo return 0; } for (auto &update_type_name : value.get_array()) { - if (update_type_name.type() != JsonValue::Type::String) { + if (update_type_name.type() != td::JsonValue::Type::String) { return 0; } auto type_name = update_type_name.get_string(); @@ -10521,7 +10516,7 @@ class UpdateJsonable final : public td::VirtuallyJsonable { public: explicit UpdateJsonable(const T &update) : update(update) { } - void store(JsonValueScope *scope) const final { + void store(td::JsonValueScope *scope) const final { *scope << update; } From 7b2acc80beaf28603979f4f240d35db12c763a8b Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Feb 2023 19:50:53 +0300 Subject: [PATCH 20/30] Avoid unneeded namespace qualification. --- telegram-bot-api/Client.cpp | 14 +++++++------- telegram-bot-api/Client.h | 7 +++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 61e357c..e9b0721 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -5417,12 +5417,12 @@ td::Result> Client::get_keyboard_butt auto restrict_chat_has_username = has_json_object_field(request_chat_object, "chat_has_username"); TRY_RESULT(chat_has_username, get_json_object_bool_field(request_chat_object, "chat_has_username")); TRY_RESULT(chat_is_created, get_json_object_bool_field(request_chat_object, "chat_is_created")); - td_api::object_ptr user_administrator_rights; + object_ptr user_administrator_rights; if (has_json_object_field(request_chat_object, "user_administrator_rights")) { TRY_RESULT_ASSIGN(user_administrator_rights, get_chat_administrator_rights(get_json_object_field_force( request_chat_object, "user_administrator_rights"))); } - td_api::object_ptr bot_administrator_rights; + object_ptr bot_administrator_rights; if (has_json_object_field(request_chat_object, "bot_administrator_rights")) { TRY_RESULT_ASSIGN(bot_administrator_rights, get_chat_administrator_rights(get_json_object_field_force( request_chat_object, "bot_administrator_rights"))); @@ -6476,7 +6476,7 @@ td::Result> Client::get_bot_menu_butto TRY_RESULT(type, get_json_object_string_field(object, "type", false)); if (type == "default") { - return td_api::make_object("", "default"); + return make_object("", "default"); } if (type == "commands") { return nullptr; @@ -6486,7 +6486,7 @@ td::Result> Client::get_bot_menu_butto TRY_RESULT(web_app, get_json_object_field(object, "web_app", td::JsonValue::Type::Object, false)); auto &web_app_object = web_app.get_object(); TRY_RESULT(url, get_json_object_string_field(web_app_object, "url", false)); - return td_api::make_object(text, url); + return make_object(text, url); } return td::Status::Error(400, "MenuButton has unsupported type"); @@ -6495,7 +6495,7 @@ td::Result> Client::get_bot_menu_butto td::Result> Client::get_bot_menu_button(const Query *query) { auto menu_button = query->arg("menu_button"); if (menu_button.empty()) { - return td_api::make_object("", "default"); + return make_object("", "default"); } LOG(INFO) << "Parsing JSON object: " << menu_button; @@ -8976,7 +8976,7 @@ td::Status Client::process_set_chat_administrator_custom_title_query(PromisedQue if (chat_member->status_->get_id() != td_api::chatMemberStatusAdministrator::ID) { return fail_query(400, "Bad Request: user is not an administrator", std::move(query)); } - auto administrator = td_api::move_object_as(chat_member->status_); + auto administrator = move_object_as(chat_member->status_); if (!administrator->can_be_edited_) { return fail_query(400, "Bad Request: not enough rights to change custom title of the user", std::move(query)); @@ -9195,7 +9195,7 @@ td::Status Client::process_get_custom_emoji_stickers_query(PromisedQueryPtr &que td::Status Client::process_upload_sticker_file_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); object_ptr sticker_format; - td_api::object_ptr sticker; + object_ptr sticker; if (query->has_arg("sticker") || query->file("sticker") != nullptr) { TRY_RESULT_ASSIGN(sticker_format, get_sticker_format(query->arg("sticker_format"))); sticker = get_input_file(query.get(), "sticker", true); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index df98b5e..4ec4eb9 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -368,10 +368,10 @@ class Client final : public WebhookActor::Callback { struct BotCommandScope { object_ptr scope_; td::string chat_id_; - td::int64 user_id_ = 0; + int64 user_id_ = 0; explicit BotCommandScope(object_ptr scope, td::string chat_id = td::string(), - td::int64 user_id = 0) + int64 user_id = 0) : scope_(std::move(scope)), chat_id_(std::move(chat_id)), user_id_(user_id) { } }; @@ -868,8 +868,7 @@ class Client final : public WebhookActor::Callback { struct FullMessageIdHash { td::uint32 operator()(FullMessageId full_message_id) const { - return td::Hash()(full_message_id.chat_id) * 2023654985u + - td::Hash()(full_message_id.message_id); + return td::Hash()(full_message_id.chat_id) * 2023654985u + td::Hash()(full_message_id.message_id); } }; From 4dc418b8d319937a5f2f8d0f2ecaf0c0adf7ebe5 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Feb 2023 20:45:37 +0300 Subject: [PATCH 21/30] Add optional web_app_name to WriteAccessAllowed. --- telegram-bot-api/Client.cpp | 22 ++++++++++++++++++++-- telegram-bot-api/Client.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index e9b0721..bc2af0b 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -1732,6 +1732,22 @@ class Client::JsonChatSetMessageAutoDeleteTime final : public td::Jsonable { const td_api::messageChatSetMessageAutoDeleteTime *chat_set_message_auto_delete_time_; }; +class Client::JsonWriteAccessAllowed final : public td::Jsonable { + public: + explicit JsonWriteAccessAllowed(const td_api::messageBotWriteAccessAllowed *write_access_allowed) + : write_access_allowed_(write_access_allowed) { + } + void store(td::JsonValueScope *scope) const { + auto object = scope->enter_object(); + if (write_access_allowed_->web_app_ != nullptr) { + object("web_app_name", write_access_allowed_->web_app_->short_name_); + } + } + + private: + const td_api::messageBotWriteAccessAllowed *write_access_allowed_; +}; + class Client::JsonUserShared final : public td::Jsonable { public: explicit JsonUserShared(const td_api::messageUserShared *user_shared) : user_shared_(user_shared) { @@ -2231,9 +2247,11 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const { break; case td_api::messageSuggestProfilePhoto::ID: break; - case td_api::messageBotWriteAccessAllowed::ID: - object("write_access_allowed", JsonEmptyObject()); + case td_api::messageBotWriteAccessAllowed::ID: { + auto content = static_cast(message_->content.get()); + object("write_access_allowed", JsonWriteAccessAllowed(content)); break; + } case td_api::messageUserShared::ID: { auto content = static_cast(message_->content.get()); object("user_shared", JsonUserShared(content)); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 4ec4eb9..a0b4525 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -159,6 +159,7 @@ class Client final : public WebhookActor::Callback { class JsonVideoChatEnded; class JsonInviteVideoChatParticipants; class JsonChatSetMessageAutoDeleteTime; + class JsonWriteAccessAllowed; class JsonUserShared; class JsonChatShared; class JsonUpdateTypes; From 1720ba3e81f7302a4e12e1f0d18e8da68a7905c5 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 22 Feb 2023 21:01:05 +0300 Subject: [PATCH 22/30] Support "web_app" button in inline query results. --- telegram-bot-api/Client.cpp | 63 ++++++++++++++++++++++++++++++++----- telegram-bot-api/Client.h | 6 ++++ 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index bc2af0b..01c8d46 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -6039,6 +6039,54 @@ td_api::object_ptr Client::get_message_send_options( return make_object(disable_notification, false, protect_content, false, nullptr, 0); } +td::Result> Client::get_inline_query_results_button( + td::JsonValue &&value) { + if (value.type() != td::JsonValue::Type::Object) { + return td::Status::Error(400, "InlineQueryResultsButton must be an Object"); + } + + auto &object = value.get_object(); + + TRY_RESULT(text, get_json_object_string_field(object, "text", false)); + + if (has_json_object_field(object, "start_parameter")) { + TRY_RESULT(start_parameter, get_json_object_string_field(object, "start_parameter", false)); + return make_object( + text, make_object(start_parameter)); + } + + if (has_json_object_field(object, "web_app")) { + TRY_RESULT(web_app, get_json_object_field(object, "web_app", td::JsonValue::Type::Object, false)); + auto &web_app_object = web_app.get_object(); + TRY_RESULT(url, get_json_object_string_field(web_app_object, "url", false)); + return make_object(text, + make_object(url)); + } + + return td::Status::Error(400, "InlineQueryResultsButton must have exactly one optional field"); +} + +td::Result> Client::get_inline_query_results_button( + td::MutableSlice button) { + if (button.empty()) { + return nullptr; + } + + LOG(INFO) << "Parsing JSON object: " << button; + auto r_value = json_decode(button); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return td::Status::Error(400, "Can't parse inline query results button JSON object"); + } + + auto r_button = get_inline_query_results_button(r_value.move_as_ok()); + if (r_button.is_error()) { + return td::Status::Error(400, PSLICE() + << "Can't parse inline query results button: " << r_button.error().message()); + } + return r_button.move_as_ok(); +} + td::Result>> Client::get_inline_query_results( const Query *query) { auto results_encoded = query->arg("results"); @@ -8422,14 +8470,15 @@ td::Status Client::process_answer_inline_query_query(PromisedQueryPtr &query) { auto is_personal = to_bool(query->arg("is_personal")); int32 cache_time = get_integer_arg(query.get(), "cache_time", 300, 0, 24 * 60 * 60); auto next_offset = query->arg("next_offset"); - auto switch_pm_text = query->arg("switch_pm_text"); - object_ptr button; - if (!switch_pm_text.empty()) { - button = make_object( - switch_pm_text.str(), - make_object(query->arg("switch_pm_parameter").str())); + TRY_RESULT(button, get_inline_query_results_button(query->arg("button"))); + if (button == nullptr) { + auto switch_pm_text = query->arg("switch_pm_text"); + if (!switch_pm_text.empty()) { + button = make_object( + switch_pm_text.str(), + make_object(query->arg("switch_pm_parameter").str())); + } } - TRY_RESULT(results, get_inline_query_results(query.get())); resolve_inline_query_results_bot_usernames( diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index a0b4525..564c49e 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -358,6 +358,12 @@ class Client final : public WebhookActor::Callback { object_ptr get_input_thumbnail(const Query *query) const; + static td::Result> get_inline_query_results_button( + td::JsonValue &&value); + + static td::Result> get_inline_query_results_button( + td::MutableSlice value); + td::Result> get_inline_query_result(const Query *query); td::Result> get_inline_query_result(td::JsonValue &&value); From ab5406136534d60a62fffddb1e72eaee11800506 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 26 Feb 2023 22:23:38 +0300 Subject: [PATCH 23/30] Add emoji to sendSticker. --- telegram-bot-api/Client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 01c8d46..e9b059b 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -7924,7 +7924,8 @@ td::Status Client::process_send_sticker_query(PromisedQueryPtr &query) { if (sticker == nullptr) { return td::Status::Error(400, "There is no sticker in the request"); } - do_send_message(make_object(std::move(sticker), nullptr, 0, 0, td::string()), + auto emoji = query->arg("emoji"); + do_send_message(make_object(std::move(sticker), nullptr, 0, 0, emoji.str()), std::move(query)); return td::Status::OK(); } From f25e81c015bbf879805d852ebceafbe4b3b1cda2 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 27 Feb 2023 02:19:10 +0300 Subject: [PATCH 24/30] Add setMyDescription. --- telegram-bot-api/Client.cpp | 9 +++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 10 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index e9b059b..9ec6293 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -205,6 +205,7 @@ bool Client::init_methods() { methods_.emplace("deletemycommands", &Client::process_delete_my_commands_query); methods_.emplace("getmydefaultadministratorrights", &Client::process_get_my_default_administrator_rights_query); methods_.emplace("setmydefaultadministratorrights", &Client::process_set_my_default_administrator_rights_query); + methods_.emplace("setmydescription", &Client::process_set_my_description_query); methods_.emplace("getchatmenubutton", &Client::process_get_chat_menu_button_query); methods_.emplace("setchatmenubutton", &Client::process_set_chat_menu_button_query); methods_.emplace("getuserprofilephotos", &Client::process_get_user_profile_photos_query); @@ -7794,6 +7795,14 @@ td::Status Client::process_set_my_default_administrator_rights_query(PromisedQue return td::Status::OK(); } +td::Status Client::process_set_my_description_query(PromisedQueryPtr &query) { + auto language_code = query->arg("language_code"); + auto description = query->arg("description"); + send_request(make_object(language_code.str(), description.str()), + td::make_unique(std::move(query))); + return td::Status::OK(); +} + td::Status Client::process_get_chat_menu_button_query(PromisedQueryPtr &query) { if (query->has_arg("chat_id")) { TRY_RESULT(user_id, get_user_id(query.get(), "chat_id")); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 564c49e..627f678 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -505,6 +505,7 @@ class Client final : public WebhookActor::Callback { td::Status process_delete_my_commands_query(PromisedQueryPtr &query); td::Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query); td::Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query); + td::Status process_set_my_description_query(PromisedQueryPtr &query); td::Status process_get_chat_menu_button_query(PromisedQueryPtr &query); td::Status process_set_chat_menu_button_query(PromisedQueryPtr &query); td::Status process_get_user_profile_photos_query(PromisedQueryPtr &query); From ac28919390a8de44fd08711f26f0727eb878fa6e Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 27 Feb 2023 21:32:38 +0300 Subject: [PATCH 25/30] Add getMyDescription. --- telegram-bot-api/Client.cpp | 40 +++++++++++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 3 +++ 2 files changed, 43 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 9ec6293..ea19cb7 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -205,6 +205,7 @@ bool Client::init_methods() { methods_.emplace("deletemycommands", &Client::process_delete_my_commands_query); methods_.emplace("getmydefaultadministratorrights", &Client::process_get_my_default_administrator_rights_query); methods_.emplace("setmydefaultadministratorrights", &Client::process_set_my_default_administrator_rights_query); + methods_.emplace("getmydescription", &Client::process_get_my_description_query); methods_.emplace("setmydescription", &Client::process_set_my_description_query); methods_.emplace("getchatmenubutton", &Client::process_get_chat_menu_button_query); methods_.emplace("setchatmenubutton", &Client::process_set_chat_menu_button_query); @@ -2581,6 +2582,19 @@ class Client::JsonBotMenuButton final : public td::Jsonable { const td_api::botMenuButton *menu_button_; }; +class Client::JsonBotInfoDescription final : public td::Jsonable { + public: + explicit JsonBotInfoDescription(const td_api::text *text) : text_(text) { + } + void store(td::JsonValueScope *scope) const { + auto object = scope->enter_object(); + object("description", text_->text_); + } + + private: + const td_api::text *text_; +}; + class Client::JsonChatAdministratorRights final : public td::Jsonable { public: JsonChatAdministratorRights(const td_api::chatAdministratorRights *rights, Client::ChatType chat_type) @@ -3721,6 +3735,25 @@ class Client::TdOnGetMyDefaultAdministratorRightsCallback final : public TdQuery PromisedQueryPtr query_; }; +class Client::TdOnGetMyDescriptionCallback final : public TdQueryCallback { + public: + explicit TdOnGetMyDescriptionCallback(PromisedQueryPtr query) : query_(std::move(query)) { + } + + void on_result(object_ptr result) final { + if (result->get_id() == td_api::error::ID) { + return fail_query_with_error(std::move(query_), move_object_as(result)); + } + + CHECK(result->get_id() == td_api::text::ID); + auto text = move_object_as(result); + answer_query(JsonBotInfoDescription(text.get()), std::move(query_)); + } + + private: + PromisedQueryPtr query_; +}; + class Client::TdOnGetForumTopicInfoCallback final : public TdQueryCallback { public: explicit TdOnGetForumTopicInfoCallback(PromisedQueryPtr query) : query_(std::move(query)) { @@ -7795,6 +7828,13 @@ td::Status Client::process_set_my_default_administrator_rights_query(PromisedQue return td::Status::OK(); } +td::Status Client::process_get_my_description_query(PromisedQueryPtr &query) { + auto language_code = query->arg("language_code"); + send_request(make_object(language_code.str()), + td::make_unique(std::move(query))); + return td::Status::OK(); +} + td::Status Client::process_set_my_description_query(PromisedQueryPtr &query) { auto language_code = query->arg("language_code"); auto description = query->arg("description"); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 627f678..125273a 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -137,6 +137,7 @@ class Client final : public WebhookActor::Callback { class JsonPreCheckoutQuery; class JsonBotCommand; class JsonBotMenuButton; + class JsonBotInfoDescription; class JsonChatAdministratorRights; class JsonChatPhotos; class JsonChatMember; @@ -187,6 +188,7 @@ class Client final : public WebhookActor::Callback { class TdOnGetMenuButtonCallback; class TdOnGetMyCommandsCallback; class TdOnGetMyDefaultAdministratorRightsCallback; + class TdOnGetMyDescriptionCallback; class TdOnGetChatFullInfoCallback; class TdOnGetChatStickerSetCallback; class TdOnGetChatPinnedMessageCallback; @@ -505,6 +507,7 @@ class Client final : public WebhookActor::Callback { td::Status process_delete_my_commands_query(PromisedQueryPtr &query); td::Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query); td::Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query); + td::Status process_get_my_description_query(PromisedQueryPtr &query); td::Status process_set_my_description_query(PromisedQueryPtr &query); td::Status process_get_chat_menu_button_query(PromisedQueryPtr &query); td::Status process_set_chat_menu_button_query(PromisedQueryPtr &query); From 4df8df2f171c334dff2ad5026bb058263d569897 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 27 Feb 2023 22:12:12 +0300 Subject: [PATCH 26/30] Improve BotStatActor::get_score. --- telegram-bot-api/Stats.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/telegram-bot-api/Stats.cpp b/telegram-bot-api/Stats.cpp index 5c76e7f..350caf1 100644 --- a/telegram-bot-api/Stats.cpp +++ b/telegram-bot-api/Stats.cpp @@ -151,13 +151,18 @@ td::string BotStatActor::get_description() const { double BotStatActor::get_score(double now) { auto minute_stat = stat_[2].stat_duration(now); - double result = minute_stat.first.request_count_ + minute_stat.first.update_count_; + double minute_score = minute_stat.first.request_count_ + minute_stat.first.update_count_; if (minute_stat.second != 0) { - result /= minute_stat.second; + minute_score /= minute_stat.second; } - result += td::max(static_cast(get_active_request_count() - 10), static_cast(0)); - result += static_cast(get_active_file_upload_bytes()) * 1e-8; - return result; + auto all_time_stat = stat_[0].stat_duration(now); + double all_time_score = 0.01 * (all_time_stat.first.request_count_ + all_time_stat.first.update_count_); + if (all_time_stat.second != 0) { + all_time_score /= all_time_stat.second; + } + auto active_request_score = static_cast(td::max(get_active_request_count() - 10, static_cast(0))); + auto active_file_upload_score = static_cast(get_active_file_upload_bytes()) * 1e-8; + return minute_score + all_time_score + active_request_score + active_file_upload_score; } double BotStatActor::get_minute_update_count(double now) { From 8ee91caacfe7dfc4c3c570d4561f68bdf31b0147 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 4 Mar 2023 22:12:34 +0300 Subject: [PATCH 27/30] Add getMyShortDescription. --- telegram-bot-api/Client.cpp | 40 +++++++++++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 3 +++ 2 files changed, 43 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index ea19cb7..f39970f 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -207,6 +207,7 @@ bool Client::init_methods() { methods_.emplace("setmydefaultadministratorrights", &Client::process_set_my_default_administrator_rights_query); methods_.emplace("getmydescription", &Client::process_get_my_description_query); methods_.emplace("setmydescription", &Client::process_set_my_description_query); + methods_.emplace("getmyshortdescription", &Client::process_get_my_short_description_query); methods_.emplace("getchatmenubutton", &Client::process_get_chat_menu_button_query); methods_.emplace("setchatmenubutton", &Client::process_set_chat_menu_button_query); methods_.emplace("getuserprofilephotos", &Client::process_get_user_profile_photos_query); @@ -2595,6 +2596,19 @@ class Client::JsonBotInfoDescription final : public td::Jsonable { const td_api::text *text_; }; +class Client::JsonBotInfoShortDescription final : public td::Jsonable { + public: + explicit JsonBotInfoShortDescription(const td_api::text *text) : text_(text) { + } + void store(td::JsonValueScope *scope) const { + auto object = scope->enter_object(); + object("short_description", text_->text_); + } + + private: + const td_api::text *text_; +}; + class Client::JsonChatAdministratorRights final : public td::Jsonable { public: JsonChatAdministratorRights(const td_api::chatAdministratorRights *rights, Client::ChatType chat_type) @@ -3754,6 +3768,25 @@ class Client::TdOnGetMyDescriptionCallback final : public TdQueryCallback { PromisedQueryPtr query_; }; +class Client::TdOnGetMyShortDescriptionCallback final : public TdQueryCallback { + public: + explicit TdOnGetMyShortDescriptionCallback(PromisedQueryPtr query) : query_(std::move(query)) { + } + + void on_result(object_ptr result) final { + if (result->get_id() == td_api::error::ID) { + return fail_query_with_error(std::move(query_), move_object_as(result)); + } + + CHECK(result->get_id() == td_api::text::ID); + auto text = move_object_as(result); + answer_query(JsonBotInfoShortDescription(text.get()), std::move(query_)); + } + + private: + PromisedQueryPtr query_; +}; + class Client::TdOnGetForumTopicInfoCallback final : public TdQueryCallback { public: explicit TdOnGetForumTopicInfoCallback(PromisedQueryPtr query) : query_(std::move(query)) { @@ -7843,6 +7876,13 @@ td::Status Client::process_set_my_description_query(PromisedQueryPtr &query) { return td::Status::OK(); } +td::Status Client::process_get_my_short_description_query(PromisedQueryPtr &query) { + auto language_code = query->arg("language_code"); + send_request(make_object(language_code.str()), + td::make_unique(std::move(query))); + return td::Status::OK(); +} + td::Status Client::process_get_chat_menu_button_query(PromisedQueryPtr &query) { if (query->has_arg("chat_id")) { TRY_RESULT(user_id, get_user_id(query.get(), "chat_id")); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 125273a..91e3433 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -138,6 +138,7 @@ class Client final : public WebhookActor::Callback { class JsonBotCommand; class JsonBotMenuButton; class JsonBotInfoDescription; + class JsonBotInfoShortDescription; class JsonChatAdministratorRights; class JsonChatPhotos; class JsonChatMember; @@ -189,6 +190,7 @@ class Client final : public WebhookActor::Callback { class TdOnGetMyCommandsCallback; class TdOnGetMyDefaultAdministratorRightsCallback; class TdOnGetMyDescriptionCallback; + class TdOnGetMyShortDescriptionCallback; class TdOnGetChatFullInfoCallback; class TdOnGetChatStickerSetCallback; class TdOnGetChatPinnedMessageCallback; @@ -509,6 +511,7 @@ class Client final : public WebhookActor::Callback { td::Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query); td::Status process_get_my_description_query(PromisedQueryPtr &query); td::Status process_set_my_description_query(PromisedQueryPtr &query); + td::Status process_get_my_short_description_query(PromisedQueryPtr &query); td::Status process_get_chat_menu_button_query(PromisedQueryPtr &query); td::Status process_set_chat_menu_button_query(PromisedQueryPtr &query); td::Status process_get_user_profile_photos_query(PromisedQueryPtr &query); From 8fd2a693784d5e9b2ec26d97745edde552e5b1ba Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 4 Mar 2023 22:13:39 +0300 Subject: [PATCH 28/30] Add setMyShortDescription. --- telegram-bot-api/Client.cpp | 9 +++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 10 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index f39970f..4519df5 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -208,6 +208,7 @@ bool Client::init_methods() { methods_.emplace("getmydescription", &Client::process_get_my_description_query); methods_.emplace("setmydescription", &Client::process_set_my_description_query); methods_.emplace("getmyshortdescription", &Client::process_get_my_short_description_query); + methods_.emplace("setmyshortdescription", &Client::process_set_my_short_description_query); methods_.emplace("getchatmenubutton", &Client::process_get_chat_menu_button_query); methods_.emplace("setchatmenubutton", &Client::process_set_chat_menu_button_query); methods_.emplace("getuserprofilephotos", &Client::process_get_user_profile_photos_query); @@ -7883,6 +7884,14 @@ td::Status Client::process_get_my_short_description_query(PromisedQueryPtr &quer return td::Status::OK(); } +td::Status Client::process_set_my_short_description_query(PromisedQueryPtr &query) { + auto language_code = query->arg("language_code"); + auto short_description = query->arg("short_description"); + send_request(make_object(language_code.str(), short_description.str()), + td::make_unique(std::move(query))); + return td::Status::OK(); +} + td::Status Client::process_get_chat_menu_button_query(PromisedQueryPtr &query) { if (query->has_arg("chat_id")) { TRY_RESULT(user_id, get_user_id(query.get(), "chat_id")); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 91e3433..3beb6db 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -512,6 +512,7 @@ class Client final : public WebhookActor::Callback { td::Status process_get_my_description_query(PromisedQueryPtr &query); td::Status process_set_my_description_query(PromisedQueryPtr &query); td::Status process_get_my_short_description_query(PromisedQueryPtr &query); + td::Status process_set_my_short_description_query(PromisedQueryPtr &query); td::Status process_get_chat_menu_button_query(PromisedQueryPtr &query); td::Status process_set_chat_menu_button_query(PromisedQueryPtr &query); td::Status process_get_user_profile_photos_query(PromisedQueryPtr &query); From 79ea50766498dc949e676b9ffd7c7899f9885ecf Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 9 Mar 2023 18:54:59 +0300 Subject: [PATCH 29/30] Minor improvements. --- telegram-bot-api/Client.cpp | 2 +- telegram-bot-api/HttpServer.h | 3 ++- telegram-bot-api/WebhookActor.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 4519df5..75dd162 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -6839,7 +6839,7 @@ td::Result> Client::get_input_sticker(c TRY_RESULT(sticker, get_json_object_string_field(object, "sticker")); auto input_file = get_input_file(query, td::Slice(), sticker, false); if (input_file == nullptr) { - return td::Status::Error("sticker not found"); + return td::Status::Error(400, "sticker not found"); } TRY_RESULT(emoji_list, get_json_object_field(object, "emoji_list", td::JsonValue::Type::Array, false)); TRY_RESULT(emojis, get_sticker_emojis(std::move(emoji_list))); diff --git a/telegram-bot-api/HttpServer.h b/telegram-bot-api/HttpServer.h index 13a03c8..8686a3f 100644 --- a/telegram-bot-api/HttpServer.h +++ b/telegram-bot-api/HttpServer.h @@ -12,6 +12,7 @@ #include "td/actor/actor.h" #include "td/utils/BufferedFd.h" +#include "td/utils/common.h" #include "td/utils/FloodControlFast.h" #include "td/utils/format.h" #include "td/utils/logging.h" @@ -47,7 +48,7 @@ class HttpServer final : public td::TcpListener::Callback { return; } flood_control_.add_event(now); - LOG(INFO) << "Create tcp listener " << td::tag("address", ip_address_) << td::tag("port", port_); + LOG(INFO) << "Create TCP listener " << td::tag("address", ip_address_) << td::tag("port", port_); listener_ = td::create_actor( PSLICE() << "TcpListener" << td::tag("address", ip_address_) << td::tag("port", port_), port_, actor_shared(this, 1), ip_address_); diff --git a/telegram-bot-api/WebhookActor.cpp b/telegram-bot-api/WebhookActor.cpp index 91b4e69..9c67bb3 100644 --- a/telegram-bot-api/WebhookActor.cpp +++ b/telegram-bot-api/WebhookActor.cpp @@ -399,7 +399,7 @@ void WebhookActor::load_updates() { CHECK(update.id.is_valid()); auto &dest_ptr = update_map_[update.id]; if (dest_ptr != nullptr) { - LOG(ERROR) << "Receive duplicated event " << update.id << " from TQueue"; + LOG(ERROR) << "Receive duplicate event " << update.id << " from TQueue"; continue; } dest_ptr = td::make_unique(); From c5b8e34cd31276c9bfa4940c96adfd757542b9ce Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 9 Mar 2023 18:55:26 +0300 Subject: [PATCH 30/30] Update version to 6.6. --- CMakeLists.txt | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ad72e5..2a1928a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 6.5 LANGUAGES CXX) +project(TelegramBotApi VERSION 6.6 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index c2e4581..c91c6aa 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "6.5"; + parameters->version_ = "6.6"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats();