twilight_model/guild/auto_moderation/
trigger_type.rs

1use serde::{Deserialize, Serialize};
2
3/// Characterizes the type of content which can trigger the rule.
4#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
5#[serde(from = "u8", into = "u8")]
6pub enum AutoModerationTriggerType {
7    /// Check if content contains words from a user defined list of keywords.
8    ///
9    /// Maximum of 5 per guild.
10    Keyword,
11    /// Check if content represents generic spam.
12    ///
13    /// Currently unreleased. Maximum of 1 per guild.
14    Spam,
15    /// Check if content contains words from internal pre-defined wordsets.
16    ///
17    /// Maximum of 1 per guild.
18    KeywordPreset,
19    /// Check if content contains more unique mentions than allowed.
20    MentionSpam,
21    /// Check if member profile contains words from a user defined list of keywords.
22    MemberProfile,
23    /// Variant value is unknown to the library.
24    Unknown(u8),
25}
26
27impl From<u8> for AutoModerationTriggerType {
28    fn from(value: u8) -> Self {
29        match value {
30            1 => Self::Keyword,
31            3 => Self::Spam,
32            4 => Self::KeywordPreset,
33            5 => Self::MentionSpam,
34            6 => Self::MemberProfile,
35            _ => Self::Unknown(value),
36        }
37    }
38}
39
40impl From<AutoModerationTriggerType> for u8 {
41    fn from(value: AutoModerationTriggerType) -> Self {
42        match value {
43            AutoModerationTriggerType::Keyword => 1,
44            AutoModerationTriggerType::Spam => 3,
45            AutoModerationTriggerType::KeywordPreset => 4,
46            AutoModerationTriggerType::MentionSpam => 5,
47            AutoModerationTriggerType::MemberProfile => 6,
48            AutoModerationTriggerType::Unknown(unknown) => unknown,
49        }
50    }
51}
52
53#[cfg(test)]
54mod tests {
55    use super::AutoModerationTriggerType;
56    use serde::{Deserialize, Serialize};
57    use static_assertions::assert_impl_all;
58    use std::{fmt::Debug, hash::Hash};
59
60    assert_impl_all!(
61        AutoModerationTriggerType: Clone,
62        Copy,
63        Debug,
64        Deserialize<'static>,
65        Eq,
66        Hash,
67        PartialEq,
68        Send,
69        Serialize,
70        Sync,
71    );
72
73    #[test]
74    fn values() {
75        assert_eq!(1, u8::from(AutoModerationTriggerType::Keyword));
76        assert_eq!(3, u8::from(AutoModerationTriggerType::Spam));
77        assert_eq!(4, u8::from(AutoModerationTriggerType::KeywordPreset));
78        assert_eq!(5, u8::from(AutoModerationTriggerType::MentionSpam));
79        assert_eq!(6, u8::from(AutoModerationTriggerType::MemberProfile));
80        assert_eq!(250, u8::from(AutoModerationTriggerType::Unknown(250)));
81    }
82}