rust_tdlib/types/
input_sticker.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7/// Describes a sticker that needs to be added to a sticker set
8pub trait TDInputSticker: Debug + RObject {}
9
10/// Describes a sticker that needs to be added to a sticker set
11#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum InputSticker {
14    #[doc(hidden)]
15    #[default]
16    _Default,
17    /// An animated sticker in TGS format
18    #[serde(rename = "inputStickerAnimated")]
19    Animated(InputStickerAnimated),
20    /// A static sticker in PNG format, which will be converted to WEBP server-side
21    #[serde(rename = "inputStickerStatic")]
22    Static(InputStickerStatic),
23}
24
25impl RObject for InputSticker {
26    #[doc(hidden)]
27    fn extra(&self) -> Option<&str> {
28        match self {
29            InputSticker::Animated(t) => t.extra(),
30            InputSticker::Static(t) => t.extra(),
31
32            _ => None,
33        }
34    }
35    #[doc(hidden)]
36    fn client_id(&self) -> Option<i32> {
37        match self {
38            InputSticker::Animated(t) => t.client_id(),
39            InputSticker::Static(t) => t.client_id(),
40
41            _ => None,
42        }
43    }
44}
45
46impl InputSticker {
47    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
48        Ok(serde_json::from_str(json.as_ref())?)
49    }
50    #[doc(hidden)]
51    pub fn _is_default(&self) -> bool {
52        matches!(self, InputSticker::_Default)
53    }
54}
55
56impl AsRef<InputSticker> for InputSticker {
57    fn as_ref(&self) -> &InputSticker {
58        self
59    }
60}
61
62/// An animated sticker in TGS format
63#[derive(Debug, Clone, Default, Serialize, Deserialize)]
64pub struct InputStickerAnimated {
65    #[doc(hidden)]
66    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
67    extra: Option<String>,
68    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
69    client_id: Option<i32>,
70    /// File with the animated sticker. Only local or uploaded within a week files are supported. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
71
72    #[serde(skip_serializing_if = "InputFile::_is_default")]
73    sticker: InputFile,
74    /// Emojis corresponding to the sticker
75
76    #[serde(default)]
77    emojis: String,
78}
79
80impl RObject for InputStickerAnimated {
81    #[doc(hidden)]
82    fn extra(&self) -> Option<&str> {
83        self.extra.as_deref()
84    }
85    #[doc(hidden)]
86    fn client_id(&self) -> Option<i32> {
87        self.client_id
88    }
89}
90
91impl TDInputSticker for InputStickerAnimated {}
92
93impl InputStickerAnimated {
94    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
95        Ok(serde_json::from_str(json.as_ref())?)
96    }
97    pub fn builder() -> InputStickerAnimatedBuilder {
98        let mut inner = InputStickerAnimated::default();
99        inner.extra = Some(Uuid::new_v4().to_string());
100
101        InputStickerAnimatedBuilder { inner }
102    }
103
104    pub fn sticker(&self) -> &InputFile {
105        &self.sticker
106    }
107
108    pub fn emojis(&self) -> &String {
109        &self.emojis
110    }
111}
112
113#[doc(hidden)]
114pub struct InputStickerAnimatedBuilder {
115    inner: InputStickerAnimated,
116}
117
118#[deprecated]
119pub type RTDInputStickerAnimatedBuilder = InputStickerAnimatedBuilder;
120
121impl InputStickerAnimatedBuilder {
122    pub fn build(&self) -> InputStickerAnimated {
123        self.inner.clone()
124    }
125
126    pub fn sticker<T: AsRef<InputFile>>(&mut self, sticker: T) -> &mut Self {
127        self.inner.sticker = sticker.as_ref().clone();
128        self
129    }
130
131    pub fn emojis<T: AsRef<str>>(&mut self, emojis: T) -> &mut Self {
132        self.inner.emojis = emojis.as_ref().to_string();
133        self
134    }
135}
136
137impl AsRef<InputStickerAnimated> for InputStickerAnimated {
138    fn as_ref(&self) -> &InputStickerAnimated {
139        self
140    }
141}
142
143impl AsRef<InputStickerAnimated> for InputStickerAnimatedBuilder {
144    fn as_ref(&self) -> &InputStickerAnimated {
145        &self.inner
146    }
147}
148
149/// A static sticker in PNG format, which will be converted to WEBP server-side
150#[derive(Debug, Clone, Default, Serialize, Deserialize)]
151pub struct InputStickerStatic {
152    #[doc(hidden)]
153    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
154    extra: Option<String>,
155    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
156    client_id: Option<i32>,
157    /// PNG image with the sticker; must be up to 512 KB in size and fit in a 512x512 square
158
159    #[serde(skip_serializing_if = "InputFile::_is_default")]
160    sticker: InputFile,
161    /// Emojis corresponding to the sticker
162
163    #[serde(default)]
164    emojis: String,
165    /// For masks, position where the mask is placed; pass null if unspecified
166    mask_position: MaskPosition,
167}
168
169impl RObject for InputStickerStatic {
170    #[doc(hidden)]
171    fn extra(&self) -> Option<&str> {
172        self.extra.as_deref()
173    }
174    #[doc(hidden)]
175    fn client_id(&self) -> Option<i32> {
176        self.client_id
177    }
178}
179
180impl TDInputSticker for InputStickerStatic {}
181
182impl InputStickerStatic {
183    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
184        Ok(serde_json::from_str(json.as_ref())?)
185    }
186    pub fn builder() -> InputStickerStaticBuilder {
187        let mut inner = InputStickerStatic::default();
188        inner.extra = Some(Uuid::new_v4().to_string());
189
190        InputStickerStaticBuilder { inner }
191    }
192
193    pub fn sticker(&self) -> &InputFile {
194        &self.sticker
195    }
196
197    pub fn emojis(&self) -> &String {
198        &self.emojis
199    }
200
201    pub fn mask_position(&self) -> &MaskPosition {
202        &self.mask_position
203    }
204}
205
206#[doc(hidden)]
207pub struct InputStickerStaticBuilder {
208    inner: InputStickerStatic,
209}
210
211#[deprecated]
212pub type RTDInputStickerStaticBuilder = InputStickerStaticBuilder;
213
214impl InputStickerStaticBuilder {
215    pub fn build(&self) -> InputStickerStatic {
216        self.inner.clone()
217    }
218
219    pub fn sticker<T: AsRef<InputFile>>(&mut self, sticker: T) -> &mut Self {
220        self.inner.sticker = sticker.as_ref().clone();
221        self
222    }
223
224    pub fn emojis<T: AsRef<str>>(&mut self, emojis: T) -> &mut Self {
225        self.inner.emojis = emojis.as_ref().to_string();
226        self
227    }
228
229    pub fn mask_position<T: AsRef<MaskPosition>>(&mut self, mask_position: T) -> &mut Self {
230        self.inner.mask_position = mask_position.as_ref().clone();
231        self
232    }
233}
234
235impl AsRef<InputStickerStatic> for InputStickerStatic {
236    fn as_ref(&self) -> &InputStickerStatic {
237        self
238    }
239}
240
241impl AsRef<InputStickerStatic> for InputStickerStaticBuilder {
242    fn as_ref(&self) -> &InputStickerStatic {
243        &self.inner
244    }
245}