Add td_api::getStarWithdrawalUrl.

This commit is contained in:
levlam 2024-06-13 23:21:04 +03:00
parent 2f505ad101
commit 848e33bc39
6 changed files with 124 additions and 0 deletions

View File

@ -10705,6 +10705,13 @@ getChatRevenueWithdrawalUrl chat_id:int53 password:string = HttpUrl;
getChatRevenueTransactions chat_id:int53 offset:int32 limit:int32 = ChatRevenueTransactions;
//@description Returns URL for Telegram star withdrawal from a bot or a chat; requires owner privileges for the bot or in the chat
//@chat_id Chat identifier
//@star_count The number of Telegram stars to withdraw
//@password The 2-step verification password of the current user
getStarWithdrawalUrl chat_id:int53 star_count:int53 password:string = HttpUrl;
//@description Returns detailed statistics about a chat. Currently, this method can be used only for supergroups and channels. Can be used only if supergroupFullInfo.can_get_statistics == true @chat_id Chat identifier @is_dark Pass true if a dark theme is used by the application
getChatStatistics chat_id:int53 is_dark:Bool = ChatStatistics;

View File

@ -8,8 +8,10 @@
#include "td/telegram/ChatManager.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/DialogManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/InputInvoice.h"
#include "td/telegram/PasswordManager.h"
#include "td/telegram/Photo.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"
@ -182,6 +184,42 @@ class RefundStarsChargeQuery final : public Td::ResultHandler {
}
};
class GetStarsRevenueWithdrawalUrlQuery final : public Td::ResultHandler {
Promise<string> promise_;
DialogId dialog_id_;
public:
explicit GetStarsRevenueWithdrawalUrlQuery(Promise<string> &&promise) : promise_(std::move(promise)) {
}
void send(DialogId dialog_id, int64 star_count,
telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password) {
dialog_id_ = dialog_id;
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return promise_.set_error(Status::Error(400, "Have no access to the chat"));
}
send_query(G()->net_query_creator().create(telegram_api::payments_getStarsRevenueWithdrawalUrl(
std::move(input_peer), star_count, std::move(input_check_password))));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::payments_getStarsRevenueWithdrawalUrl>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(std::move(result_ptr.ok_ref()->url_));
}
void on_error(Status status) final {
td_->dialog_manager_->on_get_dialog_error(dialog_id_, status, "GetStarsRevenueWithdrawalUrlQuery");
promise_.set_error(std::move(status));
}
};
StarManager::StarManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
}
@ -206,4 +244,53 @@ void StarManager::refund_star_payment(UserId user_id, const string &telegram_pay
->send(std::move(input_user), telegram_payment_charge_id);
}
void StarManager::get_star_withdrawal_url(DialogId dialog_id, int64 star_count, const string &password,
Promise<string> &&promise) {
TRY_STATUS_PROMISE(promise, td_->dialog_manager_->check_dialog_access(dialog_id, false, AccessRights::Write,
"get_star_withdrawal_url"));
switch (dialog_id.get_type()) {
case DialogType::User: {
auto user_id = dialog_id.get_user_id();
if (!td_->user_manager_->is_user_bot(user_id)) {
return promise.set_error(Status::Error(400, "User is not a bot"));
}
break;
}
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
if (!td_->chat_manager_->is_broadcast_channel(channel_id)) {
return promise.set_error(Status::Error(400, "Chat is not a channel"));
}
if (!td_->chat_manager_->get_channel_permissions(channel_id).is_creator()) {
return promise.set_error(Status::Error(400, "Not enough rights to withdraw stars"));
}
break;
}
default:
return promise.set_error(Status::Error(400, "Unallowed chat specified"));
}
if (password.empty()) {
return promise.set_error(Status::Error(400, "PASSWORD_HASH_INVALID"));
}
send_closure(
td_->password_manager_, &PasswordManager::get_input_check_password_srp, password,
PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, star_count, promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP>> result) mutable {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
send_closure(actor_id, &StarManager::send_get_star_withdrawal_url_query, dialog_id, star_count,
result.move_as_ok(), std::move(promise));
}));
}
void StarManager::send_get_star_withdrawal_url_query(
DialogId dialog_id, int64 star_count,
telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password, Promise<string> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
td_->create_handler<GetStarsRevenueWithdrawalUrlQuery>(std::move(promise))
->send(dialog_id, star_count, std::move(input_check_password));
}
} // namespace td

View File

@ -6,7 +6,9 @@
//
#pragma once
#include "td/telegram/DialogId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/actor/actor.h"
@ -29,9 +31,15 @@ class StarManager final : public Actor {
void refund_star_payment(UserId user_id, const string &telegram_payment_charge_id, Promise<Unit> &&promise);
void get_star_withdrawal_url(DialogId dialog_id, int64 star_count, const string &password, Promise<string> &&promise);
private:
void tear_down() final;
void send_get_star_withdrawal_url_query(
DialogId dialog_id, int64 star_count,
telegram_api::object_ptr<telegram_api::InputCheckPasswordSRP> input_check_password, Promise<string> &&promise);
Td *td_;
ActorShared<> parent_;
};

View File

@ -8734,6 +8734,20 @@ void Td::on_request(uint64 id, const td_api::getChatRevenueTransactions &request
std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getStarWithdrawalUrl &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
promise.set_value(td_api::make_object<td_api::httpUrl>(result.move_as_ok()));
}
});
star_manager_->get_star_withdrawal_url(DialogId(request.chat_id_), request.star_count_, request.password_,
std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::getMessageStatistics &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -1697,6 +1697,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getChatRevenueTransactions &request);
void on_request(uint64 id, const td_api::getStarWithdrawalUrl &request);
void on_request(uint64 id, const td_api::getMessageStatistics &request);
void on_request(uint64 id, const td_api::getStoryStatistics &request);

View File

@ -6775,6 +6775,12 @@ class CliClient final : public Actor {
string limit;
get_args(args, chat_id, offset, limit);
send_request(td_api::make_object<td_api::getChatRevenueTransactions>(chat_id, offset, as_limit(limit)));
} else if (op == "gswu") {
ChatId chat_id;
int32 star_count;
string password;
get_args(args, chat_id, star_count, password);
send_request(td_api::make_object<td_api::getStarWithdrawalUrl>(chat_id, star_count, password));
} else {
op_not_found_count++;
}