Add a context menu button to delete interactions

This commit is contained in:
TheKodeToad 2024-05-05 15:32:38 +01:00
parent 94571c64bc
commit 3d4396ac8b
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
4 changed files with 27 additions and 5 deletions

View file

@ -0,0 +1,23 @@
use eyre::Result;
use poise::serenity_prelude::Message;
use crate::{Context, Error};
#[poise::command(context_menu_command = "Delete command", ephemeral)]
pub async fn delete_interaction(ctx: Context<'_>, message: Message) -> Result<(), Error> {
let Some(interaction) = &message.interaction else {
ctx.say("❌ This message does not contain a command")
.await?;
return Ok(());
};
if interaction.user.id != ctx.author().id {
ctx.say("❌ You cannot delete commands run by other users")
.await?;
return Ok(());
}
message.delete(ctx).await?;
ctx.say("🗑️ Deleted command!").await?;
Ok(())
}

View file

@ -1,3 +1,4 @@
pub mod delete_interaction;
pub mod joke;
pub mod members;
pub mod ping;

View file

@ -34,6 +34,7 @@ pub type Command = poise::Command<Data, Error>;
pub fn all() -> Vec<Command> {
vec![
general!(delete_interaction),
general!(joke),
general!(members),
general!(ping),

View file

@ -1,6 +1,6 @@
use eyre::{Context as _, Result};
use log::trace;
use poise::serenity_prelude::{Context, InteractionType, Reaction};
use poise::serenity_prelude::{Context, Reaction};
pub async fn handle(ctx: &Context, reaction: &Reaction) -> Result<()> {
let user = reaction
@ -14,10 +14,7 @@ pub async fn handle(ctx: &Context, reaction: &Reaction) -> Result<()> {
.wrap_err("Couldn't fetch message from reaction!")?;
if let Some(interaction) = &message.interaction {
if interaction.kind == InteractionType::Command
&& interaction.user == user
&& reaction.emoji.unicode_eq("")
{
if interaction.user == user && reaction.emoji.unicode_eq("") {
trace!("Deleting our own message at the request of {}", user.tag());
message.delete(ctx).await?;
}