Add setStickerEmojiList.

This commit is contained in:
levlam 2023-02-14 17:43:08 +03:00
parent bb5f3651b2
commit c48dfe5d4d
2 changed files with 32 additions and 0 deletions

View File

@ -300,6 +300,7 @@ bool Client::init_methods() {
methods_.emplace("setcustomemojistickersetthumbnail", &Client::process_set_custom_emoji_sticker_set_thumbnail_query);
methods_.emplace("setstickerpositioninset", &Client::process_set_sticker_position_in_set_query);
methods_.emplace("deletestickerfromset", &Client::process_delete_sticker_from_set_query);
methods_.emplace("setstickeremojilist", &Client::process_set_sticker_emoji_list_query);
methods_.emplace("setpassportdataerrors", &Client::process_set_passport_data_errors_query);
methods_.emplace("sendcustomrequest", &Client::process_send_custom_request_query);
methods_.emplace("answercustomquery", &Client::process_answer_custom_query_query);
@ -6632,6 +6633,10 @@ td::Result<td_api::object_ptr<td_api::maskPosition>> Client::get_mask_position(c
}
td::Result<td::string> Client::get_sticker_emojis(JsonValue &&value) {
if (value.type() != JsonValue::Type::Array) {
return Status::Error(400, "expected an Array of string");
}
td::string result;
auto emoji_count = value.get_array().size();
if (emoji_count == 0) {
@ -6652,6 +6657,21 @@ td::Result<td::string> Client::get_sticker_emojis(JsonValue &&value) {
return std::move(result);
}
td::Result<td::string> Client::get_sticker_emojis(td::MutableSlice emoji_list) {
LOG(INFO) << "Parsing JSON object: " << emoji_list;
auto r_value = json_decode(emoji_list);
if (r_value.is_error()) {
LOG(INFO) << "Can't parse JSON object: " << r_value.error();
return Status::Error(400, "Can't parse emoji list JSON array");
}
auto r_emojis = get_sticker_emojis(r_value.move_as_ok());
if (r_emojis.is_error()) {
return Status::Error(400, PSLICE() << "Can't parse emoji list: " << r_emojis.error().message());
}
return r_emojis.move_as_ok();
}
td::Result<td_api::object_ptr<td_api::StickerFormat>> Client::get_sticker_format(Slice sticker_format) {
if (sticker_format == "static") {
return make_object<td_api::stickerFormatWebp>();
@ -9272,6 +9292,15 @@ td::Status Client::process_delete_sticker_from_set_query(PromisedQueryPtr &query
return Status::OK();
}
td::Status Client::process_set_sticker_emoji_list_query(PromisedQueryPtr &query) {
TRY_RESULT(input_file, get_sticker_input_file(query.get()));
TRY_RESULT(emojis, get_sticker_emojis(query->arg("emoji_list")));
send_request(make_object<td_api::setStickerEmojis>(std::move(input_file), emojis),
td::make_unique<TdOnOkQueryCallback>(std::move(query)));
return Status::OK();
}
td::Status Client::process_set_passport_data_errors_query(PromisedQueryPtr &query) {
TRY_RESULT(user_id, get_user_id(query.get()));
TRY_RESULT(passport_element_errors, get_passport_element_errors(query.get()));

View File

@ -405,6 +405,8 @@ class Client final : public WebhookActor::Callback {
static td::Result<td::string> get_sticker_emojis(td::JsonValue &&value);
static td::Result<td::string> get_sticker_emojis(td::MutableSlice emoji_list);
static td::Result<object_ptr<td_api::StickerFormat>> get_sticker_format(Slice sticker_format);
td::Result<object_ptr<td_api::inputSticker>> get_input_sticker(const Query *query) const;
@ -586,6 +588,7 @@ class Client final : public WebhookActor::Callback {
Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query);
Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query);
Status process_delete_sticker_from_set_query(PromisedQueryPtr &query);
Status process_set_sticker_emoji_list_query(PromisedQueryPtr &query);
Status process_set_passport_data_errors_query(PromisedQueryPtr &query);
Status process_send_custom_request_query(PromisedQueryPtr &query);
Status process_answer_custom_query_query(PromisedQueryPtr &query);