serenity/builder/
edit_sticker.rs

1#[cfg(feature = "http")]
2use super::Builder;
3#[cfg(feature = "http")]
4use crate::http::CacheHttp;
5#[cfg(feature = "http")]
6use crate::internal::prelude::*;
7#[cfg(any(feature = "http", doc))]
8use crate::model::prelude::*;
9
10/// A builder to create or edit a [`Sticker`] for use via a number of model methods.
11///
12/// These are:
13///
14/// - [`Guild::edit_sticker`]
15/// - [`PartialGuild::edit_sticker`]
16/// - [`GuildId::edit_sticker`]
17/// - [`Sticker::edit`]
18///
19/// [Discord docs](https://discord.com/developers/docs/resources/sticker#modify-guild-sticker)
20#[derive(Clone, Debug, Default, Serialize)]
21#[must_use]
22pub struct EditSticker<'a> {
23    #[serde(skip_serializing_if = "Option::is_none")]
24    name: Option<String>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    description: Option<String>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    tags: Option<String>,
29
30    #[serde(skip)]
31    audit_log_reason: Option<&'a str>,
32}
33
34impl<'a> EditSticker<'a> {
35    /// Equivalent to [`Self::default`].
36    pub fn new() -> Self {
37        Self::default()
38    }
39
40    /// The name of the sticker to set.
41    ///
42    /// **Note**: Must be between 2 and 30 characters long.
43    pub fn name(mut self, name: impl Into<String>) -> Self {
44        self.name = Some(name.into());
45        self
46    }
47
48    /// The description of the sticker.
49    ///
50    /// **Note**: If not empty, must be between 2 and 100 characters long.
51    pub fn description(mut self, description: impl Into<String>) -> Self {
52        self.description = Some(description.into());
53        self
54    }
55
56    /// The Discord name of a unicode emoji representing the sticker's expression.
57    ///
58    /// **Note**: Must be between 2 and 200 characters long.
59    pub fn tags(mut self, tags: impl Into<String>) -> Self {
60        self.tags = Some(tags.into());
61        self
62    }
63
64    /// Sets the request's audit log reason.
65    pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
66        self.audit_log_reason = Some(reason);
67        self
68    }
69}
70
71#[cfg(feature = "http")]
72#[async_trait::async_trait]
73impl Builder for EditSticker<'_> {
74    type Context<'ctx> = (GuildId, StickerId);
75    type Built = Sticker;
76
77    /// Edits the sticker.
78    ///
79    /// **Note**: If the sticker was created by the current user, requires either the [Create Guild
80    /// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
81    /// Expressions] permission is required.
82    ///
83    /// # Errors
84    ///
85    /// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
86    ///
87    /// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
88    /// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS
89    async fn execute(
90        self,
91        cache_http: impl CacheHttp,
92        ctx: Self::Context<'_>,
93    ) -> Result<Self::Built> {
94        cache_http.http().edit_sticker(ctx.0, ctx.1, &self, self.audit_log_reason).await
95    }
96}