twilight_model/gateway/payload/incoming/
auto_moderation_action_execution.rsuse crate::{
guild::auto_moderation::{AutoModerationAction, AutoModerationTriggerType},
id::{
marker::{AutoModerationRuleMarker, ChannelMarker, GuildMarker, MessageMarker, UserMarker},
Id,
},
};
use serde::{Deserialize, Serialize};
#[allow(clippy::doc_markdown)]
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct AutoModerationActionExecution {
pub action: AutoModerationAction,
#[serde(skip_serializing_if = "Option::is_none")]
pub alert_system_message_id: Option<Id<MessageMarker>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub channel_id: Option<Id<ChannelMarker>>,
pub content: String,
pub guild_id: Id<GuildMarker>,
pub matched_content: Option<String>,
pub matched_keyword: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub message_id: Option<Id<MessageMarker>>,
pub rule_id: Id<AutoModerationRuleMarker>,
pub rule_trigger_type: AutoModerationTriggerType,
pub user_id: Id<UserMarker>,
}
#[cfg(test)]
mod tests {
use super::AutoModerationActionExecution;
use crate::{
guild::auto_moderation::{
AutoModerationAction, AutoModerationActionType, AutoModerationTriggerType,
},
id::{
marker::{
AutoModerationRuleMarker, ChannelMarker, GuildMarker, MessageMarker, UserMarker,
},
Id,
},
};
use serde::{Deserialize, Serialize};
use serde_test::Token;
use static_assertions::{assert_fields, assert_impl_all};
use std::{fmt::Debug, hash::Hash};
assert_fields!(
AutoModerationActionExecution: action,
alert_system_message_id,
channel_id,
content,
guild_id,
matched_content,
matched_keyword,
message_id,
rule_id,
rule_trigger_type,
user_id
);
assert_impl_all!(
AutoModerationActionExecution: Clone,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Serialize,
Send,
Sync
);
#[test]
fn action_execution() {
const ALERT_SYSTEM_MESSAGE_ID: Id<MessageMarker> = Id::new(1);
const CHANNEL_ID: Id<ChannelMarker> = Id::new(2);
const GUILD_ID: Id<GuildMarker> = Id::new(3);
const MESSAGE_ID: Id<MessageMarker> = Id::new(4);
const RULE_ID: Id<AutoModerationRuleMarker> = Id::new(5);
const USER_ID: Id<UserMarker> = Id::new(6);
let value = AutoModerationActionExecution {
action: AutoModerationAction {
kind: AutoModerationActionType::BlockMessage,
metadata: None,
},
alert_system_message_id: Some(ALERT_SYSTEM_MESSAGE_ID),
channel_id: Some(CHANNEL_ID),
content: "darn".into(),
guild_id: GUILD_ID,
matched_content: Some("darn".into()),
matched_keyword: Some("darn".into()),
message_id: Some(MESSAGE_ID),
rule_id: RULE_ID,
rule_trigger_type: AutoModerationTriggerType::Keyword,
user_id: USER_ID,
};
serde_test::assert_tokens(
&value,
&[
Token::Struct {
name: "AutoModerationActionExecution",
len: 11,
},
Token::Str("action"),
Token::Struct {
name: "AutoModerationAction",
len: 1,
},
Token::Str("type"),
Token::U8(u8::from(AutoModerationActionType::BlockMessage)),
Token::StructEnd,
Token::Str("alert_system_message_id"),
Token::Some,
Token::NewtypeStruct { name: "Id" },
Token::Str("1"),
Token::Str("channel_id"),
Token::Some,
Token::NewtypeStruct { name: "Id" },
Token::Str("2"),
Token::Str("content"),
Token::Str("darn"),
Token::Str("guild_id"),
Token::NewtypeStruct { name: "Id" },
Token::Str("3"),
Token::Str("matched_content"),
Token::Some,
Token::Str("darn"),
Token::Str("matched_keyword"),
Token::Some,
Token::Str("darn"),
Token::Str("message_id"),
Token::Some,
Token::NewtypeStruct { name: "Id" },
Token::Str("4"),
Token::Str("rule_id"),
Token::NewtypeStruct { name: "Id" },
Token::Str("5"),
Token::Str("rule_trigger_type"),
Token::U8(u8::from(AutoModerationTriggerType::Keyword)),
Token::Str("user_id"),
Token::NewtypeStruct { name: "Id" },
Token::Str("6"),
Token::StructEnd,
],
);
}
}