Add attachments to message delete logs
This commit is contained in:
parent
0354cc6569
commit
be130790ea
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "manifold"
|
||||
version = "3.2.0"
|
||||
version = "3.3.0"
|
||||
authors = ["Lucy Bladen <admin@lbladen.uk>"]
|
||||
edition = "2021"
|
||||
|
||||
|
|
|
|||
|
|
@ -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<()> {
|
||||
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) {
|
||||
Some(c) => c.name,
|
||||
None => format!("Not Available / Not Cached ({})", channel_id)
|
||||
};
|
||||
|
||||
if let Some(msg) = ctx.cache.message(channel_id, deleted_message_id) {
|
||||
content = msg.content_safe(&ctx.cache);
|
||||
author = msg.author;
|
||||
} else {
|
||||
author = User::default();
|
||||
match ctx.cache.message(channel_id, deleted_message_id) {
|
||||
Some(msg) => {
|
||||
|
||||
let mut attachment_urls: Vec<String> = Vec::new();
|
||||
for attachment in &msg.attachments {
|
||||
attachment_urls.push(attachment.url.clone());
|
||||
}
|
||||
|
||||
log_channel.send_message(ctx, |f| {
|
||||
|
|
@ -241,14 +239,33 @@ impl Handler {
|
|||
.content("")
|
||||
.embed(|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))
|
||||
.author(|a| a.name(author.name))
|
||||
.field("Message Content", content, false)
|
||||
.author(|a| a.name(&msg.author.name))
|
||||
.field("Message Content", msg.content_safe(&ctx.cache), false)
|
||||
.field("Message Attachments", attachment_urls.join(", "), false)
|
||||
.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?;
|
||||
},
|
||||
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(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue