From 217bdb094654ea52ba7c50319e00cbffd9b24294 Mon Sep 17 00:00:00 2001 From: CuriouslyCurious Date: Mon, 1 Feb 2021 10:11:07 +0100 Subject: [PATCH 1/4] Add GetStickerSet implementation --- lib/src/util/messages.rs | 2 ++ raw/src/requests/get_sticker_set.rs | 43 +++++++++++++++++++++++++++++ raw/src/requests/mod.rs | 2 ++ raw/src/types/message.rs | 25 +++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 raw/src/requests/get_sticker_set.rs diff --git a/lib/src/util/messages.rs b/lib/src/util/messages.rs index 14fa6d3c8e..05a958f70a 100644 --- a/lib/src/util/messages.rs +++ b/lib/src/util/messages.rs @@ -40,6 +40,7 @@ impl MessageText for MessageKind { } MessageKind::Photo { caption, .. } => caption.to_owned(), MessageKind::Sticker { .. } => None, + MessageKind::StickerSet { data } => Some(data.name.to_owned()), MessageKind::Video { caption, .. } => caption.to_owned(), MessageKind::Voice { .. } => None, MessageKind::VideoNote { .. } => None, @@ -110,6 +111,7 @@ impl MessageGetFiles for MessageKind { Some(data.into_iter().map(|f| f.get_file()).collect()) } MessageKind::Sticker { data } => Some(vec![data.get_file()]), + MessageKind::StickerSet { .. } => None, MessageKind::Video { data, .. } => { let mut files = vec![data.get_file()]; if let Some(thumb) = &data.thumb { diff --git a/raw/src/requests/get_sticker_set.rs b/raw/src/requests/get_sticker_set.rs new file mode 100644 index 0000000000..72b1b352a1 --- /dev/null +++ b/raw/src/requests/get_sticker_set.rs @@ -0,0 +1,43 @@ +use crate::requests::*; +use crate::types::*; + +/// Use this method to get a sticker set. +#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)] +#[must_use = "requests do nothing unless sent"] +pub struct GetStickerSet { + name: String, +} + +impl Request for GetStickerSet { + type Type = JsonRequestType; + type Response = JsonIdResponse; + + fn serialize(&self) -> Result { + Self::Type::serialize(RequestUrl::method("getStickerSet"), self) + } +} + +impl GetStickerSet { + pub fn new(set: S) -> Self + where + S: ToString, + { + Self { + name: set.to_string(), + } + } +} + +/// Get basic info about a sticker set and prepare it for downloading. +pub trait CanGetStickerSet { + fn get_set(&self) -> GetStickerSet; +} + +impl CanGetStickerSet for S +where + S: ToString + std::fmt::Display, +{ + fn get_set(&self) -> GetStickerSet { + GetStickerSet::new(self) + } +} diff --git a/raw/src/requests/mod.rs b/raw/src/requests/mod.rs index 4d744a2d1a..590be240cd 100644 --- a/raw/src/requests/mod.rs +++ b/raw/src/requests/mod.rs @@ -15,6 +15,7 @@ pub mod get_chat_member; pub mod get_chat_members_count; pub mod get_file; pub mod get_me; +pub mod get_sticker_set; pub mod get_updates; pub mod get_user_profile_photos; pub mod kick_chat_member; @@ -51,6 +52,7 @@ pub use self::get_chat_member::*; pub use self::get_chat_members_count::*; pub use self::get_file::*; pub use self::get_me::*; +pub use self::get_sticker_set::*; pub use self::get_updates::*; pub use self::get_user_profile_photos::*; pub use self::kick_chat_member::*; diff --git a/raw/src/types/message.rs b/raw/src/types/message.rs index b43824e64f..d3c7b8f148 100644 --- a/raw/src/types/message.rs +++ b/raw/src/types/message.rs @@ -117,6 +117,10 @@ pub enum MessageKind { /// Information about the sticker. data: Sticker, }, + /// Message is a sticker set. + StickerSet { + data: StickerSet, + }, /// Message is a video. Video { /// Information about the video. @@ -324,6 +328,7 @@ impl Message { maybe_field_with_caption!(document, Document); maybe_field_with_caption_and_group!(photo, Photo); maybe_field!(sticker, Sticker); + maybe_field!(sticker_set, StickerSet); maybe_field_with_caption_and_group!(video, Video); maybe_field!(voice, Voice); maybe_field!(video_note, VideoNote); @@ -463,6 +468,7 @@ impl ChannelPost { maybe_field_with_caption!(document, Document); maybe_field_with_caption_and_group!(photo, Photo); maybe_field!(sticker, Sticker); + maybe_field!(sticker_set, StickerSet); maybe_field_with_caption_and_group!(video, Video); maybe_field!(voice, Voice); maybe_field!(video_note, VideoNote); @@ -561,6 +567,8 @@ pub struct RawMessage { pub photo: Option>, /// Message is a sticker, information about the sticker. pub sticker: Option, + /// Message is a sticker set, information about the sticker set. + pub sticker_set: Option, /// Message is a video, information about the video. pub video: Option