titanium_model/
voice.rs

1//! Voice-related types for Discord.
2//!
3//! This module contains voice state, voice server, stage instance,
4//! and voice channel effect types.
5
6use crate::member::GuildMember;
7use crate::reaction::ReactionEmoji;
8use crate::Snowflake;
9use crate::TitanString;
10use serde::{Deserialize, Serialize};
11use serde_repr::{Deserialize_repr, Serialize_repr};
12
13// ============================================================================
14// Voice State (merged from voice_state.rs)
15// ============================================================================
16
17/// Partial voice state from `GUILD_CREATE`.
18#[derive(Debug, Clone, Deserialize, Serialize)]
19pub struct PartialVoiceState<'a> {
20    pub channel_id: Option<Snowflake>,
21    pub user_id: Snowflake,
22
23    pub session_id: TitanString<'a>,
24    pub deaf: bool,
25    pub mute: bool,
26    pub self_deaf: bool,
27    pub self_mute: bool,
28    #[serde(default)]
29    pub self_video: bool,
30    pub suppress: bool,
31    #[serde(default)]
32    pub request_to_speak_timestamp: Option<TitanString<'a>>,
33}
34
35// ============================================================================
36// Voice Events
37// ============================================================================
38
39/// Voice state update event.
40#[derive(Debug, Clone, Deserialize, Serialize)]
41pub struct VoiceStateUpdateEvent<'a> {
42    #[serde(default)]
43    pub guild_id: Option<Snowflake>,
44    pub channel_id: Option<Snowflake>,
45    pub user_id: Snowflake,
46    #[serde(default)]
47    pub member: Option<GuildMember<'a>>,
48    pub session_id: String,
49    pub deaf: bool,
50    pub mute: bool,
51    pub self_deaf: bool,
52    pub self_mute: bool,
53    #[serde(default)]
54    pub self_stream: bool,
55    pub self_video: bool,
56    pub suppress: bool,
57    #[serde(default)]
58    pub request_to_speak_timestamp: Option<String>,
59}
60
61/// Voice server update event.
62#[derive(Debug, Clone, Deserialize, Serialize)]
63pub struct VoiceServerUpdateEvent {
64    pub token: String,
65    pub guild_id: Snowflake,
66    #[serde(default)]
67    pub endpoint: Option<String>,
68}
69
70/// Voice channel effect send event.
71#[derive(Debug, Clone, Deserialize, Serialize)]
72pub struct VoiceChannelEffectSendEvent<'a> {
73    pub channel_id: Snowflake,
74    pub guild_id: Snowflake,
75    pub user_id: Snowflake,
76    #[serde(default)]
77    pub emoji: Option<ReactionEmoji<'a>>,
78    #[serde(default)]
79    pub animation_type: Option<u8>,
80    #[serde(default)]
81    pub animation_id: Option<u64>,
82    #[serde(default)]
83    pub sound_id: Option<Snowflake>,
84    #[serde(default)]
85    pub sound_volume: Option<f64>,
86}
87
88// ============================================================================
89// Stage Instance (merged from stage.rs)
90// ============================================================================
91
92/// A stage instance holds information about a live stage.
93#[derive(Debug, Clone, Deserialize, Serialize)]
94pub struct StageInstance {
95    /// The ID of this stage instance.
96    pub id: Snowflake,
97
98    /// The guild ID of the associated stage channel.
99    pub guild_id: Snowflake,
100
101    /// The ID of the associated stage channel.
102    pub channel_id: Snowflake,
103
104    /// The topic of the stage instance (1-120 characters).
105    pub topic: String,
106
107    /// The privacy level of the stage instance.
108    pub privacy_level: StagePrivacyLevel,
109
110    /// Whether or not stage discovery is disabled (deprecated).
111    #[serde(default)]
112    pub discoverable_disabled: bool,
113
114    /// The ID of the scheduled event for this stage instance.
115    #[serde(default)]
116    pub guild_scheduled_event_id: Option<Snowflake>,
117}
118
119/// Privacy level of a stage instance.
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize_repr, Deserialize_repr, Default)]
121#[repr(u8)]
122pub enum StagePrivacyLevel {
123    /// The stage instance is visible publicly (deprecated).
124    Public = 1,
125    /// The stage instance is visible to only guild members.
126    #[default]
127    GuildOnly = 2,
128}
129
130#[cfg(test)]
131mod tests {
132    use super::*;
133
134    #[test]
135    fn test_stage_instance() {
136        let json = r#"{
137            "id": "123",
138            "guild_id": "456",
139            "channel_id": "789",
140            "topic": "Welcome to the stage!",
141            "privacy_level": 2
142        }"#;
143
144        let stage: StageInstance = crate::json::from_str(json).unwrap();
145        assert_eq!(stage.topic, "Welcome to the stage!");
146        assert_eq!(stage.privacy_level, StagePrivacyLevel::GuildOnly);
147    }
148}