feat: bot core and moderation logging updates
This commit is contained in:
parent
bfdc5ce282
commit
6dc68159df
2 changed files with 28 additions and 12 deletions
|
|
@ -91,14 +91,12 @@ impl EventHandler for Handler {
|
||||||
&self,
|
&self,
|
||||||
ctx: Context,
|
ctx: Context,
|
||||||
_old: Option<serenity::all::Message>,
|
_old: Option<serenity::all::Message>,
|
||||||
new: Option<serenity::all::Message>,
|
_new: Option<serenity::all::Message>,
|
||||||
event: serenity::all::MessageUpdateEvent,
|
event: serenity::all::MessageUpdateEvent,
|
||||||
) {
|
) {
|
||||||
if let Some(msg) = new {
|
// All guards (real-edit only, bot/webhook authors, #mod-logs itself)
|
||||||
if msg.author.bot {
|
// live in moderation::logging - serenity message cache is off, so the
|
||||||
return;
|
// `new` argument is always None and cannot be used for bot filtering.
|
||||||
}
|
|
||||||
}
|
|
||||||
crate::feature::moderation::logging::on_message_edit(&ctx, &event).await;
|
crate::feature::moderation::logging::on_message_edit(&ctx, &event).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,19 +25,37 @@ pub async fn on_member_leave(
|
||||||
let _ = MOD_LOGS.send_message(&ctx.http, CreateMessage::new().embed(embed)).await;
|
let _ = MOD_LOGS.send_message(&ctx.http, CreateMessage::new().embed(embed)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Guards against non-edits: Discord sends `MESSAGE_UPDATE` with
|
||||||
|
/// `edited_timestamp = null` ~1s after `MESSAGE_CREATE` for embed-only
|
||||||
|
/// messages. Logging that would post a new embed, which gets its own spurious
|
||||||
|
/// update → infinite self-sustaining loop in #mod-logs.
|
||||||
pub async fn on_message_edit(ctx: &Context, event: &MessageUpdateEvent) {
|
pub async fn on_message_edit(ctx: &Context, event: &MessageUpdateEvent) {
|
||||||
|
if event.edited_timestamp.is_none() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Never log #mod-logs itself (feedback guard).
|
||||||
|
if event.channel_id == MOD_LOGS {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Author lives in the event payload: serenity message cache is off
|
||||||
|
// (`max_messages = 0`), so the `new: Option<Message>` bot filter never fires.
|
||||||
|
// Webhooks report `bot = true` too (GitHub integrations update themselves).
|
||||||
|
let Some(author) = event.author.as_ref() else { return };
|
||||||
|
if author.bot {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let Some(content) = event.content.clone() else { return };
|
let Some(content) = event.content.clone() else { return };
|
||||||
if content.len() > 1000 {
|
if content.len() > 1000 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let body = if content.is_empty() {
|
||||||
|
"*content cleared*".to_string()
|
||||||
|
} else {
|
||||||
|
format!("```{}```", content.chars().take(900).collect::<String>())
|
||||||
|
};
|
||||||
let embed = CreateEmbed::new()
|
let embed = CreateEmbed::new()
|
||||||
.title("Message edited")
|
.title("Message edited")
|
||||||
.description(format!(
|
.description(format!("<#{}> by <@{}>\n{}", event.channel_id, author.id, body))
|
||||||
"<#{}> by <@{}>\n```{}```",
|
|
||||||
event.channel_id,
|
|
||||||
event.author.as_ref().map(|a| a.id.to_string()).unwrap_or_default(),
|
|
||||||
content.chars().take(900).collect::<String>()
|
|
||||||
))
|
|
||||||
.color(0x00FAA81A);
|
.color(0x00FAA81A);
|
||||||
let _ = MOD_LOGS.send_message(&ctx.http, CreateMessage::new().embed(embed)).await;
|
let _ = MOD_LOGS.send_message(&ctx.http, CreateMessage::new().embed(embed)).await;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue