titanium_model/
soundboard.rs

1//! Soundboard types for Discord's soundboard feature.
2//!
3//! Soundboard sounds can be played in voice channels.
4
5use crate::Snowflake;
6use serde::{Deserialize, Serialize};
7
8/// A soundboard sound.
9#[derive(Debug, Clone, Deserialize, Serialize)]
10pub struct SoundboardSound<'a> {
11    /// The name of this sound.
12    pub name: String,
13
14    /// The ID of this sound.
15    pub sound_id: Snowflake,
16
17    /// The volume of this sound (0 to 1).
18    pub volume: f64,
19
20    /// The ID of this sound's custom emoji.
21    #[serde(default)]
22    pub emoji_id: Option<Snowflake>,
23
24    /// The unicode character of this sound's standard emoji.
25    #[serde(default)]
26    pub emoji_name: Option<String>,
27
28    /// The ID of the guild this sound is in.
29    #[serde(default)]
30    pub guild_id: Option<Snowflake>,
31
32    /// Whether this sound can be used.
33    #[serde(default)]
34    pub available: bool,
35
36    /// The user who created this sound.
37    #[serde(default)]
38    pub user: Option<super::User<'a>>,
39}
40
41/// Event data for SOUNDBOARD_SOUND_DELETE.
42#[derive(Debug, Clone, Deserialize, Serialize)]
43pub struct SoundboardSoundDeleteEvent {
44    /// The ID of the sound.
45    pub sound_id: Snowflake,
46
47    /// The ID of the guild.
48    pub guild_id: Snowflake,
49}
50
51/// Event data for SOUNDBOARD_SOUNDS_UPDATE.
52#[derive(Debug, Clone, Deserialize, Serialize)]
53pub struct SoundboardSoundsUpdateEvent<'a> {
54    /// The soundboard sounds.
55    pub soundboard_sounds: Vec<SoundboardSound<'a>>,
56
57    /// The ID of the guild (not in payload but added by gateway).
58    #[serde(default)]
59    pub guild_id: Option<Snowflake>,
60}
61
62/// Event data for GUILD_SOUNDBOARD_SOUNDS_UPDATE.
63#[derive(Debug, Clone, Deserialize, Serialize)]
64pub struct GuildSoundboardSoundsUpdateEvent<'a> {
65    /// The soundboard sounds.
66    pub soundboard_sounds: Vec<SoundboardSound<'a>>,
67
68    /// The ID of the guild.
69    pub guild_id: Snowflake,
70}
71
72#[cfg(test)]
73mod tests {
74    use super::*;
75
76    #[test]
77    fn test_soundboard_sound() {
78        let json = r#"{
79            "name": "airhorn",
80            "sound_id": "123456789",
81            "volume": 0.5,
82            "available": true
83        }"#;
84
85        let sound: SoundboardSound = crate::json::from_str(json).unwrap();
86        assert_eq!(sound.name, "airhorn");
87        assert_eq!(sound.volume, 0.5);
88    }
89}