From 0b12724003f25ce62347f65f379290757b69511e Mon Sep 17 00:00:00 2001 From: kozabrada123 <“kozabrada123@users.noreply.github.com”> Date: Sat, 27 May 2023 17:05:25 +0200 Subject: [PATCH] Add Stage Instance & events --- src/gateway.rs | 23 ++++++++++++++++++--- src/types/entities/mod.rs | 4 +++- src/types/entities/stage_instance.rs | 29 +++++++++++++++++++++++++++ src/types/events/mod.rs | 2 ++ src/types/events/stage_instance.rs | 30 ++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/types/entities/stage_instance.rs create mode 100644 src/types/events/stage_instance.rs diff --git a/src/gateway.rs b/src/gateway.rs index 87a9c32..2f3136d 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -462,9 +462,18 @@ impl Gateway { let new_data: types::RelationshipRemove = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); self.events.lock().await.relationship.remove.update_data(new_data).await; } - "STAGE_INSTANCE_CREATE" => {} - "STAGE_INSTANCE_UPDATE" => {} - "STAGE_INSTANCE_DELETE" => {} + "STAGE_INSTANCE_CREATE" => { + let new_data: types::StageInstanceCreate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); + self.events.lock().await.stage_instance.create.update_data(new_data).await; + } + "STAGE_INSTANCE_UPDATE" => { + let new_data: types::StageInstanceUpdate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); + self.events.lock().await.stage_instance.update.update_data(new_data).await; + } + "STAGE_INSTANCE_DELETE" => { + let new_data: types::StageInstanceDelete = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); + self.events.lock().await.stage_instance.delete.update_data(new_data).await; + } "SESSIONS_REPLACE" => { let sessions: Vec = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); let new_data = types::SessionsReplace {sessions}; @@ -714,6 +723,7 @@ mod events { pub guild: Guild, pub invite: Invite, pub integration: Integration, + pub stage_instance: StageInstance, pub call: Call, pub voice: Voice, pub webhooks: Webhooks, @@ -736,6 +746,13 @@ mod events { pub replace: GatewayEvent } + #[derive(Default, Debug)] + pub struct StageInstance { + pub create: GatewayEvent, + pub update: GatewayEvent, + pub delete: GatewayEvent, + } + #[derive(Default, Debug)] pub struct Message { pub create: GatewayEvent, diff --git a/src/types/entities/mod.rs b/src/types/entities/mod.rs index 5ade576..5c8306b 100644 --- a/src/types/entities/mod.rs +++ b/src/types/entities/mod.rs @@ -19,6 +19,7 @@ mod webhook; mod audit_log; mod relationship; mod auto_moderation; +mod stage_instance; pub use application::*; pub use attachment::*; @@ -40,4 +41,5 @@ pub use voice_state::*; pub use webhook::*; pub use audit_log::*; pub use relationship::*; -pub use auto_moderation::*; \ No newline at end of file +pub use auto_moderation::*; +pub use stage_instance::*; \ No newline at end of file diff --git a/src/types/entities/stage_instance.rs b/src/types/entities/stage_instance.rs new file mode 100644 index 0000000..66376ef --- /dev/null +++ b/src/types/entities/stage_instance.rs @@ -0,0 +1,29 @@ +use serde::{Deserialize, Serialize}; +use serde_repr::{Serialize_repr, Deserialize_repr}; + +use crate::types::Snowflake; + +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +/// See https://discord.com/developers/docs/resources/stage-instance +pub struct StageInstance { + pub id: Snowflake, + pub guild_id: Snowflake, + pub channel_id: Snowflake, + /// 1 - 120 chars + pub topic: String, + pub privacy_level: StageInstancePrivacyLevel, + /// deprecated, apparently + pub discoverable_disabled: Option, + pub guild_scheduled_event_id: Option, +} + +#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)] +#[repr(u8)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +/// See https://discord.com/developers/docs/resources/stage-instance#stage-instance-object-privacy-level +pub enum StageInstancePrivacyLevel { + /// deprecated, apparently + Public = 1, + #[default] + GuildOnly = 2 +} \ No newline at end of file diff --git a/src/types/events/mod.rs b/src/types/events/mod.rs index 8afb5b8..41396f3 100644 --- a/src/types/events/mod.rs +++ b/src/types/events/mod.rs @@ -22,6 +22,7 @@ mod call; mod lazy_request; mod relationship; mod auto_moderation; +mod stage_instance; pub use channel::*; pub use guild::*; @@ -45,6 +46,7 @@ pub use call::*; pub use lazy_request::*; pub use relationship::*; pub use auto_moderation::*; +pub use stage_instance::*; pub trait WebSocketEvent {} diff --git a/src/types/events/stage_instance.rs b/src/types/events/stage_instance.rs new file mode 100644 index 0000000..b308576 --- /dev/null +++ b/src/types/events/stage_instance.rs @@ -0,0 +1,30 @@ +use serde::{Deserialize, Serialize}; + +use crate::types::{WebSocketEvent, StageInstance}; + +#[derive(Debug, Deserialize, Serialize, Default)] +/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-create +pub struct StageInstanceCreate { + #[serde(flatten)] + pub stage_instance: StageInstance, +} + +impl WebSocketEvent for StageInstanceCreate {} + +#[derive(Debug, Deserialize, Serialize, Default)] +/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-update +pub struct StageInstanceUpdate { + #[serde(flatten)] + pub stage_instance: StageInstance, +} + +impl WebSocketEvent for StageInstanceUpdate {} + +#[derive(Debug, Deserialize, Serialize, Default)] +/// See https://discord.com/developers/docs/topics/gateway-events#stage-instance-delete +pub struct StageInstanceDelete { + #[serde(flatten)] + pub stage_instance: StageInstance, +} + +impl WebSocketEvent for StageInstanceDelete {} \ No newline at end of file