twilight_model/guild/auto_moderation/
preset_type.rs

1use serde::{Deserialize, Serialize};
2
3/// Internally pre-defined wordsets which will be searched for in content.
4#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
5#[serde(from = "u8", into = "u8")]
6pub enum AutoModerationKeywordPresetType {
7    /// Words that may be considered forms of swearing or cursing.
8    Profanity,
9    /// Words that refer to sexually explicit behavior or activity.
10    SexualContent,
11    /// Personal insults or words that may be considered hate speech.
12    Slurs,
13    /// Variant value is unknown to the library.
14    Unknown(u8),
15}
16
17impl From<u8> for AutoModerationKeywordPresetType {
18    fn from(value: u8) -> Self {
19        match value {
20            1 => Self::Profanity,
21            2 => Self::SexualContent,
22            3 => Self::Slurs,
23            _ => Self::Unknown(value),
24        }
25    }
26}
27
28impl From<AutoModerationKeywordPresetType> for u8 {
29    fn from(value: AutoModerationKeywordPresetType) -> Self {
30        match value {
31            AutoModerationKeywordPresetType::Profanity => 1,
32            AutoModerationKeywordPresetType::SexualContent => 2,
33            AutoModerationKeywordPresetType::Slurs => 3,
34            AutoModerationKeywordPresetType::Unknown(unknown) => unknown,
35        }
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use super::AutoModerationKeywordPresetType;
42    use serde::{Deserialize, Serialize};
43    use static_assertions::assert_impl_all;
44    use std::{fmt::Debug, hash::Hash};
45
46    assert_impl_all!(
47        AutoModerationKeywordPresetType: Clone,
48        Copy,
49        Debug,
50        Deserialize<'static>,
51        Eq,
52        Hash,
53        PartialEq,
54        Send,
55        Serialize,
56        Sync,
57    );
58
59    #[test]
60    fn values() {
61        assert_eq!(1, u8::from(AutoModerationKeywordPresetType::Profanity));
62        assert_eq!(2, u8::from(AutoModerationKeywordPresetType::SexualContent));
63        assert_eq!(3, u8::from(AutoModerationKeywordPresetType::Slurs));
64        assert_eq!(250, u8::from(AutoModerationKeywordPresetType::Unknown(250)));
65    }
66}