feat: delete messages on ❌ again
Signed-off-by: seth <getchoo@tuta.io>
This commit is contained in:
parent
30cc4a6220
commit
368b5e0cb0
3 changed files with 38 additions and 2 deletions
25
src/handlers/event/delete.rs
Normal file
25
src/handlers/event/delete.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use color_eyre::eyre::{Context as _, Result};
|
||||
use poise::serenity_prelude::{Context, InteractionType, Reaction};
|
||||
|
||||
pub async fn handle(ctx: &Context, reaction: &Reaction) -> Result<()> {
|
||||
let user = reaction
|
||||
.user(ctx)
|
||||
.await
|
||||
.wrap_err_with(|| "Couldn't fetch user from reaction!")?;
|
||||
|
||||
let message = reaction
|
||||
.message(ctx)
|
||||
.await
|
||||
.wrap_err_with(|| "Couldn't fetch message from reaction!")?;
|
||||
|
||||
if let Some(interaction) = &message.interaction {
|
||||
if interaction.kind == InteractionType::ApplicationCommand
|
||||
&& interaction.user == user
|
||||
&& reaction.emoji.unicode_eq("❌")
|
||||
{
|
||||
message.delete(ctx).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -3,7 +3,7 @@ use crate::{consts, utils};
|
|||
use color_eyre::eyre::Result;
|
||||
use poise::serenity_prelude::{Context, Message};
|
||||
|
||||
pub async fn handle_eta(ctx: &Context, message: &Message) -> Result<()> {
|
||||
pub async fn handle(ctx: &Context, message: &Message) -> Result<()> {
|
||||
if !message.content.contains(" eta ") {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use color_eyre::eyre::{Report, Result};
|
|||
use poise::serenity_prelude::Context;
|
||||
use poise::{Event, FrameworkContext};
|
||||
|
||||
mod delete;
|
||||
mod eta;
|
||||
|
||||
pub async fn handle(
|
||||
|
@ -17,7 +18,17 @@ pub async fn handle(
|
|||
log::info!("Logged in as {}!", data_about_bot.user.name)
|
||||
}
|
||||
|
||||
Event::Message { new_message } => eta::handle_eta(ctx, new_message).await?,
|
||||
Event::Message { new_message } => {
|
||||
// ignore new messages from bots
|
||||
// NOTE: the webhook_id check allows us to still respond to PK users
|
||||
if new_message.author.bot && new_message.webhook_id.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
eta::handle(ctx, new_message).await?
|
||||
}
|
||||
|
||||
Event::ReactionAdd { add_reaction } => delete::handle(ctx, add_reaction).await?,
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue