|
| 1 | +use super::{format_change_value, EmbedField}; |
| 2 | +use crate::handlers::audit_log::{ |
| 3 | + AuditLogContext, AuditLogFormatter, COLOR_DANGER, COLOR_INFO, COLOR_SUCCESS, COLOR_WARNING, |
| 4 | +}; |
| 5 | +use serenity::all::AutoModAction; |
| 6 | + |
| 7 | +pub struct AutoModFormatter(pub AutoModAction); |
| 8 | + |
| 9 | +#[async_trait::async_trait] |
| 10 | +impl AuditLogFormatter for AutoModFormatter { |
| 11 | + fn emoji(&self) -> &'static str { |
| 12 | + match self.0 { |
| 13 | + AutoModAction::RuleCreate => "🛡️", |
| 14 | + AutoModAction::RuleUpdate => "✏️", |
| 15 | + AutoModAction::RuleDelete => "🗑️", |
| 16 | + AutoModAction::BlockMessage => "🚫", |
| 17 | + AutoModAction::FlagToChannel => "🚩", |
| 18 | + AutoModAction::UserCommunicationDisabled => "🔇", |
| 19 | + _ => "🛡️", |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + fn color(&self) -> u32 { |
| 24 | + match self.0 { |
| 25 | + AutoModAction::RuleCreate => COLOR_SUCCESS, |
| 26 | + AutoModAction::RuleUpdate => COLOR_WARNING, |
| 27 | + AutoModAction::RuleDelete => COLOR_DANGER, |
| 28 | + AutoModAction::BlockMessage => COLOR_DANGER, |
| 29 | + AutoModAction::FlagToChannel => COLOR_WARNING, |
| 30 | + AutoModAction::UserCommunicationDisabled => COLOR_INFO, |
| 31 | + _ => COLOR_INFO, |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + async fn title(&self, alc: &AuditLogContext<'_>) -> String { |
| 36 | + let key = match self.0 { |
| 37 | + AutoModAction::RuleCreate => "audit_log.automod.rule_create", |
| 38 | + AutoModAction::RuleUpdate => "audit_log.automod.rule_update", |
| 39 | + AutoModAction::RuleDelete => "audit_log.automod.rule_delete", |
| 40 | + AutoModAction::BlockMessage => "audit_log.automod.block_message", |
| 41 | + AutoModAction::FlagToChannel => "audit_log.automod.flag_to_channel", |
| 42 | + AutoModAction::UserCommunicationDisabled => "audit_log.automod.user_timeout", |
| 43 | + _ => "audit_log.automod.unknown", |
| 44 | + }; |
| 45 | + alc.translate(key, None).await |
| 46 | + } |
| 47 | + |
| 48 | + async fn description(&self, alc: &AuditLogContext<'_>) -> String { |
| 49 | + let target_label = alc.translate("audit_log.target", None).await; |
| 50 | + |
| 51 | + let target = if let Some(target_id) = alc.target_id() { |
| 52 | + match self.0 { |
| 53 | + AutoModAction::UserCommunicationDisabled => { |
| 54 | + format!("<@{}> (`{}`)", target_id, target_id) |
| 55 | + } |
| 56 | + _ => format!("`{}`", target_id), |
| 57 | + } |
| 58 | + } else { |
| 59 | + alc.translate("audit_log.unknown", None).await |
| 60 | + }; |
| 61 | + |
| 62 | + format!("**{}:** {}", target_label, target) |
| 63 | + } |
| 64 | + |
| 65 | + async fn format_changes(&self, alc: &AuditLogContext<'_>) -> Vec<EmbedField> { |
| 66 | + let mut fields = Vec::new(); |
| 67 | + for change in alc.changes() { |
| 68 | + if let Some(field) = format_change_value(alc, change).await { |
| 69 | + fields.push(field); |
| 70 | + } |
| 71 | + } |
| 72 | + fields |
| 73 | + } |
| 74 | +} |
0 commit comments