mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Format the code
This commit is contained in:
parent
e3873ca3b4
commit
7ddd8fce06
20 changed files with 64 additions and 75 deletions
|
@ -1,14 +1,14 @@
|
|||
use crate::{
|
||||
bot::Bot,
|
||||
requests::{
|
||||
AnswerPreCheckoutQuery, AnswerShippingQuery,
|
||||
EditMessageLiveLocation, ForwardMessage, GetFile, GetMe,
|
||||
KickChatMember, PinChatMessage, PromoteChatMember, RestrictChatMember,
|
||||
SendAudio, SendChatAction, SendContact, SendLocation, SendMediaGroup,
|
||||
SendMessage, SendPhoto, SendPoll, SendVenue, SendVideoNote, SendVoice,
|
||||
StopMessageLiveLocation, UnbanChatMember, UnpinChatMessage,
|
||||
AnswerPreCheckoutQuery, AnswerShippingQuery, EditMessageLiveLocation,
|
||||
ForwardMessage, GetFile, GetMe, KickChatMember, PinChatMessage,
|
||||
PromoteChatMember, RestrictChatMember, SendAudio, SendChatAction,
|
||||
SendContact, SendLocation, SendMediaGroup, SendMessage, SendPhoto,
|
||||
SendPoll, SendVenue, SendVideoNote, SendVoice, StopMessageLiveLocation,
|
||||
UnbanChatMember, UnpinChatMessage,
|
||||
},
|
||||
types::{ChatPermissions, InputFile, InputMedia, ChatAction, ChatId},
|
||||
types::{ChatAction, ChatId, ChatPermissions, InputFile, InputMedia},
|
||||
};
|
||||
|
||||
/// Telegram functions
|
||||
|
|
|
@ -1,17 +1,11 @@
|
|||
use tokio::io::AsyncWrite;
|
||||
#[cfg(feature = "unstable-stream")]
|
||||
use ::{
|
||||
bytes::Bytes,
|
||||
tokio::stream::Stream,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
bot::Bot,
|
||||
DownloadError,
|
||||
network::download_file,
|
||||
};
|
||||
#[cfg(feature = "unstable-stream")]
|
||||
use ::{bytes::Bytes, tokio::stream::Stream};
|
||||
|
||||
#[cfg(feature = "unstable-stream")]
|
||||
use crate::network::download_file_stream;
|
||||
use crate::{bot::Bot, network::download_file, DownloadError};
|
||||
|
||||
impl Bot {
|
||||
/// Download file from telegram into `destination`.
|
||||
|
@ -32,8 +26,7 @@ impl Bot {
|
|||
/// let bot = Bot::new("TOKEN");
|
||||
/// let mut file = File::create("/home/waffle/Pictures/test.png").await?;
|
||||
///
|
||||
/// let TgFile { file_path, .. } =
|
||||
/// bot.get_file("*file_id*").send().await?;
|
||||
/// let TgFile { file_path, .. } = bot.get_file("*file_id*").send().await?;
|
||||
/// bot.download_file(&file_path, &mut file).await?;
|
||||
/// # Ok(()) }
|
||||
/// ```
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
use reqwest::Client;
|
||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||
|
||||
#[cfg(feature = "unstable-stream")]
|
||||
use ::{
|
||||
tokio::stream::Stream,
|
||||
bytes::Bytes,
|
||||
};
|
||||
use ::{bytes::Bytes, tokio::stream::Stream};
|
||||
|
||||
use crate::DownloadError;
|
||||
|
||||
|
@ -44,11 +42,13 @@ 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,
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#[cfg(feature = "unstable-stream")]
|
||||
pub use download::download_file_stream;
|
||||
|
||||
pub use self::{
|
||||
download::download_file,
|
||||
request::{request_json, request_multipart},
|
||||
telegram_response::TelegramResponse,
|
||||
};
|
||||
#[cfg(feature = "unstable-stream")]
|
||||
pub use download::download_file_stream;
|
||||
|
||||
mod download;
|
||||
mod request;
|
||||
|
|
|
@ -4,7 +4,7 @@ use reqwest::multipart::Form;
|
|||
|
||||
use crate::{
|
||||
requests::utils,
|
||||
types::{InputMedia, ParseMode, ChatId},
|
||||
types::{ChatId, InputMedia, ParseMode},
|
||||
};
|
||||
|
||||
/// This is a convenient struct that builds `reqwest::multipart::Form`
|
||||
|
|
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, ResponseResult},
|
||||
types::{ChatId, Message}
|
||||
types::{ChatId, Message},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
|
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, ResponseResult},
|
||||
types::{ChatId, Chat}
|
||||
types::{Chat, ChatId},
|
||||
};
|
||||
|
||||
/// Use this method to get up to date information about the chat
|
||||
|
|
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
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
|
||||
|
|
|
@ -1,40 +1,28 @@
|
|||
use async_trait::async_trait;
|
||||
use reqwest::Client;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::RequestError;
|
||||
|
||||
pub use self::{
|
||||
answer_pre_checkout_query::AnswerPreCheckoutQuery,
|
||||
answer_shipping_query::AnswerShippingQuery,
|
||||
edit_message_live_location::EditMessageLiveLocation,
|
||||
forward_message::ForwardMessage,
|
||||
get_chat::GetChat,
|
||||
get_file::GetFile,
|
||||
get_me::GetMe,
|
||||
get_updates::GetUpdates,
|
||||
forward_message::ForwardMessage, get_chat::GetChat, get_file::GetFile,
|
||||
get_me::GetMe, get_updates::GetUpdates,
|
||||
get_user_profile_photos::GetUserProfilePhotos,
|
||||
kick_chat_member::KickChatMember,
|
||||
pin_chat_message::PinChatMessage,
|
||||
kick_chat_member::KickChatMember, pin_chat_message::PinChatMessage,
|
||||
promote_chat_member::PromoteChatMember,
|
||||
restrict_chat_member::RestrictChatMember,
|
||||
send_animation::SendAnimation,
|
||||
send_audio::SendAudio,
|
||||
send_chat_action::SendChatAction,
|
||||
send_contact::SendContact,
|
||||
send_document::SendDocument,
|
||||
send_location::SendLocation,
|
||||
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,
|
||||
restrict_chat_member::RestrictChatMember, send_animation::SendAnimation,
|
||||
send_audio::SendAudio, send_chat_action::SendChatAction,
|
||||
send_contact::SendContact, send_document::SendDocument,
|
||||
send_location::SendLocation, 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,
|
||||
unban_chat_member::UnbanChatMember,
|
||||
unpin_chat_message::UnpinChatMessage,
|
||||
unban_chat_member::UnbanChatMember, unpin_chat_message::UnpinChatMessage,
|
||||
};
|
||||
|
||||
mod form_builder;
|
||||
|
|
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, ResponseResult},
|
||||
types::{ChatId, True}
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
/// Use this method to get up to date information about the chat
|
||||
|
|
|
@ -49,6 +49,7 @@ pub struct PromoteChatMember<'a> {
|
|||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub can_promote_members: Option<bool>,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Request for PromoteChatMember<'_> {
|
||||
type ReturnValue = True;
|
||||
|
@ -69,6 +70,7 @@ impl PromoteChatMember<'_> {
|
|||
.await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PromoteChatMember<'a> {
|
||||
pub(crate) fn new(
|
||||
ctx: RequestContext<'a>,
|
||||
|
|
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
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
|
||||
|
|
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, ResponseResult},
|
||||
types::{ChatId, Message, ParseMode, ReplyMarkup}
|
||||
types::{ChatId, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
||||
// 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
|
||||
/// 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: String,
|
||||
//InputFile or String
|
||||
/// 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
|
||||
|
@ -32,7 +33,8 @@ pub struct SendDocument<'a> {
|
|||
/// if the thumbnail was uploaded using multipart/form-data under
|
||||
/// <file_attach_name>. More info on Sending Files »
|
||||
#[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
|
||||
/// file_id), 0-1024 characters
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use async_trait::async_trait;
|
||||
use serde::Serialize;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, ResponseResult},
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use apply::Apply;
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::{
|
||||
network::request_multipart,
|
||||
requests::{
|
||||
form_builder::FormBuilder, Request, RequestContext,
|
||||
ResponseResult,
|
||||
form_builder::FormBuilder, Request, RequestContext, ResponseResult,
|
||||
},
|
||||
types::{ChatId, InputFile, InputMedia, Message},
|
||||
};
|
||||
|
|
|
@ -3,8 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{
|
||||
form_builder::FormBuilder, Request, RequestContext,
|
||||
ResponseResult,
|
||||
form_builder::FormBuilder, Request, RequestContext, ResponseResult,
|
||||
},
|
||||
types::{ChatId, InputFile, Message, ParseMode, ReplyMarkup},
|
||||
};
|
||||
|
|
|
@ -20,7 +20,8 @@ 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: String,
|
||||
// InputFile or String
|
||||
///Duration of sent video in seconds
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub duration: Option<u64>,
|
||||
|
@ -36,7 +37,8 @@ pub struct SendVideoNote<'a> {
|
|||
/// if the thumbnail was uploaded using multipart/form-data under
|
||||
/// <file_attach_name>. More info on Sending Files »
|
||||
#[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
|
||||
/// sound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
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
|
||||
|
@ -23,7 +23,8 @@ 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: String,
|
||||
//InputFile or String
|
||||
/// Voice message caption, 0-1024 characters
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub caption: Option<String>,
|
||||
|
|
|
@ -3,7 +3,7 @@ use async_trait::async_trait;
|
|||
use crate::{
|
||||
network,
|
||||
requests::{Request, RequestContext, ResponseResult},
|
||||
types::{ChatId, True}
|
||||
types::{ChatId, True},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
|
|
|
@ -29,7 +29,7 @@ mod tests {
|
|||
let actual_json = serde_json::to_string(&ChatId::ChannelUsername(
|
||||
String::from("@username"),
|
||||
))
|
||||
.unwrap();
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(expected_json, actual_json)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue