Skip to content

Commit 2ac6f3f

Browse files
committed
Add moderation message function
1 parent b669bec commit 2ac6f3f

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::time::SystemTime;
44

55
use clap::Parser;
66
use serenity::async_trait;
7+
use serenity::builder::CreateMessage;
78
use serenity::futures::StreamExt;
89
use serenity::model::channel::Message;
910
use serenity::model::gateway::Ready;
@@ -59,6 +60,30 @@ impl EventHandler for Handler {
5960

6061
tracing::warn!("{warn_msg}");
6162

63+
if let Some(message) = &server_config.moderation_message {
64+
match msg.author.create_dm_channel(&ctx.http).await {
65+
Ok(channel) => {
66+
if let Err(e) = channel
67+
.send_message(&ctx.http, CreateMessage::new().content(message))
68+
.await
69+
{
70+
tracing::warn!(
71+
"Failed to send DM channel to {} - {}: {e}",
72+
msg.author.name,
73+
msg.author.id
74+
);
75+
}
76+
}
77+
Err(e) => {
78+
tracing::warn!(
79+
"Failed to create DM channel to {} - {}: {e}",
80+
msg.author.name,
81+
msg.author.id
82+
);
83+
}
84+
}
85+
}
86+
6287
match server_config.moderation {
6388
Moderation::Disabled => tracing::info!("Do nothing"),
6489
Moderation::Kick => {

src/model.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub struct ServerConfig {
4343
pub traps: Vec<u64>,
4444
pub whitelist: Vec<u64>,
4545

46+
pub moderation_message: Option<String>,
47+
4648
#[serde(default = "default_moderation")]
4749
pub moderation: Moderation,
4850
}

0 commit comments

Comments
 (0)