mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
cargo fmt
This commit is contained in:
parent
f37552536e
commit
f95ea5ee31
14 changed files with 48 additions and 49 deletions
|
@ -1,17 +1,12 @@
|
||||||
use reqwest::r#async::Chunk;
|
use reqwest::r#async::Chunk;
|
||||||
use tokio::{
|
use tokio::{io::AsyncWrite, stream::Stream};
|
||||||
io::AsyncWrite,
|
|
||||||
stream::Stream,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
DownloadError,
|
|
||||||
bot::Bot,
|
bot::Bot,
|
||||||
network::{download_file, download_file_stream},
|
network::{download_file, download_file_stream},
|
||||||
|
DownloadError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
impl Bot {
|
impl Bot {
|
||||||
/// Download file from telegram into `destination`.
|
/// Download file from telegram into `destination`.
|
||||||
/// `path` can be obtained from [`get_file`] method.
|
/// `path` can be obtained from [`get_file`] method.
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
use reqwest::r#async::{Client, Chunk};
|
use reqwest::r#async::{Chunk, Client};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
stream::Stream,
|
|
||||||
io::{AsyncWrite, AsyncWriteExt},
|
io::{AsyncWrite, AsyncWriteExt},
|
||||||
|
stream::Stream,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
network::{file_url, TELEGRAM_API_URL},
|
||||||
DownloadError,
|
DownloadError,
|
||||||
network::{TELEGRAM_API_URL, file_url},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
pub async fn download_file<D>(
|
pub async fn download_file<D>(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
token: &str,
|
token: &str,
|
||||||
path: &str,
|
path: &str,
|
||||||
destination: &mut D,
|
destination: &mut D,
|
||||||
) -> Result<(), DownloadError>
|
) -> Result<(), DownloadError>
|
||||||
where
|
where
|
||||||
D: AsyncWrite + Unpin,
|
D: AsyncWrite + Unpin,
|
||||||
{
|
{
|
||||||
let mut stream = download_file_stream(client, token, path).await?;
|
let mut stream = download_file_stream(client, token, path).await?;
|
||||||
|
|
||||||
|
@ -36,4 +35,4 @@ pub(crate) async fn download_file_stream(
|
||||||
let url = file_url(TELEGRAM_API_URL, token, path);
|
let url = file_url(TELEGRAM_API_URL, token, path);
|
||||||
let resp = client.get(&url).send().await?.error_for_status()?;
|
let resp = client.get(&url).send().await?.error_for_status()?;
|
||||||
Ok(resp.into_body())
|
Ok(resp.into_body())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
|
||||||
use reqwest::r#async::{
|
|
||||||
Client, multipart::Form, Response,
|
|
||||||
};
|
|
||||||
use apply::Apply;
|
use apply::Apply;
|
||||||
|
use reqwest::r#async::{multipart::Form, Client, Response};
|
||||||
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
RequestError,
|
|
||||||
requests::ResponseResult,
|
|
||||||
network::{method_url, TELEGRAM_API_URL},
|
network::{method_url, TELEGRAM_API_URL},
|
||||||
|
requests::ResponseResult,
|
||||||
|
RequestError,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
pub async fn request_multipart<T>(
|
pub async fn request_multipart<T>(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
token: &str,
|
token: &str,
|
||||||
method_name: &str,
|
method_name: &str,
|
||||||
params: Option<Form>,
|
params: Option<Form>,
|
||||||
) -> ResponseResult<T> where T: DeserializeOwned {
|
) -> ResponseResult<T>
|
||||||
|
where
|
||||||
|
T: DeserializeOwned,
|
||||||
|
{
|
||||||
process_response(
|
process_response(
|
||||||
client
|
client
|
||||||
.post(&method_url(TELEGRAM_API_URL, token, method_name))
|
.post(&method_url(TELEGRAM_API_URL, token, method_name))
|
||||||
|
@ -28,7 +28,7 @@ pub async fn request_multipart<T>(
|
||||||
.await
|
.await
|
||||||
.map_err(RequestError::NetworkError)?,
|
.map_err(RequestError::NetworkError)?,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn request_json<T: DeserializeOwned, P: Serialize>(
|
pub async fn request_json<T: DeserializeOwned, P: Serialize>(
|
||||||
|
@ -45,7 +45,7 @@ pub async fn request_json<T: DeserializeOwned, P: Serialize>(
|
||||||
.await
|
.await
|
||||||
.map_err(RequestError::NetworkError)?,
|
.map_err(RequestError::NetworkError)?,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_response<T: DeserializeOwned>(
|
async fn process_response<T: DeserializeOwned>(
|
||||||
|
@ -54,7 +54,7 @@ async fn process_response<T: DeserializeOwned>(
|
||||||
let response = serde_json::from_str::<TelegramResponse<T>>(
|
let response = serde_json::from_str::<TelegramResponse<T>>(
|
||||||
&response.text().await.map_err(RequestError::NetworkError)?,
|
&response.text().await.map_err(RequestError::NetworkError)?,
|
||||||
)
|
)
|
||||||
.map_err(RequestError::InvalidJson)?;
|
.map_err(RequestError::InvalidJson)?;
|
||||||
|
|
||||||
response.into()
|
response.into()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
network,
|
network,
|
||||||
requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult},
|
requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
},
|
||||||
types::{Message, ReplyMarkup},
|
types::{Message, ReplyMarkup},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
network,
|
network,
|
||||||
|
requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
},
|
||||||
types::Chat,
|
types::Chat,
|
||||||
requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Use this method to get up to date information about the chat
|
/// Use this method to get up to date information about the chat
|
||||||
/// (current name of the user for one-on-one conversations,
|
/// (current name of the user for one-on-one conversations,
|
||||||
/// current username of a user, group or channel, etc.).
|
/// current username of a user, group or channel, etc.).
|
||||||
/// Returns a Chat object on success.
|
/// Returns a Chat object on success.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
pub struct GetChat<'a> {
|
pub struct GetChat<'a> {
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip_serializing)]
|
||||||
ctx: RequestContext<'a>,
|
ctx: RequestContext<'a>,
|
||||||
/// Unique identifier for the target chat or username
|
/// Unique identifier for the target chat or username
|
||||||
/// of the target supergroup or channel (in the format @channelusername)
|
/// of the target supergroup or channel (in the format @channelusername)
|
||||||
chat_id: ChatId,
|
chat_id: ChatId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl<'a> Request<'a> for GetChat<'a> {
|
impl<'a> Request<'a> for GetChat<'a> {
|
||||||
type ReturnValue = Chat;
|
type ReturnValue = Chat;
|
||||||
|
|
||||||
|
@ -28,16 +29,16 @@ impl<'a> Request<'a> for GetChat<'a> {
|
||||||
&self.ctx.token,
|
&self.ctx.token,
|
||||||
"getChat",
|
"getChat",
|
||||||
&self,
|
&self,
|
||||||
).await
|
)
|
||||||
|
.await
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> GetChat<'a> {
|
||||||
impl<'a> GetChat<'a>{
|
|
||||||
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
pub fn chat_id<T>(mut self, chat_id: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<ChatId>,
|
T: Into<ChatId>,
|
||||||
{
|
{
|
||||||
self.chat_id = chat_id.into();
|
self.chat_id = chat_id.into();
|
||||||
self
|
self
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::{
|
||||||
types::File,
|
types::File,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Use this method to get basic info about a file and prepare it for
|
/// Use this method to get basic info about a file and prepare it for
|
||||||
/// downloading. For the moment, bots can download files of up to 20MB in size.
|
/// downloading. For the moment, bots can download files of up to 20MB in size.
|
||||||
/// On success, a File object is returned.
|
/// On success, a File object is returned.
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
network,
|
network,
|
||||||
requests::{
|
requests::{
|
||||||
form_builder::FormBuilder, ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
form_builder::FormBuilder, ChatId, Request, RequestContext,
|
||||||
|
RequestFuture, ResponseResult,
|
||||||
},
|
},
|
||||||
types::{InputFile, Message, ParseMode, ReplyMarkup},
|
types::{InputFile, Message, ParseMode, ReplyMarkup},
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
network,
|
network,
|
||||||
requests::{
|
requests::{
|
||||||
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
///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
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
network,
|
network,
|
||||||
requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult},
|
requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
},
|
||||||
types::{Message, ReplyMarkup},
|
types::{Message, ReplyMarkup},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Use this method to send phone contacts.
|
/// Use this method to send phone contacts.
|
||||||
/// returned.
|
/// returned.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
|
|
@ -9,7 +9,6 @@ use crate::{
|
||||||
types::{InputFile, InputMedia, Message},
|
types::{InputFile, InputMedia, Message},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Use this method to send a group of photos or videos as an album.
|
/// Use this method to send a group of photos or videos as an album.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SendMediaGroup<'a> {
|
pub struct SendMediaGroup<'a> {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
network,
|
network,
|
||||||
requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult},
|
requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
},
|
||||||
types::{Message, ReplyMarkup},
|
types::{Message, ReplyMarkup},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Use this method to send a native poll. A native poll can't be sent to a
|
/// Use this method to send a native poll. A native poll can't be sent to a
|
||||||
/// private chat. On success, the sent Message is returned.
|
/// private chat. On success, the sent Message is returned.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
network,
|
network,
|
||||||
requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult},
|
requests::{
|
||||||
|
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
|
||||||
|
},
|
||||||
types::{Message, ReplyMarkup},
|
types::{Message, ReplyMarkup},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Use this method to send information about a venue.
|
/// Use this method to send information about a venue.
|
||||||
/// Message is returned.
|
/// Message is returned.
|
||||||
#[derive(Debug, Clone, Serialize)]
|
#[derive(Debug, Clone, Serialize)]
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
/// A placeholder, currently holds no information. Use [BotFather](https://t.me/botfather) to set up your game.
|
/// A placeholder, currently holds no information. Use [BotFather](https://t.me/botfather) to set up your game.
|
||||||
pub struct CallbackGame;
|
pub struct CallbackGame;
|
||||||
|
|
|
@ -7,4 +7,4 @@ pub struct LoginUrl {
|
||||||
pub bot_username: Option<String>,
|
pub bot_username: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub request_write_access: Option<bool>,
|
pub request_write_access: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue