twilight_model/guild/audit_log/
mod.rs

1//! Audit Logs, created whenever an administrative action is performed within a
2//! guild.
3//!
4//! For additional information refer to [Discord Docs/Audit Logs].
5//!
6//! [Discord Docs/Audit Logs]: https://discord.com/developers/docs/resources/audit-log
7
8mod change;
9mod change_key;
10mod entry;
11mod event_type;
12mod integration;
13mod optional_entry_info;
14
15pub use self::{
16    change::{AffectedRole, AuditLogChange, AuditLogChangeTypeValue},
17    change_key::AuditLogChangeKey,
18    entry::AuditLogEntry,
19    event_type::AuditLogEventType,
20    integration::AuditLogGuildIntegration,
21    optional_entry_info::AuditLogOptionalEntryInfo,
22};
23
24use super::auto_moderation::AutoModerationRule;
25use crate::{
26    application::command::Command,
27    channel::{Channel, Webhook},
28    guild::scheduled_event::GuildScheduledEvent,
29    user::User,
30};
31use serde::{Deserialize, Serialize};
32
33/// Paginated audit log entries with additional information.
34///
35/// For additional information refer to [Discord Docs/Audit Logs][1].
36///
37/// [1]: https://discord.com/developers/docs/resources/audit-log#audit-log-object
38#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
39pub struct AuditLog {
40    /// List of referenced application commands.
41    pub application_commands: Vec<Command>,
42    /// List of referenced auto moderation rules.
43    pub auto_moderation_rules: Vec<AutoModerationRule>,
44    /// Paginated entries in a guild's audit log.
45    #[serde(rename = "audit_log_entries")]
46    pub entries: Vec<AuditLogEntry>,
47    /// Information about mentioned scheduled events.
48    pub guild_scheduled_events: Vec<GuildScheduledEvent>,
49    /// Information about mentioned integrations.
50    pub integrations: Vec<AuditLogGuildIntegration>,
51    /// Information about mentioned threads.
52    pub threads: Vec<Channel>,
53    /// Information about mentioned users.
54    ///
55    /// For example, [users that performed the action][`AuditLogEntry::user_id`]
56    /// to create an entry are in this list.
57    pub users: Vec<User>,
58    /// Information about mentioned webhooks.
59    pub webhooks: Vec<Webhook>,
60}
61
62#[cfg(test)]
63mod tests {
64    use super::AuditLog;
65    use serde::{Deserialize, Serialize};
66    use serde_test::Token;
67    use static_assertions::{assert_fields, assert_impl_all};
68    use std::fmt::Debug;
69
70    assert_fields!(
71        AuditLog: entries,
72        guild_scheduled_events,
73        integrations,
74        users,
75        webhooks
76    );
77    assert_impl_all!(
78        AuditLog: Clone,
79        Debug,
80        Deserialize<'static>,
81        PartialEq,
82        Send,
83        Serialize,
84        Sync
85    );
86
87    /// Test the (de)serialization of an audit log.
88    ///
89    /// We don't need to test with values since they're individually tested, so
90    /// we just need to test that fields are present in deserialization and
91    /// serialization as expected.
92    #[test]
93    fn serde() {
94        let value = AuditLog {
95            application_commands: Vec::new(),
96            auto_moderation_rules: Vec::new(),
97            entries: Vec::new(),
98            guild_scheduled_events: Vec::new(),
99            integrations: Vec::new(),
100            threads: Vec::new(),
101            users: Vec::new(),
102            webhooks: Vec::new(),
103        };
104
105        serde_test::assert_tokens(
106            &value,
107            &[
108                Token::Struct {
109                    name: "AuditLog",
110                    len: 8,
111                },
112                Token::Str("application_commands"),
113                Token::Seq { len: Some(0) },
114                Token::SeqEnd,
115                Token::Str("auto_moderation_rules"),
116                Token::Seq { len: Some(0) },
117                Token::SeqEnd,
118                Token::Str("audit_log_entries"),
119                Token::Seq { len: Some(0) },
120                Token::SeqEnd,
121                Token::Str("guild_scheduled_events"),
122                Token::Seq { len: Some(0) },
123                Token::SeqEnd,
124                Token::Str("integrations"),
125                Token::Seq { len: Some(0) },
126                Token::SeqEnd,
127                Token::Str("threads"),
128                Token::Seq { len: Some(0) },
129                Token::SeqEnd,
130                Token::Str("users"),
131                Token::Seq { len: Some(0) },
132                Token::SeqEnd,
133                Token::Str("webhooks"),
134                Token::Seq { len: Some(0) },
135                Token::SeqEnd,
136                Token::StructEnd,
137            ],
138        )
139    }
140}