twilight_model/guild/auto_moderation/
trigger_metadata.rsuse super::AutoModerationKeywordPresetType;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct AutoModerationTriggerMetadata {
#[serde(skip_serializing_if = "Option::is_none")]
pub allow_list: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub keyword_filter: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub presets: Option<Vec<AutoModerationKeywordPresetType>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mention_raid_protection_enabled: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mention_total_limit: Option<u8>,
#[serde(skip_serializing_if = "Option::is_none")]
pub regex_patterns: Option<Vec<String>>,
}
#[cfg(test)]
mod tests {
use super::{AutoModerationKeywordPresetType, AutoModerationTriggerMetadata};
use serde::{Deserialize, Serialize};
use serde_test::Token;
use static_assertions::{assert_fields, assert_impl_all};
use std::{fmt::Debug, hash::Hash};
assert_fields!(AutoModerationTriggerMetadata: keyword_filter, presets);
assert_impl_all!(
AutoModerationTriggerMetadata: Clone,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Serialize,
Send,
Sync
);
#[test]
fn trigger_metadata() {
let value = AutoModerationTriggerMetadata {
allow_list: Some(Vec::from(["heck".into()])),
keyword_filter: Some(Vec::from(["shoot".into(), "darn".into()])),
presets: Some(Vec::from([
AutoModerationKeywordPresetType::Profanity,
AutoModerationKeywordPresetType::SexualContent,
AutoModerationKeywordPresetType::Slurs,
])),
mention_raid_protection_enabled: Some(true),
mention_total_limit: Some(5),
regex_patterns: Some(Vec::from(["^\\d+$".into()])),
};
serde_test::assert_ser_tokens(
&value,
&[
Token::Struct {
name: "AutoModerationTriggerMetadata",
len: 6,
},
Token::Str("allow_list"),
Token::Some,
Token::Seq { len: Some(1) },
Token::Str("heck"),
Token::SeqEnd,
Token::Str("keyword_filter"),
Token::Some,
Token::Seq { len: Some(2) },
Token::Str("shoot"),
Token::Str("darn"),
Token::SeqEnd,
Token::Str("presets"),
Token::Some,
Token::Seq { len: Some(3) },
Token::U8(u8::from(AutoModerationKeywordPresetType::Profanity)),
Token::U8(u8::from(AutoModerationKeywordPresetType::SexualContent)),
Token::U8(u8::from(AutoModerationKeywordPresetType::Slurs)),
Token::SeqEnd,
Token::Str("mention_raid_protection_enabled"),
Token::Some,
Token::Bool(true),
Token::Str("mention_total_limit"),
Token::Some,
Token::U8(5),
Token::Str("regex_patterns"),
Token::Some,
Token::Seq { len: Some(1) },
Token::Str("^\\d+$"),
Token::SeqEnd,
Token::StructEnd,
],
);
}
}