Skip to main content

djs_model/rest/
guild_template.rs

1//! Bodies of the [guild template endpoints](https://docs.discord.com/developers/resources/guild-template).
2
3use compact_str::CompactString;
4use serde::Serialize;
5
6use crate::util::Patch;
7
8/// The body of [Create Guild Template](https://docs.discord.com/developers/resources/guild-template#create-guild-template).
9///
10/// discord.js counterpart: the arguments of `Guild#createTemplate`.
11///
12/// # Examples
13///
14/// ```
15/// use djs_model::rest::CreateGuildTemplate;
16///
17/// let mut body = CreateGuildTemplate::new("Study group");
18/// body.description = Some("Channels and roles for a study group".into());
19/// assert_eq!(
20///     serde_json::to_string(&body)?,
21///     r#"{"name":"Study group","description":"Channels and roles for a study group"}"#
22/// );
23/// # Ok::<(), serde_json::Error>(())
24/// ```
25#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
26#[non_exhaustive]
27pub struct CreateGuildTemplate {
28    /// The name (1-100 characters).
29    pub name: CompactString,
30    /// The description (0-120 characters).
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub description: Option<CompactString>,
33}
34
35impl CreateGuildTemplate {
36    /// A template named `name`, without a description.
37    ///
38    /// discord.js counterpart: `Guild#createTemplate`.
39    #[must_use]
40    pub fn new(name: impl Into<CompactString>) -> Self {
41        Self {
42            name: name.into(),
43            description: None,
44        }
45    }
46}
47
48/// The body of [Modify Guild Template](https://docs.discord.com/developers/resources/guild-template#modify-guild-template).
49///
50/// Every field is optional. The template's guild snapshot is updated with
51/// `sync_guild_template` instead.
52///
53/// discord.js counterpart: the argument of `GuildTemplate#edit`.
54#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize)]
55#[non_exhaustive]
56pub struct ModifyGuildTemplate {
57    /// The new name (1-100 characters).
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub name: Option<CompactString>,
60    /// The new description (0-120 characters); [`Patch::Clear`] removes it.
61    #[serde(skip_serializing_if = "Patch::is_keep")]
62    pub description: Patch<CompactString>,
63}