From 873b06b8a61e6fc4486167806bc0ac5eb12d9bbc Mon Sep 17 00:00:00 2001 From: uku Date: Mon, 20 Nov 2023 02:44:48 +0100 Subject: add image attachments to pinwie --- src/handler/pinboard.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/handler/pinboard.rs b/src/handler/pinboard.rs index 02dfdf9..53a5838 100644 --- a/src/handler/pinboard.rs +++ b/src/handler/pinboard.rs @@ -58,6 +58,18 @@ impl PinBoard { .and_then(|(role, _)| role.to_role_cached(&ctx.cache)) .map(|role| role.colour); + let attachment = pin + .attachments + .iter() + .filter(|a| { + a.content_type + .as_ref() + .filter(|ct| ct.contains("image/")) + .is_some() + }) + .map(|a| a.url.clone()) + .next(); + self.target .send_message(&ctx.http, |m| { m.allowed_mentions(|am| am.empty_parse()) @@ -70,6 +82,18 @@ impl PinBoard { if let Some(color) = color { embed.color(color); } + + if let Some(attachment) = attachment { + embed.image(attachment); + } + + if !pin.attachments.is_empty() { + embed.footer(|footer| { + // yes it will say '1 attachments' no i do not care + footer.text(format!("{} attachment(s)", pin.attachments.len())) + }); + } + embed.description(truncated_content) }) }) -- cgit v1.2.3