From df2c3e3747b670a3226c006ef23c6ec6fbbbc1a7 Mon Sep 17 00:00:00 2001 From: Valentine Briese Date: Tue, 16 Apr 2024 09:59:45 -0700 Subject: [PATCH] Add support for image attachments in #portside embeds --- src/portside.rs | 55 +++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/portside.rs b/src/portside.rs index a029696..dc1fd76 100644 --- a/src/portside.rs +++ b/src/portside.rs @@ -66,33 +66,44 @@ pub(super) async fn check_portside_reactions( // if not, check if reaction count meets minimum if tomato_reaction_count >= MINIMUM_TOMATO_REACTIONS { // if it does, send new message in #portside + + let mut embed_builder = CreateEmbed::new() + .color(Color::RED) + .author( + CreateEmbedAuthor::new( + reaction_message + .author + .global_name + .as_ref() + .unwrap_or(&reaction_message.author.name), + ) + .icon_url(reaction_message.author.face()), + ) + .description(reaction_message.content) + .field( + "", + format!("[Jump to Message]({reaction_message_link})"), + false, + ) + .footer(CreateEmbedFooter::new(reaction_message_id)) + .timestamp(reaction_message.timestamp); + + if !reaction_message.attachments.is_empty() { + for attachment in reaction_message.attachments { + if let Some(content_type) = attachment.content_type { + if content_type.starts_with("image") { + embed_builder = embed_builder.image(attachment.url); + } + } + } + } + portside .send_message( &ctx, CreateMessage::new() .content(portside_message_content) - .embed( - CreateEmbed::new() - .color(Color::RED) - .author( - CreateEmbedAuthor::new( - reaction_message - .author - .global_name - .as_ref() - .unwrap_or(&reaction_message.author.name), - ) - .icon_url(reaction_message.author.face()), - ) - .description(reaction_message.content) - .field( - "", - format!("[Jump to Message]({reaction_message_link})"), - false, - ) - .footer(CreateEmbedFooter::new(reaction_message_id)) - .timestamp(reaction_message.timestamp), - ), + .embed(embed_builder), ) .await?; }