Add Stage Instance & events

This commit is contained in:
kozabrada123 2023-05-27 17:05:25 +02:00
parent 8d0083e11d
commit 5b04370d46
5 changed files with 84 additions and 4 deletions

View File

@ -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<types::Session> = 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<types::SessionsReplace>
}
#[derive(Default, Debug)]
pub struct StageInstance {
pub create: GatewayEvent<types::StageInstanceCreate>,
pub update: GatewayEvent<types::StageInstanceUpdate>,
pub delete: GatewayEvent<types::StageInstanceDelete>,
}
#[derive(Default, Debug)]
pub struct Message {
pub create: GatewayEvent<types::MessageCreate>,

View File

@ -19,6 +19,7 @@ mod webhook;
mod audit_log;
mod relationship;
mod auto_moderation;
mod stage_instance;
pub use application::*;
pub use attachment::*;
@ -41,3 +42,4 @@ pub use webhook::*;
pub use audit_log::*;
pub use relationship::*;
pub use auto_moderation::*;
pub use stage_instance::*;

View File

@ -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<bool>,
pub guild_scheduled_event_id: Option<Snowflake>,
}
#[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
}

View File

@ -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 {}

View File

@ -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 {}