From af62a72afddcc3a9bf8161e6255cb598ca0d00f1 Mon Sep 17 00:00:00 2001 From: RustemB Date: Tue, 17 Sep 2019 21:58:45 +0500 Subject: [PATCH 01/55] inline_query + _result_article --- src/core/types/inline_query.rs | 10 ++++++++++ src/core/types/inline_query_result_article.rs | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/core/types/inline_query.rs create mode 100644 src/core/types/inline_query_result_article.rs diff --git a/src/core/types/inline_query.rs b/src/core/types/inline_query.rs new file mode 100644 index 00000000..b06256d6 --- /dev/null +++ b/src/core/types/inline_query.rs @@ -0,0 +1,10 @@ +use crate::core::types::{User, Location}; + +#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)] +pub struct InlineQuery { + pub id: i64, + pub from: User, + pub location: Option, + pub query: String, + pub offset: String, +} diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs new file mode 100644 index 00000000..fd7ba834 --- /dev/null +++ b/src/core/types/inline_query_result_article.rs @@ -0,0 +1,16 @@ +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; + +#[derive(Debug, Deserialize, PartialEq, Clone)] +pub struct InlineQueryResultArticle { + pub r#type: String, + pub id: String, + pub title: String, + pub input_message_content: InputMessageContent, + pub reply_markup: Option, + pub url: Option, + pub hide_url: Option, + pub description: Option, + pub thumb_url: Option, + pub thumb_width: Option, + pub thumb_height: Option, +} From cc542b6eae6b781e5cee5ad38b9df78b6a40a2bf Mon Sep 17 00:00:00 2001 From: RustemB Date: Tue, 17 Sep 2019 22:15:19 +0500 Subject: [PATCH 02/55] commentd --- src/core/types/inline_query.rs | 7 ++++++- src/core/types/inline_query_result_article.rs | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/types/inline_query.rs b/src/core/types/inline_query.rs index b06256d6..2b6ef480 100644 --- a/src/core/types/inline_query.rs +++ b/src/core/types/inline_query.rs @@ -2,9 +2,14 @@ use crate::core::types::{User, Location}; #[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)] pub struct InlineQuery { - pub id: i64, + /// Unique identifier for this query + pub id: String, + /// Sender pub from: User, + /// Optional. Sender location, only for bots that request user location pub location: Option, + /// Text of the query (up to 512 characters) pub query: String, + /// Offset of the results to be returned, can be controlled by the bot pub offset: String, } diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs index fd7ba834..787a4201 100644 --- a/src/core/types/inline_query_result_article.rs +++ b/src/core/types/inline_query_result_article.rs @@ -2,15 +2,24 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; #[derive(Debug, Deserialize, PartialEq, Clone)] pub struct InlineQueryResultArticle { - pub r#type: String, + /// Unique identifier for this result, 1-64 Bytes pub id: String, + /// Title of the result pub title: String, + /// Content of the message to be sent pub input_message_content: InputMessageContent, + /// Optional. Inline keyboard attached to the message pub reply_markup: Option, + /// Optional. URL of the result pub url: Option, + /// Optional. Pass True, if you don't want the URL to be shown in the message pub hide_url: Option, + /// Optional. Short description of the result pub description: Option, + /// Optional. Url of the thumbnail for the result pub thumb_url: Option, - pub thumb_width: Option, - pub thumb_height: Option, + /// Optional. Thumbnail width + pub thumb_width: Option, + /// Optional. Thumbnail height + pub thumb_height: Option, } From aef4d51179cf1971a8c8703804968207de92fa6f Mon Sep 17 00:00:00 2001 From: RustemB Date: Tue, 17 Sep 2019 22:31:41 +0500 Subject: [PATCH 03/55] fixes --- src/core/types/inline_query.rs | 2 +- src/core/types/inline_query_result_article.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/types/inline_query.rs b/src/core/types/inline_query.rs index 2b6ef480..4ee13687 100644 --- a/src/core/types/inline_query.rs +++ b/src/core/types/inline_query.rs @@ -1,6 +1,6 @@ use crate::core::types::{User, Location}; -#[derive(Debug, Serialize, Deserialize, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] pub struct InlineQuery { /// Unique identifier for this query pub id: String, diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs index 787a4201..2979ea1b 100644 --- a/src/core/types/inline_query_result_article.rs +++ b/src/core/types/inline_query_result_article.rs @@ -1,6 +1,6 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, PartialEq, Clone)] +#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] pub struct InlineQueryResultArticle { /// Unique identifier for this result, 1-64 Bytes pub id: String, From 2bc2ce56633b5e5c53e5d2541066be0a3df049c5 Mon Sep 17 00:00:00 2001 From: RustemB Date: Tue, 17 Sep 2019 22:33:50 +0500 Subject: [PATCH 04/55] i32 as dimensions --- src/core/types/inline_query_result_article.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs index 2979ea1b..1fbdfc8b 100644 --- a/src/core/types/inline_query_result_article.rs +++ b/src/core/types/inline_query_result_article.rs @@ -19,7 +19,7 @@ pub struct InlineQueryResultArticle { /// Optional. Url of the thumbnail for the result pub thumb_url: Option, /// Optional. Thumbnail width - pub thumb_width: Option, + pub thumb_width: Option, /// Optional. Thumbnail height - pub thumb_height: Option, + pub thumb_height: Option, } From 5124750be9a9a6276ab25d4cd893c83484eb36d2 Mon Sep 17 00:00:00 2001 From: Waffle Date: Tue, 17 Sep 2019 20:43:31 +0300 Subject: [PATCH 05/55] Replace `i64` with `i32` --- src/bot/mod.rs | 2 +- src/core/requests/edit_message_live_location.rs | 4 ++-- src/core/requests/forward_message.rs | 6 +++--- src/core/requests/send_audio.rs | 4 ++-- src/core/requests/send_location.rs | 4 ++-- src/core/requests/send_media_group.rs | 4 ++-- src/core/requests/send_message.rs | 4 ++-- src/core/requests/send_photo.rs | 4 ++-- src/core/types/contact.rs | 2 +- src/core/types/invoice.rs | 2 +- src/core/types/label_price.rs | 2 +- src/core/types/message.rs | 4 ++-- src/core/types/pre_checkout_query.rs | 2 +- src/core/types/response_parameters.rs | 2 +- src/core/types/send_invoice.rs | 13 +++++++------ src/core/types/successful_payment.rs | 2 +- src/core/types/user.rs | 2 +- 17 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 74ff89d4..96472626 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -92,7 +92,7 @@ impl Bot { where C: Into, F: Into, - M: Into, + M: Into, { ForwardMessage::new( self.ctx(), diff --git a/src/core/requests/edit_message_live_location.rs b/src/core/requests/edit_message_live_location.rs index 091b9161..3d1171d8 100644 --- a/src/core/requests/edit_message_live_location.rs +++ b/src/core/requests/edit_message_live_location.rs @@ -23,7 +23,7 @@ pub struct EditMessageLiveLocation<'a> { #[serde(skip_serializing_if = "Option::is_none")] /// Required if inline_message_id is not specified. Identifier of the /// message to edit - message_id: Option, + message_id: Option, #[serde(skip_serializing_if = "Option::is_none")] /// Required if chat_id and message_id are not specified. Identifier of /// the inline message @@ -75,7 +75,7 @@ impl<'a> EditMessageLiveLocation<'a> { self } - pub fn message_id>(mut self, message_id: T) -> Self { + pub fn message_id>(mut self, message_id: T) -> Self { self.message_id = Some(message_id.into()); self } diff --git a/src/core/requests/forward_message.rs b/src/core/requests/forward_message.rs index dc751bfd..2de100f4 100644 --- a/src/core/requests/forward_message.rs +++ b/src/core/requests/forward_message.rs @@ -24,7 +24,7 @@ pub struct ForwardMessage<'a> { /// (in the format @channelusername) pub from_chat_id: ChatId, /// Message identifier in the chat specified in from_chat_id - pub message_id: i64, + pub message_id: i32, /// Sends the message silently. Users will receive a notification with no /// sound. @@ -53,7 +53,7 @@ impl<'a> ForwardMessage<'a> { ctx: RequestContext<'a>, chat_id: ChatId, from_chat_id: ChatId, - message_id: i64, + message_id: i32, ) -> Self { Self { ctx, @@ -74,7 +74,7 @@ impl<'a> ForwardMessage<'a> { self } - pub fn message_id>(mut self, val: T) -> Self { + pub fn message_id>(mut self, val: T) -> Self { self.message_id = val.into(); self } diff --git a/src/core/requests/send_audio.rs b/src/core/requests/send_audio.rs index ab63980d..7580b7ce 100644 --- a/src/core/requests/send_audio.rs +++ b/src/core/requests/send_audio.rs @@ -55,7 +55,7 @@ pub struct SendAudio<'a> { /// sound. pub disable_notification: Option, /// If the message is a reply, ID of the original message - pub reply_to_message_id: Option, + pub reply_to_message_id: Option, pub reply_markup: Option, } @@ -174,7 +174,7 @@ impl<'a> SendAudio<'a> { self } - pub fn reply_to_message_id>( + pub fn reply_to_message_id>( mut self, reply_to_message_id: T, ) -> Self { diff --git a/src/core/requests/send_location.rs b/src/core/requests/send_location.rs index cf9770ad..9dd8af1b 100644 --- a/src/core/requests/send_location.rs +++ b/src/core/requests/send_location.rs @@ -33,7 +33,7 @@ pub struct SendLocation<'a> { disable_notification: Option, #[serde(skip_serializing_if = "Option::is_none")] /// If the message is a reply, ID of the original message - reply_to_message_id: Option, + reply_to_message_id: Option, #[serde(skip_serializing_if = "Option::is_none")] reply_markup: Option, } @@ -98,7 +98,7 @@ impl<'a> SendLocation<'a> { self } - pub fn reply_to_message_id>(mut self, val: T) -> Self { + pub fn reply_to_message_id>(mut self, val: T) -> Self { self.reply_to_message_id = Some(val.into()); self } diff --git a/src/core/requests/send_media_group.rs b/src/core/requests/send_media_group.rs index 52c41453..d95d4234 100644 --- a/src/core/requests/send_media_group.rs +++ b/src/core/requests/send_media_group.rs @@ -17,7 +17,7 @@ pub struct SendMediaGroup<'a> { pub media: Vec, pub disable_notification: Option, - pub reply_to_message_id: Option, + pub reply_to_message_id: Option, } impl<'a> Request<'a> for SendMediaGroup<'a> { @@ -96,7 +96,7 @@ impl<'a> SendMediaGroup<'a> { self } - pub fn reply_to_message_id>(mut self, val: T) -> Self { + pub fn reply_to_message_id>(mut self, val: T) -> Self { self.reply_to_message_id = Some(val.into()); self } diff --git a/src/core/requests/send_message.rs b/src/core/requests/send_message.rs index d3bf2421..ed0fcf85 100644 --- a/src/core/requests/send_message.rs +++ b/src/core/requests/send_message.rs @@ -42,7 +42,7 @@ pub struct SendMessage<'a> { pub disable_notification: Option, /// If the message is a reply, ID of the original message #[serde(skip_serializing_if = "Option::is_none")] - pub reply_to_message_id: Option, + pub reply_to_message_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, } @@ -106,7 +106,7 @@ impl<'a> SendMessage<'a> { self } - pub fn reply_to_message_id>(mut self, val: T) -> Self { + pub fn reply_to_message_id>(mut self, val: T) -> Self { self.reply_to_message_id = Some(val.into()); self } diff --git a/src/core/requests/send_photo.rs b/src/core/requests/send_photo.rs index 9d2a07b5..69f1e5d7 100644 --- a/src/core/requests/send_photo.rs +++ b/src/core/requests/send_photo.rs @@ -39,7 +39,7 @@ pub struct SendPhoto<'a> { /// sound. pub disable_notification: Option, /// If the message is a reply, ID of the original message - pub reply_to_message_id: Option, + pub reply_to_message_id: Option, pub reply_markup: Option, } @@ -125,7 +125,7 @@ impl<'a> SendPhoto<'a> { self } - pub fn reply_to_message_id>( + pub fn reply_to_message_id>( mut self, reply_to_message_id: T, ) -> Self { diff --git a/src/core/types/contact.rs b/src/core/types/contact.rs index 83a1d81d..d5ffedca 100644 --- a/src/core/types/contact.rs +++ b/src/core/types/contact.rs @@ -8,7 +8,7 @@ pub struct Contact { /// Optional. Contact's last name pub last_name: Option, /// Optional. Contact's user identifier in Telegram - pub user_id: Option, + pub user_id: Option, /// Optional. Additional data about the contact in the form of a /// [vCard](https://en.wikipedia.org/wiki/VCard) pub vcard: Option, diff --git a/src/core/types/invoice.rs b/src/core/types/invoice.rs index 8a429e6e..201cb3fd 100644 --- a/src/core/types/invoice.rs +++ b/src/core/types/invoice.rs @@ -4,5 +4,5 @@ pub struct Invoice { pub description: String, pub start_parameter: String, pub currency: String, - pub total_amount: i64, + pub total_amount: i32, } diff --git a/src/core/types/label_price.rs b/src/core/types/label_price.rs index d7816ef3..b1d04e3d 100644 --- a/src/core/types/label_price.rs +++ b/src/core/types/label_price.rs @@ -9,7 +9,7 @@ pub struct LabeledPrice { /// amount = 145. See the exp parameter in [`currencies.json`](https://core.telegram.org/bots/payments/currencies.json), /// it shows the number of digits past the decimal point for each currency /// (2 for the majority of currencies). - pub amount: i64, + pub amount: i32, } #[cfg(test)] diff --git a/src/core/types/message.rs b/src/core/types/message.rs index a5711fc8..ebc76355 100644 --- a/src/core/types/message.rs +++ b/src/core/types/message.rs @@ -7,7 +7,7 @@ use crate::core::types::{ #[derive(Debug, Deserialize, PartialEq, Clone)] pub struct Message { #[serde(rename = "message_id")] - pub id: i64, + pub id: i32, pub date: i32, pub chat: Chat, #[serde(flatten)] @@ -91,7 +91,7 @@ pub enum ForwardKind { #[serde(rename = "forward_from_chat")] chat: Chat, #[serde(rename = "forward_from_message_id")] - message_id: i64, + message_id: i32, #[serde(rename = "forward_signature")] signature: Option, }, diff --git a/src/core/types/pre_checkout_query.rs b/src/core/types/pre_checkout_query.rs index 4a3292ba..2d136e52 100644 --- a/src/core/types/pre_checkout_query.rs +++ b/src/core/types/pre_checkout_query.rs @@ -5,7 +5,7 @@ pub struct PreCheckoutQuery { pub id: String, pub from: User, pub currency: String, - pub total_amount: i64, + pub total_amount: i32, pub invoice_payload: String, pub shipping_option_id: Option, pub order_info: Option, diff --git a/src/core/types/response_parameters.rs b/src/core/types/response_parameters.rs index c9b71243..b456d5fd 100644 --- a/src/core/types/response_parameters.rs +++ b/src/core/types/response_parameters.rs @@ -2,7 +2,7 @@ #[serde(rename_all = "snake_case")] pub enum ResponseParameters { MigrateToChatId(i64), - RetryAfter(i64), + RetryAfter(i32), } #[cfg(test)] diff --git a/src/core/types/send_invoice.rs b/src/core/types/send_invoice.rs index 07698819..10740d81 100644 --- a/src/core/types/send_invoice.rs +++ b/src/core/types/send_invoice.rs @@ -1,8 +1,9 @@ use crate::core::types::{InlineKeyboardMarkup, LabeledPrice}; +use crate::core::requests::ChatId; -#[derive(Debug, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone)] pub struct SendInvoice { - pub chat_id: i64, + pub chat_id: ChatId, pub title: String, pub description: String, pub payload: String, @@ -12,9 +13,9 @@ pub struct SendInvoice { pub prices: Vec, pub provider_data: Option, pub photo_url: Option, - pub photo_size: Option, - pub photo_width: Option, - pub photo_height: Option, + pub photo_size: Option, + pub photo_width: Option, + pub photo_height: Option, pub need_name: Option, pub need_phone_number: Option, pub need_email: Option, @@ -23,6 +24,6 @@ pub struct SendInvoice { pub send_email_to_provider: Option, pub is_flexible: Option, pub disable_notification: Option, - pub reply_to_message_id: Option, + pub reply_to_message_id: Option, pub reply_markup: Option, } diff --git a/src/core/types/successful_payment.rs b/src/core/types/successful_payment.rs index 8c39446d..c544499b 100644 --- a/src/core/types/successful_payment.rs +++ b/src/core/types/successful_payment.rs @@ -3,7 +3,7 @@ use crate::core::types::OrderInfo; #[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)] pub struct SuccessfulPayment { pub currency: String, - pub total_amount: i64, + pub total_amount: i32, pub invoice_payload: String, pub shipping_option_id: Option, pub order_info: Option, diff --git a/src/core/types/user.rs b/src/core/types/user.rs index 19873238..953e1a23 100644 --- a/src/core/types/user.rs +++ b/src/core/types/user.rs @@ -1,6 +1,6 @@ #[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone, Serialize)] pub struct User { - pub id: i64, + pub id: i32, pub is_bot: bool, pub first_name: String, pub last_name: Option, From 8b60c026730e635bd0660b6b748917a2c4229a4e Mon Sep 17 00:00:00 2001 From: Waffle Date: Tue, 17 Sep 2019 20:50:01 +0300 Subject: [PATCH 06/55] Import `File` --- src/core/types/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index 3c1cca89..3a329d5b 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -46,6 +46,7 @@ pub use self::{ video::Video, video_note::VideoNote, voice::Voice, + file::File, }; mod animation; @@ -93,3 +94,4 @@ mod venue; mod video; mod video_note; mod voice; +mod file; From 23c63a612bf4964d5fe2cc887b60554cb434c89e Mon Sep 17 00:00:00 2001 From: nextel Date: Tue, 17 Sep 2019 20:59:07 +0300 Subject: [PATCH 07/55] add getFile implementation --- src/core/requests/get_file.rs | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/core/requests/get_file.rs b/src/core/requests/get_file.rs index 7a00e587..648d6452 100644 --- a/src/core/requests/get_file.rs +++ b/src/core/requests/get_file.rs @@ -1,8 +1,46 @@ -use crate::core::requests::RequestContext; -//TODO:: need implementation +use crate::core::requests::{RequestContext, RequestFuture, ResponseResult, Request}; +use crate::core::types::File; +use crate::core::network; +/// Use this method to get basic info about a file and prepare it for downloading. +/// For the moment, bots can download files of up to 20MB in size. +/// On success, a File object is returned. +/// The file can then be downloaded via the link https://api.telegram.org/file/bot/, +/// where is taken from the response. +/// It is guaranteed that the link will be valid for at least 1 hour. +/// When the link expires, a new one can be requested by calling getFile again. #[derive(Debug, Clone, Serialize)] struct GetFile<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, + /// File identifier to get info about + file_id: String +} + + +impl<'a> Request<'a> for GetFile<'a> { + type ReturnValue = File; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "getFile", + &self, + ) + .await + }) + } +} + + +impl<'a> GetFile<'a>{ + pub fn file_id(mut self, file_id: T) -> Self + where + T: Into, + { + self.file_id = message_id.into(); + self + } } From a7fa66754abb83b899f095d28bf7c2043321dbe1 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 18 Sep 2019 23:41:48 +0600 Subject: [PATCH 08/55] Fix src/core/types/inline_query_result_article.rs --- src/core/types/inline_query_result_article.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs index 1fbdfc8b..fb31e06c 100644 --- a/src/core/types/inline_query_result_article.rs +++ b/src/core/types/inline_query_result_article.rs @@ -2,6 +2,10 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; #[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] pub struct InlineQueryResultArticle { + // Type of the result, must be article + #[serde(rename = "type")] + pub query_type: String, + /// Unique identifier for this result, 1-64 Bytes pub id: String, /// Title of the result From 449780c606c5600860d3f4fc02ae3b11a4f41dd7 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 18 Sep 2019 23:46:31 +0600 Subject: [PATCH 09/55] Add InlineQueryResultCachedMpeg4Gif --- .../types/inline_query_result_cached_mpeg4_gif.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/core/types/inline_query_result_cached_mpeg4_gif.rs diff --git a/src/core/types/inline_query_result_cached_mpeg4_gif.rs b/src/core/types/inline_query_result_cached_mpeg4_gif.rs new file mode 100644 index 00000000..c52dbb5c --- /dev/null +++ b/src/core/types/inline_query_result_cached_mpeg4_gif.rs @@ -0,0 +1,15 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedMpeg4Gif { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub mpeg4_file_id: String, + pub title: Option, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 7c9eb4e8032280bbfe5ac45065a0b7083ad20693 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 18 Sep 2019 23:49:00 +0600 Subject: [PATCH 10/55] Add InlineQueryResultCachedSticker --- src/core/types/inline_query_result_cached_sticker.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/core/types/inline_query_result_cached_sticker.rs diff --git a/src/core/types/inline_query_result_cached_sticker.rs b/src/core/types/inline_query_result_cached_sticker.rs new file mode 100644 index 00000000..b53a7c31 --- /dev/null +++ b/src/core/types/inline_query_result_cached_sticker.rs @@ -0,0 +1,12 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedSticker { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub sticker_file_id: String, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 45ac70ecd9d1b7c1c56bf06b32d53e0d72224da6 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 18 Sep 2019 23:51:10 +0600 Subject: [PATCH 11/55] Add InlineQueryResultCachedDocument --- .../types/inline_query_result_cached_document.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/core/types/inline_query_result_cached_document.rs diff --git a/src/core/types/inline_query_result_cached_document.rs b/src/core/types/inline_query_result_cached_document.rs new file mode 100644 index 00000000..b26f973d --- /dev/null +++ b/src/core/types/inline_query_result_cached_document.rs @@ -0,0 +1,16 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedDocument { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub title: String, + pub document_file_id: String, + pub description: Option, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From ed09426c1518f818188a0f99af7edc476edd4b8c Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 18 Sep 2019 23:52:54 +0600 Subject: [PATCH 12/55] Add InlineQueryResultCachedVideo --- .../types/inline_query_result_cached_video.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/core/types/inline_query_result_cached_video.rs diff --git a/src/core/types/inline_query_result_cached_video.rs b/src/core/types/inline_query_result_cached_video.rs new file mode 100644 index 00000000..79907591 --- /dev/null +++ b/src/core/types/inline_query_result_cached_video.rs @@ -0,0 +1,16 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedVideo { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub video_file_id: String, + pub title: String, + pub description: Option, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 9a22f025dde74259d0df04ff61eef25ad5058e06 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 18 Sep 2019 23:54:26 +0600 Subject: [PATCH 13/55] Add InlineQueryResultCachedVoice --- .../types/inline_query_result_cached_voice.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/core/types/inline_query_result_cached_voice.rs diff --git a/src/core/types/inline_query_result_cached_voice.rs b/src/core/types/inline_query_result_cached_voice.rs new file mode 100644 index 00000000..b4068cff --- /dev/null +++ b/src/core/types/inline_query_result_cached_voice.rs @@ -0,0 +1,15 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedVoice { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub voice_file_id: String, + pub title: String, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 0426a15017018b51a3386ccdf324f79b28037f3a Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Wed, 18 Sep 2019 23:55:57 +0600 Subject: [PATCH 14/55] Add InlineQueryResultCachedAudio --- src/core/types/inline_query_result_cached_audio.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/core/types/inline_query_result_cached_audio.rs diff --git a/src/core/types/inline_query_result_cached_audio.rs b/src/core/types/inline_query_result_cached_audio.rs new file mode 100644 index 00000000..00266a66 --- /dev/null +++ b/src/core/types/inline_query_result_cached_audio.rs @@ -0,0 +1,14 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedAudio { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub audio_file_id: String, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 16b5473daed036a14629ff7887716ae949482f97 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 19 Sep 2019 00:03:14 +0600 Subject: [PATCH 15/55] Add InlineQueryResult --- src/core/types/inline_query_result.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/core/types/inline_query_result.rs diff --git a/src/core/types/inline_query_result.rs b/src/core/types/inline_query_result.rs new file mode 100644 index 00000000..99be2d4b --- /dev/null +++ b/src/core/types/inline_query_result.rs @@ -0,0 +1,25 @@ +use super::inline_query_result_cached_audio::InlineQueryResultCachedAudio; + +#[derive(Debug, Deserialize, Serialize, Eq, Clone, PartialEq, Hash)] +pub enum InlineQueryResult { + CachedAudio(InlineQueryResultCachedAudio), + CachedDocument(InlineQueryResultCachedDocument), + CachedGif(InlineQueryResultCachedGif), + CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif), + CachedPhoto(InlineQueryResultCachedPhoto), + CachedSticker(InlineQueryResultCachedSticker), + CachedVideo(InlineQueryResultCachedVideo), + CachedVoice(InlineQueryResultCachedVoice), + Article(InlineQueryResultArticle), + Audio(InlineQueryResultAudio), + Contact(InlineQueryResultContact), + Game(InlineQueryResultGame), + Document(InlineQueryResultDocument), + Gif(InlineQueryResultGif), + Location(InlineQueryResultLocation), + Mpeg4Gif(InlineQueryResultMpeg4Gif), + Photo(InlineQueryResultPhoto), + Venue(InlineQueryResultVenue), + Video(InlineQueryResultVideo), + Voice(InlineQueryResultVoice), +} From 4e19627f38dd886598b698347bb0ac315234942c Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 19 Sep 2019 00:03:44 +0600 Subject: [PATCH 16/55] Fix the errors --- src/core/requests/get_file.rs | 2 +- src/core/requests/send_chat_action.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/requests/get_file.rs b/src/core/requests/get_file.rs index 648d6452..01d04593 100644 --- a/src/core/requests/get_file.rs +++ b/src/core/requests/get_file.rs @@ -40,7 +40,7 @@ impl<'a> GetFile<'a>{ where T: Into, { - self.file_id = message_id.into(); + self.file_id = file_id.into(); self } } diff --git a/src/core/requests/send_chat_action.rs b/src/core/requests/send_chat_action.rs index f8a1142c..9ab28bee 100644 --- a/src/core/requests/send_chat_action.rs +++ b/src/core/requests/send_chat_action.rs @@ -1,6 +1,5 @@ use crate::core::network; use crate::core::requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}; -use crate::core::types::Message; ///Use this method when you need to tell the user that something is happening on the bot's side. ///The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). From cc534cb95b12eaf97cafee4c603b2e23d6f84c0c Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 19 Sep 2019 00:04:58 +0600 Subject: [PATCH 17/55] Fix the warnings --- src/core/types/inline_keyboard_markup.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/types/inline_keyboard_markup.rs b/src/core/types/inline_keyboard_markup.rs index 5dd68af3..1217a1bc 100644 --- a/src/core/types/inline_keyboard_markup.rs +++ b/src/core/types/inline_keyboard_markup.rs @@ -77,7 +77,7 @@ mod tests { } #[test] - fn append_to_row__existent_row() { + fn append_to_row_existent_row() { let button1 = InlineKeyboardButton::url( "text 1".to_string(), "url 1".to_string(), @@ -98,7 +98,7 @@ mod tests { } #[test] - fn append_to_row__nonexistent_row() { + fn append_to_row_nonexistent_row() { let button1 = InlineKeyboardButton::url( "text 1".to_string(), "url 1".to_string(), From 387e3ae8e9cbf61ef125e31756085c41977361c2 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 19 Sep 2019 00:07:32 +0600 Subject: [PATCH 18/55] Add InlineQueryResultPhoto --- src/core/types/inline_query_result_photo.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/core/types/inline_query_result_photo.rs diff --git a/src/core/types/inline_query_result_photo.rs b/src/core/types/inline_query_result_photo.rs new file mode 100644 index 00000000..ed18a45f --- /dev/null +++ b/src/core/types/inline_query_result_photo.rs @@ -0,0 +1,19 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedPhoto { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub photo_url: String, + pub thumb_url: String, + pub photo_width: Option, + pub photo_height: Option, + pub title: Option, + pub description: Option, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From da2ebc07c370936c6ed46c985f67629932623828 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 19 Sep 2019 00:08:14 +0600 Subject: [PATCH 19/55] Fix src/core/types/inline_query_result_photo.rs --- src/core/types/inline_query_result_photo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/types/inline_query_result_photo.rs b/src/core/types/inline_query_result_photo.rs index ed18a45f..dcc67185 100644 --- a/src/core/types/inline_query_result_photo.rs +++ b/src/core/types/inline_query_result_photo.rs @@ -2,7 +2,7 @@ use super::inline_keyboard_markup::InlineKeyboardMarkup; use super::input_message_content::InputMessageContent; #[derive(Debug, Deserialize, Clone, PartialEq)] -pub struct InlineQueryResultCachedPhoto { +pub struct InlineQueryResultPhoto { #[serde(rename = "type")] pub query_type: String, pub id: String, From 2ef4c6a0e664d5ba6ec43837793c4ac33b87d47e Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 19 Sep 2019 00:10:13 +0600 Subject: [PATCH 20/55] Add InlineQueryResultGif --- src/core/types/inline_query_result_gif.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/core/types/inline_query_result_gif.rs diff --git a/src/core/types/inline_query_result_gif.rs b/src/core/types/inline_query_result_gif.rs new file mode 100644 index 00000000..cf5ec79a --- /dev/null +++ b/src/core/types/inline_query_result_gif.rs @@ -0,0 +1,19 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultGif { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub gif_url: String, + pub gif_width: Option, + pub gif_height: Option, + pub gif_duration: Option, + pub thumb_url: String, + pub title: Option, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 1762ebe2c004731992dfc6c7907f12a2b7f05bf4 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 19 Sep 2019 00:11:47 +0600 Subject: [PATCH 21/55] Add InlineQueryResultMpeg4Gif --- .../types/inline_query_result_mpeg4_gif.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/core/types/inline_query_result_mpeg4_gif.rs diff --git a/src/core/types/inline_query_result_mpeg4_gif.rs b/src/core/types/inline_query_result_mpeg4_gif.rs new file mode 100644 index 00000000..ce72ee01 --- /dev/null +++ b/src/core/types/inline_query_result_mpeg4_gif.rs @@ -0,0 +1,19 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultMpeg4Gif { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub mpeg4_url: String, + pub mpeg4_width: Option, + pub mpeg4_height: Option, + pub mpeg4_duration: Option, + pub thumb_url: String, + pub title: Option, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 4cf17a4b680fbcd8656ff2d37f7378dc9268e839 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Thu, 19 Sep 2019 00:16:44 +0600 Subject: [PATCH 22/55] Add InlineQueryResultVideo --- src/core/types/inline_query_result_video.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/core/types/inline_query_result_video.rs diff --git a/src/core/types/inline_query_result_video.rs b/src/core/types/inline_query_result_video.rs new file mode 100644 index 00000000..56b9f9ce --- /dev/null +++ b/src/core/types/inline_query_result_video.rs @@ -0,0 +1,21 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultVideo { + #[serde(rename = "type")] + pub query_type: String, + pub id: String, + pub video_url: String, + pub mime_type: String, + pub thumb_url: String, + pub title: String, + pub caption: Option, + pub parse_mode: Option, + pub video_width: Option, + pub video_height: Option, + pub video_duration: Option, + pub description: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 3b6b147b69d9628518f5942e91d0c62affb36434 Mon Sep 17 00:00:00 2001 From: RustemB Date: Thu, 19 Sep 2019 00:22:58 +0500 Subject: [PATCH 23/55] getChat --- src/core/requests/get_chat.rs | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/core/requests/get_chat.rs diff --git a/src/core/requests/get_chat.rs b/src/core/requests/get_chat.rs new file mode 100644 index 00000000..eecf2711 --- /dev/null +++ b/src/core/requests/get_chat.rs @@ -0,0 +1,43 @@ +use crate::core::requests::{ChatId, RequestContext, RequestFuture, ResponseResult, Request}; +use crate::core::types::Chat; +use crate::core::network; + +/// Use this method to get up to date information about the chat +/// (current name of the user for one-on-one conversations, +/// current username of a user, group or channel, etc.). +/// Returns a Chat object on success. +#[derive(Debug, Clone, Serialize)] +pub struct GetChat<'a> { + #[serde(skip_serializing)] + ctx: RequestContext<'a>, + /// Unique identifier for the target chat or username + /// of the target supergroup or channel (in the format @channelusername) + chat_id: ChatId, +} + + +impl<'a> Request<'a> for GetChat<'a> { + type ReturnValue = Chat; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "getChat", + &self, + ).await + }) + } +} + + +impl<'a> GetChat<'a>{ + pub fn chat_id(mut self, chat_id: T) -> Self + where + T: Into, + { + self.chat_id = chat_id.into(); + self + } +} From 35b7a2c6cf50b6eb65de94b4683f01e3bc1f9fe8 Mon Sep 17 00:00:00 2001 From: Waffle Date: Wed, 18 Sep 2019 23:51:54 +0300 Subject: [PATCH 24/55] Add missing `InlineQueryResult*` structs --- src/core/types/inline_query_result_audio.rs | 16 ++++++++++++++++ .../types/inline_query_result_cached_gif.rs | 13 +++++++++++++ .../types/inline_query_result_cached_photo.rs | 15 +++++++++++++++ src/core/types/inline_query_result_contact.rs | 17 +++++++++++++++++ .../types/inline_query_result_document.rs | 18 ++++++++++++++++++ src/core/types/inline_query_result_game.rs | 10 ++++++++++ .../types/inline_query_result_location.rs | 18 ++++++++++++++++++ src/core/types/inline_query_result_venue.rs | 19 +++++++++++++++++++ src/core/types/inline_query_result_voice.rs | 14 ++++++++++++++ 9 files changed, 140 insertions(+) create mode 100644 src/core/types/inline_query_result_audio.rs create mode 100644 src/core/types/inline_query_result_cached_gif.rs create mode 100644 src/core/types/inline_query_result_cached_photo.rs create mode 100644 src/core/types/inline_query_result_contact.rs create mode 100644 src/core/types/inline_query_result_document.rs create mode 100644 src/core/types/inline_query_result_game.rs create mode 100644 src/core/types/inline_query_result_location.rs create mode 100644 src/core/types/inline_query_result_venue.rs create mode 100644 src/core/types/inline_query_result_voice.rs diff --git a/src/core/types/inline_query_result_audio.rs b/src/core/types/inline_query_result_audio.rs new file mode 100644 index 00000000..119184fc --- /dev/null +++ b/src/core/types/inline_query_result_audio.rs @@ -0,0 +1,16 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; +use crate::core::types::parse_mode::ParseMode; + +#[derive(Debug, Serialize, Clone, PartialEq)] +pub struct InlineQueryResultAudio { + pub id: String, + pub audio_url: String, + pub title: String, + pub caption: Option, + pub parse_mode: Option, + pub performer: Option, + pub audio_duration: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_gif.rs b/src/core/types/inline_query_result_cached_gif.rs new file mode 100644 index 00000000..4b083bfd --- /dev/null +++ b/src/core/types/inline_query_result_cached_gif.rs @@ -0,0 +1,13 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedGif { + pub id: String, + pub gif_file_id: String, + pub title: Option, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_photo.rs b/src/core/types/inline_query_result_cached_photo.rs new file mode 100644 index 00000000..645808c5 --- /dev/null +++ b/src/core/types/inline_query_result_cached_photo.rs @@ -0,0 +1,15 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; +use crate::core::types::parse_mode::ParseMode; + +#[derive(Debug, Serialize, Clone, PartialEq)] +pub struct InlineQueryResultCachedPhoto { + pub id: String, + pub photo_file_id: String, + pub title: Option, + pub description: Option, + pub caption: Option, + pub parse_mode: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file diff --git a/src/core/types/inline_query_result_contact.rs b/src/core/types/inline_query_result_contact.rs new file mode 100644 index 00000000..141aca39 --- /dev/null +++ b/src/core/types/inline_query_result_contact.rs @@ -0,0 +1,17 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; +use crate::core::types::parse_mode::ParseMode; + +#[derive(Debug, Serialize, Clone, PartialEq)] +pub struct InlineQueryResultContact { + pub id: String, + pub phone_number: String, + pub first_name: String, + pub last_name: Option, + pub vcard: Option, + pub reply_markup: Option, + pub input_message_content: Option, + pub thumb_url: Option, + pub thumb_width: Option, + pub thumb_height: Option, +} \ No newline at end of file diff --git a/src/core/types/inline_query_result_document.rs b/src/core/types/inline_query_result_document.rs new file mode 100644 index 00000000..23cb0a61 --- /dev/null +++ b/src/core/types/inline_query_result_document.rs @@ -0,0 +1,18 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Serialize, Clone, PartialEq)] +pub struct InlineQueryResultDocument { + pub id: String, + pub title: String, + pub caption: Option, + pub parse_mode: Option, + pub document_url: String, + pub mime_type: String, + pub description: Option, + pub reply_markup: Option, + pub input_message_content: Option, + pub thumb_url: Option, + pub thumb_width: Option, + pub thumb_height: Option, +} \ No newline at end of file diff --git a/src/core/types/inline_query_result_game.rs b/src/core/types/inline_query_result_game.rs new file mode 100644 index 00000000..5ce90f86 --- /dev/null +++ b/src/core/types/inline_query_result_game.rs @@ -0,0 +1,10 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; +use crate::core::types::parse_mode::ParseMode; + +#[derive(Debug, Serialize, Clone, PartialEq)] +pub struct InlineQueryResultGame { + pub id: String, + pub game_short_name: String, + pub reply_markup: Option, +} \ No newline at end of file diff --git a/src/core/types/inline_query_result_location.rs b/src/core/types/inline_query_result_location.rs new file mode 100644 index 00000000..77feb856 --- /dev/null +++ b/src/core/types/inline_query_result_location.rs @@ -0,0 +1,18 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; +use crate::core::types::parse_mode::ParseMode; + +#[derive(Debug, Serialize, Clone, PartialEq)] +pub struct InlineQueryResultLocation { + pub id: String, + pub latitude: f64, + pub longitude: f64, + pub title: String, + pub live_period: i32, + pub reply_markup: InlineKeyboardMarkup, + pub input_message_content: InputMessageContent, + pub thumb_url: String, + pub thumb_width: i32, + pub thumb_height: i32, + +} \ No newline at end of file diff --git a/src/core/types/inline_query_result_venue.rs b/src/core/types/inline_query_result_venue.rs new file mode 100644 index 00000000..1dfd9a37 --- /dev/null +++ b/src/core/types/inline_query_result_venue.rs @@ -0,0 +1,19 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; +use crate::core::types::parse_mode::ParseMode; + +#[derive(Debug, Serialize, Clone, PartialEq)] +pub struct InlineQueryResultVenue { + pub id: String, + pub latitude: f64, + pub longitude: f64, + pub title: String, + pub address: String, + pub foursquare_id: Option, + pub foursquare_type: Option, + pub reply_markup: Option, + pub input_message_content: Option, + pub thumb_url: Option, + pub thumb_width: Option, + pub thumb_height: Option, +} \ No newline at end of file diff --git a/src/core/types/inline_query_result_voice.rs b/src/core/types/inline_query_result_voice.rs new file mode 100644 index 00000000..25624795 --- /dev/null +++ b/src/core/types/inline_query_result_voice.rs @@ -0,0 +1,14 @@ +use super::inline_keyboard_markup::InlineKeyboardMarkup; +use super::input_message_content::InputMessageContent; + +#[derive(Debug, Deserialize, Clone, PartialEq)] +pub struct InlineQueryResultVoice { + pub id: String, + pub voice_url: String, + pub title: String, + pub caption: Option, + pub parse_mode: Option, + pub voice_duration: Option, + pub reply_markup: Option, + pub input_message_content: Option, +} \ No newline at end of file From 04d31cd785af463ae6de59f410a6832f09c2caf6 Mon Sep 17 00:00:00 2001 From: Waffle Date: Wed, 18 Sep 2019 23:52:24 +0300 Subject: [PATCH 25/55] Add `InlineQueryResult*` imports --- src/core/types/mod.rs | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index 3a329d5b..d8d73f97 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -47,6 +47,28 @@ pub use self::{ video_note::VideoNote, voice::Voice, file::File, + inline_query::InlineQuery, + inline_query_result::InlineQueryResult, + inline_query_result_cached_audio::InlineQueryResultCachedAudio, + inline_query_result_cached_document::InlineQueryResultCachedDocument, + inline_query_result_cached_gif::InlineQueryResultCachedGif, + inline_query_result_cached_mpeg4_gif::InlineQueryResultCachedMpeg4Gif, + inline_query_result_cached_photo::InlineQueryResultCachedPhoto, + inline_query_result_cached_sticker::InlineQueryResultCachedSticker, + inline_query_result_cached_video::InlineQueryResultCachedVideo, + inline_query_result_cached_voice::InlineQueryResultCachedVoice, + inline_query_result_article::InlineQueryResultArticle, + inline_query_result_audio::InlineQueryResultAudio, + inline_query_result_contact::InlineQueryResultContact, + inline_query_result_game::InlineQueryResultGame, + inline_query_result_document::InlineQueryResultDocument, + inline_query_result_gif::InlineQueryResultGif, + inline_query_result_location::InlineQueryResultLocation, + inline_query_result_mpeg4_gif::InlineQueryResultMpeg4Gif, + inline_query_result_photo::InlineQueryResultPhoto, + inline_query_result_venue::InlineQueryResultVenue, + inline_query_result_video::InlineQueryResultVideo, + inline_query_result_voice::InlineQueryResultVoice, }; mod animation; @@ -95,3 +117,26 @@ mod video; mod video_note; mod voice; mod file; + +mod inline_query; +mod inline_query_result; +mod inline_query_result_cached_audio; +mod inline_query_result_cached_document; +mod inline_query_result_cached_gif; +mod inline_query_result_cached_mpeg4_gif; +mod inline_query_result_cached_photo; +mod inline_query_result_cached_sticker; +mod inline_query_result_cached_video; +mod inline_query_result_cached_voice; +mod inline_query_result_article; +mod inline_query_result_audio; +mod inline_query_result_contact; +mod inline_query_result_game; +mod inline_query_result_document; +mod inline_query_result_gif; +mod inline_query_result_location; +mod inline_query_result_mpeg4_gif; +mod inline_query_result_photo; +mod inline_query_result_venue; +mod inline_query_result_video; +mod inline_query_result_voice; From 59f419f947bce2fcc73383e3fb350812ef9b6684 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:16:44 +0300 Subject: [PATCH 26/55] Clean `InlineQueryResult*` structs --- src/core/types/inline_query.rs | 2 +- src/core/types/inline_query_result.rs | 37 ++++++++++++++++++- src/core/types/inline_query_result_article.rs | 6 +-- src/core/types/inline_query_result_audio.rs | 6 +-- .../types/inline_query_result_cached_audio.rs | 7 +--- .../inline_query_result_cached_document.rs | 7 +--- .../types/inline_query_result_cached_gif.rs | 5 +-- .../inline_query_result_cached_mpeg4_gif.rs | 7 +--- .../types/inline_query_result_cached_photo.rs | 6 +-- .../inline_query_result_cached_sticker.rs | 7 +--- .../types/inline_query_result_cached_video.rs | 7 +--- .../types/inline_query_result_cached_voice.rs | 7 +--- src/core/types/inline_query_result_contact.rs | 6 +-- .../types/inline_query_result_document.rs | 5 +-- src/core/types/inline_query_result_game.rs | 6 +-- src/core/types/inline_query_result_gif.rs | 7 +--- .../types/inline_query_result_location.rs | 6 +-- .../types/inline_query_result_mpeg4_gif.rs | 7 +--- src/core/types/inline_query_result_photo.rs | 7 +--- src/core/types/inline_query_result_venue.rs | 6 +-- src/core/types/inline_query_result_video.rs | 7 +--- src/core/types/inline_query_result_voice.rs | 5 +-- src/core/types/input_message_content.rs | 2 +- src/core/types/mod.rs | 3 ++ 24 files changed, 79 insertions(+), 92 deletions(-) diff --git a/src/core/types/inline_query.rs b/src/core/types/inline_query.rs index 4ee13687..7a1fa571 100644 --- a/src/core/types/inline_query.rs +++ b/src/core/types/inline_query.rs @@ -1,6 +1,6 @@ use crate::core::types::{User, Location}; -#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQuery { /// Unique identifier for this query pub id: String, diff --git a/src/core/types/inline_query_result.rs b/src/core/types/inline_query_result.rs index 99be2d4b..c4c57e29 100644 --- a/src/core/types/inline_query_result.rs +++ b/src/core/types/inline_query_result.rs @@ -1,15 +1,47 @@ -use super::inline_query_result_cached_audio::InlineQueryResultCachedAudio; +use crate::core::types::{ + InlineQueryResultCachedAudio, + InlineQueryResultCachedDocument, + InlineQueryResultCachedGif, + InlineQueryResultCachedMpeg4Gif, + InlineQueryResultCachedPhoto, + InlineQueryResultCachedSticker, + InlineQueryResultCachedVideo, + InlineQueryResultCachedVoice, + InlineQueryResultArticle, + InlineQueryResultAudio, + InlineQueryResultContact, + InlineQueryResultGame, + InlineQueryResultDocument, + InlineQueryResultGif, + InlineQueryResultLocation, + InlineQueryResultMpeg4Gif, + InlineQueryResultPhoto, + InlineQueryResultVenue, + InlineQueryResultVideo, + InlineQueryResultVoice +}; -#[derive(Debug, Deserialize, Serialize, Eq, Clone, PartialEq, Hash)] +#[derive(Debug, Serialize, PartialEq, Clone)] +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] pub enum InlineQueryResult { + #[serde(rename = "audio")] CachedAudio(InlineQueryResultCachedAudio), + #[serde(rename = "document")] CachedDocument(InlineQueryResultCachedDocument), + #[serde(rename = "gif")] CachedGif(InlineQueryResultCachedGif), + #[serde(rename = "mpeg4_gif")] CachedMpeg4Gif(InlineQueryResultCachedMpeg4Gif), + #[serde(rename = "photo")] CachedPhoto(InlineQueryResultCachedPhoto), + #[serde(rename = "sticker")] CachedSticker(InlineQueryResultCachedSticker), + #[serde(rename = "video")] CachedVideo(InlineQueryResultCachedVideo), + #[serde(rename = "voice")] CachedVoice(InlineQueryResultCachedVoice), + Article(InlineQueryResultArticle), Audio(InlineQueryResultAudio), Contact(InlineQueryResultContact), @@ -17,6 +49,7 @@ pub enum InlineQueryResult { Document(InlineQueryResultDocument), Gif(InlineQueryResultGif), Location(InlineQueryResultLocation), + #[serde(rename = "mpeg4_gif")] Mpeg4Gif(InlineQueryResultMpeg4Gif), Photo(InlineQueryResultPhoto), Venue(InlineQueryResultVenue), diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs index fb31e06c..4020ac1f 100644 --- a/src/core/types/inline_query_result_article.rs +++ b/src/core/types/inline_query_result_article.rs @@ -1,11 +1,7 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultArticle { - // Type of the result, must be article - #[serde(rename = "type")] - pub query_type: String, - /// Unique identifier for this result, 1-64 Bytes pub id: String, /// Title of the result diff --git a/src/core/types/inline_query_result_audio.rs b/src/core/types/inline_query_result_audio.rs index 119184fc..e0b22e62 100644 --- a/src/core/types/inline_query_result_audio.rs +++ b/src/core/types/inline_query_result_audio.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{ParseMode, InlineKeyboardMarkup, InputMessageContent}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultAudio { pub id: String, pub audio_url: String, diff --git a/src/core/types/inline_query_result_cached_audio.rs b/src/core/types/inline_query_result_cached_audio.rs index 00266a66..80bb5022 100644 --- a/src/core/types/inline_query_result_cached_audio.rs +++ b/src/core/types/inline_query_result_cached_audio.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedAudio { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub audio_file_id: String, pub caption: Option, diff --git a/src/core/types/inline_query_result_cached_document.rs b/src/core/types/inline_query_result_cached_document.rs index b26f973d..624cbee7 100644 --- a/src/core/types/inline_query_result_cached_document.rs +++ b/src/core/types/inline_query_result_cached_document.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedDocument { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub title: String, pub document_file_id: String, diff --git a/src/core/types/inline_query_result_cached_gif.rs b/src/core/types/inline_query_result_cached_gif.rs index 4b083bfd..d8604013 100644 --- a/src/core/types/inline_query_result_cached_gif.rs +++ b/src/core/types/inline_query_result_cached_gif.rs @@ -1,7 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedGif { pub id: String, pub gif_file_id: String, diff --git a/src/core/types/inline_query_result_cached_mpeg4_gif.rs b/src/core/types/inline_query_result_cached_mpeg4_gif.rs index c52dbb5c..1754bdd8 100644 --- a/src/core/types/inline_query_result_cached_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_cached_mpeg4_gif.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedMpeg4Gif { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub mpeg4_file_id: String, pub title: Option, diff --git a/src/core/types/inline_query_result_cached_photo.rs b/src/core/types/inline_query_result_cached_photo.rs index 645808c5..248590ab 100644 --- a/src/core/types/inline_query_result_cached_photo.rs +++ b/src/core/types/inline_query_result_cached_photo.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedPhoto { pub id: String, pub photo_file_id: String, diff --git a/src/core/types/inline_query_result_cached_sticker.rs b/src/core/types/inline_query_result_cached_sticker.rs index b53a7c31..25c85260 100644 --- a/src/core/types/inline_query_result_cached_sticker.rs +++ b/src/core/types/inline_query_result_cached_sticker.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedSticker { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub sticker_file_id: String, pub reply_markup: Option, diff --git a/src/core/types/inline_query_result_cached_video.rs b/src/core/types/inline_query_result_cached_video.rs index 79907591..7968d0db 100644 --- a/src/core/types/inline_query_result_cached_video.rs +++ b/src/core/types/inline_query_result_cached_video.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedVideo { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub video_file_id: String, pub title: String, diff --git a/src/core/types/inline_query_result_cached_voice.rs b/src/core/types/inline_query_result_cached_voice.rs index b4068cff..9ba3df3a 100644 --- a/src/core/types/inline_query_result_cached_voice.rs +++ b/src/core/types/inline_query_result_cached_voice.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedVoice { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub voice_file_id: String, pub title: String, diff --git a/src/core/types/inline_query_result_contact.rs b/src/core/types/inline_query_result_contact.rs index 141aca39..88a22bd0 100644 --- a/src/core/types/inline_query_result_contact.rs +++ b/src/core/types/inline_query_result_contact.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultContact { pub id: String, pub phone_number: String, diff --git a/src/core/types/inline_query_result_document.rs b/src/core/types/inline_query_result_document.rs index 23cb0a61..72895276 100644 --- a/src/core/types/inline_query_result_document.rs +++ b/src/core/types/inline_query_result_document.rs @@ -1,7 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultDocument { pub id: String, pub title: String, diff --git a/src/core/types/inline_query_result_game.rs b/src/core/types/inline_query_result_game.rs index 5ce90f86..d81643b4 100644 --- a/src/core/types/inline_query_result_game.rs +++ b/src/core/types/inline_query_result_game.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] pub struct InlineQueryResultGame { pub id: String, pub game_short_name: String, diff --git a/src/core/types/inline_query_result_gif.rs b/src/core/types/inline_query_result_gif.rs index cf5ec79a..54f9d8cb 100644 --- a/src/core/types/inline_query_result_gif.rs +++ b/src/core/types/inline_query_result_gif.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultGif { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub gif_url: String, pub gif_width: Option, diff --git a/src/core/types/inline_query_result_location.rs b/src/core/types/inline_query_result_location.rs index 77feb856..dc06c07b 100644 --- a/src/core/types/inline_query_result_location.rs +++ b/src/core/types/inline_query_result_location.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultLocation { pub id: String, pub latitude: f64, diff --git a/src/core/types/inline_query_result_mpeg4_gif.rs b/src/core/types/inline_query_result_mpeg4_gif.rs index ce72ee01..d9dfa407 100644 --- a/src/core/types/inline_query_result_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_mpeg4_gif.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultMpeg4Gif { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub mpeg4_url: String, pub mpeg4_width: Option, diff --git a/src/core/types/inline_query_result_photo.rs b/src/core/types/inline_query_result_photo.rs index dcc67185..f312af43 100644 --- a/src/core/types/inline_query_result_photo.rs +++ b/src/core/types/inline_query_result_photo.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultPhoto { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub photo_url: String, pub thumb_url: String, diff --git a/src/core/types/inline_query_result_venue.rs b/src/core/types/inline_query_result_venue.rs index 1dfd9a37..724cd12f 100644 --- a/src/core/types/inline_query_result_venue.rs +++ b/src/core/types/inline_query_result_venue.rs @@ -1,8 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; -use crate::core::types::parse_mode::ParseMode; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; -#[derive(Debug, Serialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVenue { pub id: String, pub latitude: f64, diff --git a/src/core/types/inline_query_result_video.rs b/src/core/types/inline_query_result_video.rs index 56b9f9ce..d2b3927e 100644 --- a/src/core/types/inline_query_result_video.rs +++ b/src/core/types/inline_query_result_video.rs @@ -1,10 +1,7 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVideo { - #[serde(rename = "type")] - pub query_type: String, pub id: String, pub video_url: String, pub mime_type: String, diff --git a/src/core/types/inline_query_result_voice.rs b/src/core/types/inline_query_result_voice.rs index 25624795..859f48a3 100644 --- a/src/core/types/inline_query_result_voice.rs +++ b/src/core/types/inline_query_result_voice.rs @@ -1,7 +1,6 @@ -use super::inline_keyboard_markup::InlineKeyboardMarkup; -use super::input_message_content::InputMessageContent; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVoice { pub id: String, pub voice_url: String, diff --git a/src/core/types/input_message_content.rs b/src/core/types/input_message_content.rs index 0a23878f..30077945 100644 --- a/src/core/types/input_message_content.rs +++ b/src/core/types/input_message_content.rs @@ -2,7 +2,7 @@ use serde::Serialize; use crate::core::types::ParseMode; -#[derive(Debug, Serialize, Clone)] +#[derive(Debug, Serialize, Clone, PartialEq)] #[serde(untagged)] /// This object represents the content of a message to be sent as /// a result of an inline query. diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index d8d73f97..1d81a65e 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -47,6 +47,8 @@ pub use self::{ video_note::VideoNote, voice::Voice, file::File, + input_message_content::InputMessageContent, + inline_query::InlineQuery, inline_query_result::InlineQueryResult, inline_query_result_cached_audio::InlineQueryResultCachedAudio, @@ -117,6 +119,7 @@ mod video; mod video_note; mod voice; mod file; +mod input_message_content; mod inline_query; mod inline_query_result; From 0896c59c84d49d284ff35a28b335e0c0e054635b Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:17:13 +0300 Subject: [PATCH 27/55] Add `derive(Hash)` to `ParseMode` --- src/core/types/parse_mode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/types/parse_mode.rs b/src/core/types/parse_mode.rs index 44d456de..dc54c1d5 100644 --- a/src/core/types/parse_mode.rs +++ b/src/core/types/parse_mode.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Clone)] /// ## Formatting options /// The Bot API supports basic formatting for messages. /// You can use **bold** and *italic* text, as well as [inline links](https://example.com) and `pre-formatted code` in From 685d19dc344e667e704e43090d215921ec079427 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:27:05 +0300 Subject: [PATCH 28/55] Fix type of `parse_mode` (`String` -> `ParseMode`) --- src/core/types/inline_query_result_cached_audio.rs | 4 ++-- src/core/types/inline_query_result_cached_document.rs | 4 ++-- src/core/types/inline_query_result_cached_gif.rs | 4 ++-- src/core/types/inline_query_result_cached_mpeg4_gif.rs | 4 ++-- src/core/types/inline_query_result_cached_video.rs | 4 ++-- src/core/types/inline_query_result_cached_voice.rs | 4 ++-- src/core/types/inline_query_result_document.rs | 4 ++-- src/core/types/inline_query_result_gif.rs | 4 ++-- src/core/types/inline_query_result_mpeg4_gif.rs | 4 ++-- src/core/types/inline_query_result_photo.rs | 4 ++-- src/core/types/inline_query_result_video.rs | 4 ++-- src/core/types/inline_query_result_voice.rs | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/core/types/inline_query_result_cached_audio.rs b/src/core/types/inline_query_result_cached_audio.rs index 80bb5022..89497401 100644 --- a/src/core/types/inline_query_result_cached_audio.rs +++ b/src/core/types/inline_query_result_cached_audio.rs @@ -1,11 +1,11 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedAudio { pub id: String, pub audio_file_id: String, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_document.rs b/src/core/types/inline_query_result_cached_document.rs index 624cbee7..26c194b9 100644 --- a/src/core/types/inline_query_result_cached_document.rs +++ b/src/core/types/inline_query_result_cached_document.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedDocument { @@ -7,7 +7,7 @@ pub struct InlineQueryResultCachedDocument { pub document_file_id: String, pub description: Option, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_gif.rs b/src/core/types/inline_query_result_cached_gif.rs index d8604013..6ce10cdf 100644 --- a/src/core/types/inline_query_result_cached_gif.rs +++ b/src/core/types/inline_query_result_cached_gif.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedGif { @@ -6,7 +6,7 @@ pub struct InlineQueryResultCachedGif { pub gif_file_id: String, pub title: Option, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_mpeg4_gif.rs b/src/core/types/inline_query_result_cached_mpeg4_gif.rs index 1754bdd8..c8a101f2 100644 --- a/src/core/types/inline_query_result_cached_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_cached_mpeg4_gif.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedMpeg4Gif { @@ -6,7 +6,7 @@ pub struct InlineQueryResultCachedMpeg4Gif { pub mpeg4_file_id: String, pub title: Option, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_video.rs b/src/core/types/inline_query_result_cached_video.rs index 7968d0db..c880f106 100644 --- a/src/core/types/inline_query_result_cached_video.rs +++ b/src/core/types/inline_query_result_cached_video.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedVideo { @@ -7,7 +7,7 @@ pub struct InlineQueryResultCachedVideo { pub title: String, pub description: Option, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_voice.rs b/src/core/types/inline_query_result_cached_voice.rs index 9ba3df3a..08be2eed 100644 --- a/src/core/types/inline_query_result_cached_voice.rs +++ b/src/core/types/inline_query_result_cached_voice.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedVoice { @@ -6,7 +6,7 @@ pub struct InlineQueryResultCachedVoice { pub voice_file_id: String, pub title: String, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_document.rs b/src/core/types/inline_query_result_document.rs index 72895276..99f7866b 100644 --- a/src/core/types/inline_query_result_document.rs +++ b/src/core/types/inline_query_result_document.rs @@ -1,11 +1,11 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultDocument { pub id: String, pub title: String, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub document_url: String, pub mime_type: String, pub description: Option, diff --git a/src/core/types/inline_query_result_gif.rs b/src/core/types/inline_query_result_gif.rs index 54f9d8cb..0d884e6a 100644 --- a/src/core/types/inline_query_result_gif.rs +++ b/src/core/types/inline_query_result_gif.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultGif { @@ -10,7 +10,7 @@ pub struct InlineQueryResultGif { pub thumb_url: String, pub title: Option, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_mpeg4_gif.rs b/src/core/types/inline_query_result_mpeg4_gif.rs index d9dfa407..a7f33542 100644 --- a/src/core/types/inline_query_result_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_mpeg4_gif.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultMpeg4Gif { @@ -10,7 +10,7 @@ pub struct InlineQueryResultMpeg4Gif { pub thumb_url: String, pub title: Option, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_photo.rs b/src/core/types/inline_query_result_photo.rs index f312af43..85c94574 100644 --- a/src/core/types/inline_query_result_photo.rs +++ b/src/core/types/inline_query_result_photo.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultPhoto { @@ -10,7 +10,7 @@ pub struct InlineQueryResultPhoto { pub title: Option, pub description: Option, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub reply_markup: Option, pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_video.rs b/src/core/types/inline_query_result_video.rs index d2b3927e..c5b49731 100644 --- a/src/core/types/inline_query_result_video.rs +++ b/src/core/types/inline_query_result_video.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVideo { @@ -8,7 +8,7 @@ pub struct InlineQueryResultVideo { pub thumb_url: String, pub title: String, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub video_width: Option, pub video_height: Option, pub video_duration: Option, diff --git a/src/core/types/inline_query_result_voice.rs b/src/core/types/inline_query_result_voice.rs index 859f48a3..169a1ca7 100644 --- a/src/core/types/inline_query_result_voice.rs +++ b/src/core/types/inline_query_result_voice.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVoice { @@ -6,7 +6,7 @@ pub struct InlineQueryResultVoice { pub voice_url: String, pub title: String, pub caption: Option, - pub parse_mode: Option, + pub parse_mode: Option, pub voice_duration: Option, pub reply_markup: Option, pub input_message_content: Option, From f96f9a3a2b543bf364975b85e42f76e0c125696d Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:44:23 +0300 Subject: [PATCH 29/55] Fix `InlineQueryResultLocation` (Add `Option<>` to optional fields) --- src/core/types/inline_query_result_location.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/types/inline_query_result_location.rs b/src/core/types/inline_query_result_location.rs index dc06c07b..c4b5d296 100644 --- a/src/core/types/inline_query_result_location.rs +++ b/src/core/types/inline_query_result_location.rs @@ -6,11 +6,11 @@ pub struct InlineQueryResultLocation { pub latitude: f64, pub longitude: f64, pub title: String, - pub live_period: i32, - pub reply_markup: InlineKeyboardMarkup, - pub input_message_content: InputMessageContent, - pub thumb_url: String, - pub thumb_width: i32, - pub thumb_height: i32, + pub live_period: Option, + pub reply_markup: Option, + pub input_message_content: Option, + pub thumb_url: Option, + pub thumb_width: Option, + pub thumb_height: Option, } \ No newline at end of file From feee762d781d14e59085312283d350f0b42c0f8b Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:55:46 +0300 Subject: [PATCH 30/55] Fix test `core::types::input_message_content::tests::venue_serialize` --- src/core/types/input_message_content.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/types/input_message_content.rs b/src/core/types/input_message_content.rs index 30077945..d36f73b7 100644 --- a/src/core/types/input_message_content.rs +++ b/src/core/types/input_message_content.rs @@ -108,8 +108,7 @@ mod tests { #[test] fn venue_serialize() { - let expected_json = r#"{"latitude":59.08,"longitude":38.4326,"title":"some title", - "address":"some address"}"#; + let expected_json = r#"{"latitude":59.08,"longitude":38.4326,"title":"some title","address":"some address"}"#; let venue_content = InputMessageContent::Venue { latitude: 59.08, longitude: 38.4326, From 1bee0a9c265ab6433b2d0bbca219641cdcb34aba Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:57:23 +0300 Subject: [PATCH 31/55] Fix test `src/core/types/inline_keyboard_markup.rs - core::types::inline_keyboard_markup::InlineKeyboardMarkup (line 18)` --- src/core/types/inline_keyboard_markup.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/types/inline_keyboard_markup.rs b/src/core/types/inline_keyboard_markup.rs index 1217a1bc..37c753a4 100644 --- a/src/core/types/inline_keyboard_markup.rs +++ b/src/core/types/inline_keyboard_markup.rs @@ -15,20 +15,19 @@ pub struct InlineKeyboardMarkup { /// Build Markup /// /// Example: -/// ```edition2018 +/// ``` /// use async_telegram_bot::core::types::{ /// InlineKeyboardMarkup, /// InlineKeyboardButton /// }; /// -/// fn main() { -/// let url_button = InlineKeyboardButton::url( -/// "text".to_string(), -/// "http://url.com".to_string() -/// ); -/// let keyboard = InlineKeyboardMarkup::new() -/// .row(vec![url_button]); -/// } +/// +/// let url_button = InlineKeyboardButton::url( +/// "text".to_string(), +/// "http://url.com".to_string() +/// ); +/// let keyboard = InlineKeyboardMarkup::new() +/// .append_row(vec![url_button]); /// ``` impl InlineKeyboardMarkup { pub fn new() -> Self { From 3c65d34955562c6bfc691e534c1451e19e3bd391 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:58:30 +0300 Subject: [PATCH 32/55] Add `#[serde(skip_serializing_if = "Option::is_none")]` to `InlineQueryResult*` optional fields --- src/core/types/inline_query_result_article.rs | 7 +++++++ src/core/types/inline_query_result_audio.rs | 6 ++++++ src/core/types/inline_query_result_cached_audio.rs | 4 ++++ src/core/types/inline_query_result_cached_document.rs | 5 +++++ src/core/types/inline_query_result_cached_gif.rs | 5 +++++ src/core/types/inline_query_result_cached_mpeg4_gif.rs | 5 +++++ src/core/types/inline_query_result_cached_photo.rs | 6 ++++++ src/core/types/inline_query_result_cached_sticker.rs | 2 ++ src/core/types/inline_query_result_cached_video.rs | 5 +++++ src/core/types/inline_query_result_cached_voice.rs | 4 ++++ src/core/types/inline_query_result_contact.rs | 7 +++++++ src/core/types/inline_query_result_document.rs | 8 ++++++++ src/core/types/inline_query_result_game.rs | 1 + src/core/types/inline_query_result_gif.rs | 8 ++++++++ src/core/types/inline_query_result_location.rs | 7 ++++++- src/core/types/inline_query_result_mpeg4_gif.rs | 8 ++++++++ src/core/types/inline_query_result_photo.rs | 8 ++++++++ src/core/types/inline_query_result_venue.rs | 7 +++++++ src/core/types/inline_query_result_video.rs | 8 ++++++++ src/core/types/inline_query_result_voice.rs | 5 +++++ 20 files changed, 115 insertions(+), 1 deletion(-) diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs index 4020ac1f..b887c75d 100644 --- a/src/core/types/inline_query_result_article.rs +++ b/src/core/types/inline_query_result_article.rs @@ -9,17 +9,24 @@ pub struct InlineQueryResultArticle { /// Content of the message to be sent pub input_message_content: InputMessageContent, /// Optional. Inline keyboard attached to the message + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, /// Optional. URL of the result + #[serde(skip_serializing_if = "Option::is_none")] pub url: Option, /// Optional. Pass True, if you don't want the URL to be shown in the message + #[serde(skip_serializing_if = "Option::is_none")] pub hide_url: Option, /// Optional. Short description of the result + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, /// Optional. Url of the thumbnail for the result + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_url: Option, /// Optional. Thumbnail width + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_width: Option, /// Optional. Thumbnail height + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, } diff --git a/src/core/types/inline_query_result_audio.rs b/src/core/types/inline_query_result_audio.rs index e0b22e62..ac8d40b8 100644 --- a/src/core/types/inline_query_result_audio.rs +++ b/src/core/types/inline_query_result_audio.rs @@ -5,10 +5,16 @@ pub struct InlineQueryResultAudio { pub id: String, pub audio_url: String, pub title: String, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub performer: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub audio_duration: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_audio.rs b/src/core/types/inline_query_result_cached_audio.rs index 89497401..6975dbd6 100644 --- a/src/core/types/inline_query_result_cached_audio.rs +++ b/src/core/types/inline_query_result_cached_audio.rs @@ -4,8 +4,12 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; pub struct InlineQueryResultCachedAudio { pub id: String, pub audio_file_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_document.rs b/src/core/types/inline_query_result_cached_document.rs index 26c194b9..c821ffa7 100644 --- a/src/core/types/inline_query_result_cached_document.rs +++ b/src/core/types/inline_query_result_cached_document.rs @@ -5,9 +5,14 @@ pub struct InlineQueryResultCachedDocument { pub id: String, pub title: String, pub document_file_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_gif.rs b/src/core/types/inline_query_result_cached_gif.rs index 6ce10cdf..ab1dc7d6 100644 --- a/src/core/types/inline_query_result_cached_gif.rs +++ b/src/core/types/inline_query_result_cached_gif.rs @@ -4,9 +4,14 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; pub struct InlineQueryResultCachedGif { pub id: String, pub gif_file_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_mpeg4_gif.rs b/src/core/types/inline_query_result_cached_mpeg4_gif.rs index c8a101f2..8763142b 100644 --- a/src/core/types/inline_query_result_cached_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_cached_mpeg4_gif.rs @@ -4,9 +4,14 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; pub struct InlineQueryResultCachedMpeg4Gif { pub id: String, pub mpeg4_file_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_photo.rs b/src/core/types/inline_query_result_cached_photo.rs index 248590ab..f012b56d 100644 --- a/src/core/types/inline_query_result_cached_photo.rs +++ b/src/core/types/inline_query_result_cached_photo.rs @@ -4,10 +4,16 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; pub struct InlineQueryResultCachedPhoto { pub id: String, pub photo_file_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_sticker.rs b/src/core/types/inline_query_result_cached_sticker.rs index 25c85260..037cc670 100644 --- a/src/core/types/inline_query_result_cached_sticker.rs +++ b/src/core/types/inline_query_result_cached_sticker.rs @@ -4,6 +4,8 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; pub struct InlineQueryResultCachedSticker { pub id: String, pub sticker_file_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_video.rs b/src/core/types/inline_query_result_cached_video.rs index c880f106..2bebfdff 100644 --- a/src/core/types/inline_query_result_cached_video.rs +++ b/src/core/types/inline_query_result_cached_video.rs @@ -5,9 +5,14 @@ pub struct InlineQueryResultCachedVideo { pub id: String, pub video_file_id: String, pub title: String, + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_cached_voice.rs b/src/core/types/inline_query_result_cached_voice.rs index 08be2eed..e0ec1074 100644 --- a/src/core/types/inline_query_result_cached_voice.rs +++ b/src/core/types/inline_query_result_cached_voice.rs @@ -5,8 +5,12 @@ pub struct InlineQueryResultCachedVoice { pub id: String, pub voice_file_id: String, pub title: String, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_contact.rs b/src/core/types/inline_query_result_contact.rs index 88a22bd0..0c0d22b7 100644 --- a/src/core/types/inline_query_result_contact.rs +++ b/src/core/types/inline_query_result_contact.rs @@ -5,11 +5,18 @@ pub struct InlineQueryResultContact { pub id: String, pub phone_number: String, pub first_name: String, + #[serde(skip_serializing_if = "Option::is_none")] pub last_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub vcard: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_width: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_document.rs b/src/core/types/inline_query_result_document.rs index 99f7866b..7ff3bf44 100644 --- a/src/core/types/inline_query_result_document.rs +++ b/src/core/types/inline_query_result_document.rs @@ -4,14 +4,22 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; pub struct InlineQueryResultDocument { pub id: String, pub title: String, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, pub document_url: String, pub mime_type: String, + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_width: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_game.rs b/src/core/types/inline_query_result_game.rs index d81643b4..942eb2b5 100644 --- a/src/core/types/inline_query_result_game.rs +++ b/src/core/types/inline_query_result_game.rs @@ -4,5 +4,6 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; pub struct InlineQueryResultGame { pub id: String, pub game_short_name: String, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_gif.rs b/src/core/types/inline_query_result_gif.rs index 0d884e6a..c86d634a 100644 --- a/src/core/types/inline_query_result_gif.rs +++ b/src/core/types/inline_query_result_gif.rs @@ -4,13 +4,21 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; pub struct InlineQueryResultGif { pub id: String, pub gif_url: String, + #[serde(skip_serializing_if = "Option::is_none")] pub gif_width: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub gif_height: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub gif_duration: Option, pub thumb_url: String, + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_location.rs b/src/core/types/inline_query_result_location.rs index c4b5d296..09c034f5 100644 --- a/src/core/types/inline_query_result_location.rs +++ b/src/core/types/inline_query_result_location.rs @@ -6,11 +6,16 @@ pub struct InlineQueryResultLocation { pub latitude: f64, pub longitude: f64, pub title: String, + #[serde(skip_serializing_if = "Option::is_none")] pub live_period: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_width: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, - } \ No newline at end of file diff --git a/src/core/types/inline_query_result_mpeg4_gif.rs b/src/core/types/inline_query_result_mpeg4_gif.rs index a7f33542..186cdba1 100644 --- a/src/core/types/inline_query_result_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_mpeg4_gif.rs @@ -4,13 +4,21 @@ use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; pub struct InlineQueryResultMpeg4Gif { pub id: String, pub mpeg4_url: String, + #[serde(skip_serializing_if = "Option::is_none")] pub mpeg4_width: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub mpeg4_height: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub mpeg4_duration: Option, pub thumb_url: String, + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_photo.rs b/src/core/types/inline_query_result_photo.rs index 85c94574..cf2b4b51 100644 --- a/src/core/types/inline_query_result_photo.rs +++ b/src/core/types/inline_query_result_photo.rs @@ -5,12 +5,20 @@ pub struct InlineQueryResultPhoto { pub id: String, pub photo_url: String, pub thumb_url: String, + #[serde(skip_serializing_if = "Option::is_none")] pub photo_width: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub photo_height: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_venue.rs b/src/core/types/inline_query_result_venue.rs index 724cd12f..e6beb38d 100644 --- a/src/core/types/inline_query_result_venue.rs +++ b/src/core/types/inline_query_result_venue.rs @@ -7,11 +7,18 @@ pub struct InlineQueryResultVenue { pub longitude: f64, pub title: String, pub address: String, + #[serde(skip_serializing_if = "Option::is_none")] pub foursquare_id: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub foursquare_type: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_width: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_video.rs b/src/core/types/inline_query_result_video.rs index c5b49731..566eea6d 100644 --- a/src/core/types/inline_query_result_video.rs +++ b/src/core/types/inline_query_result_video.rs @@ -7,12 +7,20 @@ pub struct InlineQueryResultVideo { pub mime_type: String, pub thumb_url: String, pub title: String, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub video_width: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub video_height: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub video_duration: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file diff --git a/src/core/types/inline_query_result_voice.rs b/src/core/types/inline_query_result_voice.rs index 169a1ca7..38d2de62 100644 --- a/src/core/types/inline_query_result_voice.rs +++ b/src/core/types/inline_query_result_voice.rs @@ -5,9 +5,14 @@ pub struct InlineQueryResultVoice { pub id: String, pub voice_url: String, pub title: String, + #[serde(skip_serializing_if = "Option::is_none")] pub caption: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub parse_mode: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub voice_duration: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, } \ No newline at end of file From 2b1ce74d94d9bb2471a2d2cbedb282e4882ad8e2 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 00:59:13 +0300 Subject: [PATCH 33/55] Add 2 serialization tests to `InlineQueryResult` --- src/core/types/inline_query_result.rs | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/core/types/inline_query_result.rs b/src/core/types/inline_query_result.rs index c4c57e29..144c1cc4 100644 --- a/src/core/types/inline_query_result.rs +++ b/src/core/types/inline_query_result.rs @@ -56,3 +56,54 @@ pub enum InlineQueryResult { Video(InlineQueryResultVideo), Voice(InlineQueryResultVoice), } + +#[cfg(test)] +mod tests { + use crate::core::types::{InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent}; + use crate::core::types::parse_mode::ParseMode; + use crate::core::types::inline_keyboard_markup::InlineKeyboardMarkup; + + #[test] + fn cached_audio_min_serialize() { + let structure = InlineQueryResult::CachedAudio( + InlineQueryResultCachedAudio { + id: String::from("id"), + audio_file_id: String::from("audio_file_id"), + caption: None, + parse_mode: None, + reply_markup: None, + input_message_content: None + } + ); + + let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id"}"#; + let actual_json = serde_json::to_string(&structure).unwrap(); + + assert_eq!(expected_json, actual_json); + } + + #[test] + fn cached_audio_full_serialize() { + let structure = InlineQueryResult::CachedAudio( + InlineQueryResultCachedAudio { + id: String::from("id"), + audio_file_id: String::from("audio_file_id"), + caption: Some(String::from("caption")), + parse_mode: Some(ParseMode::HTML), + reply_markup: Some(InlineKeyboardMarkup::new()), + input_message_content: Some(InputMessageContent::Text { + message_text: String::from("message_text"), + parse_mode: Some(ParseMode::Markdown), + disable_web_page_preview: Some(true) + }) + } + ); + + let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id","caption":"caption","parse_mode":"HTML","reply_markup":{"inline_keyboard":[]},"input_message_content":{"message_text":"message_text","parse_mode":"Markdown","disable_web_page_preview":true}}"#; + let actual_json = serde_json::to_string(&structure).unwrap(); + + assert_eq!(expected_json, actual_json); + } + + // TODO: Add more tests +} \ No newline at end of file From fda1d37e779eeeba8042b4963e5974c10773fdcd Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 01:30:30 +0300 Subject: [PATCH 34/55] Run `cargo fmt` --- src/bot/mod.rs | 57 +++++------------ .../requests/answer_pre_checkout_query.rs | 22 ++++--- src/core/requests/answer_shipping_query.rs | 27 +++++--- src/core/requests/forward_message.rs | 6 +- src/core/requests/get_file.rs | 22 +++---- src/core/requests/send_chat_action.rs | 24 ++++---- src/core/requests/send_message.rs | 6 +- .../requests/stop_message_live_location.rs | 6 +- src/core/requests/utils.rs | 6 +- src/core/types/animation.rs | 6 +- src/core/types/callback_query.rs | 19 +++--- src/core/types/chat.rs | 2 - src/core/types/chosen_inline_result.rs | 8 +-- src/core/types/contact.rs | 2 +- src/core/types/file.rs | 2 +- src/core/types/game.rs | 22 ++++--- src/core/types/inline_keyboard_button.rs | 23 ++++--- src/core/types/inline_keyboard_markup.rs | 33 ++++------ src/core/types/inline_query.rs | 2 +- src/core/types/inline_query_result.rs | 61 ++++++++----------- src/core/types/inline_query_result_article.rs | 5 +- src/core/types/inline_query_result_audio.rs | 6 +- .../types/inline_query_result_cached_audio.rs | 6 +- .../inline_query_result_cached_document.rs | 6 +- .../types/inline_query_result_cached_gif.rs | 6 +- .../inline_query_result_cached_mpeg4_gif.rs | 6 +- .../types/inline_query_result_cached_photo.rs | 6 +- .../inline_query_result_cached_sticker.rs | 4 +- .../types/inline_query_result_cached_video.rs | 6 +- .../types/inline_query_result_cached_voice.rs | 6 +- src/core/types/inline_query_result_contact.rs | 6 +- .../types/inline_query_result_document.rs | 6 +- src/core/types/inline_query_result_game.rs | 6 +- src/core/types/inline_query_result_gif.rs | 6 +- .../types/inline_query_result_location.rs | 6 +- .../types/inline_query_result_mpeg4_gif.rs | 6 +- src/core/types/inline_query_result_photo.rs | 6 +- src/core/types/inline_query_result_venue.rs | 6 +- src/core/types/inline_query_result_video.rs | 6 +- src/core/types/inline_query_result_voice.rs | 6 +- src/core/types/input_message_content.rs | 32 ++++++---- src/core/types/label_price.rs | 2 +- src/core/types/location.rs | 2 +- src/core/types/mask_position.rs | 1 - src/core/types/mod.rs | 59 +++++++++--------- src/core/types/photo_size.rs | 2 +- src/core/types/send_invoice.rs | 2 +- src/core/types/shipping_option.rs | 7 ++- src/core/types/update.rs | 4 +- src/core/types/venue.rs | 7 ++- src/core/types/video_note.rs | 7 ++- src/core/types/voice.rs | 2 +- 52 files changed, 303 insertions(+), 297 deletions(-) diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 96472626..1a818920 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -1,24 +1,15 @@ use reqwest::r#async::Client; use crate::core::{ - types::{ - InputFile, - InputMedia, - }, requests::{ - ChatId, - RequestContext, - - get_me::GetMe, - send_message::SendMessage, edit_message_live_location::EditMessageLiveLocation, - forward_message::ForwardMessage, - send_audio::SendAudio, - send_location::SendLocation, - send_media_group::SendMediaGroup, - send_photo::SendPhoto, - stop_message_live_location::StopMessageLiveLocation, - } + forward_message::ForwardMessage, get_me::GetMe, send_audio::SendAudio, + send_location::SendLocation, send_media_group::SendMediaGroup, + send_message::SendMessage, send_photo::SendPhoto, + stop_message_live_location::StopMessageLiveLocation, ChatId, + RequestContext, + }, + types::{InputFile, InputMedia}, }; pub struct Bot { @@ -60,11 +51,7 @@ impl Bot { C: Into, T: Into, { - SendMessage::new( - self.ctx(), - chat_id.into(), - text.into(), - ) + SendMessage::new(self.ctx(), chat_id.into(), text.into()) } pub fn edit_message_live_location( @@ -87,7 +74,7 @@ impl Bot { &self, chat_id: C, from_chat_id: F, - message_id: M + message_id: M, ) -> ForwardMessage where C: Into, @@ -107,11 +94,7 @@ impl Bot { C: Into, A: Into, { - SendAudio::new( - self.ctx(), - chat_id.into(), - audio.into() - ) + SendAudio::new(self.ctx(), chat_id.into(), audio.into()) } pub fn send_location( @@ -136,30 +119,20 @@ impl Bot { pub fn send_media_group(&self, chat_id: C, media: M) -> SendMediaGroup where C: Into, - M: Into> + M: Into>, { - SendMediaGroup::new( - self.ctx(), - chat_id.into(), - media.into(), - ) + SendMediaGroup::new(self.ctx(), chat_id.into(), media.into()) } pub fn send_photo(&self, chat_id: C, photo: P) -> SendPhoto where C: Into, - P: Into + P: Into, { - SendPhoto::new( - self.ctx(), - chat_id.into(), - photo.into(), - ) + SendPhoto::new(self.ctx(), chat_id.into(), photo.into()) } pub fn stop_message_live_location(&self) -> StopMessageLiveLocation { - StopMessageLiveLocation::new( - self.ctx() - ) + StopMessageLiveLocation::new(self.ctx()) } } diff --git a/src/core/requests/answer_pre_checkout_query.rs b/src/core/requests/answer_pre_checkout_query.rs index fb995ae2..f494ead8 100644 --- a/src/core/requests/answer_pre_checkout_query.rs +++ b/src/core/requests/answer_pre_checkout_query.rs @@ -1,6 +1,6 @@ use crate::core::{ - requests::{RequestContext, Request, RequestFuture, ResponseResult}, - network + network, + requests::{Request, RequestContext, RequestFuture, ResponseResult}, }; #[derive(Debug, Serialize, Clone)] @@ -40,8 +40,9 @@ impl<'a> Request<'a> for AnswerPreCheckoutQuery<'a> { &self.ctx.client, &self.ctx.token, "answerPreCheckoutQuery", - &self - ).await + &self, + ) + .await }) } } @@ -50,32 +51,35 @@ impl<'a> AnswerPreCheckoutQuery<'a> { pub(crate) fn new( ctx: RequestContext<'a>, pre_checkout_query_id: String, - ok: bool + ok: bool, ) -> Self { Self { ctx, pre_checkout_query_id, ok, - error_message: None + error_message: None, } } pub fn pre_checkout_query_id(mut self, pre_checkout_query_id: T) -> Self - where T: Into + where + T: Into, { self.pre_checkout_query_id = pre_checkout_query_id.into(); self } pub fn ok(mut self, ok: T) -> Self - where T: Into + where + T: Into, { self.ok = ok.into(); self } pub fn error_message(mut self, error_message: T) -> Self - where T: Into + where + T: Into, { self.error_message = Some(error_message.into()); self diff --git a/src/core/requests/answer_shipping_query.rs b/src/core/requests/answer_shipping_query.rs index 74728d92..c66860c9 100644 --- a/src/core/requests/answer_shipping_query.rs +++ b/src/core/requests/answer_shipping_query.rs @@ -1,6 +1,8 @@ -use crate::core::types::ShippingOption; -use crate::core::requests::{RequestContext, Request, RequestFuture, ResponseResult}; use crate::core::network; +use crate::core::requests::{ + Request, RequestContext, RequestFuture, ResponseResult, +}; +use crate::core::types::ShippingOption; #[derive(Debug, Clone, Serialize)] /// If you sent an invoice requesting a shipping address and the parameter @@ -40,8 +42,9 @@ impl<'a> Request<'a> for AnswerShippingQuery<'a> { &self.ctx.client, &self.ctx.token, "answerShippingQuery", - &self - ).await + &self, + ) + .await }) } } @@ -50,40 +53,44 @@ impl<'a> AnswerShippingQuery<'a> { pub(crate) fn new( ctx: RequestContext<'a>, shipping_query_id: String, - ok: bool + ok: bool, ) -> Self { Self { ctx, shipping_query_id, ok, shipping_options: None, - error_message: None + error_message: None, } } pub fn shipping_query_id(mut self, shipping_query_id: T) -> Self - where T: Into + where + T: Into, { self.shipping_query_id = shipping_query_id.into(); self } pub fn ok(mut self, ok: T) -> Self - where T: Into + where + T: Into, { self.ok = ok.into(); self } pub fn shipping_options(mut self, shipping_options: T) -> Self - where T: Into> + where + T: Into>, { self.shipping_options = Some(shipping_options.into()); self } pub fn error_message(mut self, error_message: T) -> Self - where T: Into + where + T: Into, { self.error_message = Some(error_message.into()); self diff --git a/src/core/requests/forward_message.rs b/src/core/requests/forward_message.rs index 2de100f4..ec24a7e3 100644 --- a/src/core/requests/forward_message.rs +++ b/src/core/requests/forward_message.rs @@ -1,11 +1,7 @@ use crate::core::{ network, requests::{ - ChatId, - Request, - RequestFuture, - RequestContext, - ResponseResult, + ChatId, Request, RequestContext, RequestFuture, ResponseResult, }, types::Message, }; diff --git a/src/core/requests/get_file.rs b/src/core/requests/get_file.rs index 01d04593..089ff743 100644 --- a/src/core/requests/get_file.rs +++ b/src/core/requests/get_file.rs @@ -1,9 +1,11 @@ -use crate::core::requests::{RequestContext, RequestFuture, ResponseResult, Request}; -use crate::core::types::File; use crate::core::network; +use crate::core::requests::{ + Request, RequestContext, RequestFuture, ResponseResult, +}; +use crate::core::types::File; -/// Use this method to get basic info about a file and prepare it for downloading. -/// For the moment, bots can download files of up to 20MB in size. +/// Use this method to get basic info about a file and prepare it for +/// downloading. For the moment, bots can download files of up to 20MB in size. /// On success, a File object is returned. /// The file can then be downloaded via the link https://api.telegram.org/file/bot/, /// where is taken from the response. @@ -14,10 +16,9 @@ struct GetFile<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, /// File identifier to get info about - file_id: String + file_id: String, } - impl<'a> Request<'a> for GetFile<'a> { type ReturnValue = File; @@ -29,16 +30,15 @@ impl<'a> Request<'a> for GetFile<'a> { "getFile", &self, ) - .await + .await }) } } - -impl<'a> GetFile<'a>{ +impl<'a> GetFile<'a> { pub fn file_id(mut self, file_id: T) -> Self - where - T: Into, + where + T: Into, { self.file_id = file_id.into(); self diff --git a/src/core/requests/send_chat_action.rs b/src/core/requests/send_chat_action.rs index 9ab28bee..ae07ec05 100644 --- a/src/core/requests/send_chat_action.rs +++ b/src/core/requests/send_chat_action.rs @@ -1,9 +1,12 @@ use crate::core::network; -use crate::core::requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}; +use crate::core::requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, +}; -///Use this method when you need to tell the user that something is happening on the bot's side. -///The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). -///Returns True on success. +///Use this method when you need to tell the user that something is happening +/// on the bot's side. The status is set for 5 seconds or less (when a message +/// arrives from your bot, Telegram clients clear its typing status). +/// Returns True on success. #[derive(Debug, Clone, Serialize)] struct SendChatAction<'a> { #[serde(skip_serializing)] @@ -45,7 +48,7 @@ impl<'a> Request<'a> for SendChatAction<'a> { "sendChatAction", &self, ) - .await + .await }) } } @@ -64,19 +67,18 @@ impl<'a> SendChatAction<'a> { } pub fn chat_id(mut self, chat_id: T) -> Self - where - T: Into, + where + T: Into, { self.chat_id = chat_id.into(); self } - pub fn action(mut self, action: T) -> Self - where - T: Into, + where + T: Into, { self.action = action.into(); self } -} \ No newline at end of file +} diff --git a/src/core/requests/send_message.rs b/src/core/requests/send_message.rs index ed0fcf85..2539c04d 100644 --- a/src/core/requests/send_message.rs +++ b/src/core/requests/send_message.rs @@ -1,11 +1,7 @@ use crate::core::{ network, requests::{ - ChatId, - Request, - RequestFuture, - RequestContext, - ResponseResult, + ChatId, Request, RequestContext, RequestFuture, ResponseResult, }, types::{Message, ParseMode, ReplyMarkup}, }; diff --git a/src/core/requests/stop_message_live_location.rs b/src/core/requests/stop_message_live_location.rs index c86ee1ed..5fb62a54 100644 --- a/src/core/requests/stop_message_live_location.rs +++ b/src/core/requests/stop_message_live_location.rs @@ -1,11 +1,7 @@ use crate::core::{ network, requests::{ - ChatId, - Request, - RequestFuture, - RequestContext, - ResponseResult, + ChatId, Request, RequestContext, RequestFuture, ResponseResult, }, types::{InlineKeyboardMarkup, Message}, }; diff --git a/src/core/requests/utils.rs b/src/core/requests/utils.rs index 193bad0c..90f9c409 100644 --- a/src/core/requests/utils.rs +++ b/src/core/requests/utils.rs @@ -2,11 +2,7 @@ use std::path::PathBuf; use bytes::{Bytes, BytesMut}; use reqwest::r#async::multipart::Part; -use tokio::{ - prelude::*, - codec::FramedRead, -}; - +use tokio::{codec::FramedRead, prelude::*}; struct FileDecoder; diff --git a/src/core/types/animation.rs b/src/core/types/animation.rs index 4a60e4c5..5d2ceff1 100644 --- a/src/core/types/animation.rs +++ b/src/core/types/animation.rs @@ -19,7 +19,7 @@ pub struct Animation { /// Optional. MIME type of the file as defined by sender pub mime_type: Option, /// Optional. File size - pub file_size: Option + pub file_size: Option, } #[cfg(test)] @@ -51,11 +51,11 @@ mod tests { file_id: "id".to_string(), width: 320, height: 320, - file_size: Some(3452) + file_size: Some(3452), }), file_name: Some("some".to_string()), mime_type: Some("gif".to_string()), - file_size: Some(6500) + file_size: Some(6500), }; let actual = serde_json::from_str::(json).unwrap(); assert_eq!(actual, expected) diff --git a/src/core/types/callback_query.rs b/src/core/types/callback_query.rs index 62dae596..edcbe996 100644 --- a/src/core/types/callback_query.rs +++ b/src/core/types/callback_query.rs @@ -1,6 +1,7 @@ -use crate::core::types::{User, Message}; +use crate::core::types::{Message, User}; -/// This object represents an incoming callback query from a callback button in an inline keyboard. +/// This object represents an incoming callback query from a callback button in +/// an inline keyboard. #[derive(Debug, Deserialize, PartialEq, Clone)] pub struct CallbackQuery { /// Unique identifier for this query @@ -8,12 +9,14 @@ pub struct CallbackQuery { /// Sender pub from: User, /// Message with the callback button that originated the query. - /// Note that message content and message date will not be available if the message is too old + /// Note that message content and message date will not be available if the + /// message is too old pub message: Message, - /// Global identifier, uniquely corresponding to the chat to which the message - /// with the callback button was sent. Useful for high scores in games. + /// Global identifier, uniquely corresponding to the chat to which the + /// message with the callback button was sent. Useful for high scores + /// in games. pub chat_instance: String, - /// Data associated with the callback button. Be aware that a bad client can - /// send arbitrary data in this field. + /// Data associated with the callback button. Be aware that a bad client + /// can send arbitrary data in this field. pub data: String, -} \ No newline at end of file +} diff --git a/src/core/types/chat.rs b/src/core/types/chat.rs index b27e7686..34469b48 100644 --- a/src/core/types/chat.rs +++ b/src/core/types/chat.rs @@ -1,6 +1,5 @@ use crate::core::types::{ChatPermissions, ChatPhoto, Message}; - #[derive(Debug, Deserialize, PartialEq, Clone)] pub struct Chat { pub id: i64, @@ -9,7 +8,6 @@ pub struct Chat { pub photo: Option, } - #[derive(Debug, Deserialize, PartialEq, Clone)] #[serde(untagged)] pub enum ChatKind { diff --git a/src/core/types/chosen_inline_result.rs b/src/core/types/chosen_inline_result.rs index 9821fde2..800c0a44 100644 --- a/src/core/types/chosen_inline_result.rs +++ b/src/core/types/chosen_inline_result.rs @@ -1,4 +1,4 @@ -use crate::core::types::{User, Location}; +use crate::core::types::{Location, User}; #[derive(Debug, Deserialize, Clone, PartialEq)] /// Represents a result of an inline query that was chosen by the user and @@ -11,9 +11,9 @@ pub struct ChosenInlineResult { pub from: User, /// Optional. Sender location, only for bots that require user location pub location: Option, - /// Optional. Identifier of the sent inline message. Available only if there is an inline - /// keyboard attached to the message. Will be also received in callback queries and can - /// be used to edit the message. + /// Optional. Identifier of the sent inline message. Available only if + /// there is an inline keyboard attached to the message. Will be also + /// received in callback queries and can be used to edit the message. pub inline_message_id: Option, /// The query that was used to obtain the result pub query: String, diff --git a/src/core/types/contact.rs b/src/core/types/contact.rs index d5ffedca..15933ff6 100644 --- a/src/core/types/contact.rs +++ b/src/core/types/contact.rs @@ -12,4 +12,4 @@ pub struct Contact { /// Optional. Additional data about the contact in the form of a /// [vCard](https://en.wikipedia.org/wiki/VCard) pub vcard: Option, -} \ No newline at end of file +} diff --git a/src/core/types/file.rs b/src/core/types/file.rs index 88ce6e97..e72f81ba 100644 --- a/src/core/types/file.rs +++ b/src/core/types/file.rs @@ -2,5 +2,5 @@ pub struct File { pub file_id: String, pub file_size: u32, - pub file_path: String + pub file_path: String, } diff --git a/src/core/types/game.rs b/src/core/types/game.rs index bdd43adb..6fc488ac 100644 --- a/src/core/types/game.rs +++ b/src/core/types/game.rs @@ -1,10 +1,10 @@ use serde::Deserialize; -use crate::core::types::{MessageEntity, PhotoSize, Animation}; +use crate::core::types::{Animation, MessageEntity, PhotoSize}; #[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)] -/// This object represents a game. Use BotFather to create and edit games, their short names -/// will act as unique identifiers. +/// This object represents a game. Use BotFather to create and edit games, their +/// short names will act as unique identifiers. pub struct Game { /// Title of the game pub title: String, @@ -12,13 +12,15 @@ pub struct Game { pub description: String, /// Photo that will be displayed in the game message in chats. pub photo: Vec, - /// Optional. Brief description of the game or high scores included in the game message. - /// Can be automatically edited to include current high scores for the game when - /// the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. + /// Optional. Brief description of the game or high scores included in the + /// game message. Can be automatically edited to include current high + /// scores for the game when the bot calls setGameScore, or manually + /// edited using editMessageText. 0-4096 characters. pub text: Option, - /// Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. + /// Optional. Special entities that appear in text, such as usernames, + /// URLs, bot commands, etc. pub text_entities: Option>, - /// Optional. Animation that will be displayed in the game message in chats. - /// Upload via BotFather + /// Optional. Animation that will be displayed in the game message in + /// chats. Upload via BotFather pub animation: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_keyboard_button.rs b/src/core/types/inline_keyboard_button.rs index ba2bcc4f..228f83f7 100644 --- a/src/core/types/inline_keyboard_button.rs +++ b/src/core/types/inline_keyboard_button.rs @@ -62,32 +62,37 @@ impl InlineKeyboardButton { } } - pub fn callback(text: String, callback_data: String) - -> InlineKeyboardButton { + pub fn callback( + text: String, + callback_data: String, + ) -> InlineKeyboardButton { InlineKeyboardButton { text, kind: InlineKeyboardButtonKind::CallbackData(callback_data), } } - pub fn switch_inline_query(text: String, switch_inline_query: String) - -> InlineKeyboardButton { + pub fn switch_inline_query( + text: String, + switch_inline_query: String, + ) -> InlineKeyboardButton { InlineKeyboardButton { text, - kind: InlineKeyboardButtonKind::SwitchInlineQuery(switch_inline_query) + kind: InlineKeyboardButtonKind::SwitchInlineQuery( + switch_inline_query, + ), } } pub fn switch_inline_query_current_chat( text: String, - switch_inline_query_current_chat: String + switch_inline_query_current_chat: String, ) -> InlineKeyboardButton { - InlineKeyboardButton { text, kind: InlineKeyboardButtonKind::SwitchInlineQueryCurrentChat( - switch_inline_query_current_chat - ) + switch_inline_query_current_chat, + ), } } } diff --git a/src/core/types/inline_keyboard_markup.rs b/src/core/types/inline_keyboard_markup.rs index 37c753a4..9e02ed2e 100644 --- a/src/core/types/inline_keyboard_markup.rs +++ b/src/core/types/inline_keyboard_markup.rs @@ -17,22 +17,19 @@ pub struct InlineKeyboardMarkup { /// Example: /// ``` /// use async_telegram_bot::core::types::{ -/// InlineKeyboardMarkup, -/// InlineKeyboardButton +/// InlineKeyboardButton, InlineKeyboardMarkup, /// }; /// -/// /// let url_button = InlineKeyboardButton::url( /// "text".to_string(), -/// "http://url.com".to_string() +/// "http://url.com".to_string(), /// ); -/// let keyboard = InlineKeyboardMarkup::new() -/// .append_row(vec![url_button]); +/// let keyboard = InlineKeyboardMarkup::new().append_row(vec![url_button]); /// ``` impl InlineKeyboardMarkup { pub fn new() -> Self { Self { - inline_keyboard: vec![] + inline_keyboard: vec![], } } @@ -41,11 +38,14 @@ impl InlineKeyboardMarkup { self } - pub fn append_to_row(mut self, button: InlineKeyboardButton, index: usize) - -> Self { + pub fn append_to_row( + mut self, + button: InlineKeyboardButton, + index: usize, + ) -> Self { match self.inline_keyboard.get_mut(index) { Some(buttons) => buttons.push(button), - None => self.inline_keyboard.push(vec![button]) + None => self.inline_keyboard.push(vec![button]), }; self } @@ -68,9 +68,7 @@ mod tests { let markup = InlineKeyboardMarkup::new() .append_row(vec![button1.clone(), button2.clone()]); let expected = InlineKeyboardMarkup { - inline_keyboard: vec![ - vec![button1.clone(), button2.clone()] - ] + inline_keyboard: vec![vec![button1.clone(), button2.clone()]], }; assert_eq!(markup, expected); } @@ -89,9 +87,7 @@ mod tests { .append_row(vec![button1.clone()]) .append_to_row(button2.clone(), 0); let expected = InlineKeyboardMarkup { - inline_keyboard: vec![ - vec![button1.clone(), button2.clone()] - ] + inline_keyboard: vec![vec![button1.clone(), button2.clone()]], }; assert_eq!(markup, expected); } @@ -110,10 +106,7 @@ mod tests { .append_row(vec![button1.clone()]) .append_to_row(button2.clone(), 1); let expected = InlineKeyboardMarkup { - inline_keyboard: vec![ - vec![button1.clone()], - vec![button2.clone()] - ] + inline_keyboard: vec![vec![button1.clone()], vec![button2.clone()]], }; assert_eq!(markup, expected); } diff --git a/src/core/types/inline_query.rs b/src/core/types/inline_query.rs index 7a1fa571..c3e99ae7 100644 --- a/src/core/types/inline_query.rs +++ b/src/core/types/inline_query.rs @@ -1,4 +1,4 @@ -use crate::core::types::{User, Location}; +use crate::core::types::{Location, User}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQuery { diff --git a/src/core/types/inline_query_result.rs b/src/core/types/inline_query_result.rs index 144c1cc4..755528f5 100644 --- a/src/core/types/inline_query_result.rs +++ b/src/core/types/inline_query_result.rs @@ -1,26 +1,16 @@ use crate::core::types::{ - InlineQueryResultCachedAudio, - InlineQueryResultCachedDocument, - InlineQueryResultCachedGif, - InlineQueryResultCachedMpeg4Gif, - InlineQueryResultCachedPhoto, - InlineQueryResultCachedSticker, - InlineQueryResultCachedVideo, - InlineQueryResultCachedVoice, - InlineQueryResultArticle, - InlineQueryResultAudio, - InlineQueryResultContact, - InlineQueryResultGame, - InlineQueryResultDocument, - InlineQueryResultGif, - InlineQueryResultLocation, - InlineQueryResultMpeg4Gif, - InlineQueryResultPhoto, - InlineQueryResultVenue, - InlineQueryResultVideo, - InlineQueryResultVoice + InlineQueryResultArticle, InlineQueryResultAudio, + InlineQueryResultCachedAudio, InlineQueryResultCachedDocument, + InlineQueryResultCachedGif, InlineQueryResultCachedMpeg4Gif, + InlineQueryResultCachedPhoto, InlineQueryResultCachedSticker, + InlineQueryResultCachedVideo, InlineQueryResultCachedVoice, + InlineQueryResultContact, InlineQueryResultDocument, InlineQueryResultGame, + InlineQueryResultGif, InlineQueryResultLocation, InlineQueryResultMpeg4Gif, + InlineQueryResultPhoto, InlineQueryResultVenue, InlineQueryResultVideo, + InlineQueryResultVoice, }; +/// This object represents one result of an inline query. #[derive(Debug, Serialize, PartialEq, Clone)] #[serde(tag = "type")] #[serde(rename_all = "snake_case")] @@ -59,24 +49,26 @@ pub enum InlineQueryResult { #[cfg(test)] mod tests { - use crate::core::types::{InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent}; - use crate::core::types::parse_mode::ParseMode; use crate::core::types::inline_keyboard_markup::InlineKeyboardMarkup; + use crate::core::types::parse_mode::ParseMode; + use crate::core::types::{ + InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent, + }; #[test] fn cached_audio_min_serialize() { - let structure = InlineQueryResult::CachedAudio( - InlineQueryResultCachedAudio { + let structure = + InlineQueryResult::CachedAudio(InlineQueryResultCachedAudio { id: String::from("id"), audio_file_id: String::from("audio_file_id"), caption: None, parse_mode: None, reply_markup: None, - input_message_content: None - } - ); + input_message_content: None, + }); - let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id"}"#; + let expected_json = + r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id"}"#; let actual_json = serde_json::to_string(&structure).unwrap(); assert_eq!(expected_json, actual_json); @@ -84,8 +76,8 @@ mod tests { #[test] fn cached_audio_full_serialize() { - let structure = InlineQueryResult::CachedAudio( - InlineQueryResultCachedAudio { + let structure = + InlineQueryResult::CachedAudio(InlineQueryResultCachedAudio { id: String::from("id"), audio_file_id: String::from("audio_file_id"), caption: Some(String::from("caption")), @@ -94,10 +86,9 @@ mod tests { input_message_content: Some(InputMessageContent::Text { message_text: String::from("message_text"), parse_mode: Some(ParseMode::Markdown), - disable_web_page_preview: Some(true) - }) - } - ); + disable_web_page_preview: Some(true), + }), + }); let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id","caption":"caption","parse_mode":"HTML","reply_markup":{"inline_keyboard":[]},"input_message_content":{"message_text":"message_text","parse_mode":"Markdown","disable_web_page_preview":true}}"#; let actual_json = serde_json::to_string(&structure).unwrap(); @@ -106,4 +97,4 @@ mod tests { } // TODO: Add more tests -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_article.rs b/src/core/types/inline_query_result_article.rs index b887c75d..1edda355 100644 --- a/src/core/types/inline_query_result_article.rs +++ b/src/core/types/inline_query_result_article.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InlineKeyboardMarkup, InputMessageContent}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultArticle { @@ -14,7 +14,8 @@ pub struct InlineQueryResultArticle { /// Optional. URL of the result #[serde(skip_serializing_if = "Option::is_none")] pub url: Option, - /// Optional. Pass True, if you don't want the URL to be shown in the message + /// Optional. Pass True, if you don't want the URL to be shown in the + /// message #[serde(skip_serializing_if = "Option::is_none")] pub hide_url: Option, /// Optional. Short description of the result diff --git a/src/core/types/inline_query_result_audio.rs b/src/core/types/inline_query_result_audio.rs index ac8d40b8..867cb237 100644 --- a/src/core/types/inline_query_result_audio.rs +++ b/src/core/types/inline_query_result_audio.rs @@ -1,4 +1,6 @@ -use crate::core::types::{ParseMode, InlineKeyboardMarkup, InputMessageContent}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultAudio { @@ -17,4 +19,4 @@ pub struct InlineQueryResultAudio { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_cached_audio.rs b/src/core/types/inline_query_result_cached_audio.rs index 6975dbd6..89b7944e 100644 --- a/src/core/types/inline_query_result_cached_audio.rs +++ b/src/core/types/inline_query_result_cached_audio.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedAudio { @@ -12,4 +14,4 @@ pub struct InlineQueryResultCachedAudio { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_cached_document.rs b/src/core/types/inline_query_result_cached_document.rs index c821ffa7..f79487bc 100644 --- a/src/core/types/inline_query_result_cached_document.rs +++ b/src/core/types/inline_query_result_cached_document.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedDocument { @@ -15,4 +17,4 @@ pub struct InlineQueryResultCachedDocument { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_cached_gif.rs b/src/core/types/inline_query_result_cached_gif.rs index ab1dc7d6..c81170c4 100644 --- a/src/core/types/inline_query_result_cached_gif.rs +++ b/src/core/types/inline_query_result_cached_gif.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedGif { @@ -14,4 +16,4 @@ pub struct InlineQueryResultCachedGif { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_cached_mpeg4_gif.rs b/src/core/types/inline_query_result_cached_mpeg4_gif.rs index 8763142b..cbc46c75 100644 --- a/src/core/types/inline_query_result_cached_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_cached_mpeg4_gif.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedMpeg4Gif { @@ -14,4 +16,4 @@ pub struct InlineQueryResultCachedMpeg4Gif { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_cached_photo.rs b/src/core/types/inline_query_result_cached_photo.rs index f012b56d..d5317a17 100644 --- a/src/core/types/inline_query_result_cached_photo.rs +++ b/src/core/types/inline_query_result_cached_photo.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedPhoto { @@ -16,4 +18,4 @@ pub struct InlineQueryResultCachedPhoto { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_cached_sticker.rs b/src/core/types/inline_query_result_cached_sticker.rs index 037cc670..703ea199 100644 --- a/src/core/types/inline_query_result_cached_sticker.rs +++ b/src/core/types/inline_query_result_cached_sticker.rs @@ -1,4 +1,4 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; +use crate::core::types::{InlineKeyboardMarkup, InputMessageContent}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedSticker { @@ -8,4 +8,4 @@ pub struct InlineQueryResultCachedSticker { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_cached_video.rs b/src/core/types/inline_query_result_cached_video.rs index 2bebfdff..216ffe8a 100644 --- a/src/core/types/inline_query_result_cached_video.rs +++ b/src/core/types/inline_query_result_cached_video.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedVideo { @@ -15,4 +17,4 @@ pub struct InlineQueryResultCachedVideo { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_cached_voice.rs b/src/core/types/inline_query_result_cached_voice.rs index e0ec1074..e15b75bc 100644 --- a/src/core/types/inline_query_result_cached_voice.rs +++ b/src/core/types/inline_query_result_cached_voice.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultCachedVoice { @@ -13,4 +15,4 @@ pub struct InlineQueryResultCachedVoice { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_contact.rs b/src/core/types/inline_query_result_contact.rs index 0c0d22b7..fb4b2d28 100644 --- a/src/core/types/inline_query_result_contact.rs +++ b/src/core/types/inline_query_result_contact.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultContact { @@ -19,4 +21,4 @@ pub struct InlineQueryResultContact { pub thumb_width: Option, #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_document.rs b/src/core/types/inline_query_result_document.rs index 7ff3bf44..d65a735d 100644 --- a/src/core/types/inline_query_result_document.rs +++ b/src/core/types/inline_query_result_document.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultDocument { @@ -22,4 +24,4 @@ pub struct InlineQueryResultDocument { pub thumb_width: Option, #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_game.rs b/src/core/types/inline_query_result_game.rs index 942eb2b5..f19aa16f 100644 --- a/src/core/types/inline_query_result_game.rs +++ b/src/core/types/inline_query_result_game.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] pub struct InlineQueryResultGame { @@ -6,4 +8,4 @@ pub struct InlineQueryResultGame { pub game_short_name: String, #[serde(skip_serializing_if = "Option::is_none")] pub reply_markup: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_gif.rs b/src/core/types/inline_query_result_gif.rs index c86d634a..7131d35a 100644 --- a/src/core/types/inline_query_result_gif.rs +++ b/src/core/types/inline_query_result_gif.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultGif { @@ -21,4 +23,4 @@ pub struct InlineQueryResultGif { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_location.rs b/src/core/types/inline_query_result_location.rs index 09c034f5..a89ca988 100644 --- a/src/core/types/inline_query_result_location.rs +++ b/src/core/types/inline_query_result_location.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultLocation { @@ -18,4 +20,4 @@ pub struct InlineQueryResultLocation { pub thumb_width: Option, #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_mpeg4_gif.rs b/src/core/types/inline_query_result_mpeg4_gif.rs index 186cdba1..b690746f 100644 --- a/src/core/types/inline_query_result_mpeg4_gif.rs +++ b/src/core/types/inline_query_result_mpeg4_gif.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultMpeg4Gif { @@ -21,4 +23,4 @@ pub struct InlineQueryResultMpeg4Gif { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_photo.rs b/src/core/types/inline_query_result_photo.rs index cf2b4b51..d0626100 100644 --- a/src/core/types/inline_query_result_photo.rs +++ b/src/core/types/inline_query_result_photo.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultPhoto { @@ -21,4 +23,4 @@ pub struct InlineQueryResultPhoto { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_venue.rs b/src/core/types/inline_query_result_venue.rs index e6beb38d..9237e001 100644 --- a/src/core/types/inline_query_result_venue.rs +++ b/src/core/types/inline_query_result_venue.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVenue { @@ -21,4 +23,4 @@ pub struct InlineQueryResultVenue { pub thumb_width: Option, #[serde(skip_serializing_if = "Option::is_none")] pub thumb_height: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_video.rs b/src/core/types/inline_query_result_video.rs index 566eea6d..bc8660db 100644 --- a/src/core/types/inline_query_result_video.rs +++ b/src/core/types/inline_query_result_video.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVideo { @@ -23,4 +25,4 @@ pub struct InlineQueryResultVideo { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/inline_query_result_voice.rs b/src/core/types/inline_query_result_voice.rs index 38d2de62..b4493fc1 100644 --- a/src/core/types/inline_query_result_voice.rs +++ b/src/core/types/inline_query_result_voice.rs @@ -1,4 +1,6 @@ -use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; +use crate::core::types::{ + InlineKeyboardMarkup, InputMessageContent, ParseMode, +}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVoice { @@ -15,4 +17,4 @@ pub struct InlineQueryResultVoice { pub reply_markup: Option, #[serde(skip_serializing_if = "Option::is_none")] pub input_message_content: Option, -} \ No newline at end of file +} diff --git a/src/core/types/input_message_content.rs b/src/core/types/input_message_content.rs index d36f73b7..2c60ac5a 100644 --- a/src/core/types/input_message_content.rs +++ b/src/core/types/input_message_content.rs @@ -8,18 +8,20 @@ use crate::core::types::ParseMode; /// a result of an inline query. /// [More](https://core.telegram.org/bots/api#inputmessagecontent) pub enum InputMessageContent { - /// Represents the content of a text message to be sent as the result of an inline query. + /// Represents the content of a text message to be sent as the result of an + /// inline query. Text { /// Text of the message to be sent, 1-4096 characters message_text: String, /// Send [Markdown] or [HTML], - /// if you want Telegram apps to show [bold, italic, fixed-width text or inline URLs] - /// in the media caption. + /// if you want Telegram apps to show [bold, italic, fixed-width text + /// or inline URLs] in the media caption. /// /// [Markdown]: crate::core::types::ParseMode::Markdown /// [Html]: crate::core::types::ParseMode::Html - /// [bold, italic, fixed-width text or inline URLs]: crate::core::types::ParseMode + /// [bold, italic, fixed-width text or inline URLs]: + /// crate::core::types::ParseMode #[serde(skip_serializing_if = "Option::is_none")] parse_mode: Option, @@ -27,18 +29,21 @@ pub enum InputMessageContent { #[serde(skip_serializing_if = "Option::is_none")] disable_web_page_preview: Option, }, - /// Represents the content of a location message to be sent as the result of an inline query. + /// Represents the content of a location message to be sent as the result + /// of an inline query. Location { /// Latitude of the location in degrees latitude: f64, /// Longitude of the location in degrees longitude: f64, - /// Period in seconds for which the location can be updated, should be between 60 and 86400. + /// Period in seconds for which the location can be updated, should be + /// between 60 and 86400. #[serde(skip_serializing_if = "Option::is_none")] live_period: Option, }, - /// Represents the content of a venue message to be sent as the result of an inline query. + /// Represents the content of a venue message to be sent as the result of + /// an inline query. Venue { /// Latitude of the venue in degrees latitude: f64, @@ -53,12 +58,14 @@ pub enum InputMessageContent { #[serde(skip_serializing_if = "Option::is_none")] foursquare_id: Option, - /// Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, - /// “arts_entertainment/aquarium” or “food/icecream”.) + /// Foursquare type of the venue, if known. (For example, + /// “arts_entertainment/default”, “arts_entertainment/aquarium” + /// or “food/icecream”.) #[serde(skip_serializing_if = "Option::is_none")] foursquare_type: Option, }, - /// Represents the content of a contact message to be sent as the result of an inline query. + /// Represents the content of a contact message to be sent as the result of + /// an inline query. Contact { /// Contact's phone number phone_number: String, @@ -124,7 +131,8 @@ mod tests { #[test] fn contact_serialize() { - let expected_json = r#"{"phone_number":"+3800000000","first_name":"jhon"}"#; + let expected_json = + r#"{"phone_number":"+3800000000","first_name":"jhon"}"#; let contact_content = InputMessageContent::Contact { phone_number: String::from("+3800000000"), first_name: String::from("jhon"), @@ -135,4 +143,4 @@ mod tests { let actual_json = serde_json::to_string(&contact_content).unwrap(); assert_eq!(expected_json, actual_json); } -} \ No newline at end of file +} diff --git a/src/core/types/label_price.rs b/src/core/types/label_price.rs index b1d04e3d..3c8afe19 100644 --- a/src/core/types/label_price.rs +++ b/src/core/types/label_price.rs @@ -20,7 +20,7 @@ mod tests { fn serialize() { let labeled_price = LabeledPrice { label: "Label".to_string(), - amount: 60 + amount: 60, }; let expected = r#"{"label":"Label","amount":60}"#; let actual = serde_json::to_string(&labeled_price).unwrap(); diff --git a/src/core/types/location.rs b/src/core/types/location.rs index b560b1ef..d5d4e138 100644 --- a/src/core/types/location.rs +++ b/src/core/types/location.rs @@ -5,4 +5,4 @@ pub struct Location { pub longitude: f64, /// Latitude as defined by sender pub latitude: f64, -} \ No newline at end of file +} diff --git a/src/core/types/mask_position.rs b/src/core/types/mask_position.rs index 603181a6..09992bdf 100644 --- a/src/core/types/mask_position.rs +++ b/src/core/types/mask_position.rs @@ -5,4 +5,3 @@ pub struct MaskPosition { pub y_shift: f64, pub scale: f64, } - diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index 1d81a65e..42e9869a 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -10,12 +10,36 @@ pub use self::{ chosen_inline_result::ChosenInlineResult, contact::Contact, document::Document, + file::File, force_reply::ForceReply, game::Game, inline_keyboard_button::{InlineKeyboardButton, InlineKeyboardButtonKind}, inline_keyboard_markup::InlineKeyboardMarkup, + inline_query::InlineQuery, + inline_query_result::InlineQueryResult, + inline_query_result_article::InlineQueryResultArticle, + inline_query_result_audio::InlineQueryResultAudio, + inline_query_result_cached_audio::InlineQueryResultCachedAudio, + inline_query_result_cached_document::InlineQueryResultCachedDocument, + inline_query_result_cached_gif::InlineQueryResultCachedGif, + inline_query_result_cached_mpeg4_gif::InlineQueryResultCachedMpeg4Gif, + inline_query_result_cached_photo::InlineQueryResultCachedPhoto, + inline_query_result_cached_sticker::InlineQueryResultCachedSticker, + inline_query_result_cached_video::InlineQueryResultCachedVideo, + inline_query_result_cached_voice::InlineQueryResultCachedVoice, + inline_query_result_contact::InlineQueryResultContact, + inline_query_result_document::InlineQueryResultDocument, + inline_query_result_game::InlineQueryResultGame, + inline_query_result_gif::InlineQueryResultGif, + inline_query_result_location::InlineQueryResultLocation, + inline_query_result_mpeg4_gif::InlineQueryResultMpeg4Gif, + inline_query_result_photo::InlineQueryResultPhoto, + inline_query_result_venue::InlineQueryResultVenue, + inline_query_result_video::InlineQueryResultVideo, + inline_query_result_voice::InlineQueryResultVoice, input_file::InputFile, input_media::InputMedia, + input_message_content::InputMessageContent, invoice::Invoice, keyboard_button::KeyboardButton, label_price::LabeledPrice, @@ -46,31 +70,6 @@ pub use self::{ video::Video, video_note::VideoNote, voice::Voice, - file::File, - input_message_content::InputMessageContent, - - inline_query::InlineQuery, - inline_query_result::InlineQueryResult, - inline_query_result_cached_audio::InlineQueryResultCachedAudio, - inline_query_result_cached_document::InlineQueryResultCachedDocument, - inline_query_result_cached_gif::InlineQueryResultCachedGif, - inline_query_result_cached_mpeg4_gif::InlineQueryResultCachedMpeg4Gif, - inline_query_result_cached_photo::InlineQueryResultCachedPhoto, - inline_query_result_cached_sticker::InlineQueryResultCachedSticker, - inline_query_result_cached_video::InlineQueryResultCachedVideo, - inline_query_result_cached_voice::InlineQueryResultCachedVoice, - inline_query_result_article::InlineQueryResultArticle, - inline_query_result_audio::InlineQueryResultAudio, - inline_query_result_contact::InlineQueryResultContact, - inline_query_result_game::InlineQueryResultGame, - inline_query_result_document::InlineQueryResultDocument, - inline_query_result_gif::InlineQueryResultGif, - inline_query_result_location::InlineQueryResultLocation, - inline_query_result_mpeg4_gif::InlineQueryResultMpeg4Gif, - inline_query_result_photo::InlineQueryResultPhoto, - inline_query_result_venue::InlineQueryResultVenue, - inline_query_result_video::InlineQueryResultVideo, - inline_query_result_voice::InlineQueryResultVoice, }; mod animation; @@ -83,12 +82,14 @@ mod chat_photo; mod chosen_inline_result; mod contact; mod document; +mod file; mod force_reply; mod game; mod inline_keyboard_button; mod inline_keyboard_markup; mod input_file; mod input_media; +mod input_message_content; mod invoice; mod keyboard_button; mod label_price; @@ -118,11 +119,11 @@ mod venue; mod video; mod video_note; mod voice; -mod file; -mod input_message_content; mod inline_query; mod inline_query_result; +mod inline_query_result_article; +mod inline_query_result_audio; mod inline_query_result_cached_audio; mod inline_query_result_cached_document; mod inline_query_result_cached_gif; @@ -131,11 +132,9 @@ mod inline_query_result_cached_photo; mod inline_query_result_cached_sticker; mod inline_query_result_cached_video; mod inline_query_result_cached_voice; -mod inline_query_result_article; -mod inline_query_result_audio; mod inline_query_result_contact; -mod inline_query_result_game; mod inline_query_result_document; +mod inline_query_result_game; mod inline_query_result_gif; mod inline_query_result_location; mod inline_query_result_mpeg4_gif; diff --git a/src/core/types/photo_size.rs b/src/core/types/photo_size.rs index 8df34596..72d110df 100644 --- a/src/core/types/photo_size.rs +++ b/src/core/types/photo_size.rs @@ -24,7 +24,7 @@ mod tests { file_id: "id".to_string(), width: 320, height: 320, - file_size: Some(3452) + file_size: Some(3452), }; let actual = serde_json::from_str::(json).unwrap(); assert_eq!(actual, expected); diff --git a/src/core/types/send_invoice.rs b/src/core/types/send_invoice.rs index 10740d81..9ca27201 100644 --- a/src/core/types/send_invoice.rs +++ b/src/core/types/send_invoice.rs @@ -1,5 +1,5 @@ -use crate::core::types::{InlineKeyboardMarkup, LabeledPrice}; use crate::core::requests::ChatId; +use crate::core::types::{InlineKeyboardMarkup, LabeledPrice}; #[derive(Debug, PartialEq, Eq, Clone)] pub struct SendInvoice { diff --git a/src/core/types/shipping_option.rs b/src/core/types/shipping_option.rs index 9a6e4e8e..b5e0c11d 100644 --- a/src/core/types/shipping_option.rs +++ b/src/core/types/shipping_option.rs @@ -20,9 +20,10 @@ mod tests { let shipping_option = ShippingOption { id: "0".to_string(), title: "Option".to_string(), - prices: vec![ - LabeledPrice { label: "Label".to_string(), amount: 60 } - ] + prices: vec![LabeledPrice { + label: "Label".to_string(), + amount: 60, + }], }; let expected = r#"{"id":"0","title":"Option","prices":[{"label":"Label","amount":60}]}"#; let actual = serde_json::to_string(&shipping_option).unwrap(); diff --git a/src/core/types/update.rs b/src/core/types/update.rs index c168d831..edb2626b 100644 --- a/src/core/types/update.rs +++ b/src/core/types/update.rs @@ -1,6 +1,4 @@ -use crate::core::types::{ - Message, ChosenInlineResult, CallbackQuery, -}; +use crate::core::types::{CallbackQuery, ChosenInlineResult, Message}; #[derive(Debug, Deserialize, PartialEq, Clone)] pub struct Update { diff --git a/src/core/types/venue.rs b/src/core/types/venue.rs index c0dcc7ee..75d26820 100644 --- a/src/core/types/venue.rs +++ b/src/core/types/venue.rs @@ -1,6 +1,5 @@ use crate::core::types::Location; - /// This object represents a venue. #[derive(Debug, Deserialize, PartialEq, Serialize, Clone)] pub struct Venue { @@ -13,7 +12,9 @@ pub struct Venue { /// Foursquare identifier of the venue #[serde(skip_serializing_if = "Option::is_none")] pub foursquare_id: Option, - /// Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) + /// Foursquare type of the venue. (For example, + /// “arts_entertainment/default”, “arts_entertainment/aquarium” or + /// “food/icecream”.) #[serde(skip_serializing_if = "Option::is_none")] pub foursquare_type: Option, // TODO: is this enum?... -} \ No newline at end of file +} diff --git a/src/core/types/video_note.rs b/src/core/types/video_note.rs index 893664b4..711af479 100644 --- a/src/core/types/video_note.rs +++ b/src/core/types/video_note.rs @@ -1,5 +1,5 @@ -use serde::Deserialize; use crate::core::types::PhotoSize; +use serde::Deserialize; #[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)] /// This object represents a [video message](https://telegram.org/blog/video-messages-and-telescope) @@ -7,7 +7,8 @@ use crate::core::types::PhotoSize; pub struct VideoNote { /// Identifier for this file pub file_id: String, - /// Video width and height (diameter of the video message) as defined by sender + /// Video width and height (diameter of the video message) as defined by + /// sender pub length: u32, /// Duration of the video in seconds as defined by sender pub duration: u32, @@ -15,4 +16,4 @@ pub struct VideoNote { pub thumb: Option, /// Optional. File size pub file_size: Option, -} \ No newline at end of file +} diff --git a/src/core/types/voice.rs b/src/core/types/voice.rs index 9cd71c09..6a2abc8c 100644 --- a/src/core/types/voice.rs +++ b/src/core/types/voice.rs @@ -11,4 +11,4 @@ pub struct Voice { pub mime_type: Option, /// Optional. File size pub file_size: Option, -} \ No newline at end of file +} From d9a974472a643c5b20932dfebb3d4426ddddaa4c Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 01:34:35 +0300 Subject: [PATCH 35/55] Derive `From` for `InlineQueryResult` --- src/core/types/inline_query_result.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/types/inline_query_result.rs b/src/core/types/inline_query_result.rs index 755528f5..f2151a06 100644 --- a/src/core/types/inline_query_result.rs +++ b/src/core/types/inline_query_result.rs @@ -11,7 +11,7 @@ use crate::core::types::{ }; /// This object represents one result of an inline query. -#[derive(Debug, Serialize, PartialEq, Clone)] +#[derive(Debug, Serialize, PartialEq, Clone, From)] #[serde(tag = "type")] #[serde(rename_all = "snake_case")] pub enum InlineQueryResult { @@ -55,6 +55,21 @@ mod tests { InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent, }; + #[test] + fn into() { + let structure = + InlineQueryResult::CachedAudio(InlineQueryResultCachedAudio { + id: String::from("id"), + audio_file_id: String::from("audio_file_id"), + caption: None, + parse_mode: None, + reply_markup: None, + input_message_content: None, + }); + + let _: InlineQueryResult = structure.into(); + } + #[test] fn cached_audio_min_serialize() { let structure = From 553ffd928be6983768e1a9ae4893fe6df60e6787 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 01:37:45 +0300 Subject: [PATCH 36/55] Fix some "unused imports" warnings --- src/core/types/inline_query_result_contact.rs | 4 +--- src/core/types/inline_query_result_game.rs | 4 +--- src/core/types/inline_query_result_location.rs | 4 +--- src/core/types/inline_query_result_photo.rs | 3 +++ src/core/types/inline_query_result_venue.rs | 4 +--- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/core/types/inline_query_result_contact.rs b/src/core/types/inline_query_result_contact.rs index fb4b2d28..4f9c704d 100644 --- a/src/core/types/inline_query_result_contact.rs +++ b/src/core/types/inline_query_result_contact.rs @@ -1,6 +1,4 @@ -use crate::core::types::{ - InlineKeyboardMarkup, InputMessageContent, ParseMode, -}; +use crate::core::types::{InlineKeyboardMarkup, InputMessageContent}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultContact { diff --git a/src/core/types/inline_query_result_game.rs b/src/core/types/inline_query_result_game.rs index f19aa16f..9a01d158 100644 --- a/src/core/types/inline_query_result_game.rs +++ b/src/core/types/inline_query_result_game.rs @@ -1,6 +1,4 @@ -use crate::core::types::{ - InlineKeyboardMarkup, InputMessageContent, ParseMode, -}; +use crate::core::types::InlineKeyboardMarkup; #[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] pub struct InlineQueryResultGame { diff --git a/src/core/types/inline_query_result_location.rs b/src/core/types/inline_query_result_location.rs index a89ca988..846a3f04 100644 --- a/src/core/types/inline_query_result_location.rs +++ b/src/core/types/inline_query_result_location.rs @@ -1,6 +1,4 @@ -use crate::core::types::{ - InlineKeyboardMarkup, InputMessageContent, ParseMode, -}; +use crate::core::types::{InlineKeyboardMarkup, InputMessageContent}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultLocation { diff --git a/src/core/types/inline_query_result_photo.rs b/src/core/types/inline_query_result_photo.rs index d0626100..c752ae8a 100644 --- a/src/core/types/inline_query_result_photo.rs +++ b/src/core/types/inline_query_result_photo.rs @@ -2,6 +2,9 @@ use crate::core::types::{ InlineKeyboardMarkup, InputMessageContent, ParseMode, }; +/// Represents a link to a photo. By default, this photo will be sent by the +/// user with optional caption. Alternatively, you can use input_message_content +/// to send a message with the specified content instead of the photo. #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultPhoto { pub id: String, diff --git a/src/core/types/inline_query_result_venue.rs b/src/core/types/inline_query_result_venue.rs index 9237e001..e018a55c 100644 --- a/src/core/types/inline_query_result_venue.rs +++ b/src/core/types/inline_query_result_venue.rs @@ -1,6 +1,4 @@ -use crate::core::types::{ - InlineKeyboardMarkup, InputMessageContent, ParseMode, -}; +use crate::core::types::{InlineKeyboardMarkup, InputMessageContent}; #[derive(Debug, Serialize, PartialEq, Clone)] pub struct InlineQueryResultVenue { From 9cc5806f0779585ad6702d8f227aeae04a1ed1f5 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 01:45:40 +0300 Subject: [PATCH 37/55] Fix some visibility issues that were causing warnings --- src/core/requests/get_file.rs | 8 ++++++-- src/core/requests/send_chat_action.rs | 4 ++-- src/core/requests/send_contact.rs | 2 +- src/core/requests/send_poll.rs | 2 +- src/core/requests/send_venue.rs | 4 ++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core/requests/get_file.rs b/src/core/requests/get_file.rs index 089ff743..9ab0788d 100644 --- a/src/core/requests/get_file.rs +++ b/src/core/requests/get_file.rs @@ -12,11 +12,11 @@ use crate::core::types::File; /// It is guaranteed that the link will be valid for at least 1 hour. /// When the link expires, a new one can be requested by calling getFile again. #[derive(Debug, Clone, Serialize)] -struct GetFile<'a> { +pub struct GetFile<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, /// File identifier to get info about - file_id: String, + pub file_id: String, } impl<'a> Request<'a> for GetFile<'a> { @@ -36,6 +36,10 @@ impl<'a> Request<'a> for GetFile<'a> { } impl<'a> GetFile<'a> { + pub(crate) fn new(ctx: RequestContext<'a>, file_id: String) -> Self { + Self { ctx, file_id } + } + pub fn file_id(mut self, file_id: T) -> Self where T: Into, diff --git a/src/core/requests/send_chat_action.rs b/src/core/requests/send_chat_action.rs index ae07ec05..9b9bf940 100644 --- a/src/core/requests/send_chat_action.rs +++ b/src/core/requests/send_chat_action.rs @@ -8,7 +8,7 @@ use crate::core::requests::{ /// arrives from your bot, Telegram clients clear its typing status). /// Returns True on success. #[derive(Debug, Clone, Serialize)] -struct SendChatAction<'a> { +pub struct SendChatAction<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, /// Unique identifier for the target chat or @@ -24,7 +24,7 @@ struct SendChatAction<'a> { #[derive(Debug, Serialize, From, Clone)] #[serde(rename_all = "snake_case")] -enum ChatAction { +pub enum ChatAction { Typing, UploadPhoto, RecordVideo, diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index 16cbec0e..a064dd21 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -7,7 +7,7 @@ use crate::core::types::{Message, ReplyMarkup}; /// Use this method to send phone contacts. /// returned. #[derive(Debug, Clone, Serialize)] -struct SendContact<'a> { +pub struct SendContact<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, /// Unique identifier for the target chat or diff --git a/src/core/requests/send_poll.rs b/src/core/requests/send_poll.rs index 861c98e7..92a11901 100644 --- a/src/core/requests/send_poll.rs +++ b/src/core/requests/send_poll.rs @@ -7,7 +7,7 @@ use crate::core::types::{Message, ReplyMarkup}; /// Use this method to send a native poll. A native poll can't be sent to a /// private chat. On success, the sent Message is returned. #[derive(Debug, Clone, Serialize)] -struct SendPoll<'a> { +pub struct SendPoll<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, /// identifier for the target chat or username of the target channel (in diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index 85fee6d6..cdb5fb90 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -7,7 +7,7 @@ use crate::core::types::{Message, ReplyMarkup}; /// Use this method to send information about a venue. /// Message is returned. #[derive(Debug, Clone, Serialize)] -struct SendVenue<'a> { +pub struct SendVenue<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, /// Unique identifier for the target chat or @@ -62,7 +62,7 @@ impl<'a> Request<'a> for SendVenue<'a> { } impl<'a> SendVenue<'a> { - pub fn new( + pub(crate) fn new( ctx: RequestContext<'a>, chat_id: ChatId, latitude: f64, From fe75e0ff07ee669b5b96f0b33b18d038ea61b6b1 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 01:59:16 +0300 Subject: [PATCH 38/55] Add `MigrateToChatId` and `RetryAfter` to `RequestError` --- src/core/network/mod.rs | 56 +++++++++++++++++++++++----------------- src/core/requests/mod.rs | 12 +++++++++ 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/core/network/mod.rs b/src/core/network/mod.rs index 244c6d63..b890a173 100644 --- a/src/core/network/mod.rs +++ b/src/core/network/mod.rs @@ -57,18 +57,7 @@ pub async fn request_multipart( ) .map_err(RequestError::InvalidJson)?; - match response { - TelegramResponse::Ok { result, .. } => Ok(result), - TelegramResponse::Err { - description, - error_code, - response_parameters: _, - .. - } => Err(RequestError::ApiError { - description, - status_code: StatusCode::from_u16(error_code).unwrap(), - }), - } + response.into() } pub async fn request_json( @@ -89,18 +78,7 @@ pub async fn request_json( ) .map_err(RequestError::InvalidJson)?; - match response { - TelegramResponse::Ok { result, .. } => Ok(result), - TelegramResponse::Err { - description, - error_code, - response_parameters: _, - .. - } => Err(RequestError::ApiError { - description, - status_code: StatusCode::from_u16(error_code).unwrap(), - }), - } + response.into() } #[derive(Deserialize)] @@ -124,6 +102,36 @@ enum TelegramResponse { }, } +impl Into> for TelegramResponse { + fn into(self) -> Result { + match self { + TelegramResponse::Ok { result, .. } => Ok(result), + TelegramResponse::Err { + description, + error_code, + response_parameters, + .. + } => { + if let Some(params) = response_parameters { + match params { + ResponseParameters::RetryAfter(i) => { + Err(RequestError::RetryAfter(i)) + } + ResponseParameters::MigrateToChatId(to) => { + Err(RequestError::MigrateToChatId(to)) + } + } + } else { + Err(RequestError::ApiError { + description, + status_code: StatusCode::from_u16(error_code).unwrap(), + }) + } + } + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/core/requests/mod.rs b/src/core/requests/mod.rs index a1dfa82f..aa6bb37f 100644 --- a/src/core/requests/mod.rs +++ b/src/core/requests/mod.rs @@ -16,6 +16,16 @@ pub enum RequestError { description: String, }, + /// The group has been migrated to a supergroup with the specified + /// identifier. + #[display(fmt = "The group has been migrated to a supergroup with id {id}", id = _0)] + MigrateToChatId(i64), + + /// In case of exceeding flood control, the number of seconds left to wait + /// before the request can be repeated + #[display(fmt = "Retry after {secs} seconds", secs = _0)] + RetryAfter(i32), + #[display(fmt = "Network error: {err}", err = _0)] NetworkError(reqwest::Error), @@ -27,6 +37,8 @@ impl std::error::Error for RequestError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { RequestError::ApiError { .. } => None, + RequestError::MigrateToChatId(_) => None, + RequestError::RetryAfter(_) => None, RequestError::NetworkError(err) => Some(err), RequestError::InvalidJson(err) => Some(err), } From 9f157057ecc6524e7f3a3b57dc983b3f28049449 Mon Sep 17 00:00:00 2001 From: Waffle Date: Thu, 19 Sep 2019 16:31:11 +0300 Subject: [PATCH 39/55] Remove done TODO --- src/core/requests/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/requests/mod.rs b/src/core/requests/mod.rs index aa6bb37f..7deba0fd 100644 --- a/src/core/requests/mod.rs +++ b/src/core/requests/mod.rs @@ -11,7 +11,6 @@ mod utils; pub enum RequestError { #[display(fmt = "Telegram error #{}: {}", status_code, description)] ApiError { - // TODO: add response parameters status_code: StatusCode, description: String, }, From ced6bd8e696211b18a11fa05dcac20ed6fe1cc45 Mon Sep 17 00:00:00 2001 From: nextel Date: Thu, 19 Sep 2019 17:57:50 +0300 Subject: [PATCH 40/55] add get user profile photos template struct --- src/core/requests/get_user_profile_photos.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/requests/get_user_profile_photos.rs b/src/core/requests/get_user_profile_photos.rs index 2dfed773..fb69133f 100644 --- a/src/core/requests/get_user_profile_photos.rs +++ b/src/core/requests/get_user_profile_photos.rs @@ -1,8 +1,16 @@ use crate::core::requests::RequestContext; -//TODO:: need implementation + +//TODO: complete implementation after user_profile_fotos will be added to types/mod.rs +///Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object. #[derive(Debug, Clone, Serialize)] struct GetUserProfilePhotos<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, + /// Unique identifier of the target user + user_id: i32, + /// Sequential number of the first photo to be returned. By default, all photos are returned. + offset: Option, + ///Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100. + limit: Option, } From ccbfee24b83eba5fd8062a08755c3e0bd34ef6f7 Mon Sep 17 00:00:00 2001 From: Mr-Andersen Date: Thu, 19 Sep 2019 18:24:11 +0300 Subject: [PATCH 41/55] +Message::text(&self); message_kind->kind; IncomingMessage->CommonMessage --- src/core/types/message.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/types/message.rs b/src/core/types/message.rs index ebc76355..2252f54f 100644 --- a/src/core/types/message.rs +++ b/src/core/types/message.rs @@ -11,13 +11,26 @@ pub struct Message { pub date: i32, pub chat: Chat, #[serde(flatten)] - pub message_kind: MessageKind, + pub kind: MessageKind, +} + +impl Message { + fn text(&self) -> Option<&str> { + if let MessageKind::CommonMessage { + media_kind: MediaKind::Text { + ref text, .. + }, .. } = self.kind { + Some(text) + } else { + None + } + } } #[derive(Debug, Deserialize, PartialEq, Clone)] #[serde(untagged)] pub enum MessageKind { - IncomingMessage { + CommonMessage { #[serde(flatten)] from: Sender, #[serde(flatten)] From c395e24792d113dd8f67323cb08295e203a7bc4c Mon Sep 17 00:00:00 2001 From: P0lunin Date: Thu, 19 Sep 2019 19:37:48 +0300 Subject: [PATCH 42/55] add enum ChatMemberStatus --- src/core/types/chat_member.rs | 73 ++++++++++++++++++++++++- src/core/types/mod.rs | 2 +- src/core/types/not_implemented_types.rs | 3 - 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/core/types/chat_member.rs b/src/core/types/chat_member.rs index 600b7e2e..cee60bc6 100644 --- a/src/core/types/chat_member.rs +++ b/src/core/types/chat_member.rs @@ -1,4 +1,4 @@ -use crate::core::types::{ChatMemberStatus, User}; +use crate::core::types::User; /// This object contains information about one member of the chat. #[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)] @@ -54,3 +54,74 @@ pub struct ChatMember { /// his messages, implies can_send_media_messages pub can_add_web_page_previews: Option, } + +#[derive(Deserialize, Debug, Hash, PartialEq, Eq, Clone)] +#[serde(rename_all = "snake_case")] +pub enum ChatMemberStatus { + Creator, + Administrator, + Member, + Restricted, + Left, + Kicked +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn deserialize() { + let json = r#"{ + "user":{ + "id":12345, + "is_bot":false, + "first_name":"firstName" + }, + "status":"creator", + "until_date":123456, + "can_be_edited":true, + "can_post_messages":true, + "can_edit_messages":true, + "can_delete_messages":true, + "can_restrict_members":true, + "can_promote_members":true, + "can_change_info":true, + "can_invite_users":true, + "can_pin_messages":true, + "is_member":true, + "can_send_messages":true, + "can_send_media_messages":true, + "can_send_polls":true, + "can_send_other_messages":true, + "can_add_web_page_previews":true + }"#; + let expected = ChatMember { + user: User { + id: 12345, + is_bot: false, + first_name: "firstName".to_string(), + last_name: None, + username: None, + language_code: None + }, + status: ChatMemberStatus::Creator, + until_date: Some(123456), + can_be_edited: Some(true), + can_change_info: Some(true), + can_post_messages: Some(true), + can_edit_messages: Some(true), + can_delete_messages: Some(true), + can_invite_users: Some(true), + can_restrict_members: Some(true), + can_pin_messages: Some(true), + can_promote_members: Some(true), + can_send_messages: Some(true), + can_send_media_messages: Some(true), + can_send_other_messages: Some(true), + can_add_web_page_previews: Some(true) + }; + let actual = serde_json::from_str::(&json).unwrap(); + assert_eq!(actual, expected) + } +} \ No newline at end of file diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index 42e9869a..27ba457b 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -4,7 +4,7 @@ pub use self::{ audio::Audio, callback_query::CallbackQuery, chat::{Chat, ChatKind, NonPrivateChatKind}, - chat_member::ChatMember, + chat_member::{ChatMember, ChatMemberStatus}, chat_permissions::ChatPermissions, chat_photo::ChatPhoto, chosen_inline_result::ChosenInlineResult, diff --git a/src/core/types/not_implemented_types.rs b/src/core/types/not_implemented_types.rs index c2700b2d..c1e9d2ba 100644 --- a/src/core/types/not_implemented_types.rs +++ b/src/core/types/not_implemented_types.rs @@ -1,5 +1,2 @@ #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] pub struct PassportData; - -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] -pub struct ChatMemberStatus; From 7b638eb2c0a73b02b99d4ed04cb05a0e2cfe90a9 Mon Sep 17 00:00:00 2001 From: P0lunin Date: Thu, 19 Sep 2019 19:38:07 +0300 Subject: [PATCH 43/55] add tests --- src/core/types/audio.rs | 46 ++++++++++++++++++++++---- src/core/types/callback_query.rs | 57 ++++++++++++++++++++++++-------- src/core/types/user.rs | 27 +++++++++++++++ 3 files changed, 110 insertions(+), 20 deletions(-) diff --git a/src/core/types/audio.rs b/src/core/types/audio.rs index 304d4946..66cc0878 100644 --- a/src/core/types/audio.rs +++ b/src/core/types/audio.rs @@ -1,17 +1,51 @@ use crate::core::types::PhotoSize; -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)] +#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)] pub struct Audio { pub file_id: String, pub duration: u32, - #[serde(skip_serializing_if = "Option::is_none")] pub performer: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub mime_type: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub file_size: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub thumb: Option, } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn deserialize() { + let json = r#"{ + "file_id":"id", + "duration":60, + "performer":"Performer", + "title":"Title", + "mime_type":"MimeType", + "file_size":123456, + "thumb":{ + "file_id":"id", + "width":320, + "height":320, + "file_size":3452 + } + }"#; + let expected = Audio { + file_id: "id".to_string(), + duration: 60, + performer: Some("Performer".to_string()), + title: Some("Title".to_string()), + mime_type: Some("MimeType".to_string()), + file_size: Some(123456), + thumb: Some(PhotoSize { + file_id: "id".to_string(), + width: 320, + height: 320, + file_size: Some(3452) + }) + }; + let actual = serde_json::from_str::