Add getAvailableGifts.

This commit is contained in:
levlam 2024-11-13 17:08:57 +03:00
parent 86a7e2486b
commit e000e2610f
2 changed files with 67 additions and 0 deletions

View File

@ -253,6 +253,7 @@ bool Client::init_methods() {
methods_.emplace("createinvoicelink", &Client::process_create_invoice_link_query);
methods_.emplace("getstartransactions", &Client::process_get_star_transactions_query);
methods_.emplace("refundstarpayment", &Client::process_refund_star_payment_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("getgamehighscores", &Client::process_get_game_high_scores_query);
@ -4064,6 +4065,41 @@ class Client::JsonGameHighScore final : public td::Jsonable {
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 {
public:
JsonMessageReactionUpdated(const td_api::updateMessageReaction *update, const Client *client)
@ -5916,6 +5952,28 @@ class Client::TdOnGetUserChatBoostsCallback final : public TdQueryCallback {
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 {
public:
TdOnReturnFileCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) {
@ -11222,6 +11280,11 @@ td::Status Client::process_refund_star_payment_query(PromisedQueryPtr &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()));

View File

@ -170,6 +170,8 @@ class Client final : public WebhookActor::Callback {
class JsonForumTopicEdited;
class JsonForumTopicInfo;
class JsonGameHighScore;
class JsonGift;
class JsonGifts;
class JsonMessageReactionUpdated;
class JsonMessageReactionCountUpdated;
class JsonBusinessConnection;
@ -248,6 +250,7 @@ class Client final : public WebhookActor::Callback {
class TdOnGetSupergroupMembersCallback;
class TdOnGetSupergroupMemberCountCallback;
class TdOnGetUserChatBoostsCallback;
class TdOnGetGiftsCallback;
class TdOnCreateInvoiceLinkCallback;
class TdOnGetStarTransactionsQueryCallback;
class TdOnReplacePrimaryChatInviteLinkCallback;
@ -683,6 +686,7 @@ class Client final : public WebhookActor::Callback {
td::Status process_create_invoice_link_query(PromisedQueryPtr &query);
td::Status process_get_star_transactions_query(PromisedQueryPtr &query);
td::Status process_refund_star_payment_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_get_game_high_scores_query(PromisedQueryPtr &query);