diff --git a/raw/src/requests/mod.rs b/raw/src/requests/mod.rs index 4d744a2d1a..7815dfa5b5 100644 --- a/raw/src/requests/mod.rs +++ b/raw/src/requests/mod.rs @@ -28,6 +28,7 @@ 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; @@ -64,6 +65,7 @@ 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::*; diff --git a/raw/src/requests/send_sticker.rs b/raw/src/requests/send_sticker.rs new file mode 100644 index 0000000000..c125df7d60 --- /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) + } +} diff --git a/raw/src/types/message.rs b/raw/src/types/message.rs index b43824e64f..eeb1aad240 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,18 @@ 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 +488,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);