1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use super::*;
use serde::ser::SerializeMap;
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
pub struct PngSticker<'a> {
pub(crate) media: InputFile<'a>,
}
impl<'a> PngSticker<'a> {
const fn new(media: InputFile<'a>) -> Self {
Self {
media,
}
}
pub fn bytes(bytes: &'a [u8]) -> Self {
Self::new(InputFile::File {
filename: "sticker.png",
bytes,
})
}
pub fn id(id: &'a str) -> Self {
assert!(
!id.starts_with("attach://"),
"\n[tbot] Sticker's ID cannot start with `attach://`\n",
);
Self::new(InputFile::Id(id))
}
pub fn url(url: &'a str) -> Self {
assert!(
!url.starts_with("attach://"),
"\n[tbot] Sticker's URL cannot start with `attach://`\n",
);
Self::new(InputFile::Url(url))
}
}
impl<'a> serde::Serialize for PngSticker<'a> {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
let mut map = s.serialize_map(None)?;
map.serialize_entry("type", "png_sticker")?;
map.serialize_entry("media", &self.media.with_name("sticker"))?;
map.end()
}
}