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
use super::InputFile;
use crate::types::file;

/// Represents a sticker set thumb to be sent.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[must_use]
pub struct StickerSetThumb {
    pub(crate) media: InputFile,
}

impl StickerSetThumb {
    const fn new(media: InputFile) -> Self {
        Self { media }
    }

    /// Constructs a `StickerSetThumb` from bytes of `.png` image.
    pub fn png_bytes(bytes: impl Into<Vec<u8>>) -> Self {
        Self::new(InputFile::File {
            filename: "thumb.png".into(),
            bytes: bytes.into(),
        })
    }

    /// Constructs a `StickerSetThumb` from bytes of `.tgs` animation.
    pub fn tgs_bytes(bytes: impl Into<Vec<u8>>) -> Self {
        Self::new(InputFile::File {
            filename: "thumb.tgs".into(),
            bytes: bytes.into(),
        })
    }

    /// Constructs a `StickerSetThumb` from a file ID.
    ///
    /// # Panics
    ///
    /// Panics if the ID starts with `attach://`.
    pub fn id(id: file::Id) -> Self {
        assert!(
            !id.0.starts_with("attach://"),
            "\n[tbot] StickerSetThumb's ID cannot start with `attach://`\n",
        );

        Self::new(InputFile::Id(id))
    }

    /// Constructs a `StickerSetThumb` from an URL.
    ///
    /// # Panics
    ///
    /// Panics if the URL starts with `attach://`.
    pub fn url(url: impl Into<String>) -> Self {
        let url = url.into();
        assert!(
            !url.starts_with("attach://"),
            "\n[tbot] StickerSetThumb's URL cannot start with `attach://`\n",
        );

        Self::new(InputFile::Url(url))
    }
}