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
97
98
99
100
101
102
103
104
105
106
#[cfg(feature = "http")]
use super::Builder;
use super::CreateAttachment;
#[cfg(feature = "http")]
use crate::http::CacheHttp;
#[cfg(feature = "http")]
use crate::internal::prelude::*;
#[cfg(feature = "http")]
use crate::model::prelude::*;
/// A builder to create a guild sticker
///
/// [Discord docs](https://discord.com/developers/docs/resources/sticker#create-guild-sticker)
#[derive(Clone, Debug)]
#[must_use]
pub struct CreateSticker<'a> {
name: String,
description: String,
tags: String,
file: CreateAttachment,
audit_log_reason: Option<&'a str>,
}
impl<'a> CreateSticker<'a> {
/// Creates a new builder with the given data. All of this builder's fields are required.
pub fn new(name: impl Into<String>, file: CreateAttachment) -> Self {
Self {
name: name.into(),
tags: String::new(),
description: String::new(),
file,
audit_log_reason: None,
}
}
/// Set the name of the sticker, replacing the current value as set in [`Self::new`].
///
/// **Note**: Must be between 2 and 30 characters long.
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = name.into();
self
}
/// Set the description of the sticker.
///
/// **Note**: Must be empty or 2-100 characters.
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = description.into();
self
}
/// The Discord name of a unicode emoji representing the sticker's expression.
///
/// **Note**: Max 200 characters long.
pub fn tags(mut self, tags: impl Into<String>) -> Self {
self.tags = tags.into();
self
}
/// Set the sticker file. Replaces the current value as set in [`Self::new`].
///
/// **Note**: Must be a PNG, APNG, or Lottie JSON file, max 500 KB.
pub fn file(mut self, file: CreateAttachment) -> Self {
self.file = file;
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 CreateSticker<'_> {
type Context<'ctx> = GuildId;
type Built = Sticker;
/// Creates a new sticker in the guild with the data set, if any.
///
/// **Note**: Requires the [Create Guild Expressions] permission.
///
/// # Errors
///
/// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
/// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
///
/// [Create Guild Expressions]: Permissions::CREATE_GUILD_EXPRESSIONS
async fn execute(
self,
cache_http: impl CacheHttp,
ctx: Self::Context<'_>,
) -> Result<Self::Built> {
#[cfg(feature = "cache")]
crate::utils::user_has_guild_perms(
&cache_http,
ctx,
Permissions::CREATE_GUILD_EXPRESSIONS,
)?;
let map = [("name", self.name), ("tags", self.tags), ("description", self.description)];
cache_http.http().create_sticker(ctx, map, self.file, self.audit_log_reason).await
}
}