djs_model/rest/sticker.rs
1//! Bodies of the [sticker endpoints](https://docs.discord.com/developers/resources/sticker).
2
3use compact_str::CompactString;
4use serde::Serialize;
5
6use super::FileUpload;
7use crate::util::Patch;
8
9/// The body of [Create Guild Sticker](https://docs.discord.com/developers/resources/sticker#create-guild-sticker).
10///
11/// Unlike most bodies it is sent as `multipart/form-data` fields, not JSON, so it does not
12/// implement `Serialize`. The file must be a PNG, APNG, GIF or Lottie JSON file of at most
13/// 512 KiB and 320×320 pixels (animated: at most 5 seconds); Lottie stickers need a verified or
14/// partnered guild.
15///
16/// discord.js counterpart: `GuildStickerCreateOptions`.
17///
18/// # Examples
19///
20/// ```
21/// use djs_model::rest::{CreateGuildSticker, FileUpload};
22///
23/// let file = FileUpload::new("wave.png", b"\x89PNG\r\n\x1a\n...".to_vec());
24/// let mut body = CreateGuildSticker::new("Wave", "wave", file);
25/// body.description = "A friendly wave".into();
26/// ```
27#[derive(Clone, Debug, PartialEq)]
28#[non_exhaustive]
29pub struct CreateGuildSticker {
30 /// The name (2–30 characters).
31 pub name: CompactString,
32 /// The description: empty (the default) or 2–100 characters.
33 pub description: CompactString,
34 /// The autocomplete and suggestion tags (max 200 characters); Discord's client uses the
35 /// name of a related Unicode emoji, such as `wave`.
36 pub tags: CompactString,
37 /// The sticker image.
38 pub file: FileUpload,
39}
40
41impl CreateGuildSticker {
42 /// A sticker named `name`, suggested for `tags`, showing `file`, without a description.
43 ///
44 /// discord.js counterpart: `GuildStickerCreateOptions`.
45 #[must_use]
46 pub fn new(
47 name: impl Into<CompactString>,
48 tags: impl Into<CompactString>,
49 file: FileUpload,
50 ) -> Self {
51 Self {
52 name: name.into(),
53 description: CompactString::const_new(""),
54 tags: tags.into(),
55 file,
56 }
57 }
58}
59
60/// The body of [Modify Guild Sticker](https://docs.discord.com/developers/resources/sticker#modify-guild-sticker).
61///
62/// Every field is optional; the image cannot be changed.
63///
64/// discord.js counterpart: `GuildStickerEditOptions`.
65///
66/// # Examples
67///
68/// ```
69/// use djs_model::{rest::ModifyGuildSticker, util::Patch};
70///
71/// let mut body = ModifyGuildSticker::default();
72/// body.tags = Some("smile".into());
73/// body.description = Patch::Clear;
74/// assert_eq!(serde_json::to_string(&body)?, r#"{"description":null,"tags":"smile"}"#);
75/// # Ok::<(), serde_json::Error>(())
76/// ```
77#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize)]
78#[non_exhaustive]
79pub struct ModifyGuildSticker {
80 /// The new name (2–30 characters).
81 #[serde(skip_serializing_if = "Option::is_none")]
82 pub name: Option<CompactString>,
83 /// The new description (2–100 characters); [`Patch::Clear`] removes it.
84 #[serde(skip_serializing_if = "Patch::is_keep")]
85 pub description: Patch<CompactString>,
86 /// The new autocomplete and suggestion tags (max 200 characters).
87 #[serde(skip_serializing_if = "Option::is_none")]
88 pub tags: Option<CompactString>,
89}