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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#[cfg(feature = "http")]
use super::Builder;
#[cfg(feature = "http")]
use crate::http::CacheHttp;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
#[cfg(any(feature = "http", doc))]
use crate::model::prelude::*;
/// A builder to create or edit a [`Sticker`] for use via a number of model methods.
///
/// These are:
///
/// - [`Guild::edit_sticker`]
/// - [`PartialGuild::edit_sticker`]
/// - [`GuildId::edit_sticker`]
/// - [`Sticker::edit`]
///
/// [Discord docs](https://discord.com/developers/docs/resources/sticker#modify-guild-sticker)
#[derive(Clone, Debug, Default, Serialize)]
#[must_use]
pub struct EditSticker<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
tags: Option<String>,
#[serde(skip)]
audit_log_reason: Option<&'a str>,
}
impl<'a> EditSticker<'a> {
/// Equivalent to [`Self::default`].
pub fn new() -> Self {
Self::default()
}
/// The name of the sticker to set.
///
/// **Note**: Must be between 2 and 30 characters long.
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
/// The description of the sticker.
///
/// **Note**: If not empty, must be between 2 and 100 characters long.
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
/// The Discord name of a unicode emoji representing the sticker's expression.
///
/// **Note**: Must be between 2 and 200 characters long.
pub fn tags(mut self, tags: impl Into<String>) -> Self {
self.tags = Some(tags.into());
self
}
/// Sets the request's audit log reason.
pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
self.audit_log_reason = Some(reason);
self
}
}
#[cfg(feature = "http")]
#[async_trait::async_trait]
impl Builder for EditSticker<'_> {
type Context<'ctx> = (GuildId, StickerId);
type Built = Sticker;
/// Edits the sticker.
///
/// **Note**: If the sticker was created by the current user, requires either the [Create Guild
/// Expressions] or the [Manage Guild Expressions] permission. Otherwise, the [Manage Guild
/// Expressions] permission is required.
///
/// # Errors
///
/// Returns [`Error::Http`] if the current user lacks permission, or if invalid data is given.
///
/// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
/// [Manage Guild Expressions]: Permissions::MANAGE_GUILD_EXPRESSIONS
async fn execute(
self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
cache_http.http().edit_sticker(ctx.0, ctx.1, &self, self.audit_log_reason).await
}
}