Merge pull request #141 from teloxide/fix-update-kind

Fix UpdateKind
This commit is contained in:
Temirkhan Myrzamadi 2020-01-18 05:47:04 +06:00 committed by GitHub
commit 1821e1f703
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 14 deletions

View file

@ -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,
}
}))
}

View file

@ -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,

View file

@ -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,