twilight_model/guild/audit_log/
event_type.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
use serde::{Deserialize, Serialize};

/// Action to cause an [`AuditLogEntry`].
///
/// [`AuditLogEntry`]: super::AuditLogEntry
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(from = "u16", into = "u16")]
pub enum AuditLogEventType {
    /// [Guild] was updated.
    ///
    /// [Guild]: crate::guild::Guild
    GuildUpdate,
    /// [Channel] was created.
    ///
    /// [Channel]: crate::channel::Channel
    ChannelCreate,
    /// [Channel] was updated.
    ///
    /// [Channel]: crate::channel::Channel
    ChannelUpdate,
    /// [Channel] was deleted.
    ///
    /// [Channel]: crate::channel::Channel
    ChannelDelete,
    /// [Permission overwrite] for a [channel] was created.
    ///
    /// [channel]: crate::channel::Channel
    /// [Permission overwrite]: crate::channel::permission_overwrite::PermissionOverwrite
    ChannelOverwriteCreate,
    /// [Permission overwrite] for a [channel] was updated.
    ///
    /// [channel]: crate::channel::Channel
    /// [Permission overwrite]: crate::channel::permission_overwrite::PermissionOverwrite
    ChannelOverwriteUpdate,
    /// [Permission overwrite] for a [channel] was deleted.
    ///
    /// [channel]: crate::channel::Channel
    /// [Permission overwrite]: crate::channel::permission_overwrite::PermissionOverwrite
    ChannelOverwriteDelete,
    /// [Member] was kicked.
    ///
    /// [Member]: crate::guild::Member
    MemberKick,
    /// [Member] prune began.
    ///
    /// [Member]: crate::guild::Member
    MemberPrune,
    /// [Member] was banned.
    ///
    /// [Member]: crate::guild::Member
    MemberBanAdd,
    /// [Member]'s [ban] was removed.
    ///
    /// [ban]: crate::guild::Ban
    /// [Member]: crate::guild::Member
    MemberBanRemove,
    /// [Member] was updated.
    ///
    /// [Member]: crate::guild::Member
    MemberUpdate,
    /// [Member] either had a [role] attached or removed.
    ///
    /// [Member]: crate::guild::Member
    /// [role]: crate::guild::Role
    MemberRoleUpdate,
    /// [Member] was moved between voice [channel]s.
    ///
    /// [Member]: crate::guild::Member
    /// [channel]: crate::channel::Channel
    MemberMove,
    /// [Member] was disconnected from a voice [channel].
    ///
    /// [Member]: crate::guild::Member
    /// [channel]: crate::channel::Channel
    MemberDisconnect,
    /// [Bot user] was added to a [guild].
    ///
    /// [Bot user]: crate::user::User::bot
    /// [guild]: crate::guild::Guild
    BotAdd,
    /// [Role] was created.
    ///
    /// [Role]: crate::guild::Role
    RoleCreate,
    /// [Role] was updated.
    ///
    /// [Role]: crate::guild::Role
    RoleUpdate,
    /// [Role] was deleted.
    ///
    /// [Role]: crate::guild::Role
    RoleDelete,
    /// [Invite] was created.
    ///
    /// [Invite]: crate::guild::invite::Invite
    InviteCreate,
    /// [Invite] was updated.
    ///
    /// [Invite]: crate::guild::invite::Invite
    InviteUpdate,
    /// [Invite] was deleted.
    ///
    /// [Invite]: crate::guild::invite::Invite
    InviteDelete,
    /// [Webhook] was created.
    ///
    /// [Webhook]: crate::channel::webhook::Webhook
    WebhookCreate,
    /// [Webhook] was updated.
    ///
    /// [Webhook]: crate::channel::webhook::Webhook
    WebhookUpdate,
    /// [Webhook] was deleted.
    ///
    /// [Webhook]: crate::channel::webhook::Webhook
    WebhookDelete,
    /// [Emoji] was created.
    ///
    /// [Emoji]: crate::guild::Emoji
    EmojiCreate,
    /// [Emoji] was updated.
    ///
    /// [Emoji]: crate::guild::Emoji
    EmojiUpdate,
    /// [Emoji] was deleted.
    ///
    /// [Emoji]: crate::guild::Emoji
    EmojiDelete,
    /// [Message] was deleted.
    ///
    /// [Message]: crate::channel::message::Message
    MessageDelete,
    /// Multiple [messages] were deleted.
    ///
    /// [messages]: crate::channel::message::Message
    MessageBulkDelete,
    /// [Message] was pinned to a [channel].
    ///
    /// [Message]: crate::channel::message::Message
    /// [channel]: crate::channel::Channel
    MessagePin,
    /// [Message] was unpinned from a [channel].
    ///
    /// [Message]: crate::channel::message::Message
    /// [channel]: crate::channel::Channel
    MessageUnpin,
    /// [Integration] was created.
    ///
    /// [Integration]: crate::guild::GuildIntegration
    IntegrationCreate,
    /// [Integration] was updated.
    ///
    /// [Integration]: crate::guild::GuildIntegration
    IntegrationUpdate,
    /// [Integration] was deleted.
    ///
    /// [Integration]: crate::guild::GuildIntegration
    IntegrationDelete,
    /// [Stage instance] was created.
    ///
    /// [Stage instance]: crate::channel::stage_instance::StageInstance
    StageInstanceCreate,
    /// [Stage instance] was updated.
    ///
    /// [Stage instance]: crate::channel::stage_instance::StageInstance
    StageInstanceUpdate,
    /// [Stage instance] was deleted.
    ///
    /// [Stage instance]: crate::channel::stage_instance::StageInstance
    StageInstanceDelete,
    /// [Sticker] was created.
    ///
    /// [Sticker]: crate::channel::message::sticker::Sticker
    StickerCreate,
    /// [Sticker] was updated.
    ///
    /// [Sticker]: crate::channel::message::sticker::Sticker
    StickerUpdate,
    /// [Sticker] was deleted.
    ///
    /// [Sticker]: crate::channel::message::sticker::Sticker
    StickerDelete,
    /// [`GuildScheduledEvent`] was created.
    ///
    /// [`GuildScheduledEvent`]: crate::guild::scheduled_event::GuildScheduledEvent
    GuildScheduledEventCreate,
    /// [`GuildScheduledEvent`] was updated.
    ///
    /// [`GuildScheduledEvent`]: crate::guild::scheduled_event::GuildScheduledEvent
    GuildScheduledEventUpdate,
    /// [`GuildScheduledEvent`] was deleted.
    ///
    /// [`GuildScheduledEvent`]: crate::guild::scheduled_event::GuildScheduledEvent
    GuildScheduledEventDelete,
    /// Thread [channel] was created.
    ///
    /// [channel]: crate::channel::Channel
    ThreadCreate,
    /// Thread [channel] was updated.
    ///
    /// [channel]: crate::channel::Channel
    ThreadUpdate,
    /// Thread [channel] was deleted.
    ///
    /// [channel]: crate::channel::Channel
    ThreadDelete,
    /// A [`GuildCommandPermissions`] was updated.
    ///
    /// [`GuildCommandPermissions`]: crate::application::command::permissions::GuildCommandPermissions
    ApplicationCommandPermissionUpdate,
    /// [`AutoModerationRule`] has been created.
    ///
    /// [`AutoModerationRule`]: crate::guild::auto_moderation::AutoModerationRule
    AutoModerationRuleCreate,
    /// [`AutoModerationRule`] has been updated.
    ///
    /// [`AutoModerationRule`]: crate::guild::auto_moderation::AutoModerationRule
    AutoModerationRuleUpdate,
    /// [`AutoModerationRule`] has been deleted.
    ///
    /// [`AutoModerationRule`]: crate::guild::auto_moderation::AutoModerationRule
    AutoModerationRuleDelete,
    /// Message has been blocked by AutoMod.
    AutoModerationBlockMessage,
    /// Message has been flagged by AutoMod.
    AutoModerationFlagToChannel,
    /// A member has been timed out by AutoMod.
    AutoModerationUserCommunicationDisabled,
    /// Creator monetization request was created.
    CreatorMonetizationRequestCreated,
    /// Creator monetization terms were accepted.
    CreatorMonetizationTermsAccepted,
    /// Variant value is unknown to the library.
    Unknown(u16),
}

