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) + } +}