mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-31 16:40:37 +01:00
Update the dependencies
This commit is contained in:
parent
e9c356c4df
commit
24d76b59b3
19 changed files with 235 additions and 138 deletions
27
Cargo.toml
27
Cargo.toml
|
@ -6,21 +6,20 @@ edition = "2018"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.10.0-alpha.1", features = ["json", "unstable-stream"] }
|
||||
serde_json = "1.0.41"
|
||||
serde_json = "1.0.44"
|
||||
serde = { version = "1.0.101", features = ["derive"] }
|
||||
derive_more = "0.15.0"
|
||||
tokio = "0.2.0-alpha.6"
|
||||
bytes = "0.4.12"
|
||||
|
||||
tokio = { version = "0.2.6", features = ["full"] }
|
||||
tokio-util = { version = "0.2.0", features = ["full"] }
|
||||
|
||||
reqwest = { version = "0.10", features = ["json", "stream"] }
|
||||
log = "0.4.8"
|
||||
pin-project = "0.4.0-alpha.7"
|
||||
futures-preview = "0.3.0-alpha.19"
|
||||
async-trait = "0.1.13"
|
||||
thiserror = "1.0.2"
|
||||
bytes = "0.5.3"
|
||||
|
||||
derive_more = "0.99.2"
|
||||
thiserror = "1.0.9"
|
||||
async-trait = "0.1.22"
|
||||
futures = "0.3.1"
|
||||
pin-project = "0.4.6"
|
||||
serde_with_macros = "1.0.1"
|
||||
either = "1.5.3"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
unstable-stream = [] # add streams to public API
|
||||
|
|
|
@ -186,7 +186,8 @@ impl<'a, HandlerE, Eh> FilterDispatcher<'a, HandlerE, Eh> {
|
|||
Eh: ErrorHandler<Either<UpdaterE, HandlerE>>,
|
||||
{
|
||||
updater
|
||||
.for_each_concurrent(None, |res| async {
|
||||
.for_each_concurrent(None, |res| {
|
||||
async {
|
||||
let Update { kind, id } = match res {
|
||||
Ok(upd) => upd,
|
||||
Err(err) => {
|
||||
|
@ -261,6 +262,7 @@ impl<'a, HandlerE, Eh> FilterDispatcher<'a, HandlerE, Eh> {
|
|||
.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -308,13 +310,17 @@ mod tests {
|
|||
let counter2 = &AtomicI32::new(0);
|
||||
|
||||
let mut dp = FilterDispatcher::<Infallible, _>::new(|_| async {})
|
||||
.message_handler(true, |_mes: Message| async move {
|
||||
.message_handler(true, |_mes: Message| {
|
||||
async move {
|
||||
counter.fetch_add(1, Ordering::SeqCst);
|
||||
Ok::<_, Infallible>(())
|
||||
}
|
||||
})
|
||||
.message_handler(true, |_mes: Message| async move {
|
||||
.message_handler(true, |_mes: Message| {
|
||||
async move {
|
||||
counter2.fetch_add(1, Ordering::SeqCst);
|
||||
Ok::<_, Infallible>(())
|
||||
}
|
||||
});
|
||||
|
||||
dp.dispatch(one_message_updater()).await;
|
||||
|
|
|
@ -146,7 +146,8 @@ pub fn polling(
|
|||
|
||||
stream::unfold(
|
||||
(allowed_updates, bot, 0),
|
||||
move |(mut allowed_updates, bot, mut offset)| async move {
|
||||
move |(mut allowed_updates, bot, mut offset)| {
|
||||
async move {
|
||||
let mut req = bot.get_updates().offset(offset);
|
||||
req.timeout = timeout;
|
||||
req.limit = limit;
|
||||
|
@ -163,6 +164,7 @@ pub fn polling(
|
|||
};
|
||||
|
||||
Some((stream::iter(updates), (allowed_updates, bot, offset)))
|
||||
}
|
||||
},
|
||||
)
|
||||
.flatten()
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
use reqwest::Client;
|
||||
use tokio::io::{AsyncWrite, AsyncWriteExt};
|
||||
|
||||
#[cfg(feature = "unstable-stream")]
|
||||
use ::{bytes::Bytes, tokio::stream::Stream};
|
||||
|
||||
use crate::DownloadError;
|
||||
use crate::errors::DownloadError;
|
||||
|
||||
use super::TELEGRAM_API_URL;
|
||||
|
||||
|
@ -42,11 +39,13 @@ pub async fn download_file_stream(
|
|||
.await?
|
||||
.error_for_status()?;
|
||||
|
||||
Ok(futures::stream::unfold(res, |mut res| async {
|
||||
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,
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
|
@ -46,10 +46,15 @@ impl Request for AddStickerToSet<'_> {
|
|||
"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
|
||||
|
|
|
@ -52,12 +52,19 @@ impl Request for CreateNewStickerSet<'_> {
|
|||
"createNewStickerSet",
|
||||
FormBuilder::new()
|
||||
.add("user_id", &self.user_id)
|
||||
.await
|
||||
.add("name", &self.name)
|
||||
.await
|
||||
.add("title", &self.title)
|
||||
.await
|
||||
.add("png_sticker", &self.png_sticker)
|
||||
.await
|
||||
.add("emojis", &self.emojis)
|
||||
.await
|
||||
.add("contains_masks", &self.contains_masks)
|
||||
.await
|
||||
.add("mask_position", &self.mask_position)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -43,10 +43,13 @@ impl Request for EditMessageMedia<'_> {
|
|||
} => {
|
||||
params = params
|
||||
.add("chat_id", chat_id)
|
||||
.add("message_id", message_id);
|
||||
.await
|
||||
.add("message_id", message_id)
|
||||
.await;
|
||||
}
|
||||
ChatOrInlineMessage::Inline { inline_message_id } => {
|
||||
params = params.add("inline_message_id", inline_message_id);
|
||||
params =
|
||||
params.add("inline_message_id", inline_message_id).await;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +59,9 @@ impl Request for EditMessageMedia<'_> {
|
|||
"editMessageMedia",
|
||||
params
|
||||
.add("media", &self.media)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -72,16 +72,27 @@ impl Request for SendAnimation<'_> {
|
|||
"sendAnimation",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("animation", &self.animation)
|
||||
.await
|
||||
.add("duration", &self.duration)
|
||||
.await
|
||||
.add("width", &self.width)
|
||||
.await
|
||||
.add("height", &self.height)
|
||||
.await
|
||||
.add("thumb", &self.thumb)
|
||||
.await
|
||||
.add("caption", &self.caption)
|
||||
.await
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -68,16 +68,27 @@ impl Request for SendAudio<'_> {
|
|||
"sendAudio",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("audio", &self.audio)
|
||||
.await
|
||||
.add("caption", &self.caption)
|
||||
.await
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.await
|
||||
.add("duration", &self.duration)
|
||||
.await
|
||||
.add("performer", &self.performer)
|
||||
.await
|
||||
.add("title", &self.title)
|
||||
.await
|
||||
.add("thumb", &self.thumb)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -61,13 +61,21 @@ impl Request for SendDocument<'_> {
|
|||
"sendDocument",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("document", &self.document)
|
||||
.await
|
||||
.add("thumb", &self.thumb)
|
||||
.await
|
||||
.add("caption", &self.caption)
|
||||
.await
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -39,9 +39,13 @@ impl Request for SendMediaGroup<'_> {
|
|||
"sendMediaGroup",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("media", &self.media)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -50,12 +50,19 @@ impl Request for SendPhoto<'_> {
|
|||
"sendPhoto",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("photo", &self.photo)
|
||||
.await
|
||||
.add("caption", &self.caption)
|
||||
.await
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -45,10 +45,15 @@ impl Request for SendSticker<'_> {
|
|||
"sendSticker",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("sticker", &self.sticker)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -70,17 +70,29 @@ impl Request for SendVideo<'_> {
|
|||
"sendVideo",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("video", &self.video)
|
||||
.await
|
||||
.add("duration", &self.duration)
|
||||
.await
|
||||
.add("width", &self.width)
|
||||
.await
|
||||
.add("height", &self.height)
|
||||
.await
|
||||
.add("thumb", &self.thumb)
|
||||
.await
|
||||
.add("caption", &self.caption)
|
||||
.await
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.await
|
||||
.add("supports_streaming", &self.supports_streaming)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -59,13 +59,21 @@ impl Request for SendVideoNote<'_> {
|
|||
"sendVideoNote",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("video_note", &self.video_note)
|
||||
.await
|
||||
.add("duration", &self.duration)
|
||||
.await
|
||||
.add("length", &self.length)
|
||||
.await
|
||||
.add("thumb", &self.thumb)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -56,13 +56,21 @@ impl Request for SendVoice<'_> {
|
|||
"sendVoice",
|
||||
FormBuilder::new()
|
||||
.add("chat_id", &self.chat_id)
|
||||
.await
|
||||
.add("voice", &self.voice)
|
||||
.await
|
||||
.add("caption", &self.caption)
|
||||
.await
|
||||
.add("parse_mode", &self.parse_mode)
|
||||
.await
|
||||
.add("duration", &self.duration)
|
||||
.await
|
||||
.add("disable_notification", &self.disable_notification)
|
||||
.await
|
||||
.add("reply_to_message_id", &self.reply_to_message_id)
|
||||
.await
|
||||
.add("reply_markup", &self.reply_markup)
|
||||
.await
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -22,7 +22,7 @@ impl FormBuilder {
|
|||
}
|
||||
|
||||
/// Add the supplied key-value pair to this `FormBuilder`.
|
||||
pub fn add<'a, T, N>(self, name: N, value: &T) -> Self
|
||||
pub async fn add<'a, T, N>(self, name: N, value: &T) -> Self
|
||||
where
|
||||
N: Into<Cow<'a, str>>,
|
||||
T: IntoFormValue,
|
||||
|
@ -32,20 +32,21 @@ impl FormBuilder {
|
|||
Some(FormValue::Str(string)) => Self {
|
||||
form: self.form.text(name, string),
|
||||
},
|
||||
Some(FormValue::File(path)) => self.add_file(name, path),
|
||||
Some(FormValue::File(path)) => self.add_file(name, path).await,
|
||||
None => self,
|
||||
}
|
||||
}
|
||||
|
||||
// used in SendMediaGroup
|
||||
pub fn add_file<'a, N>(self, name: N, path_to_file: PathBuf) -> Self
|
||||
pub async fn add_file<'a, N>(self, name: N, path_to_file: PathBuf) -> Self
|
||||
where
|
||||
N: Into<Cow<'a, str>>,
|
||||
{
|
||||
Self {
|
||||
form: self
|
||||
.form
|
||||
.part(name.into().into_owned(), file_to_part(path_to_file)),
|
||||
form: self.form.part(
|
||||
name.into().into_owned(),
|
||||
file_to_part(path_to_file).await,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@ use std::path::PathBuf;
|
|||
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use reqwest::{multipart::Part, Body};
|
||||
use tokio::{codec::FramedRead, prelude::*};
|
||||
use tokio_util::codec::{Decoder, FramedRead};
|
||||
|
||||
struct FileDecoder;
|
||||
|
||||
impl tokio::codec::Decoder for FileDecoder {
|
||||
impl Decoder for FileDecoder {
|
||||
type Item = Bytes;
|
||||
type Error = std::io::Error;
|
||||
|
||||
|
@ -17,24 +17,23 @@ impl tokio::codec::Decoder for FileDecoder {
|
|||
if src.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(Some(src.take().freeze()))
|
||||
Ok(Some(src.split().freeze()))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_to_part(path_to_file: PathBuf) -> Part {
|
||||
pub async fn file_to_part(path_to_file: PathBuf) -> Part {
|
||||
let file_name = path_to_file
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
let file = tokio::fs::File::open(path_to_file)
|
||||
.map(|file| {
|
||||
FramedRead::new(
|
||||
file.unwrap(), /* TODO: this can cause panics */
|
||||
let file = FramedRead::new(
|
||||
tokio::fs::File::open(path_to_file).await.unwrap(), /* TODO: this
|
||||
* can
|
||||
* cause panics */
|
||||
FileDecoder,
|
||||
)
|
||||
})
|
||||
.flatten_stream();
|
||||
);
|
||||
|
||||
Part::stream(Body::wrap_stream(file)).file_name(file_name)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue