2
0
mirror of https://github.com/tdlib/telegram-bot-api synced 2025-08-22 01:49:24 +00:00

Compare commits

..

No commits in common. "6d1b62b51bdc543c10f854aae751e160e5b7b9c5" and "a186a9ae823d91678ace87ef5b920688c555f5b5" have entirely different histories.

5 changed files with 46 additions and 106 deletions

View File

@ -6,7 +6,7 @@ if (POLICY CMP0065)
cmake_policy(SET CMP0065 NEW)
endif()
project(TelegramBotApi VERSION 7.11 LANGUAGES CXX)
project(TelegramBotApi VERSION 7.10 LANGUAGES CXX)
if (POLICY CMP0069)
option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.")

2
td

@ -1 +1 @@
Subproject commit 056963e48fa8d3f89556239c22d6ac843d3c8a5b
Subproject commit 87d881071fe514936bb17029e96761141287d2be

View File

@ -2593,19 +2593,6 @@ class Client::JsonWebAppInfo final : public td::Jsonable {
const td::string &url_;
};
class Client::JsonCopyTextButton final : public td::Jsonable {
public:
explicit JsonCopyTextButton(const td::string &text) : text_(text) {
}
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
object("text", text_);
}
private:
const td::string &text_;
};
class Client::JsonInlineKeyboardButton final : public td::Jsonable {
public:
explicit JsonInlineKeyboardButton(const td_api::inlineKeyboardButton *button) : button_(button) {
@ -2677,11 +2664,6 @@ class Client::JsonInlineKeyboardButton final : public td::Jsonable {
object("web_app", JsonWebAppInfo(type->url_));
break;
}
case td_api::inlineKeyboardButtonTypeCopyText::ID: {
auto type = static_cast<const td_api::inlineKeyboardButtonTypeCopyText *>(button_->type_.get());
object("copy_text", JsonCopyTextButton(type->text_));
break;
}
default:
UNREACHABLE();
break;
@ -2843,11 +2825,9 @@ class Client::JsonExternalReplyInfo final : public td::Jsonable {
object("giveaway_winners", JsonGiveawayWinners(content, client_));
break;
}
case td_api::messageStory::ID: {
auto content = static_cast<const td_api::messageStory *>(reply_->content_.get());
object("story", JsonStory(content->story_sender_chat_id_, content->story_id_, client_));
case td_api::messageStory::ID:
object("story", JsonEmptyObject());
break;
}
default:
LOG(ERROR) << "Receive external reply with " << to_string(reply_->content_);
}
@ -2895,7 +2875,7 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const {
object("sender_business_bot", JsonUser(message_->sender_business_bot_user_id, client_));
}
}
object("message_id", message_->is_scheduled ? 0 : as_client_message_id(message_->id));
object("message_id", as_client_message_id(message_->id));
if (message_->sender_user_id != 0) {
object("from", JsonUser(message_->sender_user_id, client_));
}
@ -3373,8 +3353,6 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const {
break;
case td_api::messageGiveawayPrizeStars::ID:
break;
case td_api::messageGift::ID:
break;
default:
UNREACHABLE();
}
@ -3404,7 +3382,7 @@ class Client::JsonMessageId final : public td::Jsonable {
}
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
object("message_id", as_client_message_id_unchecked(message_id_));
object("message_id", as_client_message_id(message_id_));
}
private:
@ -3644,7 +3622,7 @@ class Client::JsonPaidMediaPurchased final : public td::Jsonable {
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
object("from", JsonUser(update_->user_id_, client_));
object("paid_media_payload", update_->payload_);
object("payload", update_->payload_);
}
private:
@ -4234,12 +4212,6 @@ class Client::JsonStarTransactionPartner final : public td::Jsonable {
case td_api::starTransactionPartnerTelegramAds::ID:
object("type", "telegram_ads");
break;
case td_api::starTransactionPartnerTelegramApi::ID: {
auto source = static_cast<const td_api::starTransactionPartnerTelegramApi *>(source_);
object("type", "telegram_api");
object("request_count", source->request_count_);
break;
}
case td_api::starTransactionPartnerTelegram::ID:
case td_api::starTransactionPartnerAppStore::ID:
case td_api::starTransactionPartnerGooglePlay::ID:
@ -6136,7 +6108,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<int64>(stat->get_minute_update_count(td::Time::now()) * 60);
if (stat->get_active_request_count() > 1000 + update_per_minute) {
if (stat->get_active_request_count() > 500 + 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));
}
@ -6406,8 +6378,8 @@ void Client::check_chat_access(int64 chat_id, AccessRights access_rights, const
}
template <class OnSuccess>
void Client::check_chat(td::Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success,
bool allow_unknown_user) {
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));
}
@ -6419,9 +6391,6 @@ void Client::check_chat(td::Slice chat_id_str, AccessRights access_rights, Promi
}
auto chat_id = td::to_integer<int64>(chat_id_str);
if (allow_unknown_user && 0 < chat_id && chat_id < (static_cast<int64>(1) << 40)) {
return on_success(chat_id, std::move(query));
}
auto chat_info = get_chat(chat_id);
if (chat_info != nullptr && chat_info->type == ChatInfo::Type::Private) {
const UserInfo *user_info = get_user_info(chat_info->user_id);
@ -6617,8 +6586,7 @@ void Client::check_messages(td::Slice chat_id_str, td::vector<int64> message_ids
template <class OnSuccess>
void Client::check_reply_parameters(td::Slice chat_id_str, InputReplyParameters &&reply_parameters,
int64 message_thread_id, PromisedQueryPtr query, OnSuccess on_success,
bool allow_unknown_user) {
int64 message_thread_id, PromisedQueryPtr query, OnSuccess on_success) {
if (chat_id_str == reply_parameters.reply_in_chat_id) {
reply_parameters.reply_in_chat_id.clear();
}
@ -6681,8 +6649,7 @@ void Client::check_reply_parameters(td::Slice chat_id_str, InputReplyParameters
}
check_chat(reply_parameters.reply_in_chat_id, AccessRights::Read, std::move(query),
std::move(on_reply_chat_resolved));
},
allow_unknown_user);
});
}
template <class OnSuccess>
@ -6691,7 +6658,7 @@ void Client::resolve_sticker_set(const td::string &sticker_set_name, PromisedQue
return fail_query(400, "Bad Request: sticker_set_name is empty", std::move(query));
}
send_request(make_object<td_api::searchStickerSet>(sticker_set_name, false),
send_request(make_object<td_api::searchStickerSet>(sticker_set_name),
td::make_unique<TdOnSearchStickerSetCallback<OnSuccess>>(std::move(query), std::move(on_success)));
}
@ -7774,14 +7741,6 @@ td::Result<td_api::object_ptr<td_api::inlineKeyboardButton>> Client::get_inline_
return make_object<td_api::inlineKeyboardButton>(text, make_object<td_api::inlineKeyboardButtonTypeWebApp>(url));
}
if (object.has_field("copy_text")) {
TRY_RESULT(copy_text, object.extract_required_field("copy_text", td::JsonValue::Type::Object));
auto &copy_text_object = copy_text.get_object();
TRY_RESULT(copied_text, copy_text_object.get_required_string_field("text"));
return make_object<td_api::inlineKeyboardButton>(
text, make_object<td_api::inlineKeyboardButtonTypeCopyText>(copied_text));
}
return td::Status::Error(400, "Text buttons are unallowed in the inline keyboard");
}
@ -8220,11 +8179,9 @@ td::Result<td_api::object_ptr<td_api::InputMessageContent>> Client::get_input_me
}
td_api::object_ptr<td_api::messageSendOptions> Client::get_message_send_options(bool disable_notification,
bool protect_content,
bool allow_paid_broadcast,
int64 effect_id) {
return make_object<td_api::messageSendOptions>(disable_notification, false, protect_content, allow_paid_broadcast,
false, nullptr, effect_id, 0, false);
bool protect_content, int64 effect_id) {
return make_object<td_api::messageSendOptions>(disable_notification, false, protect_content, false, nullptr,
effect_id, 0, false);
}
td::Result<td_api::object_ptr<td_api::inlineQueryResultsButton>> Client::get_inline_query_results_button(
@ -10689,11 +10646,10 @@ td::Status Client::process_copy_messages_query(PromisedQueryPtr &query) {
auto message_count = message_ids.size();
count += static_cast<int32>(message_count);
send_request(
make_object<td_api::forwardMessages>(
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<TdOnForwardMessagesCallback>(this, chat_id, message_count, std::move(query)));
send_request(make_object<td_api::forwardMessages>(
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<TdOnForwardMessagesCallback>(this, chat_id, message_count, std::move(query)));
});
};
check_reply_parameters(chat_id, InputReplyParameters(), message_thread_id, std::move(query), std::move(on_success));
@ -10746,7 +10702,7 @@ td::Status Client::process_forward_messages_query(PromisedQueryPtr &query) {
send_request(make_object<td_api::forwardMessages>(
chat_id, message_thread_id, from_chat_id, std::move(message_ids),
get_message_send_options(disable_notification, protect_content, false, 0), false, false),
get_message_send_options(disable_notification, protect_content, 0), false, false),
td::make_unique<TdOnForwardMessagesCallback>(this, chat_id, message_count, std::move(query)));
});
};
@ -10762,7 +10718,6 @@ 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<int64>(query->arg("message_effect_id"));
// TRY_RESULT(reply_markup, get_reply_markup(query.get(), bot_user_ids_));
auto reply_markup = nullptr;
@ -10771,9 +10726,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, allow_paid_broadcast,
effect_id, input_message_contents = std::move(input_message_contents)](
object_ptr<td_api::ReplyMarkup> reply_markup, PromisedQueryPtr query) mutable {
reply_parameters = std::move(reply_parameters), disable_notification, protect_content, effect_id,
input_message_contents = std::move(input_message_contents)](object_ptr<td_api::ReplyMarkup> 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),
@ -10789,7 +10744,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
});
}
auto on_success = [this, disable_notification, protect_content, allow_paid_broadcast, effect_id,
auto on_success = [this, disable_notification, protect_content, 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,
@ -10801,15 +10756,14 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
auto message_count = input_message_contents.size();
count += static_cast<int32>(message_count);
send_request(
make_object<td_api::sendMessageAlbum>(
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<TdOnSendMessageAlbumCallback>(this, chat_id, message_count, std::move(query)));
send_request(make_object<td_api::sendMessageAlbum>(
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<TdOnSendMessageAlbumCallback>(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), allow_paid_broadcast);
std::move(on_success));
});
return td::Status::OK();
}
@ -12098,7 +12052,7 @@ td::Status Client::process_get_sticker_set_query(PromisedQueryPtr &query) {
send_request(make_object<td_api::getStickerSet>(GREAT_MINDS_SET_ID),
td::make_unique<TdOnReturnStickerSetCallback>(this, true, std::move(query)));
} else {
send_request(make_object<td_api::searchStickerSet>(name.str(), false),
send_request(make_object<td_api::searchStickerSet>(name.str()),
td::make_unique<TdOnReturnStickerSetCallback>(this, true, std::move(query)));
}
return td::Status::OK();
@ -12755,7 +12709,6 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> 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<int64>(query->arg("message_effect_id"));
auto r_reply_markup = get_reply_markup(query.get(), bot_user_ids_);
if (r_reply_markup.is_error()) {
@ -12766,9 +12719,9 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> 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, allow_paid_broadcast,
effect_id, input_message_content = std::move(input_message_content)](
object_ptr<td_api::ReplyMarkup> reply_markup, PromisedQueryPtr query) mutable {
reply_parameters = std::move(reply_parameters), disable_notification, protect_content, effect_id,
input_message_content = std::move(input_message_content)](object_ptr<td_api::ReplyMarkup> 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),
@ -12784,7 +12737,7 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
});
}
auto on_success = [this, disable_notification, protect_content, allow_paid_broadcast, effect_id,
auto on_success = [this, disable_notification, protect_content, 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,
@ -12795,15 +12748,14 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
}
count++;
send_request(
make_object<td_api::sendMessage>(
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<TdOnSendMessageCallback>(this, chat_id, std::move(query)));
send_request(make_object<td_api::sendMessage>(
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<TdOnSendMessageCallback>(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), allow_paid_broadcast);
std::move(on_success));
});
}
@ -14026,8 +13978,6 @@ bool Client::need_skip_update_message(int64 chat_id, const object_ptr<td_api::me
return true;
case td_api::messageGiveawayPrizeStars::ID:
return true;
case td_api::messageGift::ID:
return true;
default:
break;
}
@ -14203,11 +14153,6 @@ bool Client::are_equal_inline_keyboard_buttons(const td_api::inlineKeyboardButto
auto rhs_type = static_cast<const td_api::inlineKeyboardButtonTypeWebApp *>(rhs->type_.get());
return lhs_type->url_ == rhs_type->url_;
}
case td_api::inlineKeyboardButtonTypeCopyText::ID: {
auto lhs_type = static_cast<const td_api::inlineKeyboardButtonTypeCopyText *>(lhs->type_.get());
auto rhs_type = static_cast<const td_api::inlineKeyboardButtonTypeCopyText *>(rhs->type_.get());
return lhs_type->text_ == rhs_type->text_;
}
default:
UNREACHABLE();
return false;
@ -14538,7 +14483,6 @@ void Client::init_message(MessageInfo *message_info, object_ptr<td_api::message>
}
message_info->can_be_saved = message->can_be_saved_;
message_info->is_scheduled = message->scheduling_state_ != nullptr;
message_info->is_from_offline = message->is_from_offline_;
message_info->is_topic_message = message->is_topic_message_;
message_info->author_signature = std::move(message->author_signature_);

