From 9ee0b517573d7ede88d2bcba52cfeda41160f61b Mon Sep 17 00:00:00 2001 From: kozabrada123 <“kozabrada123@users.noreply.github.com”> Date: Sat, 20 May 2023 13:03:44 +0200 Subject: [PATCH] Add Guild Audit Log Entry Create --- src/api/types.rs | 31 +++++++++++++++++++++++++++++++ src/gateway.rs | 7 +++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/api/types.rs b/src/api/types.rs index e70732b..00ac020 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -302,6 +302,28 @@ pub struct WelcomeScreenChannel { pub emoji_name: Option, } +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +/// See https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object +pub struct AuditLogEntry { + pub target_id: Option, + pub changes: Option>, + pub user_id: Option, + pub id: String, + // to:do implement an enum for these types + pub action_type: u8, + // to:do add better options type + pub options: Option, + pub reason: Option +} + +#[derive(Serialize, Deserialize, Debug, Default, Clone)] +/// See https://discord.com/developers/docs/resources/audit-log#audit-log-change-object +pub struct AuditLogChange { + pub new_value: Option, + pub old_value: Option, + pub key: String +} + #[derive(Serialize, Deserialize, Debug, Default, Clone)] /// See https://discord.com/developers/docs/topics/permissions#role-object pub struct RoleObject { @@ -1464,6 +1486,15 @@ pub struct GuildDelete { impl WebSocketEvent for GuildDelete {} +#[derive(Debug, Default, Deserialize, Serialize)] +/// See https://discord.com/developers/docs/topics/gateway-events#guild-audit-log-entry-create +pub struct GuildAuditLogEntryCreate { + #[serde(flatten)] + pub entry: AuditLogEntry +} + +impl WebSocketEvent for GuildAuditLogEntryCreate {} + #[derive(Debug, Default, Deserialize, Serialize)] /// See https://discord.com/developers/docs/topics/gateway-events#guild-emojis-update pub struct GuildEmojisUpdate { diff --git a/src/gateway.rs b/src/gateway.rs index 492c304..3805a06 100644 --- a/src/gateway.rs +++ b/src/gateway.rs @@ -286,7 +286,10 @@ impl Gateway { let new_data: GuildDelete = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); self.events.lock().await.guild.delete.update_data(new_data).await; } - "GUILD_AUDIT_LOG_ENTRY_CREATE" => {} + "GUILD_AUDIT_LOG_ENTRY_CREATE" => { + let new_data: GuildAuditLogEntryCreate = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); + self.events.lock().await.guild.audit_log_entry_create.update_data(new_data).await; + } "GUILD_BAN_ADD" => { let new_data: GuildBanAdd = serde_json::from_str(gateway_payload.d.unwrap().get()).unwrap(); self.events.lock().await.guild.ban_add.update_data(new_data).await; @@ -681,7 +684,7 @@ mod events { pub create: GatewayEvent, pub update: GatewayEvent, pub delete: GatewayEvent, - //pub audit_log_entry_create: GatewayEvent, + pub audit_log_entry_create: GatewayEvent, pub ban_add: GatewayEvent, pub ban_remove: GatewayEvent, pub emojis_update: GatewayEvent,