Make requested changes + allow deleting with Manage Messages perm

This commit is contained in:
TheKodeToad 2024-05-06 18:05:04 +01:00
parent 3d4396ac8b
commit 1491705cbd
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
3 changed files with 17 additions and 39 deletions

View file

@ -1,17 +1,30 @@
use eyre::Result;
use poise::serenity_prelude::Message;
use poise::serenity_prelude::{InteractionType, Message, Permissions};
use crate::{Context, Error};
#[poise::command(context_menu_command = "Delete command", ephemeral)]
pub async fn delete_interaction(ctx: Context<'_>, message: Message) -> Result<(), Error> {
const NO_COMMAND: &str = "❌ This message does not contain a command";
let Some(interaction) = &message.interaction else {
ctx.say("❌ This message does not contain a command")
.await?;
ctx.say(NO_COMMAND).await?;
return Ok(());
};
if interaction.user.id != ctx.author().id {
if interaction.kind != InteractionType::Command {
ctx.say(NO_COMMAND).await?;
return Ok(());
}
if !(interaction.user.id == ctx.author().id
|| interaction
.member
.as_ref()
.and_then(|m| m.permissions)
.map(|p| p.contains(Permissions::MANAGE_MESSAGES))
.unwrap_or(false))
{
ctx.say("❌ You cannot delete commands run by other users")
.await?;
return Ok(());

View file

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

View file

@ -5,7 +5,6 @@ use poise::serenity_prelude::{ActivityData, Context, FullEvent, OnlineStatus};
use poise::FrameworkContext;
mod analyze_logs;
mod delete_on_reaction;
mod eta;
mod expand_link;
mod give_role;
@ -66,16 +65,6 @@ pub async fn handle(
analyze_logs::handle(ctx, new_message, data).await?;
}
FullEvent::ReactionAdd { add_reaction } => {
trace!(
"Received reaction {} on message {} from {}",
add_reaction.emoji,
add_reaction.message_id.to_string(),
add_reaction.user_id.unwrap_or_default().to_string()
);
delete_on_reaction::handle(ctx, add_reaction).await?;
}
FullEvent::ThreadCreate { thread } => {
trace!("Received thread {}", thread.id);
support_onboard::handle(ctx, thread).await?;