twilight_model/guild/auto_moderation/
trigger_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
use serde::{Deserialize, Serialize};

/// Characterizes the type of content which can trigger the rule.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(from = "u8", into = "u8")]
pub enum AutoModerationTriggerType {
    /// Check if content contains words from a user defined list of keywords.
    ///
    /// Maximum of 5 per guild.
    Keyword,
    /// Check if content represents generic spam.
    ///
    /// Currently unreleased. Maximum of 1 per guild.
    Spam,
    /// Check if content contains words from internal pre-defined wordsets.
    ///
    /// Maximum of 1 per guild.
    KeywordPreset,
    /// Check if content contains more unique mentions than allowed.
    MentionSpam,
    /// Check if member profile contains words from a user defined list of keywords.
    MemberProfile,
    /// Variant value is unknown to the library.
    Unknown(u8),
}

impl From<u8> for AutoModerationTriggerType {
    fn from(value: u8) -> Self {
        match value {
            1 => Self::Keyword,
            3 => Self::Spam,
            4 => Self::KeywordPreset,
            5 => Self::MentionSpam,
            6 => Self::MemberProfile,
            _ => Self::Unknown(value),
        }
    }
}

impl From<AutoModerationTriggerType> for u8 {
    fn from(value: AutoModerationTriggerType) -> Self {
        match value {
            AutoModerationTriggerType::Keyword => 1,
            AutoModerationTriggerType::Spam => 3,
            AutoModerationTriggerType::KeywordPreset => 4,
            AutoModerationTriggerType::MentionSpam => 5,
            AutoModerationTriggerType::MemberProfile => 6,
            AutoModerationTriggerType::Unknown(unknown) => unknown,
        }
    }
}

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

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

    #[test]
    fn values() {
        assert_eq!(1, u8::from(AutoModerationTriggerType::Keyword));
        assert_eq!(3, u8::from(AutoModerationTriggerType::Spam));
        assert_eq!(4, u8::from(AutoModerationTriggerType::KeywordPreset));
        assert_eq!(5, u8::from(AutoModerationTriggerType::MentionSpam));
        assert_eq!(6, u8::from(AutoModerationTriggerType::MemberProfile));
        assert_eq!(250, u8::from(AutoModerationTriggerType::Unknown(250)));
    }
}