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

/// Internally pre-defined wordsets which will be searched for in content.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(from = "u8", into = "u8")]
pub enum AutoModerationKeywordPresetType {
    /// Words that may be considered forms of swearing or cursing.
    Profanity,
    /// Words that refer to sexually explicit behavior or activity.
    SexualContent,
    /// Personal insults or words that may be considered hate speech.
    Slurs,
    /// Variant value is unknown to the library.
    Unknown(u8),
}

impl From<u8> for AutoModerationKeywordPresetType {
    fn from(value: u8) -> Self {
        match value {
            1 => Self::Profanity,
            2 => Self::SexualContent,
            3 => Self::Slurs,
            _ => Self::Unknown(value),
        }
    }
}

impl From<AutoModerationKeywordPresetType> for u8 {
    fn from(value: AutoModerationKeywordPresetType) -> Self {
        match value {
            AutoModerationKeywordPresetType::Profanity => 1,
            AutoModerationKeywordPresetType::SexualContent => 2,
            AutoModerationKeywordPresetType::Slurs => 3,
            AutoModerationKeywordPresetType::Unknown(unknown) => unknown,
        }
    }
}

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

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

    #[test]
    fn values() {
        assert_eq!(1, u8::from(AutoModerationKeywordPresetType::Profanity));
        assert_eq!(2, u8::from(AutoModerationKeywordPresetType::SexualContent));
        assert_eq!(3, u8::from(AutoModerationKeywordPresetType::Slurs));
        assert_eq!(250, u8::from(AutoModerationKeywordPresetType::Unknown(250)));
    }
}