impl From<u16> for AuditLogEventType {
    fn from(value: u16) -> Self {
        match value {
            1 => AuditLogEventType::GuildUpdate,
            10 => AuditLogEventType::ChannelCreate,
            11 => AuditLogEventType::ChannelUpdate,
            12 => AuditLogEventType::ChannelDelete,
            13 => AuditLogEventType::ChannelOverwriteCreate,
            14 => AuditLogEventType::ChannelOverwriteUpdate,
            15 => AuditLogEventType::ChannelOverwriteDelete,
            20 => AuditLogEventType::MemberKick,
            21 => AuditLogEventType::MemberPrune,
            22 => AuditLogEventType::MemberBanAdd,
            23 => AuditLogEventType::MemberBanRemove,
            24 => AuditLogEventType::MemberUpdate,
            25 => AuditLogEventType::MemberRoleUpdate,
            26 => AuditLogEventType::MemberMove,
            17 => AuditLogEventType::MemberDisconnect,
            28 => AuditLogEventType::BotAdd,
            30 => AuditLogEventType::RoleCreate,
            31 => AuditLogEventType::RoleUpdate,
            32 => AuditLogEventType::RoleDelete,
            40 => AuditLogEventType::InviteCreate,
            41 => AuditLogEventType::InviteUpdate,
            42 => AuditLogEventType::InviteDelete,
            50 => AuditLogEventType::WebhookCreate,
            51 => AuditLogEventType::WebhookUpdate,
            52 => AuditLogEventType::WebhookDelete,
            60 => AuditLogEventType::EmojiCreate,
            61 => AuditLogEventType::EmojiUpdate,
            62 => AuditLogEventType::EmojiDelete,
            72 => AuditLogEventType::MessageDelete,
            73 => AuditLogEventType::MessageBulkDelete,
            74 => AuditLogEventType::MessagePin,
            75 => AuditLogEventType::MessageUnpin,
            80 => AuditLogEventType::IntegrationCreate,
            81 => AuditLogEventType::IntegrationUpdate,
            82 => AuditLogEventType::IntegrationDelete,
            83 => AuditLogEventType::StageInstanceCreate,
            84 => AuditLogEventType::StageInstanceUpdate,
            85 => AuditLogEventType::StageInstanceDelete,
            90 => AuditLogEventType::StickerCreate,
            91 => AuditLogEventType::StickerUpdate,
            92 => AuditLogEventType::StickerDelete,
            100 => AuditLogEventType::GuildScheduledEventCreate,
            101 => AuditLogEventType::GuildScheduledEventUpdate,
            102 => AuditLogEventType::GuildScheduledEventDelete,
            110 => AuditLogEventType::ThreadCreate,
            111 => AuditLogEventType::ThreadUpdate,
            112 => AuditLogEventType::ThreadDelete,
            121 => AuditLogEventType::ApplicationCommandPermissionUpdate,
            140 => AuditLogEventType::AutoModerationRuleCreate,
            141 => AuditLogEventType::AutoModerationRuleUpdate,
            142 => AuditLogEventType::AutoModerationRuleDelete,
            143 => AuditLogEventType::AutoModerationBlockMessage,
            144 => AuditLogEventType::AutoModerationFlagToChannel,
            145 => AuditLogEventType::AutoModerationUserCommunicationDisabled,
            150 => AuditLogEventType::CreatorMonetizationRequestCreated,
            151 => AuditLogEventType::CreatorMonetizationTermsAccepted,
            unknown => AuditLogEventType::Unknown(unknown),
        }
    }
}

