mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
commit
1821e1f703
3 changed files with 27 additions and 14 deletions
|
@ -39,13 +39,11 @@ 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,6 +1,6 @@
|
|||
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,
|
||||
/// hashtags, usernames, URLs, etc.
|
||||
|
@ -42,14 +42,16 @@ pub enum MessageEntityKind {
|
|||
impl MessageEntity {
|
||||
pub fn text_from(&self, message: &Message) -> Option<String> {
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::types::{Chat, ChatKind, MessageKind, Sender, ForwardKind, MediaKind};
|
||||
use crate::types::{
|
||||
Chat, ChatKind, ForwardKind, MediaKind, MessageKind, Sender,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn recursive_kind() {
|
||||
|
@ -111,7 +113,7 @@ mod tests {
|
|||
entities: vec![MessageEntity {
|
||||
kind: MessageEntityKind::Mention,
|
||||
offset: 3,
|
||||
length: 3
|
||||
length: 3,
|
||||
}],
|
||||
},
|
||||
reply_markup: None,
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
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.
|
||||
///
|
||||
|
@ -57,7 +60,17 @@ pub enum UpdateKind {
|
|||
|
||||
/// New incoming callback query.
|
||||
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)]
|
||||
|
@ -92,7 +105,7 @@ mod test {
|
|||
}
|
||||
}"#;
|
||||
|
||||
let expected: Update = Update {
|
||||
let expected = Update {
|
||||
id: 892_252_934,
|
||||
kind: UpdateKind::Message(Message {
|
||||
id: 6557,
|
||||
|
|
Loading…
Reference in a new issue