From d434196ddea5306e753a94f6d888291c51a0f37c Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Sun, 14 Jul 2024 20:05:04 +0300 Subject: [PATCH] fixes --- src/api_params.rs | 80 +++++++------- src/api_traits/async_telegram_api.rs | 14 +-- src/api_traits/telegram_api.rs | 14 +-- src/objects.rs | 157 +++++++++++++++------------ 4 files changed, 145 insertions(+), 120 deletions(-) diff --git a/src/api_params.rs b/src/api_params.rs index ea658b2..07e80cd 100644 --- a/src/api_params.rs +++ b/src/api_params.rs @@ -876,6 +876,47 @@ pub struct SendVideoNoteParams { pub reply_markup: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct SendPaidMediaParams { + pub chat_id: ChatId, + + pub star_count: u32, + + pub media: Vec, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub caption: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub parse_mode: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub caption_entities: Option>, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub show_caption_above_media: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub disable_notification: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub protect_content: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub reply_parameters: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub reply_markup: Option, +} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] pub struct SendMediaGroupParams { #[serde(skip_serializing_if = "Option::is_none")] @@ -2796,45 +2837,6 @@ pub struct UnpinAllGeneralForumTopicMessagesParams { pub chat_id: ChatId, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -pub struct SendPaidMediaParams { - pub chat_id: ChatId, - pub star_count: i32, - pub media: Vec, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub caption: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub parse_mode: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub caption_entities: Option>, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub show_caption_above_media: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub disable_notification: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub protect_content: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub reply_parameters: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub reply_markup: Option, -} - #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] pub struct ReplyParameters { pub message_id: i32, diff --git a/src/api_traits/async_telegram_api.rs b/src/api_traits/async_telegram_api.rs index ed72a50..01cb6dd 100644 --- a/src/api_traits/async_telegram_api.rs +++ b/src/api_traits/async_telegram_api.rs @@ -459,6 +459,13 @@ pub trait AsyncTelegramApi { .await } + async fn send_paid_media( + &self, + params: SendPaidMediaParams, + ) -> Result, Self::Error> { + self.request("sendPaidMedia", Some(params)).await + } + async fn send_location( &self, params: &SendLocationParams, @@ -1362,13 +1369,6 @@ pub trait AsyncTelegramApi { .await } - async fn send_paid_media( - &self, - params: SendPaidMediaParams, - ) -> Result, Self::Error> { - self.request("sendPaidMedia", Some(params)).await - } - async fn request_without_body( &self, method: &str, diff --git a/src/api_traits/telegram_api.rs b/src/api_traits/telegram_api.rs index ec464ae..24aa058 100644 --- a/src/api_traits/telegram_api.rs +++ b/src/api_traits/telegram_api.rs @@ -434,6 +434,13 @@ pub trait TelegramApi { self.request_with_possible_form_data(method_name, params, files) } + fn send_paid_media( + &self, + params: SendPaidMediaParams, + ) -> Result, Self::Error> { + self.request("sendPaidMedia", Some(params)) + } + fn send_location( &self, params: &SendLocationParams, @@ -1299,13 +1306,6 @@ pub trait TelegramApi { self.request("unpinAllGeneralForumTopicMessages", Some(params)) } - fn send_paid_media( - &self, - params: SendPaidMediaParams, - ) -> Result, Self::Error> { - self.request("sendPaidMedia", Some(params)) - } - fn request_without_body( &self, method: &str, diff --git a/src/objects.rs b/src/objects.rs index bc344a4..808e535 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -640,6 +640,10 @@ pub struct ChatFullInfo { #[builder(setter(into, strip_option), default)] pub permissions: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub can_send_paid_media: Option, + #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub slow_mode_delay: Option, @@ -802,6 +806,10 @@ pub struct Message { #[builder(setter(into, strip_option), default)] pub document: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub paid_media: Option>, + #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub photo: Option>, @@ -1096,6 +1104,10 @@ pub struct ExternalReplyInfo { #[builder(setter(into, strip_option), default)] pub document: Option, + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub paid_media: Option, + #[serde(skip_serializing_if = "Option::is_none")] #[builder(setter(into, strip_option), default)] pub photo: Option>, @@ -3510,6 +3522,84 @@ pub struct Invoice { pub total_amount: u32, } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct PaidMediaInfo { + pub start_count: u32, + + pub paid_media: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(tag = "type", rename_all = "snake_case")] +pub enum PaidMedia { + Preview(PaidMediaPreview), + Photo(PaidMediaPhoto), + Video(PaidMediaVideo), +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct PaidMediaPreview { + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub width: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub height: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub duration: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PaidMediaPhoto { + pub photo: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct PaidMediaVideo { + pub video: Video, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +#[serde(tag = "type", rename_all = "snake_case")] +pub enum InputPaidMedia { + Photo(InputPaidMediaPhoto), + Video(InputPaidMediaVideo), +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct InputPaidMediaPhoto { + #[builder(setter(into))] + pub media: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] +pub struct InputPaidMediaVideo { + #[builder(setter(into))] + pub media: String, + + #[builder(setter(into))] + pub thumbnail: String, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub width: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub height: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub duration: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + #[builder(setter(into, strip_option), default)] + pub supports_streaming: Option, +} + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)] pub struct ShippingAddress { #[builder(setter(into))] @@ -4172,73 +4262,6 @@ pub struct StarTransactions { pub transactions: Vec, } -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[serde(tag = "type", rename_all = "snake_case")] -pub enum PaidMedia { - Preview(PaidMediaPreview), - Photo(PaidMediaPhoto), - Video(PaidMediaVideo), -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -pub struct PaidMediaPreview { - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub width: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub height: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub duration: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct PaidMediaPhoto { - pub photo: Vec, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct PaidMediaVideo { - pub video: Video, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[serde(tag = "type", rename_all = "snake_case")] -pub enum InputPaidMedia { - Photo(InputPaidMediaPhoto), - Video(InputPaidMediaVideo), -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub struct InputPaidMediaPhoto { - pub media: String, -} - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)] -pub struct InputPaidMediaVideo { - pub media: String, - pub thumbnail: FileUpload, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub width: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub height: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub duration: Option, - - #[serde(skip_serializing_if = "Option::is_none")] - #[builder(setter(into, strip_option), default)] - pub supports_streaming: Option, -} - #[cfg(test)] mod serde_tests { use super::*;