serenity/builder/
create_soundboard.rs1#[cfg(feature = "http")]
2use super::Builder;
3use super::CreateAttachment;
4#[cfg(feature = "http")]
5use crate::http::CacheHttp;
6#[cfg(feature = "http")]
7use crate::internal::prelude::*;
8use crate::model::prelude::*;
9
10#[derive(Clone, Debug, Serialize)]
14#[must_use]
15pub struct CreateSoundboard<'a> {
16 name: String,
17 sound: String,
18 volume: f64,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 emoji_id: Option<EmojiId>,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 emoji_name: Option<String>,
23
24 #[serde(skip)]
25 audit_log_reason: Option<&'a str>,
26}
27
28impl<'a> CreateSoundboard<'a> {
29 pub fn new(name: impl Into<String>, sound: &CreateAttachment) -> Self {
31 Self {
32 name: name.into(),
33 sound: sound.to_base64(),
34 volume: 1.0,
35 emoji_id: None,
36 emoji_name: None,
37 audit_log_reason: None,
38 }
39 }
40
41 pub fn name(mut self, name: impl Into<String>) -> Self {
45 self.name = name.into();
46 self
47 }
48
49 pub fn sound(mut self, sound: &CreateAttachment) -> Self {
54 self.sound = sound.to_base64();
55 self
56 }
57
58 pub fn volume(mut self, volume: f64) -> Self {
62 self.volume = volume;
63 self
64 }
65
66 pub fn emoji_id(mut self, id: EmojiId) -> Self {
68 self.emoji_id = Some(id);
69 self
70 }
71
72 pub fn emoji_name(mut self, name: String) -> Self {
74 self.emoji_name = Some(name);
75 self
76 }
77
78 pub fn audit_log_reason(mut self, reason: &'a str) -> Self {
80 self.audit_log_reason = Some(reason);
81 self
82 }
83}
84
85#[cfg(feature = "http")]
86#[async_trait::async_trait]
87impl Builder for CreateSoundboard<'_> {
88 type Context<'ctx> = GuildId;
89 type Built = Soundboard;
90
91 async fn execute(
102 self,
103 cache_http: impl CacheHttp,
104 ctx: Self::Context<'_>,
105 ) -> Result<Self::Built> {
106 #[cfg(feature = "cache")]
107 crate::utils::user_has_guild_perms(
108 &cache_http,
109 ctx,
110 Permissions::CREATE_GUILD_EXPRESSIONS,
111 )?;
112
113 cache_http.http().create_guild_soundboard(ctx, &self, self.audit_log_reason).await
114 }
115}