Add a context menu button to delete interactions
This commit is contained in:
parent
94571c64bc
commit
3d4396ac8b
4 changed files with 27 additions and 5 deletions
23
src/commands/general/delete_interaction.rs
Normal file
23
src/commands/general/delete_interaction.rs
Normal 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(())
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
pub mod delete_interaction;
|
||||
pub mod joke;
|
||||
pub mod members;
|
||||
pub mod ping;
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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?;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue