Skip to main content

serenity/builder/
edit_soundboard.rs

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