Add td_api::setStickerEmojis.

This commit is contained in:
levlam 2023-02-09 20:42:09 +03:00
parent 4d8fae253e
commit c53b05e4e8
7 changed files with 83 additions and 10 deletions

View File

@ -5025,7 +5025,7 @@ proxies proxies:vector<proxy> = Proxies;
//@description A sticker to be added to a sticker set //@description A sticker to be added to a sticker set
//@sticker File with the sticker; must fit in a 512x512 square. For WEBP stickers the file must be in WEBP or PNG format, which will be converted to WEBP server-side. //@sticker File with the sticker; must fit in a 512x512 square. For WEBP stickers the file must be in WEBP or PNG format, which will be converted to WEBP server-side.
//-See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements //-See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
//@emojis Emojis corresponding to the sticker //@emojis String with 1-20 emoji corresponding to the sticker
//@format Sticker format //@format Sticker format
//@mask_position Position where the mask is placed; pass null if not specified //@mask_position Position where the mask is placed; pass null if not specified
//@keywords List of up to 20 keywords with total length up to 64 characters, which can be used to find the sticker //@keywords List of up to 20 keywords with total length up to 64 characters, which can be used to find the sticker
@ -8020,6 +8020,11 @@ setStickerPositionInSet sticker:InputFile position:int32 = Ok;
//@description Removes a sticker from the set to which it belongs; for bots only. The sticker set must have been created by the bot @sticker Sticker //@description Removes a sticker from the set to which it belongs; for bots only. The sticker set must have been created by the bot @sticker Sticker
removeStickerFromSet sticker:InputFile = Ok; removeStickerFromSet sticker:InputFile = Ok;
//@description Changes the list of emoji corresponding to a sticker; for bots only. The sticker must belong to a sticker set created by the bot
//@sticker Sticker
//@emojis New string with 1-20 emoji corresponding to the sticker
setStickerEmojis sticker:InputFile emojis:string = Ok;
//@description Returns information about a file with a map thumbnail in PNG format. Only map thumbnail files with size less than 1MB can be downloaded //@description Returns information about a file with a map thumbnail in PNG format. Only map thumbnail files with size less than 1MB can be downloaded
//@location Location of the map center //@location Location of the map center

View File

@ -63,7 +63,7 @@ StickerMaskPosition::StickerMaskPosition(const td_api::object_ptr<td_api::maskPo
y_shift_ = mask_position->y_shift_, scale_ = mask_position->scale_; y_shift_ = mask_position->y_shift_, scale_ = mask_position->scale_;
} }
telegram_api::object_ptr<telegram_api::maskCoords> StickerMaskPosition::get_input_mask_coords_object() const { telegram_api::object_ptr<telegram_api::maskCoords> StickerMaskPosition::get_input_mask_coords() const {
if (point_ < 0) { if (point_ < 0) {
return nullptr; return nullptr;
} }

View File

@ -32,7 +32,7 @@ class StickerMaskPosition {
explicit StickerMaskPosition(const telegram_api::object_ptr<telegram_api::maskCoords> &mask_coords); explicit StickerMaskPosition(const telegram_api::object_ptr<telegram_api::maskCoords> &mask_coords);
telegram_api::object_ptr<telegram_api::maskCoords> get_input_mask_coords_object() const; telegram_api::object_ptr<telegram_api::maskCoords> get_input_mask_coords() const;
td_api::object_ptr<td_api::maskPosition> get_mask_position_object() const; td_api::object_ptr<td_api::maskPosition> get_mask_position_object() const;

View File

@ -1387,6 +1387,53 @@ class DeleteStickerFromSetQuery final : public Td::ResultHandler {
} }
}; };
class ChangeStickerQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit ChangeStickerQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const string &short_name, tl_object_ptr<telegram_api::inputDocument> &&input_document, bool edit_emojis,
const string &emojis, bool edit_mask_position, StickerMaskPosition mask_position, bool edit_keywords,
const string &keywords) {
vector<ChainId> chain_ids;
if (!short_name.empty()) {
chain_ids.emplace_back(short_name);
}
int32 flags = 0;
if (edit_emojis) {
flags |= telegram_api::stickers_changeSticker::EMOJI_MASK;
}
if (edit_mask_position) {
flags |= telegram_api::stickers_changeSticker::MASK_COORDS_MASK;
}
if (edit_keywords) {
flags |= telegram_api::stickers_changeSticker::KEYWORDS_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::stickers_changeSticker(flags, std::move(input_document), emojis, mask_position.get_input_mask_coords(),
keywords),
std::move(chain_ids)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stickers_changeSticker>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
td_->stickers_manager_->on_get_messages_sticker_set(StickerSetId(), result_ptr.move_as_ok(), true,
"ChangeStickerQuery");
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class GetCustomEmojiDocumentsQuery final : public Td::ResultHandler { class GetCustomEmojiDocumentsQuery final : public Td::ResultHandler {
Promise<vector<telegram_api::object_ptr<telegram_api::Document>>> promise_; Promise<vector<telegram_api::object_ptr<telegram_api::Document>>> promise_;
@ -8030,7 +8077,7 @@ tl_object_ptr<telegram_api::inputStickerSetItem> StickersManager::get_input_stic
int32 flags = 0; int32 flags = 0;
auto mask_coords = StickerMaskPosition(sticker->mask_position_).get_input_mask_coords_object(); auto mask_coords = StickerMaskPosition(sticker->mask_position_).get_input_mask_coords();
if (mask_coords != nullptr) { if (mask_coords != nullptr) {
flags |= telegram_api::inputStickerSetItem::MASK_COORDS_MASK; flags |= telegram_api::inputStickerSetItem::MASK_COORDS_MASK;
} }
@ -8625,7 +8672,7 @@ Result<StickersManager::StickerInputDocument> StickersManager::get_sticker_input
return std::move(result); return std::move(result);
} }
void StickersManager::set_sticker_position_in_set(const tl_object_ptr<td_api::InputFile> &sticker, int32 position, void StickersManager::set_sticker_position_in_set(const td_api::object_ptr<td_api::InputFile> &sticker, int32 position,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
if (position < 0) { if (position < 0) {
return promise.set_error(Status::Error(400, "Wrong sticker position specified")); return promise.set_error(Status::Error(400, "Wrong sticker position specified"));
@ -8637,7 +8684,7 @@ void StickersManager::set_sticker_position_in_set(const tl_object_ptr<td_api::In
->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_), position); ->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_), position);
} }
void StickersManager::remove_sticker_from_set(const tl_object_ptr<td_api::InputFile> &sticker, void StickersManager::remove_sticker_from_set(const td_api::object_ptr<td_api::InputFile> &sticker,
Promise<Unit> &&promise) { Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_document, get_sticker_input_document(sticker)); TRY_RESULT_PROMISE(promise, input_document, get_sticker_input_document(sticker));
@ -8645,6 +8692,15 @@ void StickersManager::remove_sticker_from_set(const tl_object_ptr<td_api::InputF
->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_)); ->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_));
} }
void StickersManager::set_sticker_emojis(const td_api::object_ptr<td_api::InputFile> &sticker, const string &emojis,
Promise<Unit> &&promise) {
TRY_RESULT_PROMISE(promise, input_document, get_sticker_input_document(sticker));
td_->create_handler<ChangeStickerQuery>(std::move(promise))
->send(input_document.sticker_set_short_name_, std::move(input_document.input_document_), true, emojis, false,
StickerMaskPosition(), false, string());
}
vector<FileId> StickersManager::get_attached_sticker_file_ids(const vector<int32> &int_file_ids) { vector<FileId> StickersManager::get_attached_sticker_file_ids(const vector<int32> &int_file_ids) {
vector<FileId> result; vector<FileId> result;

View File

@ -311,10 +311,13 @@ class StickersManager final : public Actor {
void set_sticker_set_title(string short_name, string title, Promise<Unit> &&promise); void set_sticker_set_title(string short_name, string title, Promise<Unit> &&promise);
void set_sticker_position_in_set(const tl_object_ptr<td_api::InputFile> &sticker, int32 position, void set_sticker_position_in_set(const td_api::object_ptr<td_api::InputFile> &sticker, int32 position,
Promise<Unit> &&promise); Promise<Unit> &&promise);
void remove_sticker_from_set(const tl_object_ptr<td_api::InputFile> &sticker, Promise<Unit> &&promise); void remove_sticker_from_set(const td_api::object_ptr<td_api::InputFile> &sticker, Promise<Unit> &&promise);
void set_sticker_emojis(const td_api::object_ptr<td_api::InputFile> &sticker, const string &emojis,
Promise<Unit> &&promise);
vector<FileId> get_recent_stickers(bool is_attached, Promise<Unit> &&promise); vector<FileId> get_recent_stickers(bool is_attached, Promise<Unit> &&promise);

View File

@ -7332,12 +7332,19 @@ void Td::on_request(uint64 id, td_api::setStickerPositionInSet &request) {
stickers_manager_->set_sticker_position_in_set(request.sticker_, request.position_, std::move(promise)); stickers_manager_->set_sticker_position_in_set(request.sticker_, request.position_, std::move(promise));
} }
void Td::on_request(uint64 id, td_api::removeStickerFromSet &request) { void Td::on_request(uint64 id, const td_api::removeStickerFromSet &request) {
CHECK_IS_BOT(); CHECK_IS_BOT();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
stickers_manager_->remove_sticker_from_set(request.sticker_, std::move(promise)); stickers_manager_->remove_sticker_from_set(request.sticker_, std::move(promise));
} }
void Td::on_request(uint64 id, td_api::setStickerEmojis &request) {
CHECK_IS_BOT();
CLEAN_INPUT_STRING(request.emojis_);
CREATE_OK_REQUEST_PROMISE();
stickers_manager_->set_sticker_emojis(request.sticker_, request.emojis_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getRecentStickers &request) { void Td::on_request(uint64 id, const td_api::getRecentStickers &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST(GetRecentStickersRequest, request.is_attached_); CREATE_REQUEST(GetRecentStickersRequest, request.is_attached_);

View File

@ -1206,7 +1206,9 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setStickerPositionInSet &request); void on_request(uint64 id, td_api::setStickerPositionInSet &request);
void on_request(uint64 id, td_api::removeStickerFromSet &request); void on_request(uint64 id, const td_api::removeStickerFromSet &request);
void on_request(uint64 id, td_api::setStickerEmojis &request);
void on_request(uint64 id, const td_api::getRecentStickers &request); void on_request(uint64 id, const td_api::getRecentStickers &request);