Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Giuseppe Marino 2024-12-18 17:12:45 +01:00
commit bdd7594dd4
No known key found for this signature in database
GPG Key ID: C26F7A532ADEC25E
6 changed files with 454 additions and 123 deletions

View File

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

2
td

@ -1 +1 @@
Subproject commit 87d881071fe514936bb17029e96761141287d2be Subproject commit 7648b99d81d36d44bae3ca6c514a816a2fe8cfd1

View File

@ -273,10 +273,14 @@ bool Client::init_methods() {
methods_.emplace("createinvoicelink", &Client::process_create_invoice_link_query); methods_.emplace("createinvoicelink", &Client::process_create_invoice_link_query);
methods_.emplace("getstartransactions", &Client::process_get_star_transactions_query); methods_.emplace("getstartransactions", &Client::process_get_star_transactions_query);
methods_.emplace("refundstarpayment", &Client::process_refund_star_payment_query); methods_.emplace("refundstarpayment", &Client::process_refund_star_payment_query);
methods_.emplace("edituserstarsubscription", &Client::process_edit_user_star_subscription_query);
methods_.emplace("getavailablegifts", &Client::process_get_available_gifts_query);
methods_.emplace("sendgift", &Client::process_send_gift_query);
methods_.emplace("setgamescore", &Client::process_set_game_score_query); methods_.emplace("setgamescore", &Client::process_set_game_score_query);
methods_.emplace("getgamehighscores", &Client::process_get_game_high_scores_query); methods_.emplace("getgamehighscores", &Client::process_get_game_high_scores_query);
methods_.emplace("answerwebappquery", &Client::process_answer_web_app_query_query); methods_.emplace("answerwebappquery", &Client::process_answer_web_app_query_query);
methods_.emplace("answerinlinequery", &Client::process_answer_inline_query_query); methods_.emplace("answerinlinequery", &Client::process_answer_inline_query_query);
methods_.emplace("savepreparedinlinemessage", &Client::process_save_prepared_inline_message_query);
methods_.emplace("answercallbackquery", &Client::process_answer_callback_query_query); methods_.emplace("answercallbackquery", &Client::process_answer_callback_query_query);
methods_.emplace("answershippingquery", &Client::process_answer_shipping_query_query); methods_.emplace("answershippingquery", &Client::process_answer_shipping_query_query);
methods_.emplace("answerprecheckoutquery", &Client::process_answer_pre_checkout_query_query); methods_.emplace("answerprecheckoutquery", &Client::process_answer_pre_checkout_query_query);
@ -287,6 +291,7 @@ bool Client::init_methods() {
methods_.emplace("editchatsubscriptioninvitelink", &Client::process_edit_chat_subscription_invite_link_query); methods_.emplace("editchatsubscriptioninvitelink", &Client::process_edit_chat_subscription_invite_link_query);
methods_.emplace("revokechatinvitelink", &Client::process_revoke_chat_invite_link_query); methods_.emplace("revokechatinvitelink", &Client::process_revoke_chat_invite_link_query);
methods_.emplace("getbusinessconnection", &Client::process_get_business_connection_query); methods_.emplace("getbusinessconnection", &Client::process_get_business_connection_query);
methods_.emplace("setuseremojistatus", &Client::process_set_user_emoji_status_query);
methods_.emplace("getchat", &Client::process_get_chat_query); methods_.emplace("getchat", &Client::process_get_chat_query);
methods_.emplace("setchatphoto", &Client::process_set_chat_photo_query); methods_.emplace("setchatphoto", &Client::process_set_chat_photo_query);
methods_.emplace("deletechatphoto", &Client::process_delete_chat_photo_query); methods_.emplace("deletechatphoto", &Client::process_delete_chat_photo_query);
@ -2185,6 +2190,15 @@ class Client::JsonSuccessfulPaymentBot final : public td::Jsonable {
} }
object("telegram_payment_charge_id", successful_payment_->telegram_payment_charge_id_); object("telegram_payment_charge_id", successful_payment_->telegram_payment_charge_id_);
object("provider_payment_charge_id", successful_payment_->provider_payment_charge_id_); object("provider_payment_charge_id", successful_payment_->provider_payment_charge_id_);
if (successful_payment_->is_recurring_) {
object("is_recurring", td::JsonTrue());
}
if (successful_payment_->is_first_recurring_) {
object("is_first_recurring", td::JsonTrue());
}
if (successful_payment_->subscription_until_date_ > 0) {
object("subscription_expiration_date", successful_payment_->subscription_until_date_);
}
} }
private: private:
@ -2694,6 +2708,19 @@ class Client::JsonWebAppInfo final : public td::Jsonable {
const td::string &url_; 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 { class Client::JsonInlineKeyboardButton final : public td::Jsonable {
public: public:
explicit JsonInlineKeyboardButton(const td_api::inlineKeyboardButton *button) : button_(button) { explicit JsonInlineKeyboardButton(const td_api::inlineKeyboardButton *button) : button_(button) {
@ -2732,17 +2759,17 @@ class Client::JsonInlineKeyboardButton final : public td::Jsonable {
object("switch_inline_query_current_chat", type->query_); object("switch_inline_query_current_chat", type->query_);
break; break;
case td_api::targetChatChosen::ID: { case td_api::targetChatChosen::ID: {
auto target_chat = static_cast<const td_api::targetChatChosen *>(type->target_chat_.get()); auto types = static_cast<const td_api::targetChatChosen *>(type->target_chat_.get())->types_.get();
if (target_chat->allow_user_chats_ && target_chat->allow_bot_chats_ && target_chat->allow_group_chats_ && if (types->allow_user_chats_ && types->allow_bot_chats_ && types->allow_group_chats_ &&
target_chat->allow_channel_chats_) { types->allow_channel_chats_) {
object("switch_inline_query", type->query_); object("switch_inline_query", type->query_);
} else { } else {
object("switch_inline_query_chosen_chat", td::json_object([&](auto &o) { object("switch_inline_query_chosen_chat", td::json_object([&](auto &o) {
o("query", type->query_); o("query", type->query_);
o("allow_user_chats", td::JsonBool(target_chat->allow_user_chats_)); o("allow_user_chats", td::JsonBool(types->allow_user_chats_));
o("allow_bot_chats", td::JsonBool(target_chat->allow_bot_chats_)); o("allow_bot_chats", td::JsonBool(types->allow_bot_chats_));
o("allow_group_chats", td::JsonBool(target_chat->allow_group_chats_)); o("allow_group_chats", td::JsonBool(types->allow_group_chats_));
o("allow_channel_chats", td::JsonBool(target_chat->allow_channel_chats_)); o("allow_channel_chats", td::JsonBool(types->allow_channel_chats_));
})); }));
} }
break; break;
@ -2765,6 +2792,11 @@ class Client::JsonInlineKeyboardButton final : public td::Jsonable {
object("web_app", JsonWebAppInfo(type->url_)); object("web_app", JsonWebAppInfo(type->url_));
break; 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: default:
UNREACHABLE(); UNREACHABLE();
break; break;
@ -2926,9 +2958,11 @@ class Client::JsonExternalReplyInfo final : public td::Jsonable {
object("giveaway_winners", JsonGiveawayWinners(content, client_)); object("giveaway_winners", JsonGiveawayWinners(content, client_));
break; break;
} }
case td_api::messageStory::ID: case td_api::messageStory::ID: {
object("story", JsonEmptyObject()); auto content = static_cast<const td_api::messageStory *>(reply_->content_.get());
object("story", JsonStory(content->story_sender_chat_id_, content->story_id_, client_));
break; break;
}
default: default:
LOG(ERROR) << "Receive external reply with " << to_string(reply_->content_); LOG(ERROR) << "Receive external reply with " << to_string(reply_->content_);
} }
@ -3469,6 +3503,8 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const {
break; break;
case td_api::messageGiveawayPrizeStars::ID: case td_api::messageGiveawayPrizeStars::ID:
break; break;
case td_api::messageGift::ID:
break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
@ -3498,7 +3534,7 @@ class Client::JsonMessageId final : public td::Jsonable {
} }
void store(td::JsonValueScope *scope) const { void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object(); auto object = scope->enter_object();
object("message_id", as_client_message_id(message_id_)); object("message_id", as_client_message_id_unchecked(message_id_));
} }
private: private:
@ -3738,7 +3774,7 @@ class Client::JsonPaidMediaPurchased final : public td::Jsonable {
void store(td::JsonValueScope *scope) const { void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object(); auto object = scope->enter_object();
object("from", JsonUser(update_->user_id_, client_)); object("from", JsonUser(update_->user_id_, client_));
object("payload", update_->payload_); object("paid_media_payload", update_->payload_);
} }
private: private:
@ -4176,6 +4212,41 @@ class Client::JsonGameHighScore final : public td::Jsonable {
const Client *client_; const Client *client_;
}; };
class Client::JsonGift final : public td::Jsonable {
public:
JsonGift(const td_api::gift *gift, const Client *client) : gift_(gift), client_(client) {
}
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
object("id", td::to_string(gift_->id_));
object("sticker", JsonSticker(gift_->sticker_.get(), client_));
object("star_count", gift_->star_count_);
if (gift_->total_count_ > 0) {
object("remaining_count", gift_->remaining_count_);
object("total_count", gift_->total_count_);
}
}
private:
const td_api::gift *gift_;
const Client *client_;
};
class Client::JsonGifts final : public td::Jsonable {
public:
JsonGifts(const td_api::gifts *gifts, const Client *client) : gifts_(gifts), client_(client) {
}
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
object("gifts",
td::json_array(gifts_->gifts_, [client = client_](auto &gift) { return JsonGift(gift.get(), client); }));
}
private:
const td_api::gifts *gifts_;
const Client *client_;
};
class Client::JsonMessageReactionUpdated final : public td::Jsonable { class Client::JsonMessageReactionUpdated final : public td::Jsonable {
public: public:
JsonMessageReactionUpdated(const td_api::updateMessageReaction *update, const Client *client) JsonMessageReactionUpdated(const td_api::updateMessageReaction *update, const Client *client)
@ -4296,69 +4367,135 @@ class Client::JsonRevenueWithdrawalState final : public td::Jsonable {
const td_api::RevenueWithdrawalState *state_; const td_api::RevenueWithdrawalState *state_;
}; };
class Client::JsonStarTransactionPartner final : public td::Jsonable { class Client::JsonAffiliateInfo final : public td::Jsonable {
public: public:
JsonStarTransactionPartner(const td_api::StarTransactionPartner *source, const Client *client) JsonAffiliateInfo(const td_api::affiliateInfo *affiliate_info, const Client *client)
: source_(source), client_(client) { : affiliate_info_(affiliate_info), client_(client) {
} }
void store(td::JsonValueScope *scope) const { void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object(); auto object = scope->enter_object();
switch (source_->get_id()) { auto chat_info = client_->get_chat(affiliate_info_->affiliate_chat_id_);
case td_api::starTransactionPartnerFragment::ID: { CHECK(chat_info != nullptr);
auto source_fragment = static_cast<const td_api::starTransactionPartnerFragment *>(source_); if (chat_info->type == ChatInfo::Type::Private) {
object("type", "fragment"); object("affiliate_user", JsonUser(chat_info->user_id, client_));
if (source_fragment->withdrawal_state_ != nullptr) {
object("withdrawal_state", JsonRevenueWithdrawalState(source_fragment->withdrawal_state_.get()));
}
break;
}
case td_api::starTransactionPartnerBot::ID: {
auto source_user = static_cast<const td_api::starTransactionPartnerBot *>(source_);
object("type", "user");
object("user", JsonUser(source_user->user_id_, client_));
CHECK(source_user->purpose_ != nullptr);
switch (source_user->purpose_->get_id()) {
case td_api::botTransactionPurposeInvoicePayment::ID: {
auto purpose =
static_cast<const td_api::botTransactionPurposeInvoicePayment *>(source_user->purpose_.get());
if (!purpose->invoice_payload_.empty()) {
if (!td::check_utf8(purpose->invoice_payload_)) {
LOG(WARNING) << "Receive non-UTF-8 invoice payload";
object("invoice_payload", td::JsonRawString(purpose->invoice_payload_));
} else { } else {
object("invoice_payload", purpose->invoice_payload_); object("affiliate_chat", JsonChat(affiliate_info_->affiliate_chat_id_, client_));
} }
object("commission_per_mille", affiliate_info_->commission_per_mille_);
object("amount", affiliate_info_->star_amount_->star_count_);
if (affiliate_info_->star_amount_->nanostar_count_ != 0) {
object("nanostar_amount", affiliate_info_->star_amount_->nanostar_count_);
}
}
private:
const td_api::affiliateInfo *affiliate_info_;
const Client *client_;
};
class Client::JsonStarTransactionType final : public td::Jsonable {
public:
JsonStarTransactionType(const td_api::StarTransactionType *type, const Client *client)
: type_(type), client_(client) {
}
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
switch (type_->get_id()) {
case td_api::starTransactionTypeFragmentDeposit::ID:
object("type", "fragment");
break;
case td_api::starTransactionTypeFragmentWithdrawal::ID: {
auto type = static_cast<const td_api::starTransactionTypeFragmentWithdrawal *>(type_);
object("type", "fragment");
if (type->withdrawal_state_ != nullptr) {
object("withdrawal_state", JsonRevenueWithdrawalState(type->withdrawal_state_.get()));
} }
break; break;
} }
case td_api::botTransactionPurposePaidMedia::ID: { case td_api::starTransactionTypeBotPaidMediaSale::ID: {
auto purpose = static_cast<const td_api::botTransactionPurposePaidMedia *>(source_user->purpose_.get()); auto type = static_cast<const td_api::starTransactionTypeBotPaidMediaSale *>(type_);
object("paid_media", td::json_array(purpose->media_, [client = client_](auto &media) { object("type", "user");
object("user", JsonUser(type->user_id_, client_));
object("paid_media", td::json_array(type->media_, [client = client_](auto &media) {
return JsonPaidMedia(media.get(), client); return JsonPaidMedia(media.get(), client);
})); }));
if (!purpose->payload_.empty()) { if (!type->payload_.empty()) {
object("paid_media_payload", purpose->payload_); object("paid_media_payload", type->payload_);
}
if (type->affiliate_ != nullptr) {
object("affiliate", JsonAffiliateInfo(type->affiliate_.get(), client_));
} }
break; break;
} }
default: case td_api::starTransactionTypeBotInvoiceSale::ID: {
UNREACHABLE(); auto type = static_cast<const td_api::starTransactionTypeBotInvoiceSale *>(type_);
object("type", "user");
object("user", JsonUser(type->user_id_, client_));
if (!type->invoice_payload_.empty()) {
if (!td::check_utf8(type->invoice_payload_)) {
LOG(WARNING) << "Receive non-UTF-8 invoice payload";
object("invoice_payload", td::JsonRawString(type->invoice_payload_));
} else {
object("invoice_payload", type->invoice_payload_);
}
}
if (type->affiliate_ != nullptr) {
object("affiliate", JsonAffiliateInfo(type->affiliate_.get(), client_));
} }
break; break;
} }
case td_api::starTransactionPartnerTelegramAds::ID: case td_api::starTransactionTypeBotSubscriptionSale::ID: {
auto type = static_cast<const td_api::starTransactionTypeBotSubscriptionSale *>(type_);
object("type", "user");
object("user", JsonUser(type->user_id_, client_));
if (!type->invoice_payload_.empty()) {
if (!td::check_utf8(type->invoice_payload_)) {
LOG(WARNING) << "Receive non-UTF-8 invoice payload";
object("invoice_payload", td::JsonRawString(type->invoice_payload_));
} else {
object("invoice_payload", type->invoice_payload_);
}
}
if (type->subscription_period_ > 0) {
object("subscription_period", type->subscription_period_);
}
if (type->affiliate_ != nullptr) {
object("affiliate", JsonAffiliateInfo(type->affiliate_.get(), client_));
}
break;
}
case td_api::starTransactionTypeTelegramAdsWithdrawal::ID:
object("type", "telegram_ads"); object("type", "telegram_ads");
break; break;
case td_api::starTransactionPartnerTelegram::ID: case td_api::starTransactionTypeTelegramApiUsage::ID: {
case td_api::starTransactionPartnerAppStore::ID: auto type = static_cast<const td_api::starTransactionTypeTelegramApiUsage *>(type_);
case td_api::starTransactionPartnerGooglePlay::ID: object("type", "telegram_api");
case td_api::starTransactionPartnerUser::ID: object("request_count", type->request_count_);
case td_api::starTransactionPartnerBusiness::ID:
case td_api::starTransactionPartnerChat::ID:
LOG(ERROR) << "Receive " << to_string(*source_);
object("type", "other");
break; break;
case td_api::starTransactionPartnerUnsupported::ID: }
case td_api::starTransactionTypeGiftPurchase::ID: {
auto type = static_cast<const td_api::starTransactionTypeGiftPurchase *>(type_);
object("type", "user");
object("user", JsonUser(type->user_id_, client_));
object("gift", JsonGift(type->gift_.get(), client_));
break;
}
case td_api::starTransactionTypeAffiliateProgramCommission::ID: {
auto type = static_cast<const td_api::starTransactionTypeAffiliateProgramCommission *>(type_);
object("type", "affiliate_program");
auto chat_info = client_->get_chat(type->chat_id_);
CHECK(chat_info != nullptr);
if (chat_info->type == ChatInfo::Type::Private) {
object("sponsor_user", JsonUser(chat_info->user_id, client_));
} else {
LOG(ERROR) << "Receive chat " << type->chat_id_ << " as an affiliate program sponsor";
object("sponsor_chat", JsonChat(type->chat_id_, client_));
}
object("commission_per_mille", type->commission_per_mille_);
break;
}
case td_api::starTransactionTypeUnsupported::ID:
object("type", "other"); object("type", "other");
break; break;
default: default:
@ -4367,7 +4504,7 @@ class Client::JsonStarTransactionPartner final : public td::Jsonable {
} }
private: private:
const td_api::StarTransactionPartner *source_; const td_api::StarTransactionType *type_;
const Client *client_; const Client *client_;
}; };
@ -4380,12 +4517,18 @@ class Client::JsonStarTransaction final : public td::Jsonable {
auto object = scope->enter_object(); auto object = scope->enter_object();
object("id", transaction_->id_); object("id", transaction_->id_);
object("date", transaction_->date_); object("date", transaction_->date_);
if (transaction_->star_count_ > 0) { auto star_count = transaction_->star_amount_->star_count_;
object("amount", transaction_->star_count_); auto nanostar_count = transaction_->star_amount_->nanostar_count_;
object("source", JsonStarTransactionPartner(transaction_->partner_.get(), client_)); if (star_count > 0 || nanostar_count > 0) {
object("source", JsonStarTransactionType(transaction_->type_.get(), client_));
} else { } else {
object("amount", -transaction_->star_count_); star_count = -star_count;
object("receiver", JsonStarTransactionPartner(transaction_->partner_.get(), client_)); nanostar_count = -nanostar_count;
object("receiver", JsonStarTransactionType(transaction_->type_.get(), client_));
}
object("amount", star_count);
if (nanostar_count != 0) {
object("nanostar_amount", nanostar_count);
} }
} }
@ -4516,6 +4659,20 @@ class Client::JsonSentWebAppMessage final : public td::Jsonable {
const td_api::sentWebAppMessage *message_; const td_api::sentWebAppMessage *message_;
}; };
class Client::JsonPreparedInlineMessageId final : public td::Jsonable {
public:
explicit JsonPreparedInlineMessageId(const td_api::preparedInlineMessageId *message) : message_(message) {
}
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
object("id", message_->id_);
object("expiration_date", message_->expiration_date_);
}
private:
const td_api::preparedInlineMessageId *message_;
};
// start custom Json objects impl // start custom Json objects impl
class Client::JsonAuthorizationState : public td::Jsonable { class Client::JsonAuthorizationState : public td::Jsonable {
@ -6240,6 +6397,25 @@ class Client::TdOnAnswerWebAppQueryCallback final : public TdQueryCallback {
PromisedQueryPtr query_; PromisedQueryPtr query_;
}; };
class Client::TdOnSavePreparedInlineMessageCallback final : public TdQueryCallback {
public:
explicit TdOnSavePreparedInlineMessageCallback(PromisedQueryPtr query) : query_(std::move(query)) {
}
void on_result(object_ptr<td_api::Object> result) final {
if (result->get_id() == td_api::error::ID) {
return fail_query_with_error(std::move(query_), move_object_as<td_api::error>(result));
}
CHECK(result->get_id() == td_api::preparedInlineMessageId::ID);
auto message = move_object_as<td_api::preparedInlineMessageId>(result);
answer_query(JsonPreparedInlineMessageId(message.get()), std::move(query_));
}
private:
PromisedQueryPtr query_;
};
class Client::TdOnGetUserChatBoostsCallback final : public TdQueryCallback { class Client::TdOnGetUserChatBoostsCallback final : public TdQueryCallback {
public: public:
TdOnGetUserChatBoostsCallback(Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { TdOnGetUserChatBoostsCallback(Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) {
@ -6260,6 +6436,28 @@ class Client::TdOnGetUserChatBoostsCallback final : public TdQueryCallback {
PromisedQueryPtr query_; PromisedQueryPtr query_;
}; };
class Client::TdOnGetGiftsCallback final : public TdQueryCallback {
public:
TdOnGetGiftsCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) {
}
void on_result(object_ptr<td_api::Object> result) final {
if (result->get_id() == td_api::error::ID) {
return fail_query_with_error(std::move(query_), move_object_as<td_api::error>(result));
}
CHECK(result->get_id() == td_api::gifts::ID);
auto gifts = move_object_as<td_api::gifts>(result);
td::remove_if(gifts->gifts_,
[](const auto &gift) { return gift->total_count_ > 0 && gift->remaining_count_ == 0; });
answer_query(JsonGifts(gifts.get(), client_), std::move(query_));
}
private:
const Client *client_;
PromisedQueryPtr query_;
};
class Client::TdOnReturnFileCallback final : public TdQueryCallback { class Client::TdOnReturnFileCallback final : public TdQueryCallback {
public: public:
TdOnReturnFileCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { TdOnReturnFileCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) {
@ -6761,7 +6959,7 @@ void Client::send(PromisedQueryPtr query) {
td::Time::now() > parameters_->start_time_ + 60) { td::Time::now() > parameters_->start_time_ + 60) {
BotStatActor *stat = stat_actor_.get_actor_unsafe(); BotStatActor *stat = stat_actor_.get_actor_unsafe();
auto update_per_minute = static_cast<int64>(stat->get_minute_update_count(td::Time::now()) * 60); auto update_per_minute = static_cast<int64>(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; LOG(INFO) << "Fail a query, because there are too many active queries: " << *query;
return fail_query_flood_limit_exceeded(std::move(query)); return fail_query_flood_limit_exceeded(std::move(query));
} }
@ -7031,8 +7229,8 @@ void Client::check_chat_access(int64 chat_id, AccessRights access_rights, const
} }
template <class OnSuccess> template <class OnSuccess>
void Client::check_chat(td::Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, void Client::check_chat(td::Slice chat_id_str, AccessRights access_rights, PromisedQueryPtr query, OnSuccess on_success,
OnSuccess on_success) { bool allow_unknown_user) {
if (chat_id_str.empty()) { if (chat_id_str.empty()) {
return fail_query(400, "Bad Request: chat_id is empty", std::move(query)); return fail_query(400, "Bad Request: chat_id is empty", std::move(query));
} }
@ -7044,6 +7242,9 @@ void Client::check_chat(td::Slice chat_id_str, AccessRights access_rights, Promi
} }
auto chat_id = td::to_integer<int64>(chat_id_str); 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); auto chat_info = get_chat(chat_id);
if (chat_info != nullptr && chat_info->type == ChatInfo::Type::Private) { if (chat_info != nullptr && chat_info->type == ChatInfo::Type::Private) {
const UserInfo *user_info = get_user_info(chat_info->user_id); const UserInfo *user_info = get_user_info(chat_info->user_id);
@ -7118,7 +7319,7 @@ void Client::check_business_connection_chat_id(const td::string &business_connec
} }
auto chat_id = r_chat_id.move_as_ok(); auto chat_id = r_chat_id.move_as_ok();
check_business_connection(business_connection_id, std::move(query), check_business_connection(business_connection_id, std::move(query),
[this, chat_id, on_success = std::move(on_success)]( [chat_id, on_success = std::move(on_success)](
const BusinessConnection *business_connection, PromisedQueryPtr query) mutable { const BusinessConnection *business_connection, PromisedQueryPtr query) mutable {
on_success(business_connection, chat_id, std::move(query)); on_success(business_connection, chat_id, std::move(query));
}); });
@ -7240,7 +7441,8 @@ void Client::check_messages(td::Slice chat_id_str, td::vector<int64> message_ids
template <class OnSuccess> template <class OnSuccess>
void Client::check_reply_parameters(td::Slice chat_id_str, InputReplyParameters &&reply_parameters, void Client::check_reply_parameters(td::Slice chat_id_str, InputReplyParameters &&reply_parameters,
int64 message_thread_id, PromisedQueryPtr query, OnSuccess on_success) { int64 message_thread_id, PromisedQueryPtr query, OnSuccess on_success,
bool allow_unknown_user) {
if (chat_id_str == reply_parameters.reply_in_chat_id) { if (chat_id_str == reply_parameters.reply_in_chat_id) {
reply_parameters.reply_in_chat_id.clear(); reply_parameters.reply_in_chat_id.clear();
} }
@ -7303,7 +7505,8 @@ void Client::check_reply_parameters(td::Slice chat_id_str, InputReplyParameters
} }
check_chat(reply_parameters.reply_in_chat_id, AccessRights::Read, std::move(query), check_chat(reply_parameters.reply_in_chat_id, AccessRights::Read, std::move(query),
std::move(on_reply_chat_resolved)); std::move(on_reply_chat_resolved));
}); },
allow_unknown_user);
} }
template <class OnSuccess> template <class OnSuccess>
@ -7312,7 +7515,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)); return fail_query(400, "Bad Request: sticker_set_name is empty", std::move(query));
} }
send_request(make_object<td_api::searchStickerSet>(sticker_set_name), send_request(make_object<td_api::searchStickerSet>(sticker_set_name, false),
td::make_unique<TdOnSearchStickerSetCallback<OnSuccess>>(std::move(query), std::move(on_success))); td::make_unique<TdOnSearchStickerSetCallback<OnSuccess>>(std::move(query), std::move(on_success)));
} }
@ -8209,7 +8412,7 @@ td::Result<Client::InputReplyParameters> Client::get_reply_parameters(td::JsonVa
result.reply_in_chat_id = std::move(chat_id); result.reply_in_chat_id = std::move(chat_id);
result.reply_to_message_id = as_tdlib_message_id(td::max(message_id, 0)); result.reply_to_message_id = as_tdlib_message_id(td::max(message_id, 0));
result.allow_sending_without_reply = allow_sending_without_reply; result.allow_sending_without_reply = allow_sending_without_reply;
result.quote = td_api::make_object<td_api::inputTextQuote>(std::move(quote), quote_position); result.quote = make_object<td_api::inputTextQuote>(std::move(quote), quote_position);
return std::move(result); return std::move(result);
} }
@ -8355,7 +8558,8 @@ td::Result<td_api::object_ptr<td_api::inlineKeyboardButton>> Client::get_inline_
TRY_RESULT(switch_inline_query, object.get_required_string_field("switch_inline_query")); TRY_RESULT(switch_inline_query, object.get_required_string_field("switch_inline_query"));
return make_object<td_api::inlineKeyboardButton>( return make_object<td_api::inlineKeyboardButton>(
text, make_object<td_api::inlineKeyboardButtonTypeSwitchInline>( text, make_object<td_api::inlineKeyboardButtonTypeSwitchInline>(
switch_inline_query, td_api::make_object<td_api::targetChatChosen>(true, true, true, true))); switch_inline_query,
make_object<td_api::targetChatChosen>(make_object<td_api::targetChatTypes>(true, true, true, true))));
} }
if (object.has_field("switch_inline_query_chosen_chat")) { if (object.has_field("switch_inline_query_chosen_chat")) {
@ -8370,15 +8574,15 @@ td::Result<td_api::object_ptr<td_api::inlineKeyboardButton>> Client::get_inline_
TRY_RESULT(allow_channel_chats, switch_inline_query_object.get_optional_bool_field("allow_channel_chats")); TRY_RESULT(allow_channel_chats, switch_inline_query_object.get_optional_bool_field("allow_channel_chats"));
return make_object<td_api::inlineKeyboardButton>( return make_object<td_api::inlineKeyboardButton>(
text, make_object<td_api::inlineKeyboardButtonTypeSwitchInline>( text, make_object<td_api::inlineKeyboardButtonTypeSwitchInline>(
query, td_api::make_object<td_api::targetChatChosen>(allow_user_chats, allow_bot_chats, query, make_object<td_api::targetChatChosen>(make_object<td_api::targetChatTypes>(
allow_group_chats, allow_channel_chats))); allow_user_chats, allow_bot_chats, allow_group_chats, allow_channel_chats))));
} }
if (object.has_field("switch_inline_query_current_chat")) { if (object.has_field("switch_inline_query_current_chat")) {
TRY_RESULT(switch_inline_query, object.get_required_string_field("switch_inline_query_current_chat")); TRY_RESULT(switch_inline_query, object.get_required_string_field("switch_inline_query_current_chat"));
return make_object<td_api::inlineKeyboardButton>( return make_object<td_api::inlineKeyboardButton>(
text, make_object<td_api::inlineKeyboardButtonTypeSwitchInline>( text, make_object<td_api::inlineKeyboardButtonTypeSwitchInline>(switch_inline_query,
switch_inline_query, td_api::make_object<td_api::targetChatCurrent>())); make_object<td_api::targetChatCurrent>()));
} }
if (object.has_field("login_url")) { if (object.has_field("login_url")) {
@ -8429,6 +8633,14 @@ 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)); 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"); return td::Status::Error(400, "Text buttons are unallowed in the inline keyboard");
} }
@ -8852,7 +9064,7 @@ td::Result<td_api::object_ptr<td_api::InputMessageContent>> Client::get_input_me
TRY_RESULT(is_flexible, object.get_optional_bool_field("is_flexible")); TRY_RESULT(is_flexible, object.get_optional_bool_field("is_flexible"));
return make_object<td_api::inputMessageInvoice>( return make_object<td_api::inputMessageInvoice>(
make_object<td_api::invoice>(currency, std::move(prices), max_tip_amount, std::move(suggested_tip_amounts), make_object<td_api::invoice>(currency, std::move(prices), 0, max_tip_amount, std::move(suggested_tip_amounts),
td::string(), td::string(), false, need_name, need_phone_number, td::string(), td::string(), false, need_name, need_phone_number,
need_email_address, need_shipping_address, send_phone_number_to_provider, need_email_address, need_shipping_address, send_phone_number_to_provider,
send_email_address_to_provider, is_flexible), send_email_address_to_provider, is_flexible),
@ -8867,9 +9079,12 @@ 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, td_api::object_ptr<td_api::messageSendOptions> Client::get_message_send_options(bool disable_notification,
bool protect_content, int64 effect_id, bool protect_content,
bool allow_paid_broadcast,
int64 effect_id,
td_api::object_ptr<td_api::MessageSchedulingState> &&scheduling_state) { td_api::object_ptr<td_api::MessageSchedulingState> &&scheduling_state) {
return make_object<td_api::messageSendOptions>(disable_notification, false, protect_content, false, std::move(scheduling_state), effect_id, 0, false); return make_object<td_api::messageSendOptions>(disable_notification, false, protect_content, allow_paid_broadcast,
false, std::move(scheduling_state), effect_id, 0, false);
} }
td::Result<td_api::object_ptr<td_api::inlineQueryResultsButton>> Client::get_inline_query_results_button( td::Result<td_api::object_ptr<td_api::inlineQueryResultsButton>> Client::get_inline_query_results_button(
@ -10499,12 +10714,13 @@ td::Result<td_api::object_ptr<td_api::inputMessageInvoice>> Client::get_input_me
TRY_RESULT(paid_media_caption, get_formatted_text(query->arg("paid_media_caption").str(), TRY_RESULT(paid_media_caption, get_formatted_text(query->arg("paid_media_caption").str(),
query->arg("paid_media_caption_parse_mode").str(), query->arg("paid_media_caption_parse_mode").str(),
get_input_entities(query, "paid_media_caption_entities"))); get_input_entities(query, "paid_media_caption_entities")));
int32 subscription_period = get_integer_arg(query, "subscription_period", 0, 0);
return make_object<td_api::inputMessageInvoice>( return make_object<td_api::inputMessageInvoice>(
make_object<td_api::invoice>(currency.str(), std::move(prices), max_tip_amount, std::move(suggested_tip_amounts), make_object<td_api::invoice>(currency.str(), std::move(prices), subscription_period, max_tip_amount,
td::string(), td::string(), false, need_name, need_phone_number, need_email_address, std::move(suggested_tip_amounts), td::string(), td::string(), false, need_name,
need_shipping_address, send_phone_number_to_provider, send_email_address_to_provider, need_phone_number, need_email_address, need_shipping_address,
is_flexible), send_phone_number_to_provider, send_email_address_to_provider, is_flexible),
title.str(), description.str(), photo_url.str(), photo_size, photo_width, photo_height, payload.str(), title.str(), description.str(), photo_url.str(), photo_size, photo_width, photo_height, payload.str(),
provider_token.str(), provider_data.str(), start_parameter.str(), std::move(paid_media), provider_token.str(), provider_data.str(), start_parameter.str(), std::move(paid_media),
std::move(paid_media_caption)); std::move(paid_media_caption));
@ -11478,9 +11694,10 @@ td::Status Client::process_copy_messages_query(PromisedQueryPtr &query) {
auto message_count = message_ids.size(); auto message_count = message_ids.size();
count += static_cast<int32>(message_count); count += static_cast<int32>(message_count);
send_request(make_object<td_api::forwardMessages>( send_request(
make_object<td_api::forwardMessages>(
chat_id, message_thread_id, from_chat_id, std::move(message_ids), chat_id, message_thread_id, from_chat_id, std::move(message_ids),
get_message_send_options(disable_notification, protect_content, 0, std::move(send_at)), true, remove_caption), get_message_send_options(disable_notification, protect_content, false, 0, std::move(send_at)), true, remove_caption),
td::make_unique<TdOnForwardMessagesCallback>(this, chat_id, message_count, std::move(query))); td::make_unique<TdOnForwardMessagesCallback>(this, chat_id, message_count, std::move(query)));
}); });
}; };
@ -11536,7 +11753,7 @@ td::Status Client::process_forward_messages_query(PromisedQueryPtr &query) {
send_request(make_object<td_api::forwardMessages>( send_request(make_object<td_api::forwardMessages>(
chat_id, message_thread_id, from_chat_id, std::move(message_ids), chat_id, message_thread_id, from_chat_id, std::move(message_ids),
get_message_send_options(disable_notification, protect_content, 0, std::move(send_at)), false, false), get_message_send_options(disable_notification, protect_content, false, 0, std::move(send_at)), false, false),
td::make_unique<TdOnForwardMessagesCallback>(this, chat_id, message_count, std::move(query))); td::make_unique<TdOnForwardMessagesCallback>(this, chat_id, message_count, std::move(query)));
}); });
}; };
@ -11552,6 +11769,7 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
auto business_connection_id = query->arg("business_connection_id"); auto business_connection_id = query->arg("business_connection_id");
auto disable_notification = to_bool(query->arg("disable_notification")); auto disable_notification = to_bool(query->arg("disable_notification"));
auto protect_content = to_bool(query->arg("protect_content")); 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 effect_id = td::to_integer<int64>(query->arg("message_effect_id"));
// TRY_RESULT(reply_markup, get_reply_markup(query.get(), bot_user_ids_)); // TRY_RESULT(reply_markup, get_reply_markup(query.get(), bot_user_ids_));
auto reply_markup = nullptr; auto reply_markup = nullptr;
@ -11562,9 +11780,9 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
std::move(reply_markup), std::move(query), std::move(reply_markup), std::move(query),
[this, chat_id_str = chat_id.str(), message_thread_id, business_connection_id = business_connection_id.str(), [this, chat_id_str = chat_id.str(), message_thread_id, business_connection_id = business_connection_id.str(),
send_at = std::move(send_at), send_at = std::move(send_at),
reply_parameters = std::move(reply_parameters), disable_notification, protect_content, effect_id, reply_parameters = std::move(reply_parameters), disable_notification, protect_content, allow_paid_broadcast,
input_message_contents = std::move(input_message_contents)](object_ptr<td_api::ReplyMarkup> reply_markup, effect_id, input_message_contents = std::move(input_message_contents)](
PromisedQueryPtr query) mutable { object_ptr<td_api::ReplyMarkup> reply_markup, PromisedQueryPtr query) mutable {
if (!business_connection_id.empty()) { if (!business_connection_id.empty()) {
return check_business_connection_chat_id( return check_business_connection_chat_id(
business_connection_id, chat_id_str, std::move(query), business_connection_id, chat_id_str, std::move(query),
@ -11580,7 +11798,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), input_message_contents = std::move(input_message_contents),
send_at = std::move(send_at), send_at = std::move(send_at),
reply_markup = std::move(reply_markup)](int64 chat_id, int64 message_thread_id, reply_markup = std::move(reply_markup)](int64 chat_id, int64 message_thread_id,
@ -11593,14 +11811,15 @@ td::Status Client::process_send_media_group_query(PromisedQueryPtr &query) {
auto message_count = input_message_contents.size(); auto message_count = input_message_contents.size();
count += static_cast<int32>(message_count); count += static_cast<int32>(message_count);
send_request(make_object<td_api::sendMessageAlbum>( send_request(
make_object<td_api::sendMessageAlbum>(
chat_id, message_thread_id, get_input_message_reply_to(std::move(reply_parameters)), 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(send_at)), get_message_send_options(disable_notification, protect_content, allow_paid_broadcast, effect_id, std::move(send_at)),
std::move(input_message_contents)), std::move(input_message_contents)),
td::make_unique<TdOnSendMessageAlbumCallback>(this, chat_id, message_count, std::move(query))); 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), check_reply_parameters(chat_id_str, std::move(reply_parameters), message_thread_id, std::move(query),
std::move(on_success)); std::move(on_success), allow_paid_broadcast);
}); });
return td::Status::OK(); return td::Status::OK();
} }
@ -11945,7 +12164,18 @@ td::Status Client::process_delete_messages_query(PromisedQueryPtr &query) {
td::Status Client::process_create_invoice_link_query(PromisedQueryPtr &query) { td::Status Client::process_create_invoice_link_query(PromisedQueryPtr &query) {
TRY_RESULT(input_message_invoice, get_input_message_invoice(query.get())); TRY_RESULT(input_message_invoice, get_input_message_invoice(query.get()));
send_request(make_object<td_api::createInvoiceLink>(std::move(input_message_invoice)), auto business_connection_id = query->arg("business_connection_id").str();
if (!business_connection_id.empty()) {
check_business_connection(business_connection_id, std::move(query),
[this, input_message_invoice = std::move(input_message_invoice)](
const BusinessConnection *business_connection, PromisedQueryPtr query) mutable {
send_request(make_object<td_api::createInvoiceLink>(business_connection->id_,
std::move(input_message_invoice)),
td::make_unique<TdOnCreateInvoiceLinkCallback>(std::move(query)));
});
return td::Status::OK();
}
send_request(make_object<td_api::createInvoiceLink>(td::string(), std::move(input_message_invoice)),
td::make_unique<TdOnCreateInvoiceLinkCallback>(std::move(query))); td::make_unique<TdOnCreateInvoiceLinkCallback>(std::move(query)));
return td::Status::OK(); return td::Status::OK();
} }
@ -11971,6 +12201,38 @@ td::Status Client::process_refund_star_payment_query(PromisedQueryPtr &query) {
return td::Status::OK(); return td::Status::OK();
} }
td::Status Client::process_edit_user_star_subscription_query(PromisedQueryPtr &query) {
TRY_RESULT(user_id, get_user_id(query.get()));
auto telegram_payment_charge_id = query->arg("telegram_payment_charge_id");
auto is_canceled = to_bool(query->arg("is_canceled"));
check_user_no_fail(
user_id, std::move(query),
[this, user_id, telegram_payment_charge_id = telegram_payment_charge_id.str(),
is_canceled](PromisedQueryPtr query) {
send_request(make_object<td_api::editUserStarSubscription>(user_id, telegram_payment_charge_id, is_canceled),
td::make_unique<TdOnOkQueryCallback>(std::move(query)));
});
return td::Status::OK();
}
td::Status Client::process_get_available_gifts_query(PromisedQueryPtr &query) {
send_request(make_object<td_api::getAvailableGifts>(), td::make_unique<TdOnGetGiftsCallback>(this, std::move(query)));
return td::Status::OK();
}
td::Status Client::process_send_gift_query(PromisedQueryPtr &query) {
auto gift_id = td::to_integer<int64>(query->arg("gift_id"));
TRY_RESULT(user_id, get_user_id(query.get()));
TRY_RESULT(text, get_formatted_text(query->arg("text").str(), query->arg("text_parse_mode").str(),
get_input_entities(query.get(), "text_entities")));
check_user(user_id, std::move(query),
[this, gift_id, user_id, text = std::move(text)](PromisedQueryPtr query) mutable {
send_request(make_object<td_api::sendGift>(gift_id, user_id, std::move(text), false),
td::make_unique<TdOnOkQueryCallback>(std::move(query)));
});
return td::Status::OK();
}
td::Status Client::process_set_game_score_query(PromisedQueryPtr &query) { td::Status Client::process_set_game_score_query(PromisedQueryPtr &query) {
CHECK_IS_BOT(); CHECK_IS_BOT();
auto chat_id = query->arg("chat_id"); auto chat_id = query->arg("chat_id");
@ -12081,6 +12343,30 @@ td::Status Client::process_answer_inline_query_query(PromisedQueryPtr &query) {
return td::Status::OK(); return td::Status::OK();
} }
td::Status Client::process_save_prepared_inline_message_query(PromisedQueryPtr &query) {
TRY_RESULT(user_id, get_user_id(query.get()));
TRY_RESULT(result, get_inline_query_result(query.get(), bot_user_ids_));
auto allow_user_chats = to_bool(query->arg("allow_user_chats"));
auto allow_bot_chats = to_bool(query->arg("allow_bot_chats"));
auto allow_group_chats = to_bool(query->arg("allow_group_chats"));
auto allow_channel_chats = to_bool(query->arg("allow_channel_chats"));
auto types =
make_object<td_api::targetChatTypes>(allow_user_chats, allow_bot_chats, allow_group_chats, allow_channel_chats);
td::vector<object_ptr<td_api::InputInlineQueryResult>> results;
results.push_back(std::move(result));
resolve_inline_query_results_bot_usernames(
std::move(results), std::move(query),
[this, user_id, types = std::move(types)](td::vector<object_ptr<td_api::InputInlineQueryResult>> results,
PromisedQueryPtr query) mutable {
CHECK(results.size() == 1);
send_request(make_object<td_api::savePreparedInlineMessage>(user_id, std::move(results[0]), std::move(types)),
td::make_unique<TdOnSavePreparedInlineMessageCallback>(std::move(query)));
});
return td::Status::OK();
}
td::Status Client::process_answer_callback_query_query(PromisedQueryPtr &query) { td::Status Client::process_answer_callback_query_query(PromisedQueryPtr &query) {
CHECK_IS_BOT(); CHECK_IS_BOT();
auto callback_query_id = td::to_integer<int64>(query->arg("callback_query_id")); auto callback_query_id = td::to_integer<int64>(query->arg("callback_query_id"));
@ -12220,6 +12506,23 @@ td::Status Client::process_get_business_connection_query(PromisedQueryPtr &query
return td::Status::OK(); return td::Status::OK();
} }
td::Status Client::process_set_user_emoji_status_query(PromisedQueryPtr &query) {
TRY_RESULT(user_id, get_user_id(query.get()));
auto emoji_status_custom_emoji_id = td::to_integer<int64>(query->arg("emoji_status_custom_emoji_id"));
auto emoji_status_expiration_date = td::to_integer<int32>(query->arg("emoji_status_expiration_date"));
check_user(
user_id, std::move(query),
[this, user_id, emoji_status_custom_emoji_id, emoji_status_expiration_date](PromisedQueryPtr query) mutable {
send_request(make_object<td_api::setUserEmojiStatus>(
user_id, emoji_status_custom_emoji_id == 0
? nullptr
: make_object<td_api::emojiStatus>(emoji_status_custom_emoji_id,
emoji_status_expiration_date)),
td::make_unique<TdOnOkQueryCallback>(std::move(query)));
});
return td::Status::OK();
}
td::Status Client::process_get_chat_query(PromisedQueryPtr &query) { td::Status Client::process_get_chat_query(PromisedQueryPtr &query) {
auto chat_id = query->arg("chat_id"); auto chat_id = query->arg("chat_id");
@ -12902,7 +13205,7 @@ td::Status Client::process_get_sticker_set_query(PromisedQueryPtr &query) {
send_request(make_object<td_api::getStickerSet>(GREAT_MINDS_SET_ID), send_request(make_object<td_api::getStickerSet>(GREAT_MINDS_SET_ID),
td::make_unique<TdOnReturnStickerSetCallback>(this, true, std::move(query))); td::make_unique<TdOnReturnStickerSetCallback>(this, true, std::move(query)));
} else { } else {
send_request(make_object<td_api::searchStickerSet>(name.str()), send_request(make_object<td_api::searchStickerSet>(name.str(), false),
td::make_unique<TdOnReturnStickerSetCallback>(this, true, std::move(query))); td::make_unique<TdOnReturnStickerSetCallback>(this, true, std::move(query)));
} }
return td::Status::OK(); return td::Status::OK();
@ -14045,6 +14348,7 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
auto reply_parameters = r_reply_parameters.move_as_ok(); auto reply_parameters = r_reply_parameters.move_as_ok();
auto disable_notification = to_bool(query->arg("disable_notification")); auto disable_notification = to_bool(query->arg("disable_notification"));
auto protect_content = to_bool(query->arg("protect_content")); 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 effect_id = td::to_integer<int64>(query->arg("message_effect_id"));
auto r_reply_markup = get_reply_markup(query.get(), bot_user_ids_); auto r_reply_markup = get_reply_markup(query.get(), bot_user_ids_);
if (r_reply_markup.is_error()) { if (r_reply_markup.is_error()) {
@ -14065,9 +14369,9 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
std::move(reply_markup), std::move(query), std::move(reply_markup), std::move(query),
[this, chat_id_str = chat_id.str(), message_thread_id, business_connection_id = business_connection_id.str(), [this, chat_id_str = chat_id.str(), message_thread_id, business_connection_id = business_connection_id.str(),
send_at = std::move(send_at), send_at = std::move(send_at),
reply_parameters = std::move(reply_parameters), disable_notification, protect_content, effect_id, reply_parameters = std::move(reply_parameters), disable_notification, protect_content, allow_paid_broadcast,
input_message_content = std::move(input_message_content)](object_ptr<td_api::ReplyMarkup> reply_markup, effect_id, input_message_content = std::move(input_message_content)](
PromisedQueryPtr query) mutable { object_ptr<td_api::ReplyMarkup> reply_markup, PromisedQueryPtr query) mutable {
if (!business_connection_id.empty()) { if (!business_connection_id.empty()) {
return check_business_connection_chat_id( return check_business_connection_chat_id(
business_connection_id, chat_id_str, std::move(query), business_connection_id, chat_id_str, std::move(query),
@ -14083,7 +14387,7 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> 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), input_message_content = std::move(input_message_content),
send_at = std::move(send_at), send_at = std::move(send_at),
reply_markup = std::move(reply_markup)](int64 chat_id, int64 message_thread_id, reply_markup = std::move(reply_markup)](int64 chat_id, int64 message_thread_id,
@ -14095,14 +14399,15 @@ void Client::do_send_message(object_ptr<td_api::InputMessageContent> input_messa
} }
count++; count++;
send_request(make_object<td_api::sendMessage>( send_request(
make_object<td_api::sendMessage>(
chat_id, message_thread_id, get_input_message_reply_to(std::move(reply_parameters)), 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(send_at)), get_message_send_options(disable_notification, protect_content, allow_paid_broadcast, effect_id, std::move(send_at)),
std::move(reply_markup), std::move(input_message_content)), std::move(reply_markup), std::move(input_message_content)),
td::make_unique<TdOnSendMessageCallback>(this, chat_id, std::move(query))); 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), check_reply_parameters(chat_id_str, std::move(reply_parameters), message_thread_id, std::move(query),
std::move(on_success)); std::move(on_success), allow_paid_broadcast);
}); });
} }
@ -15365,6 +15670,8 @@ bool Client::need_skip_update_message(int64 chat_id, const object_ptr<td_api::me
return true; return true;
case td_api::messageGiveawayPrizeStars::ID: case td_api::messageGiveawayPrizeStars::ID:
return true; return true;
case td_api::messageGift::ID:
return true;
default: default:
break; break;
} }
@ -15417,9 +15724,10 @@ td::int64 Client::get_same_chat_reply_to_message_id(const object_ptr<td_api::mes
->old_background_message_id_; ->old_background_message_id_;
case td_api::messageGiveawayCompleted::ID: case td_api::messageGiveawayCompleted::ID:
return static_cast<const td_api::messageGiveawayCompleted *>(message->content_.get())->giveaway_message_id_; return static_cast<const td_api::messageGiveawayCompleted *>(message->content_.get())->giveaway_message_id_;
case td_api::messagePaymentSuccessful::ID: case td_api::messagePaymentSuccessful::ID: {
UNREACHABLE(); const auto *content = static_cast<const td_api::messagePaymentSuccessful *>(message->content_.get());
return static_cast<int64>(0); return content->invoice_chat_id_ == message->chat_id_ ? content->invoice_message_id_ : static_cast<int64>(0);
}
default: default:
return static_cast<int64>(0); return static_cast<int64>(0);
} }
@ -15540,6 +15848,11 @@ bool Client::are_equal_inline_keyboard_buttons(const td_api::inlineKeyboardButto
auto rhs_type = static_cast<const td_api::inlineKeyboardButtonTypeWebApp *>(rhs->type_.get()); auto rhs_type = static_cast<const td_api::inlineKeyboardButtonTypeWebApp *>(rhs->type_.get());
return lhs_type->url_ == rhs_type->url_; 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: default:
UNREACHABLE(); UNREACHABLE();
return false; return false;
@ -15881,6 +16194,7 @@ void Client::init_message(MessageInfo *message_info, object_ptr<td_api::message>
} }
message_info->can_be_saved = message->can_be_saved_; 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_from_offline = message->is_from_offline_;
message_info->is_topic_message = message->is_topic_message_; message_info->is_topic_message = message->is_topic_message_;
message_info->author_signature = std::move(message->author_signature_); message_info->author_signature = std::move(message->author_signature_);

