twilight_model/guild/auto_moderation/
action.rsuse crate::id::{marker::ChannelMarker, Id};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct AutoModerationAction {
#[serde(rename = "type")]
pub kind: AutoModerationActionType,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<AutoModerationActionMetadata>,
}
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct AutoModerationActionMetadata {
#[serde(skip_serializing_if = "Option::is_none")]
pub channel_id: Option<Id<ChannelMarker>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub custom_message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration_seconds: Option<u32>,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[serde(from = "u8", into = "u8")]
pub enum AutoModerationActionType {
BlockMessage,
SendAlertMessage,
Timeout,
BlockMemberInteraction,
Unknown(u8),
}
impl From<u8> for AutoModerationActionType {
fn from(value: u8) -> Self {
match value {
1 => Self::BlockMessage,
2 => Self::SendAlertMessage,
3 => Self::Timeout,
4 => Self::BlockMemberInteraction,
_ => Self::Unknown(value),
}
}
}
impl From<AutoModerationActionType> for u8 {
fn from(value: AutoModerationActionType) -> Self {
match value {
AutoModerationActionType::BlockMessage => 1,
AutoModerationActionType::SendAlertMessage => 2,
AutoModerationActionType::Timeout => 3,
AutoModerationActionType::BlockMemberInteraction => 4,
AutoModerationActionType::Unknown(unknown) => unknown,
}
}
}
#[cfg(test)]
mod tests {
use super::{AutoModerationAction, AutoModerationActionMetadata, AutoModerationActionType};
use serde::{Deserialize, Serialize};
use static_assertions::{assert_fields, assert_impl_all};
use std::{fmt::Debug, hash::Hash};
assert_fields!(AutoModerationAction: kind, metadata);
assert_fields!(
AutoModerationActionMetadata: channel_id,
custom_message,
duration_seconds
);
assert_impl_all!(
AutoModerationAction: Clone,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Serialize,
Send,
Sync
);
assert_impl_all!(
AutoModerationActionMetadata: Clone,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Serialize,
Send,
Sync
);
assert_impl_all!(
AutoModerationActionType: Clone,
Copy,
Debug,
Deserialize<'static>,
Eq,
Hash,
PartialEq,
Send,
Serialize,
Sync,
);
#[test]
fn values() {
assert_eq!(1, u8::from(AutoModerationActionType::BlockMessage));
assert_eq!(2, u8::from(AutoModerationActionType::SendAlertMessage));
assert_eq!(3, u8::from(AutoModerationActionType::Timeout));
assert_eq!(
4,
u8::from(AutoModerationActionType::BlockMemberInteraction)
);
assert_eq!(250, u8::from(AutoModerationActionType::Unknown(250)));
}
}