Skip to content

Commit

Permalink
Allow edited interactions to be sent without removing existing embeds
Browse files Browse the repository at this point in the history
  • Loading branch information
TapGhoul committed Sep 11, 2024
1 parent 5750259 commit 39ffbe2
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions src/reply/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct CreateReply {
/// Message content.
pub content: Option<String>,
/// Embeds, if present.
pub embeds: Vec<serenity::CreateEmbed>,
pub embeds: Option<Vec<serenity::CreateEmbed>>,
/// Message attachments.
pub attachments: Vec<serenity::CreateAttachment>,
/// Whether the message is ephemeral (only has an effect in application commands)
Expand All @@ -32,9 +32,18 @@ impl CreateReply {

/// Adds an embed to the message.
///
/// Existing embeds are kept.
/// Existing embeds on this are kept.
/// When editing a message, this will overwrite previously sent embeds.
pub fn embed(mut self, embed: serenity::CreateEmbed) -> Self {
self.embeds.push(embed);
self.embeds.get_or_insert_with(|| Default::default()).push(embed);
self
}

/// Set embeds for the message.
///
/// Any previously set embeds will be overwritten.
pub fn embeds(mut self, embeds: Vec<serenity::CreateEmbed>) -> Self {
self.embeds = Some(embeds);
self
}

Expand Down Expand Up @@ -112,8 +121,11 @@ impl CreateReply {
if let Some(ephemeral) = ephemeral {
builder = builder.ephemeral(ephemeral);
}
if let Some(embeds) = embeds {
builder = builder.embeds(embeds);
}

builder.add_files(attachments).embeds(embeds)
builder.add_files(attachments)
}

/// Serialize this response builder to a [`serenity::CreateInteractionResponseFollowup`]
Expand All @@ -135,7 +147,9 @@ impl CreateReply {
if let Some(content) = content {
builder = builder.content(content);
}
builder = builder.embeds(embeds);
if let Some(embeds) = embeds {
builder = builder.embeds(embeds);
}
if let Some(components) = components {
builder = builder.components(components)
}
Expand Down Expand Up @@ -174,8 +188,11 @@ impl CreateReply {
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
if let Some(embeds) = embeds {
builder = builder.embeds(embeds);
}

builder.embeds(embeds)
builder
}

/// Serialize this response builder to a [`serenity::EditMessage`]
Expand Down Expand Up @@ -205,8 +222,11 @@ impl CreateReply {
if let Some(components) = components {
builder = builder.components(components);
}
if let Some(embeds) = embeds {
builder = builder.embeds(embeds);
}

builder.embeds(embeds).attachments(attachments_builder)
builder.attachments(attachments_builder)
}

/// Serialize this response builder to a [`serenity::CreateMessage`]
Expand Down Expand Up @@ -235,6 +255,9 @@ impl CreateReply {
if let Some(components) = components {
builder = builder.components(components);
}
if let Some(embeds) = embeds {
builder = builder.embeds(embeds)
}
if reply {
builder = builder.reference_message(invocation_message);
}
Expand All @@ -243,6 +266,6 @@ impl CreateReply {
builder = builder.add_file(attachment);
}

builder.embeds(embeds)
builder
}
}

0 comments on commit 39ffbe2

Please sign in to comment.