From 0a87a8ecd2d239c7fba3ccdbe4068bad91bf0203 Mon Sep 17 00:00:00 2001 From: Mr-Andersen Date: Thu, 12 Sep 2019 15:22:56 +0300 Subject: [PATCH 1/8] Message test: english -> francais --- src/core/types/message.rs | 394 +++++++++++++++++--------------------- 1 file changed, 177 insertions(+), 217 deletions(-) diff --git a/src/core/types/message.rs b/src/core/types/message.rs index 3b2d0f08..48e667be 100644 --- a/src/core/types/message.rs +++ b/src/core/types/message.rs @@ -193,232 +193,192 @@ mod tests { use serde_json::from_str; #[test] - fn sent_message_de() { - let expected = Message { - id: 6534, - date: 1567898953, - chat: Chat { - id: 218485655, - photo: None, - kind: ChatKind::Private { - type_: (), - first_name: Some("W".to_string()), - last_name: None, - username: Some("WaffleLapkin".to_string()), - }, - }, - message_kind: MessageKind::IncomingMessage { - from: Sender::User(User { - id: 457569668, - is_bot: true, - first_name: "BT".to_string(), - last_name: None, - username: Some("BloodyTestBot".to_string()), - language_code: None, - }), - forward_kind: ForwardKind::Origin { - reply_to_message: None, - }, - edit_date: None, - media_kind: MediaKind::Text { - text: "text".to_string(), - entities: vec![], - }, - reply_markup: None, - }, - }; - // actual message from telegram + fn de_media_forwarded() { let json = r#"{ - "message_id": 6534, - "from": { - "id": 457569668, - "is_bot": true, - "first_name": "BT", - "username": "BloodyTestBot" - }, - "chat": { - "id": 218485655, - "first_name": "W", - "username": "WaffleLapkin", - "type": "private" - }, - "date": 1567898953, - "text": "text" -}"#; - let actual = from_str::(json).unwrap(); - assert_eq!(expected, actual); + "message_id": 198283, + "from": { + "id": 250918540, + "is_bot": false, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "language_code": "en" + }, + "chat": { + "id": 250918540, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "type": "private" + }, + "date": 1567927221, + "video": { + "duration": 13, + "width": 512, + "height": 640, + "mime_type": "video/mp4", + "thumb": { + "file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE", + "file_size": 10339, + "width": 256, + "height": 320 + }, + "file_id": "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE", + "file_size": 1381334 + } + }"#; + let message = from_str::(json); + assert!(message.is_ok()); } #[test] - fn media_message_de() { + fn de_media_group_forwarded() { let json = r#"{ - "message_id": 198283, - "from": { - "id": 250918540, - "is_bot": false, - "first_name": "Андрей", - "last_name": "Власов", - "username": "aka_dude", - "language_code": "en" - }, - "chat": { - "id": 250918540, - "first_name": "Андрей", - "last_name": "Власов", - "username": "aka_dude", - "type": "private" - }, - "date": 1567927221, - "video": { - "duration": 13, - "width": 512, - "height": 640, - "mime_type": "video/mp4", - "thumb": { - "file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE", - "file_size": 10339, - "width": 256, - "height": 320 - }, - "file_id": "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE", - "file_size": 1381334 - } -}"#; - let actual = from_str::(json).unwrap(); - let expected = Message { - id: 198283, - date: 1567927221, - chat: Chat { - id: 250918540, - photo: None, - kind: ChatKind::Private { - first_name: Some("Андрей".to_string()), - last_name: Some("Власов".to_string()), - username: Some("aka_dude".to_string()), - type_: () - } + "message_id": 198283, + "from": { + "id": 250918540, + "is_bot": false, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "language_code": "en" + }, + "chat": { + "id": 250918540, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "type": "private" + }, + "date": 1567927221, + "media_group_id": "12543417770506682", + "video": { + "duration": 13, + "width": 512, + "height": 640, + "mime_type": "video/mp4", + "thumb": { + "file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE", + "file_size": 10339, + "width": 256, + "height": 320 }, - message_kind: MessageKind::IncomingMessage { - from: Sender::User(User { - id: 250918540, - is_bot: false, - first_name: "Андрей".to_string(), - last_name: Some("Власов".to_string()), - username: Some("aka_dude".to_string()), - language_code: Some("en".to_string()) - }), - forward_kind: ForwardKind::Origin { reply_to_message: None }, - edit_date: None, - media_kind: MediaKind::Video { - video: Video { - duration: 13, - width: 512, - height: 640, - mime_type: Some("video/mp4".to_string()), - thumb: Some(PhotoSize { - file_id: "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE".to_string(), - file_size: Some(10339), - width: 256, - height: 320 - }), - file_id: "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE".to_string(), - file_size: Some(1381334) - }, - caption: None, - caption_entities: vec![], - media_group_id: None - }, - reply_markup: None - }, - - }; - assert_eq!(actual, expected); + "file_id": "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE", + "file_size": 1381334 + } + }"#; + let message = from_str::(json); + assert!(message.is_ok()); } #[test] - fn media_group_message_de() { + fn de_text() { let json = r#"{ - "message_id": 198283, - "from": { - "id": 250918540, - "is_bot": false, - "first_name": "Андрей", - "last_name": "Власов", - "username": "aka_dude", - "language_code": "en" - }, - "chat": { - "id": 250918540, - "first_name": "Андрей", - "last_name": "Власов", - "username": "aka_dude", - "type": "private" - }, - "date": 1567927221, - "media_group_id": "12543417770506682", - "video": { - "duration": 13, - "width": 512, - "height": 640, - "mime_type": "video/mp4", - "thumb": { - "file_id": "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE", - "file_size": 10339, - "width": 256, - "height": 320 - }, - "file_id": "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE", - "file_size": 1381334 - } -}"#; - let actual = from_str::(json).unwrap(); - let expected = Message { - id: 198283, - date: 1567927221, - chat: Chat { - id: 250918540, - photo: None, - kind: ChatKind::Private { - first_name: Some("Андрей".to_string()), - last_name: Some("Власов".to_string()), - username: Some("aka_dude".to_string()), - type_: () - } - }, - message_kind: MessageKind::IncomingMessage { - from: Sender::User(User { - id: 250918540, - is_bot: false, - first_name: "Андрей".to_string(), - last_name: Some("Власов".to_string()), - username: Some("aka_dude".to_string()), - language_code: Some("en".to_string()) - }), - forward_kind: ForwardKind::Origin { reply_to_message: None }, - edit_date: None, - media_kind: MediaKind::Video { - video: Video { - duration: 13, - width: 512, - height: 640, - mime_type: Some("video/mp4".to_string()), - thumb: Some(PhotoSize { - file_id: "AAQCAAOmBAACBf2oS53pByA-I4CWWCObDwAEAQAHbQADMWcAAhYE".to_string(), - file_size: Some(10339), - width: 256, - height: 320 - }), - file_id: "BAADAgADpgQAAgX9qEud6QcgPiOAlhYE".to_string(), - file_size: Some(1381334) - }, - caption: None, - caption_entities: vec![], - media_group_id: Some("12543417770506682".to_string()) - }, - reply_markup: None - }, - - }; - assert_eq!(actual, expected); + "message_id": 199785, + "from": { + "id": 250918540, + "is_bot": false, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "language_code": "en" + }, + "chat": { + "id": 250918540, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "type": "private" + }, + "date": 1568289890, + "text": "Лол кек 😂" + }"#; + let message = from_str::(json); + assert!(message.is_ok()); + } + + #[test] + fn de_sticker() { + let json = r#"{ + "message_id": 199787, + "from": { + "id": 250918540, + "is_bot": false, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "language_code": "en" + }, + "chat": { + "id": 250918540, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "type": "private" + }, + "date": 1568290188, + "sticker": { + "width": 512, + "height": 512, + "emoji": "😡", + "set_name": "AdvenTimeAnim", + "is_animated": true, + "thumb": { + "file_id": "AAQCAAMjAAOw0PgMaabKAcaXKCBLubkPAAQBAAdtAAPGKwACFgQ", + "file_size": 4118, + "width": 128, + "height": 128 + }, + "file_id": "CAADAgADIwADsND4DGmmygHGlyggFgQ", + "file_size": 16639 + } + }"#; + let message = from_str::(json); + assert!(message.is_ok()); + } + + #[test] + fn de_image() { + let json = r#"{ + "message_id": 199791, + "from": { + "id": 250918540, + "is_bot": false, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "language_code": "en" + }, + "chat": { + "id": 250918540, + "first_name": "Андрей", + "last_name": "Власов", + "username": "aka_dude", + "type": "private" + }, + "date": 1568290622, + "photo": [ + { + "file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA20AAybcBAABFgQ", + "file_size": 18188, + "width": 320, + "height": 239 + }, + { + "file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA3gAAyfcBAABFgQ", + "file_size": 62123, + "width": 800, + "height": 598 + }, + { + "file_id": "AgADAgAD36sxG-PX0UvQSXIn9rccdw-ACA4ABAEAAwIAA3kAAyTcBAABFgQ", + "file_size": 75245, + "width": 962, + "height": 719 + } + ] + }"#; + let message = from_str::(json); + assert!(message.is_ok()); } } From 383d17ef477df3d3059042b39375c3a41474b5c9 Mon Sep 17 00:00:00 2001 From: Mr-Andersen Date: Thu, 12 Sep 2019 16:02:36 +0300 Subject: [PATCH 2/8] Added Poll, PollOption --- src/core/types/poll.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/core/types/poll.rs diff --git a/src/core/types/poll.rs b/src/core/types/poll.rs new file mode 100644 index 00000000..5ffec2aa --- /dev/null +++ b/src/core/types/poll.rs @@ -0,0 +1,13 @@ +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +pub struct Poll { + pub id: String, + pub question: String, + pub options: Vec, + pub is_closed: bool +} + +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +pub struct PollOption { + pub text: String, + pub voter_count: i32 +} \ No newline at end of file From 7482534335371d9fbeb737069ec67ddd82345248 Mon Sep 17 00:00:00 2001 From: Mr-Andersen Date: Thu, 12 Sep 2019 16:03:04 +0300 Subject: [PATCH 3/8] Little bit of refactoring --- src/core/types/message.rs | 12 ++++++------ src/core/types/mod.rs | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/types/message.rs b/src/core/types/message.rs index 48e667be..76406b4f 100644 --- a/src/core/types/message.rs +++ b/src/core/types/message.rs @@ -4,7 +4,7 @@ use crate::core::types::{ SuccessfulPayment, User, Venue, Video, VideoNote, Voice, }; -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub struct Message { #[serde(rename = "message_id")] pub id: i64, @@ -14,7 +14,7 @@ pub struct Message { pub message_kind: MessageKind, } -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] #[serde(untagged)] pub enum MessageKind { IncomingMessage { @@ -72,7 +72,7 @@ pub enum MessageKind { }, } -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub enum Sender { /// If message is sent from Chat #[serde(rename = "from")] @@ -82,7 +82,7 @@ pub enum Sender { Signature(String), } -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] #[serde(untagged)] pub enum ForwardKind { ChannelForward { @@ -106,7 +106,7 @@ pub enum ForwardKind { }, } -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub enum ForwardedFrom { #[serde(rename = "forward_from")] User(User), @@ -114,7 +114,7 @@ pub enum ForwardedFrom { SenderName(String), } -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] #[serde(untagged)] pub enum MediaKind { Animation { diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index e1d3921c..06e855e7 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -19,6 +19,7 @@ pub use self::{ order_info::OrderInfo, parse_mode::ParseMode, photo_size::PhotoSize, + poll::{Poll, PollOption}, pre_checkout_query::PreCheckoutQuery, response_parameters::ResponseParameters, send_invoice::SendInvoice, @@ -60,6 +61,7 @@ mod not_implemented_types; mod order_info; mod parse_mode; mod photo_size; +mod poll; mod pre_checkout_query; mod response_parameters; mod reply_markup; From cc19034bcaf3464823cdb77cb99631a136c75b3a Mon Sep 17 00:00:00 2001 From: Mr-Andersen Date: Thu, 12 Sep 2019 16:04:13 +0300 Subject: [PATCH 4/8] Dropped implemented types from not_implemented_types --- src/core/types/not_implemented_types.rs | 27 ------------------------- 1 file changed, 27 deletions(-) diff --git a/src/core/types/not_implemented_types.rs b/src/core/types/not_implemented_types.rs index d4bdd311..8587f7dd 100644 --- a/src/core/types/not_implemented_types.rs +++ b/src/core/types/not_implemented_types.rs @@ -1,35 +1,8 @@ -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct Location; - -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct InlineKeyboardMarkup; - #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] pub struct PassportData; -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct Poll; - #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] pub struct Animation; -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct Game; - -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct Contact; - -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct VideoNote; - -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct Venue; - -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct Voice; - -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct MaskPosition; - #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] pub struct ChatMemberStatus; From 7de6f9f25288966968e0fbfe2645da8f4593e6ee Mon Sep 17 00:00:00 2001 From: Mr-Andersen Date: Thu, 12 Sep 2019 16:51:24 +0300 Subject: [PATCH 5/8] `pub` fixes --- src/core/types/contact.rs | 6 ++---- src/core/types/location.rs | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/core/types/contact.rs b/src/core/types/contact.rs index 7a5840ee..83a1d81d 100644 --- a/src/core/types/contact.rs +++ b/src/core/types/contact.rs @@ -1,8 +1,6 @@ -use serde::Deserialization; - -#[derive(Debug, Deserialization, Clone)] +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] /// This object represents a phone contact. -struct Contact { +pub struct Contact { /// Contact's phone number pub phone_number: String, /// Contact's first name diff --git a/src/core/types/location.rs b/src/core/types/location.rs index 3fd0eeb9..abaf63c8 100644 --- a/src/core/types/location.rs +++ b/src/core/types/location.rs @@ -1,8 +1,6 @@ -use serde::{Deserialization, Serialization}; - #[derive(Debug, Serialization, Deserialization, Clone)] /// This object represents a point on the map. -struct Location { +pub struct Location { /// Longitude as defined by sender pub longitude: f64, /// Latitude as defined by sender From a5f1b7fb70d93393703a9fbf219526416e32e903 Mon Sep 17 00:00:00 2001 From: Mr-Andersen Date: Thu, 12 Sep 2019 16:51:45 +0300 Subject: [PATCH 6/8] Added Animation, File, UserProfilePhotos --- src/core/types/animation.rs | 13 +++++++++++++ src/core/types/file.rs | 6 ++++++ src/core/types/not_implemented_types.rs | 3 --- src/core/types/user_profile_photos.rs | 7 +++++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/core/types/animation.rs create mode 100644 src/core/types/file.rs create mode 100644 src/core/types/user_profile_photos.rs diff --git a/src/core/types/animation.rs b/src/core/types/animation.rs new file mode 100644 index 00000000..f5b1d342 --- /dev/null +++ b/src/core/types/animation.rs @@ -0,0 +1,13 @@ +use crate::core::types::PhotoSize; + +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +pub struct Animation { + pub file_id: String, + pub width: u32, + pub height: u32, + pub duration: u32, + pub thumb: PhotoSize, + pub file_name: Option, + pub mime_type: Option, + pub file_size: Option +} \ No newline at end of file diff --git a/src/core/types/file.rs b/src/core/types/file.rs new file mode 100644 index 00000000..88ce6e97 --- /dev/null +++ b/src/core/types/file.rs @@ -0,0 +1,6 @@ +#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)] +pub struct File { + pub file_id: String, + pub file_size: u32, + pub file_path: String +} diff --git a/src/core/types/not_implemented_types.rs b/src/core/types/not_implemented_types.rs index 8587f7dd..c2700b2d 100644 --- a/src/core/types/not_implemented_types.rs +++ b/src/core/types/not_implemented_types.rs @@ -1,8 +1,5 @@ #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] pub struct PassportData; -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct Animation; - #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] pub struct ChatMemberStatus; diff --git a/src/core/types/user_profile_photos.rs b/src/core/types/user_profile_photos.rs new file mode 100644 index 00000000..6364706e --- /dev/null +++ b/src/core/types/user_profile_photos.rs @@ -0,0 +1,7 @@ +use crate::core::types::PhotoSize; + +#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Serialize)] +pub struct UserProfilePhotos { + pub total_count: u32, + pub photos: Vec> +} From 6d3aeb45c473acaed5763680009d49940b9af2a1 Mon Sep 17 00:00:00 2001 From: Andrew Andersen Date: Thu, 12 Sep 2019 18:49:54 +0300 Subject: [PATCH 7/8] Update src/core/types/animation.rs Co-Authored-By: Waffle Lapkin --- src/core/types/animation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/types/animation.rs b/src/core/types/animation.rs index f5b1d342..09fccf40 100644 --- a/src/core/types/animation.rs +++ b/src/core/types/animation.rs @@ -10,4 +10,4 @@ pub struct Animation { pub file_name: Option, pub mime_type: Option, pub file_size: Option -} \ No newline at end of file +} From 5d06f4a0f8b81dee787e695efba50fdae30cbb7f Mon Sep 17 00:00:00 2001 From: Andrew Andersen Date: Thu, 12 Sep 2019 18:50:01 +0300 Subject: [PATCH 8/8] Update src/core/types/poll.rs Co-Authored-By: Waffle Lapkin --- src/core/types/poll.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/types/poll.rs b/src/core/types/poll.rs index 5ffec2aa..160870c5 100644 --- a/src/core/types/poll.rs +++ b/src/core/types/poll.rs @@ -10,4 +10,4 @@ pub struct Poll { pub struct PollOption { pub text: String, pub voter_count: i32 -} \ No newline at end of file +}