Merge 10bde98e4b
into 04faac4de3
This commit is contained in:
commit
074976a0ba
5 changed files with 24 additions and 37 deletions
22
src/commands/general/delete_interaction.rs
Normal file
22
src/commands/general/delete_interaction.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use poise::serenity_prelude::{Message, MessageInteractionMetadata::Command};
|
||||
|
||||
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(Command(interaction)) = message.interaction_metadata.as_deref() 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 help;
|
||||
pub mod joke;
|
||||
pub mod members;
|
||||
|
|
|
@ -34,6 +34,7 @@ pub type Command = poise::Command<Data, Error>;
|
|||
|
||||
pub fn all() -> Vec<Command> {
|
||||
vec![
|
||||
general!(delete_interaction),
|
||||
general!(help),
|
||||
general!(joke),
|
||||
general!(members),
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
use eyre::{Context as _, Result};
|
||||
use log::trace;
|
||||
use poise::serenity_prelude::{Context, MessageInteractionMetadata, 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(MessageInteractionMetadata::Command(metadata)) =
|
||||
message.interaction_metadata.as_deref()
|
||||
{
|
||||
if metadata.user == user && reaction.emoji.unicode_eq("❌") {
|
||||
trace!("Deleting our own message at the request of {}", user.tag());
|
||||
message.delete(ctx).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -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?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue