titanium_http/
audit_log.rs

1use crate::error::HttpError;
2use crate::HttpClient;
3use serde::{Deserialize, Serialize};
4use titanium_model::{
5    AuditLogEntry, AutoModRule, Channel, Integration, ScheduledEvent, Snowflake, User, Webhook,
6};
7
8/// Response structure for Get Guild Audit Log.
9#[derive(Debug, Deserialize, Serialize)]
10pub struct AuditLog<'a> {
11    pub audit_log_entries: Vec<AuditLogEntry>,
12    pub auto_moderation_rules: Vec<AutoModRule>,
13    pub guild_scheduled_events: Vec<ScheduledEvent<'a>>,
14    pub integrations: Vec<Integration<'a>>,
15    pub threads: Vec<Channel<'a>>, // Threads are Channels in model usually
16    pub users: Vec<User<'a>>,
17    pub webhooks: Vec<Webhook<'a>>,
18}
19
20impl HttpClient {
21    /// Get guild audit log.
22    pub async fn get_guild_audit_log(
23        &self,
24        guild_id: Snowflake,
25        params: &GetAuditLogParams,
26    ) -> Result<AuditLog<'static>, HttpError> {
27        let route = format!("/guilds/{}/audit-logs", guild_id);
28        self.get_with_query(&route, params).await
29    }
30}
31
32#[derive(Debug, Default, Serialize)]
33pub struct GetAuditLogParams {
34    pub user_id: Option<Snowflake>,
35    pub action_type: Option<u8>,
36    pub before: Option<Snowflake>,
37    pub after: Option<Snowflake>,
38    pub limit: Option<u32>,
39}