Skip to content

Commit

Permalink
Add send sticker
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalucario committed Oct 12, 2020
1 parent b2c1f1f commit ede3a67
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
2 changes: 2 additions & 0 deletions raw/src/requests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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::*;
111 changes: 111 additions & 0 deletions raw/src/requests/send_sticker.rs
Original file line number Diff line number Diff line change
@@ -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<MessageId>,
reply_markup: Option<ReplyMarkup>,
}

impl ToMultipart for SendSticker {
fn to_multipart(&self) -> Result<Multipart, Error> {
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<Self>;
type Response = JsonIdResponse<Message>;

fn serialize(&self) -> Result<HttpRequest, Error> {
Self::Type::serialize(RequestUrl::method("sendSticker"), self)
}
}

impl SendSticker {
pub fn new<C, V>(chat: C, photo: V) -> Self
where
C: ToChatRef,
V: Into<InputFile>,
{
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<R>(&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<R>(&mut self, reply_markup: R) -> &mut Self
where
R: Into<ReplyMarkup>,
{
self.reply_markup = Some(reply_markup.into());
self
}
}

/// Can reply with an photo
pub trait CanReplySendSticker {
fn sticker_reply<T>(&self, photo: T) -> SendSticker
where
T: Into<InputFile>;
}

impl<M> CanReplySendSticker for M
where
M: ToMessageId + ToSourceChat,
{
fn sticker_reply<T>(&self, photo: T) -> SendSticker
where
T: Into<InputFile>,
{
let mut req = SendSticker::new(self.to_source_chat(), photo);
req.reply_to(self);
req
}
}

/// Send an photo
pub trait CanSendSticker {
fn sticker<T>(&self, photo: T) -> SendSticker
where
T: Into<InputFile>;
}

impl<M> CanSendSticker for M
where
M: ToChatRef,
{
fn sticker<T>(&self, photo: T) -> SendSticker
where
T: Into<InputFile>,
{
SendSticker::new(self.to_chat_ref(), photo)
}
}

0 comments on commit ede3a67

Please sign in to comment.