From 8d7f4390e7015ecdfd101a6e52f85257addbb981 Mon Sep 17 00:00:00 2001 From: Pmarquez <48651252+pxp9@users.noreply.github.com> Date: Sat, 13 Aug 2022 09:05:31 +0000 Subject: [PATCH] Bot API 6.2 * August 12 most api changes * some fixes * Eq derive * Fixing tests and fixing Serialize for Sticker and StickerSet * Eq my bad xd * Some more changes * Just one StickerType * Fix comments * import Sticker async api * Deprecated and hidden * Allow deprecated in Api Params --- src/api/telegram_api_impl.rs | 6 +++--- src/api_params.rs | 15 ++++++++++++- src/api_traits/async_telegram_api.rs | 8 +++++++ src/api_traits/telegram_api.rs | 9 ++++++++ src/objects.rs | 32 ++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/api/telegram_api_impl.rs b/src/api/telegram_api_impl.rs index 4f9473e..9390bf6 100644 --- a/src/api/telegram_api_impl.rs +++ b/src/api/telegram_api_impl.rs @@ -1595,7 +1595,7 @@ mod tests { #[test] fn send_sticker_success() { - let response_string = "{\"ok\":true,\"result\":{\"message_id\":2788,\"from\":{\"id\":1276618370,\"is_bot\":true,\"first_name\":\"test_el_bot\",\"username\":\"el_mon_test_bot\"},\"date\":1619245784,\"chat\":{\"id\":275808073,\"type\":\"private\",\"username\":\"Ayrat555\",\"first_name\":\"Ayrat\",\"last_name\":\"Badykov\"},\"sticker\":{\"file_id\":\"CAACAgIAAxkDAAIK5GCDutgNxc07rqqtjkGWrGskbHfQAAIMEAACRx8ZSKJ6Z5GkdVHcHwQ\",\"file_unique_id\":\"AgADDBAAAkcfGUg\",\"width\":512,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumb\":{\"file_id\":\"AAMCAgADGQMAAgrkYIO62A3FzTuuqq2OQZasayRsd9AAAgwQAAJHHxlIonpnkaR1Udz29bujLgADAQAHbQADzR4AAh8E\",\"file_unique_id\":\"AQAD9vW7oy4AA80eAAI\",\"width\":320,\"height\":320,\"file_size\":19264},\"file_size\":36596}}}"; + let response_string = "{\"ok\":true,\"result\":{\"message_id\":2788,\"from\":{\"id\":1276618370,\"is_bot\":true,\"first_name\":\"test_el_bot\",\"username\":\"el_mon_test_bot\"},\"date\":1619245784,\"chat\":{\"id\":275808073,\"type\":\"private\",\"username\":\"Ayrat555\",\"first_name\":\"Ayrat\",\"last_name\":\"Badykov\"},\"sticker\":{\"file_id\":\"CAACAgIAAxkDAAIK5GCDutgNxc07rqqtjkGWrGskbHfQAAIMEAACRx8ZSKJ6Z5GkdVHcHwQ\",\"file_unique_id\":\"AgADDBAAAkcfGUg\",\"type\":\"regular\",\"width\":512,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumb\":{\"file_id\":\"AAMCAgADGQMAAgrkYIO62A3FzTuuqq2OQZasayRsd9AAAgwQAAJHHxlIonpnkaR1Udz29bujLgADAQAHbQADzR4AAh8E\",\"file_unique_id\":\"AQAD9vW7oy4AA80eAAI\",\"width\":320,\"height\":320,\"file_size\":19264},\"file_size\":36596}}}"; let file = std::path::PathBuf::from("./frankenstein_logo.png"); let params = SendStickerParams::builder() @@ -1617,14 +1617,14 @@ mod tests { #[test] fn get_sticker_set_success() { - let response_string = "{\"ok\":true,\"result\":{\"name\":\"unocards\",\"title\":\"UNO Bot\",\"is_animated\":false,\"is_video\":false,\"contains_masks\":false,\"stickers\":[{\"file_id\":\"CAACAgQAAxUAAWCDxAQVJ6X7FGiBD5NyjN5DDvgfAALZAQACX1eZAAEqnpNt3SpG_x8E\",\"file_unique_id\":\"AgAD2QEAAl9XmQAB\",\"width\":342,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumb\":{\"file_id\":\"AAMCBAADFQABYIPEBBUnpfsUaIEPk3KM3kMO-B8AAtkBAAJfV5kAASqek23dKkb_P75BGQAEAQAHbQADBBEAAh8E\",\"file_unique_id\":\"AQADP75BGQAEBBEAAg\",\"width\":85,\"height\":128,\"file_size\":2452},\"emoji\":\"dd\",\"set_name\":\"unocards\",\"file_size\":8898}]}}"; + let response_string = "{\"ok\":true,\"result\":{\"name\":\"unocards\",\"title\":\"UNO Bot\",\"sticker_type\":\"regular\",\"is_animated\":false,\"is_video\":false,\"contains_masks\":false,\"stickers\":[{\"file_id\":\"CAACAgQAAxUAAWCDxAQVJ6X7FGiBD5NyjN5DDvgfAALZAQACX1eZAAEqnpNt3SpG_x8E\",\"file_unique_id\":\"AgAD2QEAAl9XmQAB\",\"type\":\"regular\",\"width\":342,\"height\":512,\"is_animated\":false,\"is_video\":false,\"thumb\":{\"file_id\":\"AAMCBAADFQABYIPEBBUnpfsUaIEPk3KM3kMO-B8AAtkBAAJfV5kAASqek23dKkb_P75BGQAEAQAHbQADBBEAAh8E\",\"file_unique_id\":\"AQADP75BGQAEBBEAAg\",\"width\":85,\"height\":128,\"file_size\":2452},\"emoji\":\"dd\",\"set_name\":\"unocards\",\"file_size\":8898}]}}"; + let params = GetStickerSetParams::builder().name("unocards").build(); let _m = mockito::mock("POST", "/getStickerSet") .with_status(200) .with_body(response_string) .create(); let api = Api::new_url(mockito::server_url()); - let response = api.get_sticker_set(¶ms).unwrap(); let json = serde_json::to_string(&response).unwrap(); diff --git a/src/api_params.rs b/src/api_params.rs index 5a38222..c6d7985 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -1,3 +1,4 @@ +#![allow(deprecated)] use crate::objects::{ BotCommand, ChatAdministratorRights, ChatPermissions, ForceReply, InlineKeyboardMarkup, InlineQueryResultArticle, InlineQueryResultAudio, InlineQueryResultCachedAudio, @@ -11,7 +12,7 @@ use crate::objects::{ PassportElementErrorFiles, PassportElementErrorFrontSide, PassportElementErrorReverseSide, PassportElementErrorSelfie, PassportElementErrorTranslationFile, PassportElementErrorTranslationFiles, PassportElementErrorUnspecified, PollType, - ReplyKeyboardMarkup, ReplyKeyboardRemove, ShippingOption, + ReplyKeyboardMarkup, ReplyKeyboardRemove, ShippingOption, StickerType, }; use crate::{AllowedUpdate, ParseMode}; use serde::Deserialize; @@ -1645,9 +1646,15 @@ pub struct CreateNewStickerSetParams { #[builder(setter(into, strip_option), default)] pub webm_sticker: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option))] + pub sticker_type: Option, + #[builder(setter(into))] pub emojis: String, + #[doc(hidden)] + #[deprecated(since = "0.19.2", note = "Please use `sticker_type` instead")] #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub contains_masks: Option, @@ -1657,6 +1664,12 @@ pub struct CreateNewStickerSetParams { pub mask_position: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] +pub struct GetCustomEmojiStickersParams { + #[builder(setter(into))] + pub custom_emoji_ids: Vec, +} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] pub struct AddStickerToSetParams { pub user_id: u64, diff --git a/src/api_traits/async_telegram_api.rs b/src/api_traits/async_telegram_api.rs index 8380339..606adb1 100644 --- a/src/api_traits/async_telegram_api.rs +++ b/src/api_traits/async_telegram_api.rs @@ -34,6 +34,7 @@ use crate::api_params::GetChatMemberCountParams; use crate::api_params::GetChatMemberParams; use crate::api_params::GetChatMenuButtonParams; use crate::api_params::GetChatParams; +use crate::api_params::GetCustomEmojiStickersParams; use crate::api_params::GetFileParams; use crate::api_params::GetGameHighScoresParams; use crate::api_params::GetMyCommandsParams; @@ -102,6 +103,7 @@ use crate::objects::Update; use crate::objects::User; use crate::objects::UserProfilePhotos; use crate::objects::WebhookInfo; +use crate::Sticker; use async_trait::async_trait; use std::path::PathBuf; @@ -913,6 +915,12 @@ pub trait AsyncTelegramApi { .await } + async fn get_custom_emoji_stickers( + &self, + params: &GetCustomEmojiStickersParams, + ) -> Result>, Self::Error> { + self.request("getCustomEmojiStickers", Some(params)).await + } async fn add_sticker_to_set( &self, params: &AddStickerToSetParams, diff --git a/src/api_traits/telegram_api.rs b/src/api_traits/telegram_api.rs index 183327d..9ddf87f 100644 --- a/src/api_traits/telegram_api.rs +++ b/src/api_traits/telegram_api.rs @@ -102,6 +102,8 @@ use crate::objects::Update; use crate::objects::User; use crate::objects::UserProfilePhotos; use crate::objects::WebhookInfo; +use crate::GetCustomEmojiStickersParams; +use crate::Sticker; use std::path::PathBuf; pub trait TelegramApi { @@ -864,6 +866,13 @@ pub trait TelegramApi { self.request_with_possible_form_data(method_name, params, files) } + fn get_custom_emoji_stickers( + &self, + params: &GetCustomEmojiStickersParams, + ) -> Result>, Self::Error> { + self.request("getCustomEmojiStickers", Some(params)) + } + fn add_sticker_to_set( &self, params: &AddStickerToSetParams, diff --git a/src/objects.rs b/src/objects.rs index 5da128f..9a487c6 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -1,8 +1,19 @@ +#![allow(deprecated)] use serde::{Deserialize, Serialize}; use typed_builder::TypedBuilder as Builder; use crate::ParseMode; +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub enum StickerType { + #[serde(rename = "regular")] + Regular, + #[serde(rename = "mask")] + Mask, + #[serde(rename = "custom_emoji")] + CustomEmoji, +} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(untagged)] pub enum InputMessageContent { @@ -58,6 +69,7 @@ pub enum MessageEntityType { Pre, TextLink, TextMention, + CustomEmoji, } #[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)] @@ -433,6 +445,10 @@ pub struct Chat { #[builder(setter(into, strip_option), default)] pub has_private_forwards: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub has_restricted_voice_and_video_messages: Option, + #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub join_to_send_messages: Option, @@ -745,6 +761,10 @@ pub struct MessageEntity { #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub language: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub custom_emoji_id: Option, } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] @@ -1425,6 +1445,9 @@ pub struct Sticker { #[builder(setter(into))] pub file_unique_id: String, + #[serde(rename = "type")] + pub sticker_type: StickerType, + pub width: u32, pub height: u32, @@ -1453,6 +1476,10 @@ pub struct Sticker { #[builder(setter(into, strip_option), default)] pub mask_position: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub custom_emoji_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub file_size: Option, @@ -1466,10 +1493,15 @@ pub struct StickerSet { #[builder(setter(into))] pub title: String, + #[serde(rename = "sticker_type")] + pub sticker_type: StickerType, + pub is_animated: bool, pub is_video: bool, + #[doc(hidden)] + #[deprecated(since = "0.19.2", note = "Please use `sticker_type` instead")] pub contains_masks: bool, pub stickers: Vec,