Add replaceStickerInSet.

This commit is contained in:
levlam 2024-03-22 15:09:08 +03:00
parent e89489b1b2
commit f684e4c503
2 changed files with 23 additions and 3 deletions

View File

@ -303,6 +303,7 @@ bool Client::init_methods() {
methods_.emplace("uploadstickerfile", &Client::process_upload_sticker_file_query);
methods_.emplace("createnewstickerset", &Client::process_create_new_sticker_set_query);
methods_.emplace("addstickertoset", &Client::process_add_sticker_to_set_query);
methods_.emplace("replacestickerinset", &Client::process_replace_sticker_in_set_query);
methods_.emplace("setstickersettitle", &Client::process_set_sticker_set_title_query);
methods_.emplace("setstickersetthumb", &Client::process_set_sticker_set_thumbnail_query);
methods_.emplace("setstickersetthumbnail", &Client::process_set_sticker_set_thumbnail_query);
@ -8421,8 +8422,9 @@ td::Result<td::vector<td_api::object_ptr<td_api::inputSticker>>> Client::get_inp
return std::move(stickers);
}
td::Result<td_api::object_ptr<td_api::InputFile>> Client::get_sticker_input_file(const Query *query) {
auto file_id = trim(query->arg("sticker"));
td::Result<td_api::object_ptr<td_api::InputFile>> Client::get_sticker_input_file(const Query *query,
td::Slice field_name) {
auto file_id = trim(query->arg(field_name));
if (file_id.empty()) {
return td::Status::Error(400, "Sticker is not specified");
}
@ -11217,6 +11219,22 @@ td::Status Client::process_add_sticker_to_set_query(PromisedQueryPtr &query) {
return td::Status::OK();
}
td::Status Client::process_replace_sticker_in_set_query(PromisedQueryPtr &query) {
TRY_RESULT(user_id, get_user_id(query.get()));
auto name = query->arg("name");
TRY_RESULT(input_file, get_sticker_input_file(query.get(), "old_sticker"));
TRY_RESULT(sticker, get_input_sticker(query.get()));
check_user(user_id, std::move(query),
[this, user_id, name, input_file = std::move(input_file),
sticker = std::move(sticker)](PromisedQueryPtr query) mutable {
send_request(make_object<td_api::replaceStickerInSet>(user_id, name.str(), std::move(input_file),
std::move(sticker)),
td::make_unique<TdOnOkQueryCallback>(std::move(query)));
});
return td::Status::OK();
}
td::Status Client::process_set_sticker_set_title_query(PromisedQueryPtr &query) {
auto name = query->arg("name");
auto title = query->arg("title");

View File

@ -502,7 +502,8 @@ class Client final : public WebhookActor::Callback {
td::Result<td::vector<object_ptr<td_api::inputSticker>>> get_input_stickers(const Query *query) const;
static td::Result<object_ptr<td_api::InputFile>> get_sticker_input_file(const Query *query);
static td::Result<object_ptr<td_api::InputFile>> get_sticker_input_file(const Query *query,
td::Slice field_name = "sticker");
static td::Result<td::string> get_passport_element_hash(td::Slice encoded_hash);
@ -697,6 +698,7 @@ class Client final : public WebhookActor::Callback {
td::Status process_upload_sticker_file_query(PromisedQueryPtr &query);
td::Status process_create_new_sticker_set_query(PromisedQueryPtr &query);
td::Status process_add_sticker_to_set_query(PromisedQueryPtr &query);
td::Status process_replace_sticker_in_set_query(PromisedQueryPtr &query);
td::Status process_set_sticker_set_title_query(PromisedQueryPtr &query);
td::Status process_set_sticker_set_thumbnail_query(PromisedQueryPtr &query);
td::Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query);