Skip to content

Commit

Permalink
feat: add suppress embeds command
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Feb 10, 2024
1 parent 859d641 commit a01ba79
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub fn to_vec() -> Vec<
command!(useful, self_timeout),
command!(useful, self_timeout, transparency),
command!(useful, translate),
command!(useful, suppress_embeds),
command!(fun, owo),
command!(fun, pomelo),
command!(fun, shiggy),
Expand Down
1 change: 1 addition & 0 deletions src/commands/useful/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod lighthouse;
pub mod self_timeout;
pub mod suppress_embeds;
pub mod translate;
46 changes: 46 additions & 0 deletions src/commands/useful/suppress_embeds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use color_eyre::eyre::Result;
use poise::serenity_prelude as serenity;

use crate::Context;

/// Translates a message
#[poise::command(context_menu_command = "Suppress Embeds", guild_only, ephemeral)]
#[allow(clippy::redundant_closure_for_method_calls)]
pub async fn suppress_embeds(ctx: Context<'_>, message: serenity::Message) -> Result<()> {
ctx.defer_ephemeral().await?;

if ctx.author() == &message.author
|| ctx
.author_member()
.await
.is_some_and(|m| m.permissions(ctx).is_ok_and(|p| p.manage_messages()))
{
let suppressed = message
.flags
.is_some_and(|flags| flags.contains(serenity::MessageFlags::SUPPRESS_EMBEDS));

ctx.http()
.edit_message(
message.channel_id,
message.id,
&serenity::EditMessage::new().suppress_embeds(!suppressed),
Vec::new(),
)
.await?;

ctx.say(format!(
"Embeds have been {} on this message.",
if suppressed {
"unsuppressed"
} else {
"suppressed"
}
))
.await?;
} else {
ctx.say("You do not have permissions to suppress embeds on this message!")
.await?;
}

Ok(())
}

0 comments on commit a01ba79

Please sign in to comment.