mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 19:33:53 +01:00
commit
1821e1f703
3 changed files with 27 additions and 14 deletions
|
@ -39,13 +39,11 @@ pub async fn download_file_stream(
|
||||||
.await?
|
.await?
|
||||||
.error_for_status()?;
|
.error_for_status()?;
|
||||||
|
|
||||||
Ok(futures::stream::unfold(res, |mut res| {
|
Ok(futures::stream::unfold(res, |mut res| async {
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::types::{User, Message};
|
use crate::types::{Message, User};
|
||||||
|
|
||||||
/// This object represents one special entity in a text message. For example,
|
/// This object represents one special entity in a text message. For example,
|
||||||
/// hashtags, usernames, URLs, etc.
|
/// hashtags, usernames, URLs, etc.
|
||||||
|
@ -42,14 +42,16 @@ pub enum MessageEntityKind {
|
||||||
impl MessageEntity {
|
impl MessageEntity {
|
||||||
pub fn text_from(&self, message: &Message) -> Option<String> {
|
pub fn text_from(&self, message: &Message) -> Option<String> {
|
||||||
let text = message.text();
|
let text = message.text();
|
||||||
Some(String::from(&text?[self.offset..self.offset+self.length]))
|
Some(String::from(&text?[self.offset..self.offset + self.length]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::types::{Chat, ChatKind, MessageKind, Sender, ForwardKind, MediaKind};
|
use crate::types::{
|
||||||
|
Chat, ChatKind, ForwardKind, MediaKind, MessageKind, Sender,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recursive_kind() {
|
fn recursive_kind() {
|
||||||
|
@ -111,7 +113,7 @@ mod tests {
|
||||||
entities: vec![MessageEntity {
|
entities: vec![MessageEntity {
|
||||||
kind: MessageEntityKind::Mention,
|
kind: MessageEntityKind::Mention,
|
||||||
offset: 3,
|
offset: 3,
|
||||||
length: 3
|
length: 3,
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
reply_markup: None,
|
reply_markup: None,
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::types::{CallbackQuery, ChosenInlineResult, InlineQuery, Message};
|
use crate::types::{
|
||||||
|
CallbackQuery, ChosenInlineResult, InlineQuery, Message, Poll,
|
||||||
|
PreCheckoutQuery, ShippingQuery,
|
||||||
|
};
|
||||||
|
|
||||||
/// This [object] represents an incoming update.
|
/// This [object] represents an incoming update.
|
||||||
///
|
///
|
||||||
|
@ -57,7 +60,17 @@ pub enum UpdateKind {
|
||||||
|
|
||||||
/// New incoming callback query.
|
/// New incoming callback query.
|
||||||
CallbackQuery(CallbackQuery),
|
CallbackQuery(CallbackQuery),
|
||||||
// TODO: Add more variants
|
|
||||||
|
/// New incoming shipping query. Only for invoices with flexible price.
|
||||||
|
ShippingQuery(ShippingQuery),
|
||||||
|
|
||||||
|
/// New incoming pre-checkout query. Contains full information about
|
||||||
|
/// checkout.
|
||||||
|
PreCheckoutQuery(PreCheckoutQuery),
|
||||||
|
|
||||||
|
/// New poll state. Bots receive only updates about stopped polls and
|
||||||
|
/// polls, which are sent by the bot.
|
||||||
|
Poll(Poll),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -92,7 +105,7 @@ mod test {
|
||||||
}
|
}
|
||||||
}"#;
|
}"#;
|
||||||
|
|
||||||
let expected: Update = Update {
|
let expected = Update {
|
||||||
id: 892_252_934,
|
id: 892_252_934,
|
||||||
kind: UpdateKind::Message(Message {
|
kind: UpdateKind::Message(Message {
|
||||||
id: 6557,
|
id: 6557,
|
||||||
|
|
Loading…
Reference in a new issue