From 7c687ab3fedbbc9fb55620304bdfadccc5f2b346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Gr=C3=BCnewald?= Date: Mon, 5 Oct 2020 00:20:21 +0200 Subject: [PATCH 1/4] Add caption entities --- raw/src/types/message.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/raw/src/types/message.rs b/raw/src/types/message.rs index b43824e64f..795be12c4f 100644 --- a/raw/src/types/message.rs +++ b/raw/src/types/message.rs @@ -109,6 +109,8 @@ pub enum MessageKind { data: Vec, /// Caption for the photo, 0-200 characters. caption: Option, + + caption_entities: Option>, /// The unique identifier of a media message group this message belongs to. media_group_id: Option, }, @@ -304,6 +306,19 @@ impl Message { }}; } + macro_rules! maybe_field_with_caption_and_group_and_caption_entities { + ($name:ident, $variant:ident) => {{ + if let Some(val) = raw.$name { + return make_message(MessageKind::$variant { + data: val, + caption: raw.caption, + caption_entities: raw.entities, + media_group_id: raw.media_group_id, + }); + } + }}; + } + macro_rules! maybe_true_field { ($name:ident, $variant:ident) => {{ if let Some(True) = raw.$name { @@ -322,7 +337,7 @@ impl Message { maybe_field!(audio, Audio); maybe_field_with_caption!(document, Document); - maybe_field_with_caption_and_group!(photo, Photo); + maybe_field_with_caption_and_group_and_caption_entities!(photo, Photo); maybe_field!(sticker, Sticker); maybe_field_with_caption_and_group!(video, Video); maybe_field!(voice, Voice); @@ -443,6 +458,19 @@ impl ChannelPost { }}; } + macro_rules! maybe_field_with_caption_and_group_and_caption_entities { + ($name:ident, $variant:ident) => {{ + if let Some(val) = raw.$name { + return make_message(MessageKind::$variant { + data: val, + caption: raw.caption, + caption_entities: raw.entities, + media_group_id: raw.media_group_id, + }); + } + }}; + + } macro_rules! maybe_true_field { ($name:ident, $variant:ident) => {{ if let Some(True) = raw.$name { @@ -461,7 +489,7 @@ impl ChannelPost { maybe_field!(audio, Audio); maybe_field_with_caption!(document, Document); - maybe_field_with_caption_and_group!(photo, Photo); + maybe_field_with_caption_and_group_and_caption_entities!(photo, Photo); maybe_field!(sticker, Sticker); maybe_field_with_caption_and_group!(video, Video); maybe_field!(voice, Voice); From b2c1f1fd392bd49e77cfc958f5cfaa10e5fdfd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Gr=C3=BCnewald?= Date: Mon, 5 Oct 2020 00:23:47 +0200 Subject: [PATCH 2/4] Cargo format message.rs --- raw/src/types/message.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/raw/src/types/message.rs b/raw/src/types/message.rs index 795be12c4f..eeb1aad240 100644 --- a/raw/src/types/message.rs +++ b/raw/src/types/message.rs @@ -469,7 +469,6 @@ impl ChannelPost { }); } }}; - } macro_rules! maybe_true_field { ($name:ident, $variant:ident) => {{ From ede3a675d28c43384a0a109d0e75edc361a4c494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Gr=C3=BCnewald?= Date: Tue, 13 Oct 2020 01:12:21 +0200 Subject: [PATCH 3/4] Add send sticker --- raw/src/requests/mod.rs | 2 + raw/src/requests/send_sticker.rs | 111 +++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 raw/src/requests/send_sticker.rs diff --git a/raw/src/requests/mod.rs b/raw/src/requests/mod.rs index 4d744a2d1a..92ec1f84a1 100644 --- a/raw/src/requests/mod.rs +++ b/raw/src/requests/mod.rs @@ -34,6 +34,7 @@ pub mod stop_message_live_location; pub mod stop_poll; pub mod unban_chat_member; pub mod unpin_chat_message; +pub mod send_sticker; pub use self::_base::*; pub use self::answer_callback_query::*; @@ -70,3 +71,4 @@ pub use self::stop_message_live_location::*; pub use self::stop_poll::*; pub use self::unban_chat_member::*; pub use self::unpin_chat_message::*; +pub use self::send_sticker::*; \ No newline at end of file diff --git a/raw/src/requests/send_sticker.rs b/raw/src/requests/send_sticker.rs new file mode 100644 index 0000000000..f3ed05bff9 --- /dev/null +++ b/raw/src/requests/send_sticker.rs @@ -0,0 +1,111 @@ +use crate::requests::*; +use crate::types::*; + +#[derive(Debug, Clone, PartialEq, PartialOrd)] +#[must_use = "requests do nothing unless sent"] +pub struct SendSticker { + chat_id: ChatRef, + sticker: InputFile, + disable_notification: bool, + reply_to_message_id: Option, + reply_markup: Option, +} + +impl ToMultipart for SendSticker { + fn to_multipart(&self) -> Result { + multipart_map! { + self, + (chat_id (text)); + (sticker (raw)); + (disable_notification (text), when_true); + (reply_to_message_id (text), optional); + (reply_markup (json), optional); + } + } +} + +impl Request for SendSticker { + type Type = MultipartRequestType; + type Response = JsonIdResponse; + + fn serialize(&self) -> Result { + Self::Type::serialize(RequestUrl::method("sendSticker"), self) + } +} + +impl SendSticker { + pub fn new(chat: C, photo: V) -> Self + where + C: ToChatRef, + V: Into, + { + Self { + chat_id: chat.to_chat_ref(), + sticker: photo.into(), + reply_to_message_id: None, + reply_markup: None, + disable_notification: false, + } + } + + pub fn reply_to(&mut self, to: R) -> &mut Self + where + R: ToMessageId, + { + self.reply_to_message_id = Some(to.to_message_id()); + self + } + + pub fn disable_notification(&mut self) -> &mut Self { + self.disable_notification = true; + self + } + + pub fn reply_markup(&mut self, reply_markup: R) -> &mut Self + where + R: Into, + { + self.reply_markup = Some(reply_markup.into()); + self + } +} + +/// Can reply with an photo +pub trait CanReplySendSticker { + fn sticker_reply(&self, photo: T) -> SendSticker + where + T: Into; +} + +impl CanReplySendSticker for M + where + M: ToMessageId + ToSourceChat, +{ + fn sticker_reply(&self, photo: T) -> SendSticker + where + T: Into, + { + let mut req = SendSticker::new(self.to_source_chat(), photo); + req.reply_to(self); + req + } +} + +/// Send an photo +pub trait CanSendSticker { + fn sticker(&self, photo: T) -> SendSticker + where + T: Into; +} + +impl CanSendSticker for M + where + M: ToChatRef, +{ + fn sticker(&self, photo: T) -> SendSticker + where + T: Into, + { + SendSticker::new(self.to_chat_ref(), photo) + } +} From db6603437d2816903a39416446ca426b0346456b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Gr=C3=BCnewald?= Date: Sat, 16 Jan 2021 00:35:36 +0100 Subject: [PATCH 4/4] Add format --- raw/src/requests/mod.rs | 4 ++-- raw/src/requests/send_sticker.rs | 38 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/raw/src/requests/mod.rs b/raw/src/requests/mod.rs index 92ec1f84a1..7815dfa5b5 100644 --- a/raw/src/requests/mod.rs +++ b/raw/src/requests/mod.rs @@ -28,13 +28,13 @@ pub mod send_location; pub mod send_message; pub mod send_photo; pub mod send_poll; +pub mod send_sticker; pub mod send_venue; pub mod send_video; pub mod stop_message_live_location; pub mod stop_poll; pub mod unban_chat_member; pub mod unpin_chat_message; -pub mod send_sticker; pub use self::_base::*; pub use self::answer_callback_query::*; @@ -65,10 +65,10 @@ pub use self::send_location::*; pub use self::send_message::*; pub use self::send_photo::*; pub use self::send_poll::*; +pub use self::send_sticker::*; pub use self::send_venue::*; pub use self::send_video::*; pub use self::stop_message_live_location::*; pub use self::stop_poll::*; pub use self::unban_chat_member::*; pub use self::unpin_chat_message::*; -pub use self::send_sticker::*; \ No newline at end of file diff --git a/raw/src/requests/send_sticker.rs b/raw/src/requests/send_sticker.rs index f3ed05bff9..c125df7d60 100644 --- a/raw/src/requests/send_sticker.rs +++ b/raw/src/requests/send_sticker.rs @@ -35,9 +35,9 @@ impl Request for SendSticker { impl SendSticker { pub fn new(chat: C, photo: V) -> Self - where - C: ToChatRef, - V: Into, + where + C: ToChatRef, + V: Into, { Self { chat_id: chat.to_chat_ref(), @@ -49,8 +49,8 @@ impl SendSticker { } pub fn reply_to(&mut self, to: R) -> &mut Self - where - R: ToMessageId, + where + R: ToMessageId, { self.reply_to_message_id = Some(to.to_message_id()); self @@ -62,8 +62,8 @@ impl SendSticker { } pub fn reply_markup(&mut self, reply_markup: R) -> &mut Self - where - R: Into, + where + R: Into, { self.reply_markup = Some(reply_markup.into()); self @@ -73,17 +73,17 @@ impl SendSticker { /// Can reply with an photo pub trait CanReplySendSticker { fn sticker_reply(&self, photo: T) -> SendSticker - where - T: Into; + where + T: Into; } impl CanReplySendSticker for M - where - M: ToMessageId + ToSourceChat, +where + M: ToMessageId + ToSourceChat, { fn sticker_reply(&self, photo: T) -> SendSticker - where - T: Into, + where + T: Into, { let mut req = SendSticker::new(self.to_source_chat(), photo); req.reply_to(self); @@ -94,17 +94,17 @@ impl CanReplySendSticker for M /// Send an photo pub trait CanSendSticker { fn sticker(&self, photo: T) -> SendSticker - where - T: Into; + where + T: Into; } impl CanSendSticker for M - where - M: ToChatRef, +where + M: ToChatRef, { fn sticker(&self, photo: T) -> SendSticker - where - T: Into, + where + T: Into, { SendSticker::new(self.to_chat_ref(), photo) }