From b71088746c5e2d7a8a11c71f454946d0b4514ad3 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Sun, 26 Jan 2020 04:18:13 +0600 Subject: [PATCH] Bullshit --- src/dispatching/update_listeners.rs | 30 +++-- src/network/download.rs | 12 +- src/requests/all/.fuse_hidden000042e60000000a | 118 ++++++++++++++++++ src/requests/all/.fuse_hidden000042e60000000b | 118 ++++++++++++++++++ src/requests/all/.fuse_hidden0000454500000009 | 15 +++ src/types/message.rs | 8 +- src/types/user.rs | 3 +- 7 files changed, 279 insertions(+), 25 deletions(-) create mode 100644 src/requests/all/.fuse_hidden000042e60000000a create mode 100644 src/requests/all/.fuse_hidden000042e60000000b create mode 100644 src/requests/all/.fuse_hidden0000454500000009 diff --git a/src/dispatching/update_listeners.rs b/src/dispatching/update_listeners.rs index 815e8e96..9a0722f6 100644 --- a/src/dispatching/update_listeners.rs +++ b/src/dispatching/update_listeners.rs @@ -146,25 +146,23 @@ pub fn polling( stream::unfold( (allowed_updates, bot, 0), - move |(mut allowed_updates, bot, mut offset)| { - async move { - let mut req = bot.get_updates().offset(offset); - req.timeout = timeout; - req.limit = limit; - req.allowed_updates = allowed_updates.take(); + move |(mut allowed_updates, bot, mut offset)| async move { + let mut req = bot.get_updates().offset(offset); + req.timeout = timeout; + req.limit = limit; + req.allowed_updates = allowed_updates.take(); - let updates = match req.send().await { - Err(err) => vec![Err(err)], - Ok(updates) => { - if let Some(upd) = updates.last() { - offset = upd.id + 1; - } - updates.into_iter().map(Ok).collect::>() + let updates = match req.send().await { + Err(err) => vec![Err(err)], + Ok(updates) => { + if let Some(upd) = updates.last() { + offset = upd.id + 1; } - }; + updates.into_iter().map(Ok).collect::>() + } + }; - Some((stream::iter(updates), (allowed_updates, bot, offset))) - } + Some((stream::iter(updates), (allowed_updates, bot, offset))) }, ) .flatten() diff --git a/src/network/download.rs b/src/network/download.rs index 0e68414f..05f08f5d 100644 --- a/src/network/download.rs +++ b/src/network/download.rs @@ -39,13 +39,11 @@ pub async fn download_file_stream( .await? .error_for_status()?; - Ok(futures::stream::unfold(res, |mut res| { - async { - match res.chunk().await { - Err(err) => Some((Err(err), res)), - Ok(Some(c)) => Some((Ok(c), res)), - Ok(None) => None, - } + Ok(futures::stream::unfold(res, |mut res| async { + match res.chunk().await { + Err(err) => Some((Err(err), res)), + Ok(Some(c)) => Some((Ok(c), res)), + Ok(None) => None, } })) } diff --git a/src/requests/all/.fuse_hidden000042e60000000a b/src/requests/all/.fuse_hidden000042e60000000a new file mode 100644 index 00000000..c5a3f878 --- /dev/null +++ b/src/requests/all/.fuse_hidden000042e60000000a @@ -0,0 +1,118 @@ +use crate::{ + network, + requests::form_builder::FormBuilder, + types::{InputFile, MaskPosition, True}, + Bot, +}; + +use crate::requests::{Request, ResponseResult}; + +/// Use this method to add a new sticker to a set created by the bot. +/// +/// [The official docs](https://core.telegram.org/bots/api#addstickertoset). +#[derive(Copy, Eq, PartialEq, Debug, Clone)] +pub struct AddStickerToSet<'a> { + bot: &'a Bot, + user_id: i32, + name: String, + png_sticker: InputFile, + emojis: String, + mask_position: Option, +} + +#[async_trait::async_trait] +impl Request for AddStickerToSet<'_> { + type Output = True; + + async fn send(&self) -> ResponseResult { + network::request_multipart( + self.bot.client(), + self.bot.token(), + "addStickerToSet", + FormBuilder::new() + .add("user_id", &self.user_id) + .await + .add("name", &self.name) + .await + .add("png_sticker", &self.png_sticker) + .await + .add("emojis", &self.emojis) + .await + .add("mask_position", &self.mask_position) + .await + .build(), + ) + .await + } +} + +impl<'a> AddStickerToSet<'a> { + pub(crate) fn new( + bot: &'a Bot, + user_id: i32, + name: N, + png_sticker: InputFile, + emojis: E, + ) -> Self + where + N: Into, + E: Into, + { + Self { + bot: BotWrapper(bot), + user_id, + name: name.into(), + png_sticker, + emojis: emojis.into(), + mask_position: None, + } + } + + /// User identifier of sticker set owner. + pub fn user_id(mut self, val: i32) -> Self { + self.user_id = val; + self + } + + /// Sticker set name. + pub fn name(mut self, val: T) -> Self + where + T: Into, + { + self.name = val.into(); + self + } + + /// **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. + /// + /// Pass [`InputFile::File`] 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::FileId`]. [More info on Sending Files »]. + /// + /// [`InputFile::File`]: crate::types::InputFile::File + /// [`InputFile::Url`]: crate::types::InputFile::Url + /// [`InputFile::FileId`]: crate::types::InputFile::FileId + pub fn png_sticker(mut self, val: InputFile) -> Self { + self.png_sticker = val; + self + } + + /// One or more emoji corresponding to the sticker. + pub fn emojis(mut self, val: T) -> Self + where + T: Into, + { + self.emojis = val.into(); + self + } + + /// A JSON-serialized object for position where the mask should be placed on + /// faces. + pub fn mask_position(mut self, val: MaskPosition) -> Self { + self.mask_position = Some(val); + self + } +} diff --git a/src/requests/all/.fuse_hidden000042e60000000b b/src/requests/all/.fuse_hidden000042e60000000b new file mode 100644 index 00000000..93f36d92 --- /dev/null +++ b/src/requests/all/.fuse_hidden000042e60000000b @@ -0,0 +1,118 @@ +use crate::{ + network, + requests::form_builder::FormBuilder, + types::{InputFile, MaskPosition, True}, + Bot, +}; + +use crate::requests::{Request, ResponseResult}; + +/// Use this method to add a new sticker to a set created by the bot. +/// +/// [The official docs](https://core.telegram.org/bots/api#addstickertoset). +#[derive(Copy, Eq, PartialEq, Debug, Clone)] +pub struct AddStickerToSet<'a> { + bot: &'a Bot, + user_id: i32, + name: String, + png_sticker: InputFile, + emojis: String, + mask_position: Option, +} + +#[async_trait::async_trait] +impl Request for AddStickerToSet<'_> { + type Output = True; + + async fn send(&self) -> ResponseResult { + network::request_multipart( + self.bot.client(), + self.bot.token(), + "addStickerToSet", + FormBuilder::new() + .add("user_id", &self.user_id) + .await + .add("name", &self.name) + .await + .add("png_sticker", &self.png_sticker) + .await + .add("emojis", &self.emojis) + .await + .add("mask_position", &self.mask_position) + .await + .build(), + ) + .await + } +} + +impl<'a> AddStickerToSet<'a> { + pub(crate) fn new( + bot: &'a Bot, + user_id: i32, + name: N, + png_sticker: InputFile, + emojis: E, + ) -> Self + where + N: Into, + E: Into, + { + Self { + bot, + user_id, + name: name.into(), + png_sticker, + emojis: emojis.into(), + mask_position: None, + } + } + + /// User identifier of sticker set owner. + pub fn user_id(mut self, val: i32) -> Self { + self.user_id = val; + self + } + + /// Sticker set name. + pub fn name(mut self, val: T) -> Self + where + T: Into, + { + self.name = val.into(); + self + } + + /// **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. + /// + /// Pass [`InputFile::File`] 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::FileId`]. [More info on Sending Files »]. + /// + /// [`InputFile::File`]: crate::types::InputFile::File + /// [`InputFile::Url`]: crate::types::InputFile::Url + /// [`InputFile::FileId`]: crate::types::InputFile::FileId + pub fn png_sticker(mut self, val: InputFile) -> Self { + self.png_sticker = val; + self + } + + /// One or more emoji corresponding to the sticker. + pub fn emojis(mut self, val: T) -> Self + where + T: Into, + { + self.emojis = val.into(); + self + } + + /// A JSON-serialized object for position where the mask should be placed on + /// faces. + pub fn mask_position(mut self, val: MaskPosition) -> Self { + self.mask_position = Some(val); + self + } +} diff --git a/src/requests/all/.fuse_hidden0000454500000009 b/src/requests/all/.fuse_hidden0000454500000009 new file mode 100644 index 00000000..f6ab9b90 --- /dev/null +++ b/src/requests/all/.fuse_hidden0000454500000009 @@ -0,0 +1,15 @@ +use crate::{ + network, + requests::form_builder::FormBuilder, + types::{InputFile, MaskPosition, True}, + Bot, +}; + +use crate::requests::{Request, ResponseResult}; + +/// Use this method to add a new sticker to a set created by the bot. +/// +/// [The official docs](https://core.telegram.org/bots/api#addstickertoset). +#[derive(Copy, Eq, PartialEq, Debug, Clone)] +pub struct AddStickerToSet<'a> { + \ No newline at end of file diff --git a/src/types/message.rs b/src/types/message.rs index e4621dde..9e0d0a73 100644 --- a/src/types/message.rs +++ b/src/types/message.rs @@ -812,7 +812,13 @@ impl Message { .. }, .. - } => Some(reqwest::Url::parse(format!("https://t.me/{0}/{1}/", username, self.id).as_str()).unwrap()), + } => Some( + reqwest::Url::parse( + format!("https://t.me/{0}/{1}/", username, self.id) + .as_str(), + ) + .unwrap(), + ), _ => None, } } diff --git a/src/types/user.rs b/src/types/user.rs index 26455ab2..f1dd1180 100644 --- a/src/types/user.rs +++ b/src/types/user.rs @@ -41,7 +41,8 @@ impl User { } pub fn url(&self) -> reqwest::Url { - reqwest::Url::parse(format!("tg://user/?id={}", self.id).as_str()).unwrap() + reqwest::Url::parse(format!("tg://user/?id={}", self.id).as_str()) + .unwrap() } }