Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow edited messages and interactions to be sent without removing existing embeds #301

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/builtins/pretty_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Default for PrettyHelpConfiguration<'_> {
}
}

/// A help command that works similarly to `builtin::help` butt outputs text in an embed.
/// A help command that works similarly to `builtin::help` but outputs text in an embed.
///
pub async fn pretty_help<U, E>(
ctx: crate::Context<'_, U, E>,
Expand Down
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 @@ -29,9 +29,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 @@ -105,11 +114,14 @@ 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);
}

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

/// Serialize this response builder to a [`serenity::CreateInteractionResponseFollowup`]
Expand All @@ -130,10 +142,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 @@ -165,11 +179,14 @@ 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);
}

builder.embeds(embeds)
builder
}

/// Serialize this response builder to a [`serenity::EditMessage`]
Expand Down Expand Up @@ -198,8 +215,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 @@ -227,6 +247,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 @@ -235,6 +258,6 @@ impl CreateReply {
builder = builder.add_file(attachment);
}

builder.embeds(embeds)
builder
}
}
6 changes: 3 additions & 3 deletions src/slash_argument/slash_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum SlashArgError {
/// A string parameter was found, but it could not be parsed into the target type.
#[non_exhaustive]
Parse {
/// Error that occured while parsing the string into the target type
/// Error that occurred while parsing the string into the target type
error: Box<dyn std::error::Error + Send + Sync>,
/// Original input string
input: String,
Expand All @@ -32,7 +32,7 @@ pub enum SlashArgError {
/// Human readable description of the error
&'static str,
),
/// HTTP error occured while retrieving the model type from Discord
/// HTTP error occurred while retrieving the model type from Discord
Http(serenity::Error),
#[doc(hidden)]
__NonExhaustive,
Expand Down Expand Up @@ -91,7 +91,7 @@ impl std::fmt::Display for SlashArgError {
Self::Http(error) => {
write!(
f,
"Error occured while retrieving data from Discord: {error}",
"Error occurred while retrieving data from Discord: {error}",
)
}
Self::__NonExhaustive => unreachable!(),
Expand Down
4 changes: 2 additions & 2 deletions src/structs/framework_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum FrameworkError<'a, U, E> {
#[derivative(Debug = "ignore")]
framework: crate::FrameworkContext<'a, U, E>,
},
/// Error occured during command execution
/// Error occurred during command execution
#[non_exhaustive]
Command {
/// Error which was thrown in the command code
Expand All @@ -47,7 +47,7 @@ pub enum FrameworkError<'a, U, E> {
/// General context
ctx: crate::Context<'a, U, E>,
},
/// Panic occured at any phase of command execution after constructing the `crate::Context`.
/// Panic occurred at any phase of command execution after constructing the `crate::Context`.
///
/// This feature is intended as a last-resort safeguard to gracefully print an error message to
/// the user on a panic. Panics should only be thrown for bugs in the code, don't use this for
Expand Down