Format the code

This commit is contained in:
Temirkhan Myrzamadi 2019-10-11 19:13:43 +06:00
parent e3873ca3b4
commit 7ddd8fce06
20 changed files with 64 additions and 75 deletions

View file

@ -1,14 +1,14 @@
use crate::{ use crate::{
bot::Bot, bot::Bot,
requests::{ requests::{
AnswerPreCheckoutQuery, AnswerShippingQuery, AnswerPreCheckoutQuery, AnswerShippingQuery, EditMessageLiveLocation,
EditMessageLiveLocation, ForwardMessage, GetFile, GetMe, ForwardMessage, GetFile, GetMe, KickChatMember, PinChatMessage,
KickChatMember, PinChatMessage, PromoteChatMember, RestrictChatMember, PromoteChatMember, RestrictChatMember, SendAudio, SendChatAction,
SendAudio, SendChatAction, SendContact, SendLocation, SendMediaGroup, SendContact, SendLocation, SendMediaGroup, SendMessage, SendPhoto,
SendMessage, SendPhoto, SendPoll, SendVenue, SendVideoNote, SendVoice, SendPoll, SendVenue, SendVideoNote, SendVoice, StopMessageLiveLocation,
StopMessageLiveLocation, UnbanChatMember, UnpinChatMessage, UnbanChatMember, UnpinChatMessage,
}, },
types::{ChatPermissions, InputFile, InputMedia, ChatAction, ChatId}, types::{ChatAction, ChatId, ChatPermissions, InputFile, InputMedia},
}; };
/// Telegram functions /// Telegram functions

View file

@ -1,17 +1,11 @@
use tokio::io::AsyncWrite; use tokio::io::AsyncWrite;
#[cfg(feature = "unstable-stream")]
use ::{
bytes::Bytes,
tokio::stream::Stream,
};
use crate::{ #[cfg(feature = "unstable-stream")]
bot::Bot, use ::{bytes::Bytes, tokio::stream::Stream};
DownloadError,
network::download_file,
};
#[cfg(feature = "unstable-stream")] #[cfg(feature = "unstable-stream")]
use crate::network::download_file_stream; use crate::network::download_file_stream;
use crate::{bot::Bot, network::download_file, DownloadError};
impl Bot { impl Bot {
/// Download file from telegram into `destination`. /// Download file from telegram into `destination`.
@ -32,8 +26,7 @@ impl Bot {
/// let bot = Bot::new("TOKEN"); /// let bot = Bot::new("TOKEN");
/// let mut file = File::create("/home/waffle/Pictures/test.png").await?; /// let mut file = File::create("/home/waffle/Pictures/test.png").await?;
/// ///
/// let TgFile { file_path, .. } = /// let TgFile { file_path, .. } = bot.get_file("*file_id*").send().await?;
/// bot.get_file("*file_id*").send().await?;
/// bot.download_file(&file_path, &mut file).await?; /// bot.download_file(&file_path, &mut file).await?;
/// # Ok(()) } /// # Ok(()) }
/// ``` /// ```

View file

@ -1,10 +1,8 @@
use reqwest::Client; use reqwest::Client;
use tokio::io::{AsyncWrite, AsyncWriteExt}; use tokio::io::{AsyncWrite, AsyncWriteExt};
#[cfg(feature = "unstable-stream")] #[cfg(feature = "unstable-stream")]
use ::{ use ::{bytes::Bytes, tokio::stream::Stream};
tokio::stream::Stream,
bytes::Bytes,
};
use crate::DownloadError; use crate::DownloadError;
@ -44,11 +42,13 @@ pub async fn download_file_stream(
.await? .await?
.error_for_status()?; .error_for_status()?;
Ok(futures::stream::unfold(res, |mut res| async { Ok(futures::stream::unfold(res, |mut res| {
async {
match res.chunk().await { match res.chunk().await {
Err(err) => Some((Err(err), res)), Err(err) => Some((Err(err), res)),
Ok(Some(c)) => Some((Ok(c), res)), Ok(Some(c)) => Some((Ok(c), res)),
Ok(None) => None, Ok(None) => None,
} }
}
})) }))
} }

View file

@ -1,10 +1,11 @@
#[cfg(feature = "unstable-stream")]
pub use download::download_file_stream;
pub use self::{ pub use self::{
download::download_file, download::download_file,
request::{request_json, request_multipart}, request::{request_json, request_multipart},
telegram_response::TelegramResponse, telegram_response::TelegramResponse,
}; };
#[cfg(feature = "unstable-stream")]
pub use download::download_file_stream;
mod download; mod download;
mod request; mod request;

View file

@ -4,7 +4,7 @@ use reqwest::multipart::Form;
use crate::{ use crate::{
requests::utils, requests::utils,
types::{InputMedia, ParseMode, ChatId}, types::{ChatId, InputMedia, ParseMode},
}; };
/// This is a convenient struct that builds `reqwest::multipart::Form` /// This is a convenient struct that builds `reqwest::multipart::Form`

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},
types::{ChatId, Message} types::{ChatId, Message},
}; };
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},
types::{ChatId, Chat} types::{Chat, ChatId},
}; };
/// Use this method to get up to date information about the chat /// Use this method to get up to date information about the chat

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},
types::{ChatId, True} types::{ChatId, True},
}; };
/// Use this method to kick a user from a group, a supergroup or a channel. In /// Use this method to kick a user from a group, a supergroup or a channel. In

View file

@ -1,40 +1,28 @@
use async_trait::async_trait;
use reqwest::Client; use reqwest::Client;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use async_trait::async_trait;
use crate::RequestError; use crate::RequestError;
pub use self::{ pub use self::{
answer_pre_checkout_query::AnswerPreCheckoutQuery, answer_pre_checkout_query::AnswerPreCheckoutQuery,
answer_shipping_query::AnswerShippingQuery, answer_shipping_query::AnswerShippingQuery,
edit_message_live_location::EditMessageLiveLocation, edit_message_live_location::EditMessageLiveLocation,
forward_message::ForwardMessage, forward_message::ForwardMessage, get_chat::GetChat, get_file::GetFile,
get_chat::GetChat, get_me::GetMe, get_updates::GetUpdates,
get_file::GetFile,
get_me::GetMe,
get_updates::GetUpdates,
get_user_profile_photos::GetUserProfilePhotos, get_user_profile_photos::GetUserProfilePhotos,
kick_chat_member::KickChatMember, kick_chat_member::KickChatMember, pin_chat_message::PinChatMessage,
pin_chat_message::PinChatMessage,
promote_chat_member::PromoteChatMember, promote_chat_member::PromoteChatMember,
restrict_chat_member::RestrictChatMember, restrict_chat_member::RestrictChatMember, send_animation::SendAnimation,
send_animation::SendAnimation, send_audio::SendAudio, send_chat_action::SendChatAction,
send_audio::SendAudio, send_contact::SendContact, send_document::SendDocument,
send_chat_action::SendChatAction, send_location::SendLocation, send_media_group::SendMediaGroup,
send_contact::SendContact, send_message::SendMessage, send_photo::SendPhoto, send_poll::SendPoll,
send_document::SendDocument, send_venue::SendVenue, send_video::SendVideo,
send_location::SendLocation, send_video_note::SendVideoNote, send_voice::SendVoice,
send_media_group::SendMediaGroup,
send_message::SendMessage,
send_photo::SendPhoto,
send_poll::SendPoll,
send_venue::SendVenue,
send_video::SendVideo,
send_video_note::SendVideoNote,
send_voice::SendVoice,
stop_message_live_location::StopMessageLiveLocation, stop_message_live_location::StopMessageLiveLocation,
unban_chat_member::UnbanChatMember, unban_chat_member::UnbanChatMember, unpin_chat_message::UnpinChatMessage,
unpin_chat_message::UnpinChatMessage,
}; };
mod form_builder; mod form_builder;

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},
types::{ChatId, True} types::{ChatId, True},
}; };
/// Use this method to get up to date information about the chat /// Use this method to get up to date information about the chat

View file

