Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions src/reply/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::serenity_prelude as serenity;
#[allow(clippy::missing_docs_in_private_items)] // docs on setters
pub struct CreateReply {
content: Option<String>,
embeds: Vec<serenity::CreateEmbed>,
embeds: Option<Vec<serenity::CreateEmbed>>,
attachments: Vec<serenity::CreateAttachment>,
pub(crate) ephemeral: Option<bool>,
components: Option<Vec<serenity::CreateActionRow>>,
Expand All @@ -30,9 +30,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(Vec::new).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 @@ -116,14 +125,17 @@ impl CreateReply {
if let Some(components) = components {
builder = builder.components(components);
}
if let Some(embeds) = embeds {
builder = builder.embeds(embeds);
}
if let Some(ephemeral) = ephemeral {
builder = builder.ephemeral(ephemeral);
}
if let Some(poll) = poll {
builder = builder.poll(poll);
}

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

/// Serialize this response builder to a [`serenity::CreateInteractionResponseFollowup`]
Expand All @@ -145,10 +157,12 @@ impl CreateReply {
if let Some(content) = content {
builder = builder.content(content);
}
builder = builder.embeds(embeds);
if let Some(components) = components {
builder = builder.components(components)
}
if let Some(embeds) = embeds {
builder = builder.embeds(embeds);
}
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
Expand Down Expand Up @@ -185,14 +199,17 @@ impl CreateReply {
if let Some(components) = components {
builder = builder.components(components);
}
if let Some(embeds) = embeds {
builder = builder.embeds(embeds);
}
if let Some(allowed_mentions) = allowed_mentions {
builder = builder.allowed_mentions(allowed_mentions);
}
for attachment in attachments {
builder = builder.new_attachment(attachment);
}

builder.embeds(embeds)
builder
}

/// Serialize this response builder to a [`serenity::EditMessage`]
Expand Down Expand Up @@ -223,8 +240,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 @@ -253,6 +273,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 @@ -264,6 +287,6 @@ impl CreateReply {
builder = builder.add_file(attachment);
}

builder.embeds(embeds)
builder
}
}