From 03457101555fe7501d231676edf7701ef4f23b6b Mon Sep 17 00:00:00 2001 From: keiveulbugs <114590495+keiveulbugs@users.noreply.github.com> Date: Sun, 16 Jun 2024 12:28:24 +0200 Subject: [PATCH 1/5] Remove `t` from `butt` typo (#285) After feeling a bit sad that it didn't output butts, I decided to change this small spelling error. --- src/builtins/pretty_help.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/builtins/pretty_help.rs b/src/builtins/pretty_help.rs index 08f844846ca..2125f9c76ee 100644 --- a/src/builtins/pretty_help.rs +++ b/src/builtins/pretty_help.rs @@ -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( ctx: crate::Context<'_, U, E>, From 47bc6f1fc57418f77c29baa5fcc9ae91fe8cc20e Mon Sep 17 00:00:00 2001 From: jamesbt365 Date: Sun, 21 Jul 2024 20:17:20 +0100 Subject: [PATCH 2/5] fix numerous typos of "occurred" (#287) --- src/slash_argument/slash_macro.rs | 6 +++--- src/structs/framework_error.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/slash_argument/slash_macro.rs b/src/slash_argument/slash_macro.rs index e4b0003a06b..d25058b449d 100644 --- a/src/slash_argument/slash_macro.rs +++ b/src/slash_argument/slash_macro.rs @@ -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, /// Original input string input: String, @@ -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, @@ -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!(), diff --git a/src/structs/framework_error.rs b/src/structs/framework_error.rs index 441a654b6e4..f20e44d1df6 100644 --- a/src/structs/framework_error.rs +++ b/src/structs/framework_error.rs @@ -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 @@ -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 From 2a2b4c14f5ea0695d61a16e002199edcd06f7602 Mon Sep 17 00:00:00 2001 From: Andrew Silver Date: Wed, 11 Sep 2024 14:56:39 +1000 Subject: [PATCH 3/5] Allow edited interactions to be sent without removing existing embeds Fixes #300 # Conflicts: # src/reply/builder.rs --- src/reply/builder.rs | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/reply/builder.rs b/src/reply/builder.rs index 8610c3f2cd2..5614d69a388 100644 --- a/src/reply/builder.rs +++ b/src/reply/builder.rs @@ -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, - embeds: Vec, + embeds: Option>, attachments: Vec, pub(crate) ephemeral: Option, components: Option>, @@ -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(|| Default::default()).push(embed); + self + } + + /// Set embeds for the message. + /// + /// Any previously set embeds will be overwritten. + pub fn embeds(mut self, embeds: Vec) -> Self { + self.embeds = Some(embeds); self } @@ -108,8 +117,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`] @@ -130,7 +142,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) } @@ -168,8 +182,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`] @@ -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`] @@ -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); } @@ -235,6 +258,6 @@ impl CreateReply { builder = builder.add_file(attachment); } - builder.embeds(embeds) + builder } } From 7efd3f6fccec5087946ea5d59958816bd692b3f6 Mon Sep 17 00:00:00 2001 From: Andrew Silver Date: Wed, 11 Sep 2024 15:05:27 +1000 Subject: [PATCH 4/5] Slight reorganization for consistency sake --- src/reply/builder.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/reply/builder.rs b/src/reply/builder.rs index 5614d69a388..a437647159b 100644 --- a/src/reply/builder.rs +++ b/src/reply/builder.rs @@ -114,12 +114,12 @@ impl CreateReply { if let Some(components) = components { builder = builder.components(components); } - if let Some(ephemeral) = ephemeral { - builder = builder.ephemeral(ephemeral); - } if let Some(embeds) = embeds { builder = builder.embeds(embeds); } + if let Some(ephemeral) = ephemeral { + builder = builder.ephemeral(ephemeral); + } builder.add_files(attachments) } @@ -142,12 +142,12 @@ impl CreateReply { if let Some(content) = content { builder = builder.content(content); } - if let Some(embeds) = embeds { - 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); } @@ -179,12 +179,12 @@ impl CreateReply { if let Some(components) = components { builder = builder.components(components); } - if let Some(allowed_mentions) = allowed_mentions { - builder = builder.allowed_mentions(allowed_mentions); - } if let Some(embeds) = embeds { builder = builder.embeds(embeds); } + if let Some(allowed_mentions) = allowed_mentions { + builder = builder.allowed_mentions(allowed_mentions); + } builder } From 42f682320680ebe7e62c90b394fa87c4cb9b158b Mon Sep 17 00:00:00 2001 From: Andrew Silver Date: Wed, 11 Sep 2024 23:45:57 +1000 Subject: [PATCH 5/5] Switched to Vec::new for the builder to mirror Serenity's builder pattern --- src/reply/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reply/builder.rs b/src/reply/builder.rs index a437647159b..1b5b01e8c58 100644 --- a/src/reply/builder.rs +++ b/src/reply/builder.rs @@ -32,7 +32,7 @@ impl CreateReply { /// 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.get_or_insert_with(|| Default::default()).push(embed); + self.embeds.get_or_insert_with(Vec::new).push(embed); self }