@ -49,6 +49,7 @@ pub struct PromoteChatMember<'a> {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub can_promote_members: Option<bool>, pub can_promote_members: Option<bool>,
} }
#[async_trait] #[async_trait]
impl Request for PromoteChatMember<'_> { impl Request for PromoteChatMember<'_> {
type ReturnValue = True; type ReturnValue = True;
@ -69,6 +70,7 @@ impl PromoteChatMember<'_> {
.await .await
} }
} }
impl<'a> PromoteChatMember<'a> { impl<'a> PromoteChatMember<'a> {
pub(crate) fn new( pub(crate) fn new(
ctx: RequestContext<'a>, ctx: RequestContext<'a>,

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},
types::{ChatId, True, ChatAction} types::{ChatAction, ChatId, True},
}; };
///Use this method when you need to tell the user that something is happening ///Use this method when you need to tell the user that something is happening

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},
types::{ChatId, Message, ParseMode, ReplyMarkup} types::{ChatId, Message, ParseMode, ReplyMarkup},
}; };
// TODO: add method to bot/api // TODO: add method to bot/api
@ -22,7 +22,8 @@ pub struct SendDocument<'a> {
/// the Telegram servers (recommended), pass an HTTP URL as a String for /// 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 /// Telegram to get a file from the Internet, or upload a new one using
/// multipart/form-data.» /// multipart/form-data.»
pub document: String, //InputFile or String pub document: String,
//InputFile or String
/// Thumbnail of the file sent; can be ignored if thumbnail generation for /// Thumbnail of the file sent; can be ignored if thumbnail generation for
/// the file is supported server-side. The thumbnail should be in JPEG /// the file is supported server-side. The thumbnail should be in JPEG
/// format and less than 200 kB in size. A thumbnails width and height /// format and less than 200 kB in size. A thumbnails width and height
@ -32,7 +33,8 @@ pub struct SendDocument<'a> {
/// if the thumbnail was uploaded using multipart/form-data under /// if the thumbnail was uploaded using multipart/form-data under
/// <file_attach_name>. More info on Sending Files » /// <file_attach_name>. More info on Sending Files »
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<String>, //InputFile or String pub thumb: Option<String>,
//InputFile or String
/// Document caption (may also be used when resending documents by /// Document caption (may also be used when resending documents by
/// file_id), 0-1024 characters /// file_id), 0-1024 characters
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]

View file

@ -1,6 +1,7 @@
use async_trait::async_trait;
use serde::Serialize; use serde::Serialize;
use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},

View file

@ -1,11 +1,11 @@
use apply::Apply; use apply::Apply;
use async_trait::async_trait; use async_trait::async_trait;
use crate::{ use crate::{
network::request_multipart, network::request_multipart,
requests::{ requests::{
form_builder::FormBuilder, Request, RequestContext, form_builder::FormBuilder, Request, RequestContext, ResponseResult,
ResponseResult,
}, },
types::{ChatId, InputFile, InputMedia, Message}, types::{ChatId, InputFile, InputMedia, Message},
}; };

View file

@ -3,8 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{ requests::{
form_builder::FormBuilder, Request, RequestContext, form_builder::FormBuilder, Request, RequestContext, ResponseResult,
ResponseResult,
}, },
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup}, types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
}; };

View file

@ -20,7 +20,8 @@ pub struct SendVideoNote<'a> {
/// exists on the Telegram servers (recommended) or upload a new video /// exists on the Telegram servers (recommended) or upload a new video
/// using multipart/form-data. More info on Sending Files ». Sending video /// using multipart/form-data. More info on Sending Files ». Sending video
/// notes by a URL is currently unsupported /// notes by a URL is currently unsupported
pub video_note: String, // InputFile or String pub video_note: String,
// InputFile or String
///Duration of sent video in seconds ///Duration of sent video in seconds
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub duration: Option<u64>, pub duration: Option<u64>,
@ -36,7 +37,8 @@ pub struct SendVideoNote<'a> {
/// if the thumbnail was uploaded using multipart/form-data under /// if the thumbnail was uploaded using multipart/form-data under
/// <file_attach_name>. More info on Sending Files » /// <file_attach_name>. More info on Sending Files »
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumb: Option<String>, // InputFile or String pub thumb: Option<String>,
// InputFile or String
///Sends the message silently. Users will receive a notification with no ///Sends the message silently. Users will receive a notification with no
/// sound. /// sound.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},
types::{ChatId, Message, ParseMode, ReplyMarkup} types::{ChatId, Message, ParseMode, ReplyMarkup},
}; };
///Use this method to send audio files, if you want Telegram clients to display ///Use this method to send audio files, if you want Telegram clients to display
@ -23,7 +23,8 @@ pub struct SendVoice<'a> {
/// on the Telegram servers (recommended), pass an HTTP URL as a String for /// 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 /// Telegram to get a file from the Internet, or upload a new one using
/// multipart/form-data. More info on Sending Files » /// multipart/form-data. More info on Sending Files »
pub voice: String, //InputFile or String pub voice: String,
//InputFile or String
/// Voice message caption, 0-1024 characters /// Voice message caption, 0-1024 characters
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub caption: Option<String>, pub caption: Option<String>,

View file

@ -3,7 +3,7 @@ use async_trait::async_trait;
use crate::{ use crate::{
network, network,
requests::{Request, RequestContext, ResponseResult}, requests::{Request, RequestContext, ResponseResult},
types::{ChatId, True} types::{ChatId, True},
}; };
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]