From ffb88dd2206432592b7433f236d72cc3e54abcc3 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 26 Oct 2024 01:11:17 +0300 Subject: [PATCH] Update TDLib and support allow_paid_broadcast option for message sending. --- td | 2 +- telegram-bot-api/Client.cpp | 61 +++++++++++++++++++++---------------- telegram-bot-api/Client.h | 3 +- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/td b/td index d321984..38560e8 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit d321984b75fccdb76239529e8aadcf7f80b0e35a +Subproject commit 38560e87afd54f3840531fe25e12ce34a7eb279f diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 3a7e00d..06e6c53 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -6130,7 +6130,7 @@ void Client::send(PromisedQueryPtr query) { 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) { + if (stat->get_active_request_count() > 1000 + update_per_minute) { LOG(INFO) << "Fail a query, because there are too many active queries: " << *query; return fail_query_flood_limit_exceeded(std::move(query)); } @@ -8209,9 +8209,11 @@ td::Result> Client::get_input_me } td_api::object_ptr Client::get_message_send_options(bool disable_notification, - bool protect_content, int64 effect_id) { - return make_object(disable_notification, false, protect_content, false, nullptr, - effect_id, 0, false); + bool protect_content, + bool allow_paid_broadcast, + int64 effect_id) { + return make_object(disable_notification, false, protect_content, allow_paid_broadcast, + false, nullptr, effect_id, 0, false); } td::Result> Client::get_inline_query_results_button( @@ -10676,10 +10678,11 @@ td::Status Client::process_copy_messages_query(PromisedQueryPtr &query) { auto message_count = message_ids.size(); count += static_cast(message_count); - send_request(make_object( - chat_id, message_thread_id, from_chat_id, std::move(message_ids), - get_message_send_options(disable_notification, protect_content, 0), true, remove_caption), - td::make_unique(this, chat_id, message_count, std::move(query))); + send_request( + make_object( + chat_id, message_thread_id, from_chat_id, std::move(message_ids), + get_message_send_options(disable_notification, protect_content, false, 0), true, remove_caption), + td::make_unique(this, chat_id, message_count, std::move(query))); }); }; check_reply_parameters(chat_id, InputReplyParameters(), message_thread_id, std::move(query), std::move(on_success)); @@ -10732,7 +10735,7 @@ td::Status Client::process_forward_messages_query(PromisedQueryPtr &query) { send_request(make_object( chat_id, message_thread_id, from_chat_id, std::move(message_ids), - get_message_send_options(disable_notification, protect_content, 0), false, false), + get_message_send_options(disable_notification, protect_content, false, 0), false, false), td::make_unique(this, chat_id, message_count, std::move(query))); }); }; @@ -10748,6 +10751,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { auto business_connection_id = query->arg("business_connection_id"); auto disable_notification = to_bool(query->arg("disable_notification")); auto protect_content = to_bool(query->arg("protect_content")); + auto allow_paid_broadcast = to_bool(query->arg("allow_paid_broadcast")); auto effect_id = td::to_integer(query->arg("message_effect_id")); // TRY_RESULT(reply_markup, get_reply_markup(query.get(), bot_user_ids_)); auto reply_markup = nullptr; @@ -10756,9 +10760,9 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { resolve_reply_markup_bot_usernames( std::move(reply_markup), std::move(query), [this, chat_id_str = chat_id.str(), message_thread_id, business_connection_id = business_connection_id.str(), - reply_parameters = std::move(reply_parameters), disable_notification, protect_content, effect_id, - input_message_contents = std::move(input_message_contents)](object_ptr reply_markup, - PromisedQueryPtr query) mutable { + reply_parameters = std::move(reply_parameters), disable_notification, protect_content, allow_paid_broadcast, + effect_id, input_message_contents = std::move(input_message_contents)]( + object_ptr reply_markup, PromisedQueryPtr query) mutable { if (!business_connection_id.empty()) { return check_business_connection_chat_id( business_connection_id, chat_id_str, std::move(query), @@ -10774,7 +10778,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { }); } - auto on_success = [this, disable_notification, protect_content, effect_id, + auto on_success = [this, disable_notification, protect_content, allow_paid_broadcast, effect_id, input_message_contents = std::move(input_message_contents), reply_markup = std::move(reply_markup)](int64 chat_id, int64 message_thread_id, CheckedReplyParameters reply_parameters, @@ -10786,11 +10790,12 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) { auto message_count = input_message_contents.size(); count += static_cast(message_count); - send_request(make_object( - chat_id, message_thread_id, get_input_message_reply_to(std::move(reply_parameters)), - get_message_send_options(disable_notification, protect_content, effect_id), - std::move(input_message_contents)), - td::make_unique(this, chat_id, message_count, std::move(query))); + send_request( + make_object( + chat_id, message_thread_id, get_input_message_reply_to(std::move(reply_parameters)), + get_message_send_options(disable_notification, protect_content, allow_paid_broadcast, effect_id), + std::move(input_message_contents)), + td::make_unique(this, chat_id, message_count, std::move(query))); }; check_reply_parameters(chat_id_str, std::move(reply_parameters), message_thread_id, std::move(query), std::move(on_success)); @@ -12739,6 +12744,7 @@ void Client::do_send_message(object_ptr input_messa auto reply_parameters = r_reply_parameters.move_as_ok(); auto disable_notification = to_bool(query->arg("disable_notification")); auto protect_content = to_bool(query->arg("protect_content")); + auto allow_paid_broadcast = to_bool(query->arg("allow_paid_broadcast")); auto effect_id = td::to_integer(query->arg("message_effect_id")); auto r_reply_markup = get_reply_markup(query.get(), bot_user_ids_); if (r_reply_markup.is_error()) { @@ -12749,9 +12755,9 @@ void Client::do_send_message(object_ptr input_messa resolve_reply_markup_bot_usernames( std::move(reply_markup), std::move(query), [this, chat_id_str = chat_id.str(), message_thread_id, business_connection_id = business_connection_id.str(), - reply_parameters = std::move(reply_parameters), disable_notification, protect_content, effect_id, - input_message_content = std::move(input_message_content)](object_ptr reply_markup, - PromisedQueryPtr query) mutable { + reply_parameters = std::move(reply_parameters), disable_notification, protect_content, allow_paid_broadcast, + effect_id, input_message_content = std::move(input_message_content)]( + object_ptr reply_markup, PromisedQueryPtr query) mutable { if (!business_connection_id.empty()) { return check_business_connection_chat_id( business_connection_id, chat_id_str, std::move(query), @@ -12767,7 +12773,7 @@ void Client::do_send_message(object_ptr input_messa }); } - auto on_success = [this, disable_notification, protect_content, effect_id, + auto on_success = [this, disable_notification, protect_content, allow_paid_broadcast, effect_id, input_message_content = std::move(input_message_content), reply_markup = std::move(reply_markup)](int64 chat_id, int64 message_thread_id, CheckedReplyParameters reply_parameters, @@ -12778,11 +12784,12 @@ void Client::do_send_message(object_ptr input_messa } count++; - send_request(make_object( - chat_id, message_thread_id, get_input_message_reply_to(std::move(reply_parameters)), - get_message_send_options(disable_notification, protect_content, effect_id), - std::move(reply_markup), std::move(input_message_content)), - td::make_unique(this, chat_id, std::move(query))); + send_request( + make_object( + chat_id, message_thread_id, get_input_message_reply_to(std::move(reply_parameters)), + get_message_send_options(disable_notification, protect_content, allow_paid_broadcast, effect_id), + std::move(reply_markup), std::move(input_message_content)), + td::make_unique(this, chat_id, std::move(query))); }; check_reply_parameters(chat_id_str, std::move(reply_parameters), message_thread_id, std::move(query), std::move(on_success)); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 59f7a78..82b4c56 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -590,7 +590,8 @@ class Client final : public WebhookActor::Callback { td::Result> get_input_message_invoice(const Query *query) const; static object_ptr get_message_send_options(bool disable_notification, - bool protect_content, int64 effect_id); + bool protect_content, + bool allow_paid_broadcast, int64 effect_id); static td::Result>> get_poll_options(const Query *query);