View File

@ -148,6 +148,7 @@ class Client final : public WebhookActor::Callback {
class JsonEntity; class JsonEntity;
class JsonVectorEntities; class JsonVectorEntities;
class JsonWebAppInfo; class JsonWebAppInfo;
class JsonCopyTextButton;
class JsonInlineKeyboardButton; class JsonInlineKeyboardButton;
class JsonInlineKeyboard; class JsonInlineKeyboard;
class JsonReplyMarkup; class JsonReplyMarkup;
@ -182,6 +183,8 @@ class Client final : public WebhookActor::Callback {
class JsonForumTopicEdited; class JsonForumTopicEdited;
class JsonForumTopicInfo; class JsonForumTopicInfo;
class JsonGameHighScore; class JsonGameHighScore;
class JsonGift;
class JsonGifts;
class JsonMessageReactionUpdated; class JsonMessageReactionUpdated;
class JsonMessageReactionCountUpdated; class JsonMessageReactionCountUpdated;
class JsonBusinessConnection; class JsonBusinessConnection;
@ -214,13 +217,15 @@ class Client final : public WebhookActor::Callback {
class JsonGiveawayCompleted; class JsonGiveawayCompleted;
class JsonChatBoostAdded; class JsonChatBoostAdded;
class JsonRevenueWithdrawalState; class JsonRevenueWithdrawalState;
class JsonStarTransactionPartner; class JsonAffiliateInfo;
class JsonStarTransactionType;
class JsonStarTransaction; class JsonStarTransaction;
class JsonStarTransactions; class JsonStarTransactions;
class JsonUpdateTypes; class JsonUpdateTypes;
class JsonWebhookInfo; class JsonWebhookInfo;
class JsonStickerSet; class JsonStickerSet;
class JsonSentWebAppMessage; class JsonSentWebAppMessage;
class JsonPreparedInlineMessageId;
class JsonCustomJson; class JsonCustomJson;
//start custom Json objects //start custom Json objects
@ -271,12 +276,14 @@ class Client final : public WebhookActor::Callback {
class TdOnGetSupergroupMembersCallback; class TdOnGetSupergroupMembersCallback;
class TdOnGetSupergroupMemberCountCallback; class TdOnGetSupergroupMemberCountCallback;
class TdOnGetUserChatBoostsCallback; class TdOnGetUserChatBoostsCallback;
class TdOnGetGiftsCallback;
class TdOnCreateInvoiceLinkCallback; class TdOnCreateInvoiceLinkCallback;
class TdOnGetStarTransactionsQueryCallback; class TdOnGetStarTransactionsQueryCallback;
class TdOnReplacePrimaryChatInviteLinkCallback; class TdOnReplacePrimaryChatInviteLinkCallback;
class TdOnGetChatInviteLinkCallback; class TdOnGetChatInviteLinkCallback;
class TdOnGetGameHighScoresCallback; class TdOnGetGameHighScoresCallback;
class TdOnAnswerWebAppQueryCallback; class TdOnAnswerWebAppQueryCallback;
class TdOnSavePreparedInlineMessageCallback;
class TdOnReturnFileCallback; class TdOnReturnFileCallback;
class TdOnReturnStickerSetCallback; class TdOnReturnStickerSetCallback;
class TdOnGetStickerSetPromiseCallback; class TdOnGetStickerSetPromiseCallback;
@ -390,7 +397,8 @@ class Client final : public WebhookActor::Callback {
OnSuccess on_success) const; OnSuccess on_success) const;
template <class OnSuccess> template <class OnSuccess>
void check_chat(td::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,
bool allow_unknown_user = false);
template <class OnSuccess> template <class OnSuccess>
void check_chat_no_fail(td::Slice chat_id_str, PromisedQueryPtr query, OnSuccess on_success); void check_chat_no_fail(td::Slice chat_id_str, PromisedQueryPtr query, OnSuccess on_success);
@ -421,7 +429,7 @@ class Client final : public WebhookActor::Callback {
template <class OnSuccess> template <class OnSuccess>
void check_reply_parameters(td::Slice chat_id_str, InputReplyParameters &&reply_parameters, int64 message_thread_id, void check_reply_parameters(td::Slice chat_id_str, InputReplyParameters &&reply_parameters, int64 message_thread_id,
PromisedQueryPtr query, OnSuccess on_success); PromisedQueryPtr query, OnSuccess on_success, bool allow_unknown_user = false);
template <class OnSuccess> template <class OnSuccess>
void resolve_sticker_set(const td::string &sticker_set_name, PromisedQueryPtr query, OnSuccess on_success); void resolve_sticker_set(const td::string &sticker_set_name, PromisedQueryPtr query, OnSuccess on_success);
@ -634,7 +642,8 @@ class Client final : public WebhookActor::Callback {
td::Result<object_ptr<td_api::inputMessageInvoice>> get_input_message_invoice(const Query *query) const; 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, static object_ptr<td_api::messageSendOptions> get_message_send_options(bool disable_notification,
bool protect_content, int64 effect_id, bool protect_content,
bool allow_paid_broadcast, int64 effect_id,
object_ptr<td_api::MessageSchedulingState> &&scheduling_state); object_ptr<td_api::MessageSchedulingState> &&scheduling_state);
static td::Result<td::vector<object_ptr<td_api::formattedText>>> get_poll_options(const Query *query); static td::Result<td::vector<object_ptr<td_api::formattedText>>> get_poll_options(const Query *query);
@ -742,10 +751,14 @@ class Client final : public WebhookActor::Callback {
td::Status process_create_invoice_link_query(PromisedQueryPtr &query); td::Status process_create_invoice_link_query(PromisedQueryPtr &query);
td::Status process_get_star_transactions_query(PromisedQueryPtr &query); td::Status process_get_star_transactions_query(PromisedQueryPtr &query);
td::Status process_refund_star_payment_query(PromisedQueryPtr &query); td::Status process_refund_star_payment_query(PromisedQueryPtr &query);
td::Status process_edit_user_star_subscription_query(PromisedQueryPtr &query);
td::Status process_get_available_gifts_query(PromisedQueryPtr &query);
td::Status process_send_gift_query(PromisedQueryPtr &query);
td::Status process_set_game_score_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_get_game_high_scores_query(PromisedQueryPtr &query);
td::Status process_answer_web_app_query_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_inline_query_query(PromisedQueryPtr &query);
td::Status process_save_prepared_inline_message_query(PromisedQueryPtr &query);
td::Status process_answer_callback_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_shipping_query_query(PromisedQueryPtr &query);
td::Status process_answer_pre_checkout_query_query(PromisedQueryPtr &query); td::Status process_answer_pre_checkout_query_query(PromisedQueryPtr &query);
@ -756,6 +769,7 @@ class Client final : public WebhookActor::Callback {
td::Status process_edit_chat_subscription_invite_link_query(PromisedQueryPtr &query); td::Status process_edit_chat_subscription_invite_link_query(PromisedQueryPtr &query);
td::Status process_revoke_chat_invite_link_query(PromisedQueryPtr &query); td::Status process_revoke_chat_invite_link_query(PromisedQueryPtr &query);
td::Status process_get_business_connection_query(PromisedQueryPtr &query); td::Status process_get_business_connection_query(PromisedQueryPtr &query);
td::Status process_set_user_emoji_status_query(PromisedQueryPtr &query);
td::Status process_get_chat_query(PromisedQueryPtr &query); td::Status process_get_chat_query(PromisedQueryPtr &query);
td::Status process_set_chat_photo_query(PromisedQueryPtr &query); td::Status process_set_chat_photo_query(PromisedQueryPtr &query);
td::Status process_delete_chat_photo_query(PromisedQueryPtr &query); td::Status process_delete_chat_photo_query(PromisedQueryPtr &query);
@ -1079,7 +1093,6 @@ class Client final : public WebhookActor::Callback {
int32 views = 0; int32 views = 0;
int32 forwards = 0; int32 forwards = 0;
bool is_scheduled = false;
int32 scheduled_at = 0; int32 scheduled_at = 0;
// end custom properties // end custom properties
@ -1087,6 +1100,7 @@ class Client final : public WebhookActor::Callback {
bool is_automatic_forward = false; bool is_automatic_forward = false;
bool is_topic_message = false; bool is_topic_message = false;
bool is_from_offline = false; bool is_from_offline = false;
bool is_scheduled = false;
mutable bool is_content_changed = false; mutable bool is_content_changed = false;
}; };

View File

@ -23,6 +23,9 @@ ServerCpuStat::ServerCpuStat() {
void ServerCpuStat::update(double now) { void ServerCpuStat::update(double now) {
auto r_cpu_stat = td::cpu_stat(); auto r_cpu_stat = td::cpu_stat();
if (r_cpu_stat.is_error()) { if (r_cpu_stat.is_error()) {
if (r_cpu_stat.error().message() != "Not supported") {
LOG(ERROR) << "Failed to get CPU statistics: " << r_cpu_stat.error();
}
return; return;
} }

View File

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