impl From<AuditLogEventType> for u16 {
    fn from(value: AuditLogEventType) -> Self {
        match value {
            AuditLogEventType::GuildUpdate => 1,
            AuditLogEventType::ChannelCreate => 10,
            AuditLogEventType::ChannelUpdate => 11,
            AuditLogEventType::ChannelDelete => 12,
            AuditLogEventType::ChannelOverwriteCreate => 13,
            AuditLogEventType::ChannelOverwriteUpdate => 14,
            AuditLogEventType::ChannelOverwriteDelete => 15,
            AuditLogEventType::MemberKick => 20,
            AuditLogEventType::MemberPrune => 21,
            AuditLogEventType::MemberBanAdd => 22,
            AuditLogEventType::MemberBanRemove => 23,
            AuditLogEventType::MemberUpdate => 24,
            AuditLogEventType::MemberRoleUpdate => 25,
            AuditLogEventType::MemberMove => 26,
            AuditLogEventType::MemberDisconnect => 27,
            AuditLogEventType::BotAdd => 28,
            AuditLogEventType::RoleCreate => 30,
            AuditLogEventType::RoleUpdate => 31,
            AuditLogEventType::RoleDelete => 32,
            AuditLogEventType::InviteCreate => 40,
            AuditLogEventType::InviteUpdate => 41,
            AuditLogEventType::InviteDelete => 42,
            AuditLogEventType::WebhookCreate => 50,
            AuditLogEventType::WebhookUpdate => 51,
            AuditLogEventType::WebhookDelete => 52,
            AuditLogEventType::EmojiCreate => 60,
            AuditLogEventType::EmojiUpdate => 61,
            AuditLogEventType::EmojiDelete => 62,
            AuditLogEventType::MessageDelete => 72,
            AuditLogEventType::MessageBulkDelete => 73,
            AuditLogEventType::MessagePin => 74,
            AuditLogEventType::MessageUnpin => 75,
            AuditLogEventType::IntegrationCreate => 80,
            AuditLogEventType::IntegrationUpdate => 81,
            AuditLogEventType::IntegrationDelete => 82,
            AuditLogEventType::StageInstanceCreate => 83,
            AuditLogEventType::StageInstanceUpdate => 84,
            AuditLogEventType::StageInstanceDelete => 85,
            AuditLogEventType::StickerCreate => 90,
            AuditLogEventType::StickerUpdate => 91,
            AuditLogEventType::StickerDelete => 92,
            AuditLogEventType::GuildScheduledEventCreate => 100,
            AuditLogEventType::GuildScheduledEventUpdate => 101,
            AuditLogEventType::GuildScheduledEventDelete => 102,
            AuditLogEventType::ThreadCreate => 110,
            AuditLogEventType::ThreadUpdate => 111,
            AuditLogEventType::ThreadDelete => 112,
            AuditLogEventType::ApplicationCommandPermissionUpdate => 121,
            AuditLogEventType::AutoModerationRuleCreate => 140,
            AuditLogEventType::AutoModerationRuleUpdate => 141,
            AuditLogEventType::AutoModerationRuleDelete => 142,
            AuditLogEventType::AutoModerationBlockMessage => 143,
            AuditLogEventType::AutoModerationFlagToChannel => 144,
            AuditLogEventType::AutoModerationUserCommunicationDisabled => 145,
            AuditLogEventType::CreatorMonetizationRequestCreated => 150,
            AuditLogEventType::CreatorMonetizationTermsAccepted => 151,
            AuditLogEventType::Unknown(unknown) => unknown,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::AuditLogEventType;
    use serde::{Deserialize, Serialize};
    use static_assertions::assert_impl_all;
    use std::{fmt::Debug, hash::Hash};

    assert_impl_all!(
        AuditLogEventType: Clone,
        Copy,
        Debug,
        Deserialize<'static>,
        Eq,
        Hash,
        PartialEq,
        Send,
        Serialize,
        Sync,
    );

    #[test]
    fn test_values() {
        assert_eq!(1, u16::from(AuditLogEventType::GuildUpdate));
        assert_eq!(10, u16::from(AuditLogEventType::ChannelCreate));
        assert_eq!(11, u16::from(AuditLogEventType::ChannelUpdate));
        assert_eq!(12, u16::from(AuditLogEventType::ChannelDelete));
        assert_eq!(13, u16::from(AuditLogEventType::ChannelOverwriteCreate));
        assert_eq!(14, u16::from(AuditLogEventType::ChannelOverwriteUpdate));
        assert_eq!(15, u16::from(AuditLogEventType::ChannelOverwriteDelete));
        assert_eq!(20, u16::from(AuditLogEventType::MemberKick));
        assert_eq!(21, u16::from(AuditLogEventType::MemberPrune));
        assert_eq!(22, u16::from(AuditLogEventType::MemberBanAdd));
        assert_eq!(23, u16::from(AuditLogEventType::MemberBanRemove));
        assert_eq!(24, u16::from(AuditLogEventType::MemberUpdate));
        assert_eq!(25, u16::from(AuditLogEventType::MemberRoleUpdate));
        assert_eq!(26, u16::from(AuditLogEventType::MemberMove));
        assert_eq!(27, u16::from(AuditLogEventType::MemberDisconnect));
        assert_eq!(28, u16::from(AuditLogEventType::BotAdd));
        assert_eq!(30, u16::from(AuditLogEventType::RoleCreate));
        assert_eq!(31, u16::from(AuditLogEventType::RoleUpdate));
        assert_eq!(32, u16::from(AuditLogEventType::RoleDelete));
        assert_eq!(40, u16::from(AuditLogEventType::InviteCreate));
        assert_eq!(41, u16::from(AuditLogEventType::InviteUpdate));
        assert_eq!(42, u16::from(AuditLogEventType::InviteDelete));
        assert_eq!(50, u16::from(AuditLogEventType::WebhookCreate));
        assert_eq!(51, u16::from(AuditLogEventType::WebhookUpdate));
        assert_eq!(52, u16::from(AuditLogEventType::WebhookDelete));
        assert_eq!(60, u16::from(AuditLogEventType::EmojiCreate));
        assert_eq!(61, u16::from(AuditLogEventType::EmojiUpdate));
        assert_eq!(62, u16::from(AuditLogEventType::EmojiDelete));
        assert_eq!(72, u16::from(AuditLogEventType::MessageDelete));
        assert_eq!(73, u16::from(AuditLogEventType::MessageBulkDelete));
        assert_eq!(74, u16::from(AuditLogEventType::MessagePin));
        assert_eq!(75, u16::from(AuditLogEventType::MessageUnpin));
        assert_eq!(80, u16::from(AuditLogEventType::IntegrationCreate));
        assert_eq!(81, u16::from(AuditLogEventType::IntegrationUpdate));
        assert_eq!(82, u16::from(AuditLogEventType::IntegrationDelete));
        assert_eq!(83, u16::from(AuditLogEventType::StageInstanceCreate));
        assert_eq!(84, u16::from(AuditLogEventType::StageInstanceUpdate));
        assert_eq!(90, u16::from(AuditLogEventType::StickerCreate));
        assert_eq!(91, u16::from(AuditLogEventType::StickerUpdate));
        assert_eq!(92, u16::from(AuditLogEventType::StickerDelete));
        assert_eq!(100, u16::from(AuditLogEventType::GuildScheduledEventCreate));
        assert_eq!(101, u16::from(AuditLogEventType::GuildScheduledEventUpdate));
        assert_eq!(102, u16::from(AuditLogEventType::GuildScheduledEventDelete));
        assert_eq!(110, u16::from(AuditLogEventType::ThreadCreate));
        assert_eq!(111, u16::from(AuditLogEventType::ThreadUpdate));
        assert_eq!(112, u16::from(AuditLogEventType::ThreadDelete));
        assert_eq!(
            121,
            u16::from(AuditLogEventType::ApplicationCommandPermissionUpdate)
        );
        assert_eq!(140, u16::from(AuditLogEventType::AutoModerationRuleCreate));
        assert_eq!(141, u16::from(AuditLogEventType::AutoModerationRuleUpdate));
        assert_eq!(142, u16::from(AuditLogEventType::AutoModerationRuleDelete));
        assert_eq!(
            143,
            u16::from(AuditLogEventType::AutoModerationBlockMessage)
        );
        assert_eq!(
            144,
            u16::from(AuditLogEventType::AutoModerationFlagToChannel)
        );
        assert_eq!(
            145,
            u16::from(AuditLogEventType::AutoModerationUserCommunicationDisabled)
        );
        assert_eq!(
            150,
            u16::from(AuditLogEventType::CreatorMonetizationRequestCreated)
        );
        assert_eq!(
            151,
            u16::from(AuditLogEventType::CreatorMonetizationTermsAccepted)
        );
        assert_eq!(250, u16::from(AuditLogEventType::Unknown(250)));
    }
}