titanium_model/
stage.rs

1//! Stage instance types for Discord voice stages.
2//!
3//! Stage channels are special voice channels for hosting events.
4
5use crate::Snowflake;
6use serde::{Deserialize, Serialize};
7use serde_repr::{Deserialize_repr, Serialize_repr};
8
9/// A stage instance holds information about a live stage.
10#[derive(Debug, Clone, Deserialize, Serialize)]
11pub struct StageInstance {
12    /// The ID of this stage instance.
13    pub id: Snowflake,
14
15    /// The guild ID of the associated stage channel.
16    pub guild_id: Snowflake,
17
18    /// The ID of the associated stage channel.
19    pub channel_id: Snowflake,
20
21    /// The topic of the stage instance (1-120 characters).
22    pub topic: String,
23
24    /// The privacy level of the stage instance.
25    pub privacy_level: StagePrivacyLevel,
26
27    /// Whether or not stage discovery is disabled (deprecated).
28    #[serde(default)]
29    pub discoverable_disabled: bool,
30
31    /// The ID of the scheduled event for this stage instance.
32    #[serde(default)]
33    pub guild_scheduled_event_id: Option<Snowflake>,
34}
35
36/// Privacy level of a stage instance.
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize_repr, Deserialize_repr, Default)]
38#[repr(u8)]
39pub enum StagePrivacyLevel {
40    /// The stage instance is visible publicly (deprecated).
41    Public = 1,
42    /// The stage instance is visible to only guild members.
43    #[default]
44    GuildOnly = 2,
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_stage_instance() {
53        let json = r#"{
54            "id": "123",
55            "guild_id": "456",
56            "channel_id": "789",
57            "topic": "Welcome to the stage!",
58            "privacy_level": 2
59        }"#;
60
61        let stage: StageInstance = crate::json::from_str(json).unwrap();
62        assert_eq!(stage.topic, "Welcome to the stage!");
63        assert_eq!(stage.privacy_level, StagePrivacyLevel::GuildOnly);
64    }
65}