From 6ceaee4f14e9ce6f8ac353b2828c7593f34d93dd Mon Sep 17 00:00:00 2001 From: kozabrada123 <“kozabrada123@users.noreply.github.com”> Date: Sat, 20 May 2023 12:50:05 +0200 Subject: [PATCH] Add Invite Create & Delete --- src/api/types.rs | 19 +++++++++++++++++++ src/gateway.rs | 17 +++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/api/types.rs b/src/api/types.rs index a477985..e70732b 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -1611,6 +1611,25 @@ pub struct IntegrationDelete { impl WebSocketEvent for IntegrationDelete {} +#[derive(Debug, Default, Deserialize, Serialize)] +/// See https://discord.com/developers/docs/topics/gateway-events#invite-create +pub struct InviteCreate { + #[serde(flatten)] + pub invite: GuildInvite +} + +impl WebSocketEvent for InviteCreate {} + +#[derive(Debug, Default, Deserialize, Serialize)] +/// See https://discord.com/developers/docs/topics/gateway-events#invite-delete +pub struct InviteDelete { + pub channel_id: String, + pub guild_id: Option, + pub code: String, +} + +impl WebSocketEvent for InviteDelete {} + #[derive(Debug, Deserialize, Serialize, Default)] /// Officially Undocumented /// Is sent to a client by the server to signify a new being created diff --git a/src/gateway.rs b/src/gateway.rs index fab1434..492c304 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -357,8 +357,14 @@ impl Gateway { self.events.lock().await.integration.delete.update_data(new_data).await; } "INTERACTION_CREATE" => {} - "INVITE_CREATE" => {} - "INVITE_DELETE" => {} + "INVITE_CREATE" => { + let new_data: InviteCreate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); + self.events.lock().await.invite.create.update_data(new_data).await; + } + "INVITE_DELETE" => { + let new_data: InviteDelete = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); + self.events.lock().await.invite.delete.update_data(new_data).await; + } "MESSAGE_CREATE" => { let new_data: MessageCreate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); self.events.lock().await.message.create.update_data(new_data).await; @@ -616,6 +622,7 @@ mod events { pub channel: Channel, pub thread: Thread, pub guild: Guild, + pub invite: Invite, pub integration: Integration, pub call: Call, pub webhooks: Webhooks, @@ -695,6 +702,12 @@ mod events { pub passive_update_v1: GatewayEvent, } + #[derive(Default, Debug)] + pub struct Invite { + pub create: GatewayEvent, + pub delete: GatewayEvent + } + #[derive(Default, Debug)] pub struct Integration { pub create: GatewayEvent,