djs_model/rest/stage_instance.rs
1//! Bodies of the [stage instance endpoints](https://docs.discord.com/developers/resources/stage-instance).
2
3use compact_str::CompactString;
4use serde::Serialize;
5
6use crate::{
7 id::{ChannelId, ScheduledEventId},
8 stage_instance::PrivacyLevel,
9};
10
11/// The body of [Create Stage Instance](https://docs.discord.com/developers/resources/stage-instance#create-stage-instance).
12///
13/// discord.js counterpart: `StageInstanceCreateOptions`.
14///
15/// # Examples
16///
17/// ```
18/// use djs_model::{id::ChannelId, rest::CreateStageInstance};
19///
20/// let mut body = CreateStageInstance::new(ChannelId::new(1_200_000_000_000_000_005), "Q&A");
21/// body.send_start_notification = Some(true);
22/// assert_eq!(
23/// serde_json::to_string(&body)?,
24/// r#"{"channel_id":"1200000000000000005","topic":"Q&A","send_start_notification":true}"#
25/// );
26/// # Ok::<(), serde_json::Error>(())
27/// ```
28#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize)]
29#[non_exhaustive]
30pub struct CreateStageInstance {
31 /// The stage channel.
32 pub channel_id: ChannelId,
33 /// The topic (1-120 characters).
34 pub topic: CompactString,
35 /// Who can see the stage (Discord's default: [`PrivacyLevel::GuildOnly`]; `Public` is
36 /// deprecated).
37 #[serde(skip_serializing_if = "Option::is_none")]
38 pub privacy_level: Option<PrivacyLevel>,
39 /// Whether to notify `@everyone` that the stage started (the bot needs
40 /// `MENTION_EVERYONE`).
41 #[serde(skip_serializing_if = "Option::is_none")]
42 pub send_start_notification: Option<bool>,
43 /// The scheduled event the stage belongs to.
44 #[serde(skip_serializing_if = "Option::is_none")]
45 pub guild_scheduled_event_id: Option<ScheduledEventId>,
46}
47
48impl CreateStageInstance {
49 /// Opens the stage channel `channel_id` with `topic`.
50 ///
51 /// discord.js counterpart: `StageInstanceCreateOptions`.
52 #[must_use]
53 pub fn new(channel_id: ChannelId, topic: impl Into<CompactString>) -> Self {
54 Self {
55 channel_id,
56 topic: topic.into(),
57 privacy_level: None,
58 send_start_notification: None,
59 guild_scheduled_event_id: None,
60 }
61 }
62}
63
64/// The body of [Modify Stage Instance](https://docs.discord.com/developers/resources/stage-instance#modify-stage-instance).
65///
66/// Every field is optional.
67///
68/// discord.js counterpart: `StageInstanceEditOptions`.
69#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize)]
70#[non_exhaustive]
71pub struct ModifyStageInstance {
72 /// The new topic (1-120 characters).
73 #[serde(skip_serializing_if = "Option::is_none")]
74 pub topic: Option<CompactString>,
75 /// Who can see the stage.
76 #[serde(skip_serializing_if = "Option::is_none")]
77 pub privacy_level: Option<PrivacyLevel>,
78}