View File

@ -135,7 +135,6 @@ class Client final : public WebhookActor::Callback {
class JsonEntity;
class JsonVectorEntities;
class JsonWebAppInfo;
class JsonCopyTextButton;
class JsonInlineKeyboardButton;
class JsonInlineKeyboard;
class JsonReplyMarkup;
@ -346,8 +345,7 @@ class Client final : public WebhookActor::Callback {
OnSuccess on_success) const;
template <class OnSuccess>
void check_chat(td::Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success,
bool allow_unknown_user = false);
void check_chat(td::Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success);
template <class OnSuccess>
void check_chat_no_fail(td::Slice chat_id_str, PromisedQueryPtr query, OnSuccess on_success);
@ -378,7 +376,7 @@ class Client final : public WebhookActor::Callback {
template <class OnSuccess>
void check_reply_parameters(td::Slice chat_id_str, InputReplyParameters &&reply_parameters, int64 message_thread_id,
PromisedQueryPtr query, OnSuccess on_success, bool allow_unknown_user = false);
PromisedQueryPtr query, OnSuccess on_success);
template <class OnSuccess>
void resolve_sticker_set(const td::string &sticker_set_name, PromisedQueryPtr query, OnSuccess on_success);
@ -591,8 +589,7 @@ class Client final : public WebhookActor::Callback {
td::Result<object_ptr<td_api::inputMessageInvoice>> get_input_message_invoice(const Query *query) const;
static object_ptr<td_api::messageSendOptions> get_message_send_options(bool disable_notification,
bool protect_content,
bool allow_paid_broadcast, int64 effect_id);
bool protect_content, int64 effect_id);
static td::Result<td::vector<object_ptr<td_api::formattedText>>> get_poll_options(const Query *query);
@ -967,7 +964,6 @@ class Client final : public WebhookActor::Callback {
bool is_automatic_forward = false;
bool is_topic_message = false;
bool is_from_offline = false;
bool is_scheduled = false;
mutable bool is_content_changed = false;
};

View File

@ -165,7 +165,7 @@ int main(int argc, char *argv[]) {
auto start_time = td::Time::now();
auto shared_data = std::make_shared<SharedData>();
auto parameters = std::make_unique<ClientParameters>();
parameters->version_ = "7.11";
parameters->version_ = "7.10";
parameters->shared_data_ = shared_data;
parameters->start_time_ = start_time;
auto net_query_stats = td::create_net_query_stats();