From 36976e098d56acfa3ad3d695b4f0f3462c5ee88e Mon Sep 17 00:00:00 2001 From: P0lunin Date: Thu, 17 Oct 2019 18:36:03 +0300 Subject: [PATCH 1/2] changed where necessary String to InputFile --- src/bot/api.rs | 4 ++-- src/requests/send_animation.rs | 9 ++++----- src/requests/send_document.rs | 14 ++++++-------- src/requests/send_video.rs | 13 ++++++------- src/requests/send_video_note.rs | 14 ++++++-------- src/requests/send_voice.rs | 9 ++++----- 6 files changed, 28 insertions(+), 35 deletions(-) diff --git a/src/bot/api.rs b/src/bot/api.rs index 38783960..a7c6791c 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -243,7 +243,7 @@ impl Bot { ) -> SendVideoNote where C: Into, - V: Into, // TODO: InputFile + V: Into, { SendVideoNote::new(self, chat_id, video_note) } @@ -251,7 +251,7 @@ impl Bot { pub fn send_voice(&self, chat_id: C, voice: V) -> SendVoice where C: Into, - V: Into, // TODO: InputFile + V: Into, { SendVoice::new(self, chat_id, voice) } diff --git a/src/requests/send_animation.rs b/src/requests/send_animation.rs index a509e6dc..1f70465f 100644 --- a/src/requests/send_animation.rs +++ b/src/requests/send_animation.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::bot::Bot; use crate::network; use crate::requests::{Request, ResponseResult}; -use crate::types::{ChatId, Message, ParseMode, ReplyMarkup}; +use crate::types::{ChatId, Message, ParseMode, ReplyMarkup, InputFile}; ///TODO: add to bot api ///Use this method to send animation files (GIF or H.264/MPEG-4 AVC video @@ -21,8 +21,7 @@ pub struct SendAnimation<'a> { /// exists on the Telegram servers (recommended), pass an HTTP URL as a /// String for Telegram to get an animation from the Internet, or upload a /// new animation using multipart/form-data. More info on Sending Files » - pub animation: String, - // InputFile or String + pub animation: InputFile, ///Duration of sent animation in seconds #[serde(skip_serializing_if = "Option::is_none")] pub duration: Option, @@ -90,7 +89,7 @@ impl<'a> SendAnimation<'a> { pub(crate) fn new(bot: &'a Bot, chat_id: C, animation: S) -> Self where C: Into, - S: Into, + S: Into, { Self { bot, @@ -140,7 +139,7 @@ impl<'a> SendAnimation<'a> { } pub fn thumb(mut self, value: T) -> Self where - T: Into, + T: Into, { self.thumb = Some(value.into()); self diff --git a/src/requests/send_document.rs b/src/requests/send_document.rs index 93c5dc5b..6980120b 100644 --- a/src/requests/send_document.rs +++ b/src/requests/send_document.rs @@ -4,7 +4,7 @@ use crate::bot::Bot; use crate::{ network, requests::{Request, ResponseResult}, - types::{ChatId, Message, ParseMode, ReplyMarkup}, + types::{ChatId, Message, ParseMode, ReplyMarkup, InputFile}, }; // TODO: add method to bot/api @@ -23,8 +23,7 @@ pub struct SendDocument<'a> { /// the Telegram servers (recommended), 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.» - pub document: String, - //InputFile or String + pub document: InputFile, /// Thumbnail of the file sent; can be ignored if thumbnail generation for /// the file is supported server-side. The thumbnail should be in JPEG /// format and less than 200 kB in size. A thumbnail‘s width and height @@ -34,8 +33,7 @@ pub struct SendDocument<'a> { /// if the thumbnail was uploaded using multipart/form-data under /// . More info on Sending Files » #[serde(skip_serializing_if = "Option::is_none")] - pub thumb: Option, - //InputFile or String + pub thumb: Option, /// Document caption (may also be used when resending documents by /// file_id), 0-1024 characters #[serde(skip_serializing_if = "Option::is_none")] @@ -83,7 +81,7 @@ impl<'a> SendDocument<'a> { pub(crate) fn new(bot: &'a Bot, chat_id: C, document: D) -> Self where C: Into, - D: Into, + D: Into, { Self { bot, @@ -108,7 +106,7 @@ impl<'a> SendDocument<'a> { pub fn document(mut self, value: T) -> Self where - T: Into, + T: Into, { self.document = value.into(); self @@ -116,7 +114,7 @@ impl<'a> SendDocument<'a> { pub fn thumb(mut self, value: T) -> Self where - T: Into, + T: Into, { self.thumb = Some(value.into()); self diff --git a/src/requests/send_video.rs b/src/requests/send_video.rs index e6ab5712..e1f5fc54 100644 --- a/src/requests/send_video.rs +++ b/src/requests/send_video.rs @@ -3,7 +3,7 @@ use async_trait::async_trait; use crate::bot::Bot; use crate::network; use crate::requests::{Request, ResponseResult}; -use crate::types::{ChatId, Message, ParseMode, ReplyMarkup}; +use crate::types::{ChatId, Message, ParseMode, ReplyMarkup, InputFile}; //TODO: add action to bot api ///Use this method to send video files, Telegram clients support mp4 videos @@ -21,7 +21,7 @@ pub struct SendVideo<'a> { /// the Telegram servers (recommended), pass an HTTP URL as a String for /// Telegram to get a video from the Internet, or upload a new video using /// multipart/form-data. More info on Sending Files » - pub video: String, + pub video: InputFile, ///Duration of sent video in seconds #[serde(skip_serializing_if = "Option::is_none")] pub duration: Option, @@ -40,8 +40,7 @@ pub struct SendVideo<'a> { /// if the thumbnail was uploaded using multipart/form-data under /// . More info on Sending Files » #[serde(skip_serializing_if = "Option::is_none")] - pub thumb: Option, - //InputFile or String + pub thumb: Option, ///Video caption (may also be used when resending videos by file_id), /// 0-1024 characters #[serde(skip_serializing_if = "Option::is_none")] @@ -92,7 +91,7 @@ impl<'a> SendVideo<'a> { pub(crate) fn new(bot: &'a Bot, chat_id: C, video: V) -> Self where C: Into, - V: Into, + V: Into, { Self { bot, @@ -120,7 +119,7 @@ impl<'a> SendVideo<'a> { pub fn video(mut self, value: T) -> Self where - T: Into, + T: Into, { self.video = value.into(); self @@ -149,7 +148,7 @@ impl<'a> SendVideo<'a> { } pub fn thumb(mut self, value: T) -> Self where - T: Into, + T: Into, { self.thumb = Some(value.into()); self diff --git a/src/requests/send_video_note.rs b/src/requests/send_video_note.rs index bd3eb316..7d580f64 100644 --- a/src/requests/send_video_note.rs +++ b/src/requests/send_video_note.rs @@ -4,7 +4,7 @@ use crate::bot::Bot; use crate::{ network, requests::{Request, ResponseResult}, - types::{ChatId, Message, ReplyMarkup}, + types::{ChatId, Message, ReplyMarkup, InputFile}, }; ///As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 @@ -21,8 +21,7 @@ pub struct SendVideoNote<'a> { /// exists on the Telegram servers (recommended) or upload a new video /// using multipart/form-data. More info on Sending Files ». Sending video /// notes by a URL is currently unsupported - pub video_note: String, - // InputFile or String + pub video_note: InputFile, ///Duration of sent video in seconds #[serde(skip_serializing_if = "Option::is_none")] pub duration: Option, @@ -38,8 +37,7 @@ pub struct SendVideoNote<'a> { /// if the thumbnail was uploaded using multipart/form-data under /// . More info on Sending Files » #[serde(skip_serializing_if = "Option::is_none")] - pub thumb: Option, - // InputFile or String + pub thumb: Option, ///Sends the message silently. Users will receive a notification with no /// sound. #[serde(skip_serializing_if = "Option::is_none")] @@ -79,7 +77,7 @@ impl<'a> SendVideoNote<'a> { pub(crate) fn new(bot: &'a Bot, chat_id: C, video_note: V) -> Self where C: Into, - V: Into, + V: Into, { Self { bot, @@ -104,7 +102,7 @@ impl<'a> SendVideoNote<'a> { pub fn video_note(mut self, value: T) -> Self where - T: Into, + T: Into, { self.video_note = value.into(); self @@ -128,7 +126,7 @@ impl<'a> SendVideoNote<'a> { pub fn thumb(mut self, value: T) -> Self where - T: Into, + T: Into, { self.thumb = Some(value.into()); self diff --git a/src/requests/send_voice.rs b/src/requests/send_voice.rs index b591defc..184060a4 100644 --- a/src/requests/send_voice.rs +++ b/src/requests/send_voice.rs @@ -4,7 +4,7 @@ use crate::bot::Bot; use crate::{ network, requests::{Request, ResponseResult}, - types::{ChatId, Message, ParseMode, ReplyMarkup}, + types::{ChatId, Message, ParseMode, ReplyMarkup, InputFile}, }; ///Use this method to send audio files, if you want Telegram clients to display @@ -24,8 +24,7 @@ pub struct SendVoice<'a> { /// on the Telegram servers (recommended), 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 » - pub voice: String, - //InputFile or String + pub voice: InputFile, /// Voice message caption, 0-1024 characters #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, @@ -76,7 +75,7 @@ impl<'a> SendVoice<'a> { pub(crate) fn new(bot: &'a Bot, chat_id: C, voice: V) -> Self where C: Into, - V: Into, + V: Into, { Self { bot, @@ -101,7 +100,7 @@ impl<'a> SendVoice<'a> { pub fn voice(mut self, value: T) -> Self where - T: Into, + T: Into, { self.voice = value.into(); self From f2cd6278fb52eb7b5a41d0af8a587c9e16431bbb Mon Sep 17 00:00:00 2001 From: P0lunin Date: Thu, 17 Oct 2019 18:44:34 +0300 Subject: [PATCH 2/2] changed where necessary String to InputFile --- src/requests/send_animation.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/requests/send_animation.rs b/src/requests/send_animation.rs index 1f70465f..c7932270 100644 --- a/src/requests/send_animation.rs +++ b/src/requests/send_animation.rs @@ -40,8 +40,7 @@ pub struct SendAnimation<'a> { /// if the thumbnail was uploaded using multipart/form-data under /// » #[serde(skip_serializing_if = "Option::is_none")] - pub thumb: Option, - // InputFile or String Optional + pub thumb: Option, ///Animation caption (may also be used when resending animation by /// file_id), 0-1024 characters #[serde(skip_serializing_if = "Option::is_none")]