Skip to content

Commit

Permalink
Add support for image attachments in #portside embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinegb committed Apr 16, 2024
1 parent 37e3e20 commit df2c3e3
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions src/portside.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
Expand Down

0 comments on commit df2c3e3

Please sign in to comment.