Add attachments to message delete logs

This commit is contained in:
Xyon 2023-09-19 13:30:21 +01:00
parent 0354cc6569
commit be130790ea
Signed by: xyon
GPG Key ID: DD18155D6B18078D
2 changed files with 40 additions and 23 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "manifold" name = "manifold"
version = "3.2.0" version = "3.3.0"
authors = ["Lucy Bladen <admin@lbladen.uk>"] authors = ["Lucy Bladen <admin@lbladen.uk>"]
edition = "2021" edition = "2021"

View File

@ -221,19 +221,17 @@ impl Handler {
async fn message_deleted(ctx: &Context, fctx: &FrameworkContext<'_, ManifoldData, ManifoldError>, channel_id: &ChannelId, deleted_message_id: &MessageId, _guild_id: &Option<GuildId>) -> ManifoldResult<()> { async fn message_deleted(ctx: &Context, fctx: &FrameworkContext<'_, ManifoldData, ManifoldError>, channel_id: &ChannelId, deleted_message_id: &MessageId, _guild_id: &Option<GuildId>) -> ManifoldResult<()> {
let log_channel = fctx.user_data().await.bot_config.channels.log; let log_channel = fctx.user_data().await.bot_config.channels.log;
let mut content: String = "Not Available / Not Cached".to_string();
let author;
let channel = match ctx.cache.guild_channel(channel_id) { let channel = match ctx.cache.guild_channel(channel_id) {
Some(c) => c.name, Some(c) => c.name,
None => format!("Not Available / Not Cached ({})", channel_id) None => format!("Not Available / Not Cached ({})", channel_id)
}; };
if let Some(msg) = ctx.cache.message(channel_id, deleted_message_id) { match ctx.cache.message(channel_id, deleted_message_id) {
content = msg.content_safe(&ctx.cache); Some(msg) => {
author = msg.author;
} else { let mut attachment_urls: Vec<String> = Vec::new();
author = User::default(); for attachment in &msg.attachments {
attachment_urls.push(attachment.url.clone());
} }
log_channel.send_message(ctx, |f| { log_channel.send_message(ctx, |f| {
@ -243,12 +241,31 @@ impl Handler {
e e
.title(format!("Message removed in #{} ({})", channel, channel_id)) .title(format!("Message removed in #{} ({})", channel, channel_id))
.colour(Colour::from_rgb(255, 0, 0)) .colour(Colour::from_rgb(255, 0, 0))
.author(|a| a.name(author.name)) .author(|a| a.name(&msg.author.name))
.field("Message Content", content, false) .field("Message Content", msg.content_safe(&ctx.cache), false)
.field("Message Attachments", attachment_urls.join(", "), false)
.timestamp(Timestamp::now()) .timestamp(Timestamp::now())
.footer(|f| f.text(author.id)) .footer(|f| f.text(&msg.author.id));
for attachment in &msg.attachments {
e.image(attachment.url.clone());
}
e
}) })
}).await?; }).await?;
},
None => {
log_channel.send_message(ctx, |f| {
f
.content("")
.embed(|e| {
e
.title(format!("Message removed in #{} ({}) (Not cached)", channel, channel_id))
.colour(Colour::from_rgb(255, 0, 0))
.timestamp(Timestamp::now())
})
}).await?;
}
}
Ok(()) Ok(())
} }