diff --git a/crates/teloxide-core/schema.ron b/crates/teloxide-core/schema.ron index efd67cb4..1c541f4a 100644 --- a/crates/teloxide-core/schema.ron +++ b/crates/teloxide-core/schema.ron @@ -26,7 +26,6 @@ //! + `PollType` type of poll, either “quiz” or “regular” //! + `DiceEmoji` emoji that can be used in `sendDice` one of “🎲”, “🎯”, or “🏀” //! + `TargetMessage` either `inline_message_id: String` or `chat_id: ChatId` and `message_id: i64` -//! + `InputSticker` //! * Integers represented with more strict (when possible) types, e.g.: //! `u8` (unsigned, 8-bit integer), `u32` (unsigned, 32-bit), //! `i64` (signed, 64-bit), etc @@ -3503,6 +3502,11 @@ Schema( md_links: {"More info on Sending Files »": "https://core.telegram.org/bots/api#sending-files"}, ) ), + Param( + name: "emoji", + ty: Option(String), + descr: Doc(md: "Emoji associated with the sticker; only for just uploaded stickers") + ), Param( name: "disable_notification", ty: Option(bool), @@ -3580,19 +3584,24 @@ Schema( descr: Doc(md: "User identifier of sticker file owner"), ), Param( - name: "png_sticker", + name: "sticker", ty: RawTy("InputFile"), descr: Doc( - md: "PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. [More info on Sending Files »]", + md: "A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See https://core.telegram.org/stickers for technical requirements. [More info on Sending Files »]", md_links: {"More info on Sending Files »": "https://core.telegram.org/bots/api#sending-files"}, ), ), + Param( + name: "sticker_format", + ty: RawTy("StickerFormat"), + descr: Doc(md: "Format of the sticker, must be one of “static”, “animated”, “video”") + ) ], ), Method( names: ("createNewStickerSet", "CreateNewStickerSet", "create_new_sticker_set"), return_ty: True, - doc: Doc(md: "Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields _png\\_sticker_ or _tgs\\_sticker_. Returns _True_ on success."), + doc: Doc(md: "Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. Returns True on success."), tg_doc: "https://core.telegram.org/bots/api#createstickerset", tg_category: "Stickers", params: [ @@ -3612,34 +3621,31 @@ Schema( descr: Doc(md: "Sticker set title, 1-64 characters"), ), Param( - name: "sticker", - ty: RawTy("InputSticker"), - descr: Doc( - md: "**PNG** image, **TGS** animation or **WEBM** video with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a _file\\_id_ as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »]", - md_links: {"More info on Sending Files »": "https://core.telegram.org/bots/api#sending-files"}, - ), + name: "stickers", + ty: ArrayOf(RawTy("InputSticker")), + descr: Doc(md: "A JSON-serialized list of 1-50 initial stickers to be added to the sticker set") ), Param( - name: "emojis", - ty: String, - descr: Doc(md: "One or more emoji corresponding to the sticker"), + name: "sticker_format", + ty: RawTy("StickerFormat"), + descr: Doc(md: "Format of the sticker, must be one of “static”, “animated”, “video”") ), Param( name: "sticker_type", ty: Option(RawTy("StickerType")), - descr: Doc(md: "Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can't be created via the Bot API at the moment. By default, a regular sticker set is created."), + descr: Doc(md: "Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created."), ), Param( - name: "mask_position", - ty: Option(RawTy("MaskPosition")), - descr: Doc(md: "A JSON-serialized object for position where the mask should be placed on faces"), - ), + name: "needs_repainting", + ty: Option(bool), + descr: Doc(md: "Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only") + ) ], ), Method( names: ("addStickerToSet", "AddStickerToSet", "add_sticker_to_set"), return_ty: True, - doc: Doc(md: "Use this method to add a new sticker to a set created by the bot. You **must** use exactly one of the fields _png\\_sticker_ or _tgs\\_sticker_. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. Returns _True_ on success."), + doc: Doc(md: "Use this method to add a new sticker to a set created by the bot. Emoji sticker sets can have up to 200 stickers. Other sticker sets can have up to 120 stickers. Returns True on success."), tg_doc: "https://core.telegram.org/bots/api#addstickertoset", tg_category: "Stickers", params: [ @@ -3657,20 +3663,9 @@ Schema( name: "sticker", ty: RawTy("InputSticker"), descr: Doc( - md: "**PNG** or **TGS** image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a _file\\_id_ as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »]", - md_links: {"More info on Sending Files »": "https://core.telegram.org/bots/api#sending-files"}, + md: "A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set isn't changed.", ), ), - Param( - name: "emojis", - ty: String, - descr: Doc(md: "One or more emoji corresponding to the sticker"), - ), - Param( - name: "mask_position", - ty: Option(RawTy("MaskPosition")), - descr: Doc(md: "A JSON-serialized object for position where the mask should be placed on faces"), - ), ], ), Method( @@ -3707,10 +3702,10 @@ Schema( ], ), Method( - names: ("setStickerSetThumb", "SetStickerSetThumb", "set_sticker_set_thumb"), + names: ("setStickerSetThumbnail", "SetStickerSetThumbnail", "set_sticker_set_thumbnail"), return_ty: True, - doc: Doc(md: "Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only. Returns _True_ on success."), - tg_doc: "https://core.telegram.org/bots/api#setstickersetthumb", + doc: Doc(md: "Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file must match the format of the stickers in the set. Returns True on success."), + tg_doc: "https://core.telegram.org/bots/api#setstickersetthumbnail", tg_category: "Stickers", params: [ Param( @@ -3724,15 +3719,124 @@ Schema( descr: Doc(md: "User identifier of sticker file owner"), ), Param( - name: "thumb", + name: "thumbnail", ty: Option(RawTy("InputFile")), descr: Doc( - md: "A **PNG** image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a **TGS** animation with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/animated_stickers#technical-requirements for animated sticker technical requirements. Pass a _file\\_id_ as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »]. Animated sticker set thumbnail can't be uploaded via HTTP URL.", + md: "A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.", md_links: {"More info on Sending Files »": "https://core.telegram.org/bots/api#sending-files"}, ), ), ], ), + Method( + names: ("setCustomEmojiStickerSetThumbnail", "SetCustomEmojiStickerSetThumbnail", "set_custom_emoji_sticker_set_thumbnail"), + return_ty: True, + doc: Doc(md: "Use this method to set the thumbnail of a custom emoji sticker set. Returns True on success."), + tg_doc: "https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail", + tg_category: "Stickers", + params: [ + Param( + name: "name", + ty: String, + descr: Doc(md: "Sticker set name"), + ), + Param( + name: "custom_emoji_id", + ty: Option(String), + descr: Doc(md: "Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail."), + ) + ] + ), + Method( + names: ("setStickerSetTitle", "SetStickerSetTitle", "set_sticker_set_title"), + return_ty: True, + doc: Doc(md: "Use this method to set the title of a created sticker set. Returns True on success."), + tg_doc: "https://core.telegram.org/bots/api#setstickersettitle", + tg_category: "Stickers", + params: [ + Param( + name: "name", + ty: String, + descr: Doc(md: "Sticker set name"), + ), + Param( + name: "title", + ty: String, + descr: Doc(md: "Sticker set title, 1-64 characters"), + ) + ] + ), + Method( + names: ("deleteStickerSet", "DeleteStickerSet", "delete_sticker_set"), + return_ty: True, + doc: Doc(md: "Use this method to delete a sticker set that was created by the bot. Returns True on success."), + tg_doc: "https://core.telegram.org/bots/api#deletestickerset", + tg_category: "Stickers", + params: [ + Param( + name: "name", + ty: String, + descr: Doc(md: "Sticker set name"), + ), + ] + ), + Method( + names: ("setStickerEmojiList", "SetStickerEmojiList", "set_sticker_emoji_list"), + return_ty: True, + doc: Doc(md: "Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success."), + tg_doc: "https://core.telegram.org/bots/api#setstickeremojilist", + tg_category: "Stickers", + params: [ + Param( + name: "sticker", + ty: String, + descr: Doc(md: "File identifier of the sticker"), + ), + Param( + name: "emoji_list", + ty: ArrayOf(String), + descr: Doc(md: "A JSON-serialized list of 1-20 emoji associated with the sticker"), + ), + ] + ), + Method( + names: ("setStickerKeywords", "SetStickerKeywords", "set_sticker_keywords"), + return_ty: True, + doc: Doc(md: "Use this method to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success."), + tg_doc: "https://core.telegram.org/bots/api#setstickerkeywords", + tg_category: "Stickers", + params: [ + Param( + name: "sticker", + ty: String, + descr: Doc(md: "File identifier of the sticker"), + ), + Param( + name: "keywords", + ty: Option(ArrayOf(String)), + descr: Doc(md: "A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters"), + ), + ] + ), + Method( + names: ("setStickerMaskPosition", "SetStickerMaskPosition", "set_sticker_mask_position"), + return_ty: True, + doc: Doc(md: "Use this method to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot. Returns True on success."), + tg_doc: "https://core.telegram.org/bots/api#setstickermaskposition", + tg_category: "Stickers", + params: [ + Param( + name: "sticker", + ty: String, + descr: Doc(md: "File identifier of the sticker"), + ), + Param( + name: "mask_position", + ty: Option(RawTy("MaskPosition")), + descr: Doc(md: "A JSON-serialized object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position."), + ), + ] + ), Method( names: ("sendInvoice", "SendInvoice", "send_invoice"), return_ty: RawTy("Message"), diff --git a/crates/teloxide-core/src/adaptors/cache_me.rs b/crates/teloxide-core/src/adaptors/cache_me.rs index 18ea0ca2..aca6d5f7 100644 --- a/crates/teloxide-core/src/adaptors/cache_me.rs +++ b/crates/teloxide-core/src/adaptors/cache_me.rs @@ -188,7 +188,13 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, - set_sticker_set_thumb, + set_sticker_set_thumbnail, + set_custom_emoji_sticker_set_thumbnail, + set_sticker_set_title, + delete_sticker_set, + set_sticker_emoji_list, + set_sticker_keywords, + set_sticker_mask_position, send_invoice, create_invoice_link, answer_shipping_query, diff --git a/crates/teloxide-core/src/adaptors/erased.rs b/crates/teloxide-core/src/adaptors/erased.rs index 4a537b3c..0008cefe 100644 --- a/crates/teloxide-core/src/adaptors/erased.rs +++ b/crates/teloxide-core/src/adaptors/erased.rs @@ -163,6 +163,12 @@ macro_rules! fwd_erased { (@convert $m:ident, $arg:ident, custom_emoji_ids : $T:ty) => { $arg.into_iter().collect() }; + (@convert $m:ident, $arg:ident, stickers: $T:ty) => { + $arg.into_iter().collect() + }; + (@convert $m:ident, $arg:ident, emoji_list: $T:ty) => { + $arg.into_iter().collect() + }; (@convert $m:ident, $arg:ident, $arg_:ident : $T:ty) => { $arg.into() }; @@ -277,7 +283,13 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, - set_sticker_set_thumb, + set_sticker_set_thumbnail, + set_custom_emoji_sticker_set_thumbnail, + set_sticker_set_title, + delete_sticker_set, + set_sticker_emoji_list, + set_sticker_keywords, + set_sticker_mask_position, send_invoice, create_invoice_link, answer_shipping_query, @@ -807,7 +819,8 @@ trait ErasableRequester<'a> { fn upload_sticker_file( &self, user_id: UserId, - png_sticker: InputFile, + sticker: InputFile, + sticker_format: StickerFormat, ) -> ErasedRequest<'a, UploadStickerFile, Self::Err>; fn create_new_sticker_set( @@ -815,8 +828,8 @@ trait ErasableRequester<'a> { user_id: UserId, name: String, title: String, - sticker: InputSticker, - emojis: String, + stickers: Vec, + sticker_format: StickerFormat, ) -> ErasedRequest<'a, CreateNewStickerSet, Self::Err>; fn add_sticker_to_set( @@ -824,7 +837,6 @@ trait ErasableRequester<'a> { user_id: UserId, name: String, sticker: InputSticker, - emojis: String, ) -> ErasedRequest<'a, AddStickerToSet, Self::Err>; fn set_sticker_position_in_set( @@ -838,11 +850,40 @@ trait ErasableRequester<'a> { sticker: String, ) -> ErasedRequest<'a, DeleteStickerFromSet, Self::Err>; - fn set_sticker_set_thumb( + fn set_sticker_set_thumbnail( &self, name: String, user_id: UserId, - ) -> ErasedRequest<'a, SetStickerSetThumb, Self::Err>; + ) -> ErasedRequest<'a, SetStickerSetThumbnail, Self::Err>; + + fn set_custom_emoji_sticker_set_thumbnail( + &self, + name: String, + ) -> ErasedRequest<'a, SetCustomEmojiStickerSetThumbnail, Self::Err>; + + fn set_sticker_set_title( + &self, + name: String, + title: String, + ) -> ErasedRequest<'a, SetStickerSetTitle, Self::Err>; + + fn delete_sticker_set(&self, name: String) -> ErasedRequest<'a, DeleteStickerSet, Self::Err>; + + fn set_sticker_emoji_list( + &self, + sticker: String, + emoji_list: Vec, + ) -> ErasedRequest<'a, SetStickerEmojiList, Self::Err>; + + fn set_sticker_keywords( + &self, + sticker: String, + ) -> ErasedRequest<'a, SetStickerKeywords, Self::Err>; + + fn set_sticker_mask_position( + &self, + sticker: String, + ) -> ErasedRequest<'a, SetStickerMaskPosition, Self::Err>; // we can't change telegram API #[allow(clippy::too_many_arguments)] @@ -1629,9 +1670,10 @@ where fn upload_sticker_file( &self, user_id: UserId, - png_sticker: InputFile, + sticker: InputFile, + sticker_format: StickerFormat, ) -> ErasedRequest<'a, UploadStickerFile, Self::Err> { - Requester::upload_sticker_file(self, user_id, png_sticker).erase() + Requester::upload_sticker_file(self, user_id, sticker, sticker_format).erase() } fn create_new_sticker_set( @@ -1639,10 +1681,11 @@ where user_id: UserId, name: String, title: String, - sticker: InputSticker, - emojis: String, + stickers: Vec, + sticker_format: StickerFormat, ) -> ErasedRequest<'a, CreateNewStickerSet, Self::Err> { - Requester::create_new_sticker_set(self, user_id, name, title, sticker, emojis).erase() + Requester::create_new_sticker_set(self, user_id, name, title, stickers, sticker_format) + .erase() } fn add_sticker_to_set( @@ -1650,9 +1693,8 @@ where user_id: UserId, name: String, sticker: InputSticker, - emojis: String, ) -> ErasedRequest<'a, AddStickerToSet, Self::Err> { - Requester::add_sticker_to_set(self, user_id, name, sticker, emojis).erase() + Requester::add_sticker_to_set(self, user_id, name, sticker).erase() } fn set_sticker_position_in_set( @@ -1670,12 +1712,53 @@ where Requester::delete_sticker_from_set(self, sticker).erase() } - fn set_sticker_set_thumb( + fn set_sticker_set_thumbnail( &self, name: String, user_id: UserId, - ) -> ErasedRequest<'a, SetStickerSetThumb, Self::Err> { - Requester::set_sticker_set_thumb(self, name, user_id).erase() + ) -> ErasedRequest<'a, SetStickerSetThumbnail, Self::Err> { + Requester::set_sticker_set_thumbnail(self, name, user_id).erase() + } + + fn set_custom_emoji_sticker_set_thumbnail( + &self, + name: String, + ) -> ErasedRequest<'a, SetCustomEmojiStickerSetThumbnail, Self::Err> { + Requester::set_custom_emoji_sticker_set_thumbnail(self, name).erase() + } + + fn set_sticker_set_title( + &self, + name: String, + title: String, + ) -> ErasedRequest<'a, SetStickerSetTitle, Self::Err> { + Requester::set_sticker_set_title(self, name, title).erase() + } + + fn delete_sticker_set(&self, name: String) -> ErasedRequest<'a, DeleteStickerSet, Self::Err> { + Requester::delete_sticker_set(self, name).erase() + } + + fn set_sticker_emoji_list( + &self, + sticker: String, + emoji_list: Vec, + ) -> ErasedRequest<'a, SetStickerEmojiList, Self::Err> { + Requester::set_sticker_emoji_list(self, sticker, emoji_list).erase() + } + + fn set_sticker_keywords( + &self, + sticker: String, + ) -> ErasedRequest<'a, SetStickerKeywords, Self::Err> { + Requester::set_sticker_keywords(self, sticker).erase() + } + + fn set_sticker_mask_position( + &self, + sticker: String, + ) -> ErasedRequest<'a, SetStickerMaskPosition, Self::Err> { + Requester::set_sticker_mask_position(self, sticker).erase() } fn send_invoice( diff --git a/crates/teloxide-core/src/adaptors/parse_mode.rs b/crates/teloxide-core/src/adaptors/parse_mode.rs index 6198d0d6..d42e15fc 100644 --- a/crates/teloxide-core/src/adaptors/parse_mode.rs +++ b/crates/teloxide-core/src/adaptors/parse_mode.rs @@ -261,7 +261,13 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, - set_sticker_set_thumb, + set_sticker_set_thumbnail, + set_custom_emoji_sticker_set_thumbnail, + set_sticker_set_title, + delete_sticker_set, + set_sticker_emoji_list, + set_sticker_keywords, + set_sticker_mask_position, send_invoice, create_invoice_link, answer_shipping_query, diff --git a/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs b/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs index bc4c36ec..8bdfc7c0 100644 --- a/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs +++ b/crates/teloxide-core/src/adaptors/throttle/requester_impl.rs @@ -170,7 +170,13 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, - set_sticker_set_thumb, + set_sticker_set_thumbnail, + set_custom_emoji_sticker_set_thumbnail, + set_sticker_set_title, + delete_sticker_set, + set_sticker_emoji_list, + set_sticker_keywords, + set_sticker_mask_position, answer_shipping_query, create_invoice_link, answer_pre_checkout_query, diff --git a/crates/teloxide-core/src/adaptors/trace.rs b/crates/teloxide-core/src/adaptors/trace.rs index f79408dc..14130ba1 100644 --- a/crates/teloxide-core/src/adaptors/trace.rs +++ b/crates/teloxide-core/src/adaptors/trace.rs @@ -217,7 +217,13 @@ where add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, - set_sticker_set_thumb, + set_sticker_set_thumbnail, + set_custom_emoji_sticker_set_thumbnail, + set_sticker_set_title, + delete_sticker_set, + set_sticker_emoji_list, + set_sticker_keywords, + set_sticker_mask_position, send_invoice, create_invoice_link, answer_shipping_query, diff --git a/crates/teloxide-core/src/bot/api.rs b/crates/teloxide-core/src/bot/api.rs index 612cfa2a..8f0ef1b8 100644 --- a/crates/teloxide-core/src/bot/api.rs +++ b/crates/teloxide-core/src/bot/api.rs @@ -6,7 +6,7 @@ use crate::{ requests::{JsonRequest, MultipartRequest}, types::{ BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia, - InputSticker, LabeledPrice, MessageId, Recipient, ThreadId, UserId, + InputSticker, LabeledPrice, MessageId, Recipient, StickerFormat, ThreadId, UserId, }, Bot, }; @@ -1093,51 +1093,50 @@ impl Requester for Bot { fn upload_sticker_file( &self, user_id: UserId, - png_sticker: InputFile, - ) -> Self::UploadStickerFile where { + sticker: InputFile, + sticker_format: crate::types::StickerFormat, + ) -> Self::UploadStickerFile { Self::UploadStickerFile::new( self.clone(), - payloads::UploadStickerFile::new(user_id, png_sticker), + payloads::UploadStickerFile::new(user_id, sticker, sticker_format), ) } - type CreateNewStickerSet = MultipartRequest; + type CreateNewStickerSet = JsonRequest; - fn create_new_sticker_set( + fn create_new_sticker_set( &self, user_id: UserId, name: N, title: T, - sticker: InputSticker, - emojis: E, + stickers: S, + sticker_format: StickerFormat, ) -> Self::CreateNewStickerSet where N: Into, T: Into, - E: Into, + S: IntoIterator, { Self::CreateNewStickerSet::new( self.clone(), - payloads::CreateNewStickerSet::new(user_id, name, title, sticker, emojis), + payloads::CreateNewStickerSet::new(user_id, name, title, stickers, sticker_format), ) } type AddStickerToSet = MultipartRequest; - fn add_sticker_to_set( + fn add_sticker_to_set( &self, user_id: UserId, name: N, sticker: InputSticker, - emojis: E, ) -> Self::AddStickerToSet where N: Into, - E: Into, { Self::AddStickerToSet::new( self.clone(), - payloads::AddStickerToSet::new(user_id, name, sticker, emojis), + payloads::AddStickerToSet::new(user_id, name, sticker), ) } @@ -1166,15 +1165,84 @@ impl Requester for Bot { Self::DeleteStickerFromSet::new(self.clone(), payloads::DeleteStickerFromSet::new(sticker)) } - type SetStickerSetThumb = MultipartRequest; + type SetStickerSetThumbnail = MultipartRequest; - fn set_sticker_set_thumb(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumb + fn set_sticker_set_thumbnail(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumbnail where N: Into, { - Self::SetStickerSetThumb::new( + Self::SetStickerSetThumbnail::new( self.clone(), - payloads::SetStickerSetThumb::new(name, user_id), + payloads::SetStickerSetThumbnail::new(name, user_id), + ) + } + + type SetCustomEmojiStickerSetThumbnail = + JsonRequest; + + fn set_custom_emoji_sticker_set_thumbnail( + &self, + name: N, + ) -> Self::SetCustomEmojiStickerSetThumbnail + where + N: Into, + { + Self::SetCustomEmojiStickerSetThumbnail::new( + self.clone(), + payloads::SetCustomEmojiStickerSetThumbnail::new(name), + ) + } + + type SetStickerSetTitle = JsonRequest; + + fn set_sticker_set_title(&self, name: N, title: T) -> Self::SetStickerSetTitle + where + N: Into, + T: Into, + { + Self::SetStickerSetTitle::new(self.clone(), payloads::SetStickerSetTitle::new(name, title)) + } + + type DeleteStickerSet = JsonRequest; + + fn delete_sticker_set(&self, name: N) -> Self::DeleteStickerSet + where + N: Into, + { + Self::DeleteStickerSet::new(self.clone(), payloads::DeleteStickerSet::new(name)) + } + + type SetStickerEmojiList = JsonRequest; + + fn set_sticker_emoji_list(&self, sticker: S, emoji_list: E) -> Self::SetStickerEmojiList + where + S: Into, + E: IntoIterator, + { + Self::SetStickerEmojiList::new( + self.clone(), + payloads::SetStickerEmojiList::new(sticker, emoji_list), + ) + } + + type SetStickerKeywords = JsonRequest; + + fn set_sticker_keywords(&self, sticker: S) -> Self::SetStickerKeywords + where + S: Into, + { + Self::SetStickerKeywords::new(self.clone(), payloads::SetStickerKeywords::new(sticker)) + } + + type SetStickerMaskPosition = JsonRequest; + + fn set_sticker_mask_position(&self, sticker: S) -> Self::SetStickerMaskPosition + where + S: Into, + { + Self::SetStickerMaskPosition::new( + self.clone(), + payloads::SetStickerMaskPosition::new(sticker), ) } diff --git a/crates/teloxide-core/src/local_macros.rs b/crates/teloxide-core/src/local_macros.rs index 194935c6..ee5e2887 100644 --- a/crates/teloxide-core/src/local_macros.rs +++ b/crates/teloxide-core/src/local_macros.rs @@ -1231,28 +1231,27 @@ macro_rules! requester_forward { (@method upload_sticker_file $body:ident $ty:ident) => { type UploadStickerFile = $ty![UploadStickerFile]; - fn upload_sticker_file(&self, user_id: UserId, png_sticker: InputFile) -> Self::UploadStickerFile { + fn upload_sticker_file(&self, user_id: UserId, sticker: InputFile, sticker_format: StickerFormat) -> Self::UploadStickerFile { let this = self; - $body!(upload_sticker_file this (user_id: UserId, png_sticker: InputFile)) + $body!(upload_sticker_file this (user_id: UserId, sticker: InputFile, sticker_format: StickerFormat)) } }; (@method create_new_sticker_set $body:ident $ty:ident) => { type CreateNewStickerSet = $ty![CreateNewStickerSet]; - fn create_new_sticker_set(&self, user_id: UserId, name: N, title: T, sticker: InputSticker, emojis: E) -> Self::CreateNewStickerSet where N: Into, + fn create_new_sticker_set(&self, user_id: UserId, name: N, title: T, stickers: S, sticker_format: StickerFormat) -> Self::CreateNewStickerSet where N: Into, T: Into, - E: Into { + S: IntoIterator { let this = self; - $body!(create_new_sticker_set this (user_id: UserId, name: N, title: T, sticker: InputSticker, emojis: E)) + $body!(create_new_sticker_set this (user_id: UserId, name: N, title: T, stickers: S, sticker_format: StickerFormat)) } }; (@method add_sticker_to_set $body:ident $ty:ident) => { type AddStickerToSet = $ty![AddStickerToSet]; - fn add_sticker_to_set(&self, user_id: UserId, name: N, sticker: InputSticker, emojis: E) -> Self::AddStickerToSet where N: Into, - E: Into { + fn add_sticker_to_set(&self, user_id: UserId, name: N, sticker: InputSticker) -> Self::AddStickerToSet where N: Into { let this = self; - $body!(add_sticker_to_set this (user_id: UserId, name: N, sticker: InputSticker, emojis: E)) + $body!(add_sticker_to_set this (user_id: UserId, name: N, sticker: InputSticker)) } }; (@method set_sticker_position_in_set $body:ident $ty:ident) => { @@ -1271,12 +1270,62 @@ macro_rules! requester_forward { $body!(delete_sticker_from_set this (sticker: S)) } }; - (@method set_sticker_set_thumb $body:ident $ty:ident) => { - type SetStickerSetThumb = $ty![SetStickerSetThumb]; + (@method set_sticker_set_thumbnail $body:ident $ty:ident) => { + type SetStickerSetThumbnail = $ty![SetStickerSetThumbnail]; - fn set_sticker_set_thumb(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumb where N: Into { + fn set_sticker_set_thumbnail(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumbnail where N: Into { let this = self; - $body!(set_sticker_set_thumb this (name: N, user_id: UserId)) + $body!(set_sticker_set_thumbnail this (name: N, user_id: UserId)) + } + }; + (@method set_custom_emoji_sticker_set_thumbnail $body:ident $ty:ident) => { + type SetCustomEmojiStickerSetThumbnail = $ty![SetCustomEmojiStickerSetThumbnail]; + + fn set_custom_emoji_sticker_set_thumbnail(&self, name: N) -> Self::SetCustomEmojiStickerSetThumbnail where N: Into { + let this = self; + $body!(set_custom_emoji_sticker_set_thumbnail this (name: N)) + } + }; + (@method set_sticker_set_title $body:ident $ty:ident) => { + type SetStickerSetTitle = $ty![SetStickerSetTitle]; + + fn set_sticker_set_title(&self, name: N, title: T) -> Self::SetStickerSetTitle where N: Into, + T: Into { + let this = self; + $body!(set_sticker_set_title this (name: N, title: T)) + } + }; + (@method delete_sticker_set $body:ident $ty:ident) => { + type DeleteStickerSet = $ty![DeleteStickerSet]; + + fn delete_sticker_set(&self, name: N) -> Self::DeleteStickerSet where N: Into { + let this = self; + $body!(delete_sticker_set this (name: N)) + } + }; + (@method set_sticker_emoji_list $body:ident $ty:ident) => { + type SetStickerEmojiList = $ty![SetStickerEmojiList]; + + fn set_sticker_emoji_list(&self, sticker: S, emoji_list: E) -> Self::SetStickerEmojiList where S: Into, + E: IntoIterator { + let this = self; + $body!(set_sticker_emoji_list this (sticker: S, emoji_list: E)) + } + }; + (@method set_sticker_keywords $body:ident $ty:ident) => { + type SetStickerKeywords = $ty![SetStickerKeywords]; + + fn set_sticker_keywords(&self, sticker: S) -> Self::SetStickerKeywords where S: Into { + let this = self; + $body!(set_sticker_keywords this (sticker: S)) + } + }; + (@method set_sticker_mask_position $body:ident $ty:ident) => { + type SetStickerMaskPosition = $ty![SetStickerMaskPosition]; + + fn set_sticker_mask_position(&self, sticker: S) -> Self::SetStickerMaskPosition where S: Into { + let this = self; + $body!(set_sticker_mask_position this (sticker: S)) } }; (@method send_invoice $body:ident $ty:ident) => { diff --git a/crates/teloxide-core/src/payloads.rs b/crates/teloxide-core/src/payloads.rs index c20852be..25333a4f 100644 --- a/crates/teloxide-core/src/payloads.rs +++ b/crates/teloxide-core/src/payloads.rs @@ -39,6 +39,7 @@ mod delete_forum_topic; mod delete_message; mod delete_my_commands; mod delete_sticker_from_set; +mod delete_sticker_set; mod delete_webhook; mod edit_chat_invite_link; mod edit_forum_topic; @@ -109,6 +110,7 @@ mod set_chat_permissions; mod set_chat_photo; mod set_chat_sticker_set; mod set_chat_title; +mod set_custom_emoji_sticker_set_thumbnail; mod set_game_score; mod set_game_score_inline; mod set_my_commands; @@ -116,8 +118,12 @@ mod set_my_default_administrator_rights; mod set_my_description; mod set_my_short_description; mod set_passport_data_errors; +mod set_sticker_emoji_list; +mod set_sticker_keywords; +mod set_sticker_mask_position; mod set_sticker_position_in_set; -mod set_sticker_set_thumb; +mod set_sticker_set_thumbnail; +mod set_sticker_set_title; mod set_webhook; mod stop_message_live_location; mod stop_message_live_location_inline; @@ -154,6 +160,7 @@ pub use delete_forum_topic::{DeleteForumTopic, DeleteForumTopicSetters}; pub use delete_message::{DeleteMessage, DeleteMessageSetters}; pub use delete_my_commands::{DeleteMyCommands, DeleteMyCommandsSetters}; pub use delete_sticker_from_set::{DeleteStickerFromSet, DeleteStickerFromSetSetters}; +pub use delete_sticker_set::{DeleteStickerSet, DeleteStickerSetSetters}; pub use delete_webhook::{DeleteWebhook, DeleteWebhookSetters}; pub use edit_chat_invite_link::{EditChatInviteLink, EditChatInviteLinkSetters}; pub use edit_forum_topic::{EditForumTopic, EditForumTopicSetters}; @@ -234,6 +241,9 @@ pub use set_chat_permissions::{SetChatPermissions, SetChatPermissionsSetters}; pub use set_chat_photo::{SetChatPhoto, SetChatPhotoSetters}; pub use set_chat_sticker_set::{SetChatStickerSet, SetChatStickerSetSetters}; pub use set_chat_title::{SetChatTitle, SetChatTitleSetters}; +pub use set_custom_emoji_sticker_set_thumbnail::{ + SetCustomEmojiStickerSetThumbnail, SetCustomEmojiStickerSetThumbnailSetters, +}; pub use set_game_score::{SetGameScore, SetGameScoreSetters}; pub use set_game_score_inline::{SetGameScoreInline, SetGameScoreInlineSetters}; pub use set_my_commands::{SetMyCommands, SetMyCommandsSetters}; @@ -243,8 +253,12 @@ pub use set_my_default_administrator_rights::{ pub use set_my_description::{SetMyDescription, SetMyDescriptionSetters}; pub use set_my_short_description::{SetMyShortDescription, SetMyShortDescriptionSetters}; pub use set_passport_data_errors::{SetPassportDataErrors, SetPassportDataErrorsSetters}; +pub use set_sticker_emoji_list::{SetStickerEmojiList, SetStickerEmojiListSetters}; +pub use set_sticker_keywords::{SetStickerKeywords, SetStickerKeywordsSetters}; +pub use set_sticker_mask_position::{SetStickerMaskPosition, SetStickerMaskPositionSetters}; pub use set_sticker_position_in_set::{SetStickerPositionInSet, SetStickerPositionInSetSetters}; -pub use set_sticker_set_thumb::{SetStickerSetThumb, SetStickerSetThumbSetters}; +pub use set_sticker_set_thumbnail::{SetStickerSetThumbnail, SetStickerSetThumbnailSetters}; +pub use set_sticker_set_title::{SetStickerSetTitle, SetStickerSetTitleSetters}; pub use set_webhook::{SetWebhook, SetWebhookSetters}; pub use stop_message_live_location::{StopMessageLiveLocation, StopMessageLiveLocationSetters}; pub use stop_message_live_location_inline::{ diff --git a/crates/teloxide-core/src/payloads/add_sticker_to_set.rs b/crates/teloxide-core/src/payloads/add_sticker_to_set.rs index 3ef0900f..78cf814b 100644 --- a/crates/teloxide-core/src/payloads/add_sticker_to_set.rs +++ b/crates/teloxide-core/src/payloads/add_sticker_to_set.rs @@ -2,11 +2,11 @@ use serde::Serialize; -use crate::types::{InputSticker, MaskPosition, True, UserId}; +use crate::types::{InputSticker, True, UserId}; impl_payload! { @[multipart = sticker] - /// Use this method to add a new sticker to a set created by the bot. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. Returns _True_ on success. + /// Use this method to add a new sticker to a set created by the bot. Emoji sticker sets can have up to 200 stickers. Other sticker sets can have up to 120 stickers. Returns True on success. #[derive(Debug, Clone, Serialize)] pub AddStickerToSet (AddStickerToSetSetters) => True { required { @@ -14,17 +14,9 @@ impl_payload! { pub user_id: UserId, /// Sticker set name pub name: String [into], - /// **PNG** or **TGS** image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a _file\_id_ as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »] - /// - /// [More info on Sending Files »]: crate::types::InputFile + /// A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set isn't changed. #[serde(flatten)] pub sticker: InputSticker, - /// One or more emoji corresponding to the sticker - pub emojis: String [into], - } - optional { - /// A JSON-serialized object for position where the mask should be placed on faces - pub mask_position: MaskPosition, } } } diff --git a/crates/teloxide-core/src/payloads/create_new_sticker_set.rs b/crates/teloxide-core/src/payloads/create_new_sticker_set.rs index 2fa6b2b7..1e81511e 100644 --- a/crates/teloxide-core/src/payloads/create_new_sticker_set.rs +++ b/crates/teloxide-core/src/payloads/create_new_sticker_set.rs @@ -2,11 +2,10 @@ use serde::Serialize; -use crate::types::{InputSticker, MaskPosition, StickerType, True, UserId}; +use crate::types::{InputSticker, StickerFormat, StickerType, True, UserId}; impl_payload! { - @[multipart = sticker] - /// Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields _png\_sticker_ or _tgs\_sticker_. Returns _True_ on success. + /// Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. Returns True on success. #[derive(Debug, Clone, Serialize)] pub CreateNewStickerSet (CreateNewStickerSetSetters) => True { required { @@ -16,20 +15,17 @@ impl_payload! { pub name: String [into], /// Sticker set title, 1-64 characters pub title: String [into], - /// **PNG** image, **TGS** animation or **WEBM** video with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a _file\_id_ as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. [More info on Sending Files »] - /// - /// [More info on Sending Files »]: crate::types::InputFile - #[serde(flatten)] - pub sticker: InputSticker, - /// One or more emoji corresponding to the sticker - pub emojis: String [into], + /// A JSON-serialized list of 1-50 initial stickers to be added to the sticker set + pub stickers: Vec [collect], + /// Format of the sticker, must be one of “static”, “animated”, “video” + pub sticker_format: StickerFormat, } optional { - /// Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can't be created via the Bot API at the moment. By default, a regular sticker set is created. + /// Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created. #[serde(flatten)] pub sticker_type: StickerType, - /// A JSON-serialized object for position where the mask should be placed on faces - pub mask_position: MaskPosition, + /// Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only + pub needs_repainting: bool, } } } diff --git a/crates/teloxide-core/src/payloads/delete_sticker_set.rs b/crates/teloxide-core/src/payloads/delete_sticker_set.rs new file mode 100644 index 00000000..1bb4450e --- /dev/null +++ b/crates/teloxide-core/src/payloads/delete_sticker_set.rs @@ -0,0 +1,16 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::True; + +impl_payload! { + /// Use this method to delete a sticker set that was created by the bot. Returns True on success. + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub DeleteStickerSet (DeleteStickerSetSetters) => True { + required { + /// Sticker set name + pub name: String [into], + } + } +} diff --git a/crates/teloxide-core/src/payloads/send_sticker.rs b/crates/teloxide-core/src/payloads/send_sticker.rs index da0d9e57..72dd9e2f 100644 --- a/crates/teloxide-core/src/payloads/send_sticker.rs +++ b/crates/teloxide-core/src/payloads/send_sticker.rs @@ -22,6 +22,8 @@ impl_payload! { optional { /// Unique identifier for the target message thread (topic) of the forum; for forum supergroups only pub message_thread_id: ThreadId, + /// Emoji associated with the sticker; only for just uploaded stickers + pub emoji: String [into], /// Sends the message [silently]. Users will receive a notification with no sound. /// /// [silently]: https://telegram.org/blog/channels-2-0#silent-messages diff --git a/crates/teloxide-core/src/payloads/set_custom_emoji_sticker_set_thumbnail.rs b/crates/teloxide-core/src/payloads/set_custom_emoji_sticker_set_thumbnail.rs new file mode 100644 index 00000000..368c2d84 --- /dev/null +++ b/crates/teloxide-core/src/payloads/set_custom_emoji_sticker_set_thumbnail.rs @@ -0,0 +1,20 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::True; + +impl_payload! { + /// Use this method to set the thumbnail of a custom emoji sticker set. Returns True on success. + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub SetCustomEmojiStickerSetThumbnail (SetCustomEmojiStickerSetThumbnailSetters) => True { + required { + /// Sticker set name + pub name: String [into], + } + optional { + /// Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail. + pub custom_emoji_id: String [into], + } + } +} diff --git a/crates/teloxide-core/src/payloads/set_sticker_emoji_list.rs b/crates/teloxide-core/src/payloads/set_sticker_emoji_list.rs new file mode 100644 index 00000000..9874fb31 --- /dev/null +++ b/crates/teloxide-core/src/payloads/set_sticker_emoji_list.rs @@ -0,0 +1,18 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::True; + +impl_payload! { + /// Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success. + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub SetStickerEmojiList (SetStickerEmojiListSetters) => True { + required { + /// File identifier of the sticker + pub sticker: String [into], + /// A JSON-serialized list of 1-20 emoji associated with the sticker + pub emoji_list: Vec [collect], + } + } +} diff --git a/crates/teloxide-core/src/payloads/set_sticker_keywords.rs b/crates/teloxide-core/src/payloads/set_sticker_keywords.rs new file mode 100644 index 00000000..79bbce51 --- /dev/null +++ b/crates/teloxide-core/src/payloads/set_sticker_keywords.rs @@ -0,0 +1,20 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::True; + +impl_payload! { + /// Use this method to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success. + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub SetStickerKeywords (SetStickerKeywordsSetters) => True { + required { + /// File identifier of the sticker + pub sticker: String [into], + } + optional { + /// A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters + pub keywords: Vec [collect], + } + } +} diff --git a/crates/teloxide-core/src/payloads/set_sticker_mask_position.rs b/crates/teloxide-core/src/payloads/set_sticker_mask_position.rs new file mode 100644 index 00000000..e0611657 --- /dev/null +++ b/crates/teloxide-core/src/payloads/set_sticker_mask_position.rs @@ -0,0 +1,20 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::{MaskPosition, True}; + +impl_payload! { + /// Use this method to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot. Returns True on success. + #[derive(Debug, PartialEq, Clone, Serialize)] + pub SetStickerMaskPosition (SetStickerMaskPositionSetters) => True { + required { + /// File identifier of the sticker + pub sticker: String [into], + } + optional { + /// A JSON-serialized object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position. + pub mask_position: MaskPosition, + } + } +} diff --git a/crates/teloxide-core/src/payloads/set_sticker_set_thumbnail.rs b/crates/teloxide-core/src/payloads/set_sticker_set_thumbnail.rs new file mode 100644 index 00000000..4c0d6835 --- /dev/null +++ b/crates/teloxide-core/src/payloads/set_sticker_set_thumbnail.rs @@ -0,0 +1,25 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::{InputFile, True, UserId}; + +impl_payload! { + @[multipart = thumbnail] + /// Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file must match the format of the stickers in the set. Returns True on success. + #[derive(Debug, Clone, Serialize)] + pub SetStickerSetThumbnail (SetStickerSetThumbnailSetters) => True { + required { + /// Name of the sticker set + pub name: String [into], + /// User identifier of sticker file owner + pub user_id: UserId, + } + optional { + /// A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. Animated and video sticker set thumbnails can't be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail. + /// + /// [More info on Sending Files »]: crate::types::InputFile + pub thumbnail: InputFile, + } + } +} diff --git a/crates/teloxide-core/src/payloads/set_sticker_set_title.rs b/crates/teloxide-core/src/payloads/set_sticker_set_title.rs new file mode 100644 index 00000000..b07c17eb --- /dev/null +++ b/crates/teloxide-core/src/payloads/set_sticker_set_title.rs @@ -0,0 +1,18 @@ +//! Generated by `codegen_payloads`, do not edit by hand. + +use serde::Serialize; + +use crate::types::True; + +impl_payload! { + /// Use this method to set the title of a created sticker set. Returns True on success. + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] + pub SetStickerSetTitle (SetStickerSetTitleSetters) => True { + required { + /// Sticker set name + pub name: String [into], + /// Sticker set title, 1-64 characters + pub title: String [into], + } + } +} diff --git a/crates/teloxide-core/src/payloads/setters.rs b/crates/teloxide-core/src/payloads/setters.rs index a01e0e13..35595cc1 100644 --- a/crates/teloxide-core/src/payloads/setters.rs +++ b/crates/teloxide-core/src/payloads/setters.rs @@ -10,14 +10,14 @@ pub use crate::payloads::{ CreateForumTopicSetters as _, CreateInvoiceLinkSetters as _, CreateNewStickerSetSetters as _, DeclineChatJoinRequestSetters as _, DeleteChatPhotoSetters as _, DeleteChatStickerSetSetters as _, DeleteForumTopicSetters as _, DeleteMessageSetters as _, - DeleteMyCommandsSetters as _, DeleteStickerFromSetSetters as _, DeleteWebhookSetters as _, - EditChatInviteLinkSetters as _, EditForumTopicSetters as _, EditGeneralForumTopicSetters as _, - EditMessageCaptionInlineSetters as _, EditMessageCaptionSetters as _, - EditMessageLiveLocationInlineSetters as _, EditMessageLiveLocationSetters as _, - EditMessageMediaInlineSetters as _, EditMessageMediaSetters as _, - EditMessageReplyMarkupInlineSetters as _, EditMessageReplyMarkupSetters as _, - EditMessageTextInlineSetters as _, EditMessageTextSetters as _, - ExportChatInviteLinkSetters as _, ForwardMessageSetters as _, + DeleteMyCommandsSetters as _, DeleteStickerFromSetSetters as _, DeleteStickerSetSetters as _, + DeleteWebhookSetters as _, EditChatInviteLinkSetters as _, EditForumTopicSetters as _, + EditGeneralForumTopicSetters as _, EditMessageCaptionInlineSetters as _, + EditMessageCaptionSetters as _, EditMessageLiveLocationInlineSetters as _, + EditMessageLiveLocationSetters as _, EditMessageMediaInlineSetters as _, + EditMessageMediaSetters as _, EditMessageReplyMarkupInlineSetters as _, + EditMessageReplyMarkupSetters as _, EditMessageTextInlineSetters as _, + EditMessageTextSetters as _, ExportChatInviteLinkSetters as _, ForwardMessageSetters as _, GetChatAdministratorsSetters as _, GetChatMemberCountSetters as _, GetChatMemberSetters as _, GetChatMembersCountSetters as _, GetChatMenuButtonSetters as _, GetChatSetters as _, GetCustomEmojiStickersSetters as _, GetFileSetters as _, GetForumTopicIconStickersSetters as _, @@ -36,11 +36,14 @@ pub use crate::payloads::{ SendVideoNoteSetters as _, SendVideoSetters as _, SendVoiceSetters as _, SetChatAdministratorCustomTitleSetters as _, SetChatDescriptionSetters as _, SetChatMenuButtonSetters as _, SetChatPermissionsSetters as _, SetChatPhotoSetters as _, - SetChatStickerSetSetters as _, SetChatTitleSetters as _, SetGameScoreInlineSetters as _, + SetChatStickerSetSetters as _, SetChatTitleSetters as _, + SetCustomEmojiStickerSetThumbnailSetters as _, SetGameScoreInlineSetters as _, SetGameScoreSetters as _, SetMyCommandsSetters as _, SetMyDefaultAdministratorRightsSetters as _, SetMyDescriptionSetters as _, SetMyShortDescriptionSetters as _, SetPassportDataErrorsSetters as _, - SetStickerPositionInSetSetters as _, SetStickerSetThumbSetters as _, SetWebhookSetters as _, + SetStickerEmojiListSetters as _, SetStickerKeywordsSetters as _, + SetStickerMaskPositionSetters as _, SetStickerPositionInSetSetters as _, + SetStickerSetThumbnailSetters as _, SetStickerSetTitleSetters as _, SetWebhookSetters as _, StopMessageLiveLocationInlineSetters as _, StopMessageLiveLocationSetters as _, StopPollSetters as _, UnbanChatMemberSetters as _, UnbanChatSenderChatSetters as _, UnhideGeneralForumTopicSetters as _, UnpinAllChatMessagesSetters as _, diff --git a/crates/teloxide-core/src/payloads/upload_sticker_file.rs b/crates/teloxide-core/src/payloads/upload_sticker_file.rs index d856dc1d..2bf6feca 100644 --- a/crates/teloxide-core/src/payloads/upload_sticker_file.rs +++ b/crates/teloxide-core/src/payloads/upload_sticker_file.rs @@ -2,20 +2,22 @@ use serde::Serialize; -use crate::types::{FileMeta, InputFile, UserId}; +use crate::types::{FileMeta, InputFile, StickerFormat, UserId}; impl_payload! { - @[multipart = png_sticker] + @[multipart = sticker] /// Use this method to upload a .PNG file with a sticker for later use in _createNewStickerSet_ and _addStickerToSet_ methods (can be used multiple times). Returns the uploaded File on success. #[derive(Debug, Clone, Serialize)] pub UploadStickerFile (UploadStickerFileSetters) => FileMeta { required { /// User identifier of sticker file owner pub user_id: UserId, - /// PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. [More info on Sending Files »] + /// A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See https://core.telegram.org/stickers for technical requirements. [More info on Sending Files »] /// /// [More info on Sending Files »]: crate::types::InputFile - pub png_sticker: InputFile, + pub sticker: InputFile, + /// Format of the sticker, must be one of “static”, “animated”, “video” + pub sticker_format: StickerFormat, } } } diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index 4ec7e491..2061b19b 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -981,38 +981,37 @@ pub trait Requester { fn upload_sticker_file( &self, user_id: UserId, - png_sticker: InputFile, + sticker: InputFile, + sticker_format: StickerFormat, ) -> Self::UploadStickerFile; type CreateNewStickerSet: Request; /// For Telegram documentation see [`CreateNewStickerSet`]. - fn create_new_sticker_set( + fn create_new_sticker_set( &self, user_id: UserId, name: N, title: T, - sticker: InputSticker, - emojis: E, + stickers: S, + sticker_format: StickerFormat, ) -> Self::CreateNewStickerSet where N: Into, T: Into, - E: Into; + S: IntoIterator; type AddStickerToSet: Request; /// For Telegram documentation see [`AddStickerToSet`]. - fn add_sticker_to_set( + fn add_sticker_to_set( &self, user_id: UserId, name: N, sticker: InputSticker, - emojis: E, ) -> Self::AddStickerToSet where - N: Into, - E: Into; + N: Into; type SetStickerPositionInSet: Request; @@ -1032,13 +1031,67 @@ pub trait Requester { where S: Into; - type SetStickerSetThumb: Request; + type SetStickerSetThumbnail: Request; - /// For Telegram documentation see [`SetStickerSetThumb`]. - fn set_sticker_set_thumb(&self, name: N, user_id: UserId) -> Self::SetStickerSetThumb + /// For Telegram documentation see [`SetStickerSetThumbnail`]. + fn set_sticker_set_thumbnail( + &self, + name: N, + user_id: UserId, + ) -> Self::SetStickerSetThumbnail where N: Into; + type SetCustomEmojiStickerSetThumbnail: Request< + Payload = SetCustomEmojiStickerSetThumbnail, + Err = Self::Err, + >; + + /// For Telegram documentation see [`SetCustomEmojiStickerSetThumbnail`]. + fn set_custom_emoji_sticker_set_thumbnail( + &self, + name: N, + ) -> Self::SetCustomEmojiStickerSetThumbnail + where + N: Into; + + type SetStickerSetTitle: Request; + + /// For Telegram documentation see [`SetStickerSetTitle`]. + fn set_sticker_set_title(&self, name: N, title: T) -> Self::SetStickerSetTitle + where + N: Into, + T: Into; + + type DeleteStickerSet: Request; + + /// For Telegram documentation see [`DeleteStickerSet`]. + fn delete_sticker_set(&self, name: N) -> Self::DeleteStickerSet + where + N: Into; + + type SetStickerEmojiList: Request; + + /// For Telegram documentation see [`SetStickerEmojiList`]. + fn set_sticker_emoji_list(&self, sticker: S, emoji_list: E) -> Self::SetStickerEmojiList + where + S: Into, + E: IntoIterator; + + type SetStickerKeywords: Request; + + /// For Telegram documentation see [`SetStickerKeywords`]. + fn set_sticker_keywords(&self, sticker: S) -> Self::SetStickerKeywords + where + S: Into; + + type SetStickerMaskPosition: Request; + + /// For Telegram documentation see [`SetStickerMaskPosition`]. + fn set_sticker_mask_position(&self, sticker: S) -> Self::SetStickerMaskPosition + where + S: Into; + type SendInvoice: Request; /// For Telegram documentation see [`SendInvoice`]. @@ -1266,7 +1319,13 @@ macro_rules! forward_all { add_sticker_to_set, set_sticker_position_in_set, delete_sticker_from_set, - set_sticker_set_thumb, + set_sticker_set_thumbnail, + set_custom_emoji_sticker_set_thumbnail, + set_sticker_set_title, + delete_sticker_set, + set_sticker_emoji_list, + set_sticker_keywords, + set_sticker_mask_position, send_invoice, create_invoice_link, answer_shipping_query, diff --git a/crates/teloxide-core/src/serde_multipart/mod.rs b/crates/teloxide-core/src/serde_multipart/mod.rs index ffa7ad09..bef53433 100644 --- a/crates/teloxide-core/src/serde_multipart/mod.rs +++ b/crates/teloxide-core/src/serde_multipart/mod.rs @@ -90,7 +90,7 @@ mod tests { types::{ ChatId, InputFile, InputMedia, InputMediaAnimation, InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo, InputSticker, MessageEntity, - MessageEntityKind, ParseMode, UserId, + MessageEntityKind, ParseMode, StickerFormat, UserId, }, }; @@ -146,11 +146,20 @@ mod tests { #[tokio::test] async fn test_add_sticker_to_set() { + // FIXME: rewrite according to the new schema to_form_ref(&payloads::AddStickerToSet::new( UserId(0), "name", - InputSticker::Png(InputFile::file("../../media/teloxide-core-logo.png")), - "✈️⚙️", + InputSticker { + sticker: InputFile::file( + "../../media/ + teloxide-core-logo.png", + ), + format: StickerFormat::Static, + emoji_list: vec!["✈️⚙️".to_owned()], + keywords: None, + mask_position: None, + }, )) .unwrap() .await; diff --git a/crates/teloxide-core/src/types/input_file.rs b/crates/teloxide-core/src/types/input_file.rs index 5a064dac..48227388 100644 --- a/crates/teloxide-core/src/types/input_file.rs +++ b/crates/teloxide-core/src/types/input_file.rs @@ -418,14 +418,10 @@ impl InputFileLike for Option { impl InputFileLike for InputSticker { fn copy_into(&self, into: &mut dyn FnMut(InputFile)) { - let (Self::Png(input_file) | Self::Tgs(input_file) | Self::Webm(input_file)) = self; - - input_file.copy_into(into) + self.sticker.copy_into(into) } fn move_into(&mut self, into: &mut dyn FnMut(InputFile)) { - let (Self::Png(input_file) | Self::Tgs(input_file) | Self::Webm(input_file)) = self; - - input_file.move_into(into) + self.sticker.move_into(into) } } diff --git a/crates/teloxide-core/src/types/input_sticker.rs b/crates/teloxide-core/src/types/input_sticker.rs index f938106c..242cf9c1 100644 --- a/crates/teloxide-core/src/types/input_sticker.rs +++ b/crates/teloxide-core/src/types/input_sticker.rs @@ -1,39 +1,33 @@ use serde::Serialize; -use crate::types::InputFile; +use crate::types::{InputFile, MaskPosition, StickerFormat}; -/// Sticker file that may be uploaded to telegram. +/// This object describes a sticker to be added to a sticker set. +#[serde_with_macros::skip_serializing_none] #[derive(Clone, Debug, Serialize)] -pub enum InputSticker { - /// PNG image with the sticker, must be up to 512 kilobytes in size, - /// dimensions must not exceed 512px, and either width or height must be - /// exactly 512px. +pub struct InputSticker { + /// The added sticker. Pass a file_id as a String to send a file that + /// already exists on the Telegram servers, pass an HTTP URL as a String + /// for Telegram to get a file from the Internet, upload a new one using + /// multipart/form-data, or pass “attach://” to upload a + /// new one using multipart/form-data under name. + /// Animated and video stickers can't be uploaded via HTTP URL. /// - /// Pass [`InputFile::file_id`] to send a file that exists on - /// the Telegram servers (recommended), pass an [`InputFile::url`] for - /// Telegram to get a .webp file from the Internet, or upload a new one - /// using [`InputFile::file`], [`InputFile::memory`] or [`InputFile::read`]. - /// [More info on Sending Files »]. - /// - /// [`InputFile::file_id`]: InputFile::file_id - /// [`InputFile::url`]: InputFile::url - /// [`InputFile::file`]: InputFile::file - /// [`InputFile::memory`]: InputFile::memory - /// [`InputFile::read`]: InputFile::read - /// - /// [More info on Sending Files »]: https://core.telegram.org/bots/api#sending-files - #[serde(rename = "png_sticker")] - Png(InputFile), + /// More information on Sending Files + pub sticker: InputFile, - /// TGS animation with the sticker, uploaded using multipart/form-data. - /// - /// See for technical requirements. - #[serde(rename = "tgs_sticker")] - Tgs(InputFile), + /// Format of the added sticker, must be one of “static” for a .WEBP or .PNG + /// image, “animated” for a .TGS animation, “video” for a WEBM video + pub format: StickerFormat, - /// WEBM video with the sticker, uploaded using multipart/form-data. - /// - /// See for technical requirements. - #[serde(rename = "webm_sticker")] - Webm(InputFile), + /// List of 1-20 emoji associated with the sticker + pub emoji_list: Vec, + + /// Position where the mask should be placed on faces. For “mask” stickers + /// only. + pub mask_position: Option, + + /// List of 0-20 search keywords for the sticker with total length of up to + /// 64 characters. For “regular” and “custom_emoji” stickers only. + pub keywords: Option>, } diff --git a/crates/teloxide-core/src/types/sticker.rs b/crates/teloxide-core/src/types/sticker.rs index c687908b..33c2a0a5 100644 --- a/crates/teloxide-core/src/types/sticker.rs +++ b/crates/teloxide-core/src/types/sticker.rs @@ -2,7 +2,7 @@ use std::ops::Deref; use serde::{Deserialize, Serialize}; -use crate::types::{FileMeta, MaskPosition, PhotoSize}; +use crate::types::{FileMeta, MaskPosition, PhotoSize, True}; /// This object represents a sticker. /// @@ -51,6 +51,11 @@ pub struct Sticker { /// Name of the sticker set to which the sticker belongs. pub set_name: Option, + + /// True, if the sticker must be repainted to a text color in messages, the + /// color of the Telegram Premium badge in emoji status, white color on + /// chat photos, or another appropriate color in other places + pub needs_repainting: Option, } /// Kind of a [`Sticker`] - regular, mask or custom emoji. @@ -94,11 +99,11 @@ pub enum StickerType { } /// Format of a [`Sticker`] - regular/webp, animated/tgs or video/webm. -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(try_from = "StickerFormatRaw", into = "StickerFormatRaw")] pub enum StickerFormat { - /// "Normal", raster, `.webp` sticker. - Raster, + /// Image in `.png` or `.webp` format. + Static, /// [Animated], `.tgs` sticker. /// /// [Animated]: https://telegram.org/blog/animated-stickers @@ -135,10 +140,10 @@ impl Sticker { /// /// Alias to [`self.format.is_raster()`]. /// - /// [`self.format.is_raster()`]: StickerFormat::is_raster + /// [`self.format.is_static()`]: StickerFormat::is_static #[must_use] - pub fn is_raster(&self) -> bool { - self.format.is_raster() + pub fn is_static(&self) -> bool { + self.format.is_static() } /// Returns `true` is this is an [animated] sticker. @@ -257,12 +262,12 @@ impl StickerType { } impl StickerFormat { - /// Returns `true` if the sticker format is [`Raster`]. + /// Returns `true` if the sticker format is [`Static`]. /// - /// [`Raster`]: StickerFormat::Raster + /// [`Static`]: StickerFormat::Static #[must_use] - pub fn is_raster(&self) -> bool { - matches!(self, Self::Raster) + pub fn is_static(&self) -> bool { + matches!(self, Self::Static) } /// Returns `true` if the sticker format is [`Animated`]. @@ -295,7 +300,7 @@ impl TryFrom for StickerFormat { StickerFormatRaw { is_animated, is_video }: StickerFormatRaw, ) -> Result { let ret = match (is_animated, is_video) { - (false, false) => Self::Raster, + (false, false) => Self::Static, (true, false) => Self::Animated, (false, true) => Self::Video, (true, true) => return Err("`is_animated` and `is_video` present at the same time"), @@ -308,7 +313,7 @@ impl TryFrom for StickerFormat { impl From for StickerFormatRaw { fn from(kind: StickerFormat) -> Self { match kind { - StickerFormat::Raster => Self { is_animated: false, is_video: false }, + StickerFormat::Static => Self { is_animated: false, is_video: false }, StickerFormat::Animated => Self { is_animated: true, is_video: false }, StickerFormat::Video => Self { is_animated: false, is_video: true }, } @@ -411,7 +416,7 @@ mod tests { { let json = r#"{"is_animated":false,"is_video":false}"#; let fmt: StickerFormat = serde_json::from_str(json).unwrap(); - assert_eq!(fmt, StickerFormat::Raster); + assert_eq!(fmt, StickerFormat::Static); let json2 = serde_json::to_string(&fmt).unwrap(); assert_eq!(json, json2); diff --git a/crates/teloxide-core/src/types/sticker_set.rs b/crates/teloxide-core/src/types/sticker_set.rs index 0f45eacb..02bad6a3 100644 --- a/crates/teloxide-core/src/types/sticker_set.rs +++ b/crates/teloxide-core/src/types/sticker_set.rs @@ -52,12 +52,12 @@ impl Deref for StickerSet { impl StickerSet { /// Returns `true` is this is a "normal" raster sticker. /// - /// Alias to [`self.format.is_raster()`]. + /// Alias to [`self.format.is_static()`]. /// - /// [`self.format.is_raster()`]: StickerFormat::is_raster + /// [`self.format.is_static()`]: StickerFormat::is_static #[must_use] - pub fn is_raster(&self) -> bool { - self.format.is_raster() + pub fn is_static(&self) -> bool { + self.format.is_static() } /// Returns `true` is this is an [animated] sticker. @@ -141,7 +141,7 @@ mod tests { let set: StickerSet = serde_json::from_str(json).unwrap(); - assert!(set.is_raster()); + assert!(set.is_static()); assert!(set.is_regular()); assert!(set.thumb.is_none()); assert_eq!(set.stickers.len(), 2);