Skip to content

Commit

Permalink
Disable allowed mentions on certain errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbt365 committed May 26, 2024
1 parent 9f19a7d commit 4eedfa0
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/builtins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod paginate;
#[cfg(any(feature = "chrono", feature = "time"))]
pub use paginate::*;

use crate::{serenity_prelude as serenity, CreateReply};
use crate::{serenity::CreateAllowedMentions, serenity_prelude as serenity, CreateReply};

/// An error handler that logs errors either via the [`tracing`] crate or via a Discord message. Set
/// up a logger (e.g. `env_logger::init()`) or a tracing subscriber
Expand Down Expand Up @@ -50,7 +50,18 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
crate::FrameworkError::Command { ctx, error } => {
let error = error.to_string();
eprintln!("An error occured in a command: {}", error);
ctx.say(error).await?;

let mentions = CreateAllowedMentions::new()
.everyone(false)
.all_roles(false)
.all_users(false);

ctx.send(
CreateReply::default()
.content(error)
.allowed_mentions(mentions),
)
.await?;
}
crate::FrameworkError::SubcommandRequired { ctx } => {
let subcommands = ctx
Expand All @@ -63,8 +74,18 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
"You must specify one of the following subcommands: {}",
subcommands.join(", ")
);
ctx.send(CreateReply::default().content(response).ephemeral(true))
.await?;
let mentions = CreateAllowedMentions::new()
.everyone(false)
.all_roles(false)
.all_users(false);

ctx.send(
CreateReply::default()
.content(response)
.ephemeral(true)
.allowed_mentions(mentions),
)
.await?;
}
crate::FrameworkError::CommandPanic { ctx, payload: _ } => {
// Not showing the payload to the user because it may contain sensitive info
Expand All @@ -91,7 +112,18 @@ pub async fn on_error<U, E: std::fmt::Display + std::fmt::Debug>(
} else {
format!("**{}**\n{}", error, usage)
};
ctx.say(response).await?;

let mentions = CreateAllowedMentions::new()
.everyone(false)
.all_roles(false)
.all_users(false);

ctx.send(
CreateReply::default()
.content(response)
.allowed_mentions(mentions),
)
.await?;
}
crate::FrameworkError::CommandStructureMismatch { ctx, description } => {
tracing::error!(
Expand Down

0 comments on commit 4eedfa0

Please sign in to comment.