remove reactions from messages older than n days
This commit is contained in:
parent
a8d6a2b8d7
commit
94b12a1069
9 changed files with 86 additions and 18 deletions
39
src/handlers/event/block_reaction.rs
Normal file
39
src/handlers/event/block_reaction.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use crate::Data;
|
||||
|
||||
use chrono::Duration;
|
||||
use eyre::{Context as _, Result};
|
||||
use log::{debug, trace};
|
||||
use poise::serenity_prelude::{Context, Reaction, Timestamp};
|
||||
|
||||
pub async fn handle(ctx: &Context, reaction: &Reaction, data: &Data) -> Result<()> {
|
||||
let reaction_type = reaction.emoji.clone();
|
||||
let reactor = reaction.user_id;
|
||||
let message = reaction.message(ctx).await.wrap_err_with(|| {
|
||||
format!(
|
||||
"Couldn't get message {} from reaction! We won't be able to check if it's old",
|
||||
reaction.message_id
|
||||
)
|
||||
})?;
|
||||
|
||||
let time_sent = message.timestamp.to_utc();
|
||||
let age = Timestamp::now().signed_duration_since(time_sent);
|
||||
let max_days = Duration::days(data.config.discord.days_to_delete_reaction);
|
||||
|
||||
if age >= max_days {
|
||||
// NOTE: if we for some reason **didn't** get the user_id associated with the reaction,
|
||||
// this will clear **all** reactions of this type. this is intentional as older reactions
|
||||
// being removed > harmful reactions being kept
|
||||
debug!(
|
||||
"Removing reaction {reaction_type} from message {}",
|
||||
message.id
|
||||
);
|
||||
message.delete_reaction(ctx, reactor, reaction_type).await?;
|
||||
} else {
|
||||
trace!(
|
||||
"Keeping reaction {reaction_type} for message {}",
|
||||
message.id
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -5,6 +5,7 @@ use poise::serenity_prelude::{ActivityData, Context, FullEvent, OnlineStatus};
|
|||
use poise::FrameworkContext;
|
||||
|
||||
mod analyze_logs;
|
||||
mod block_reaction;
|
||||
mod delete_on_reaction;
|
||||
mod eta;
|
||||
mod expand_link;
|
||||
|
@ -71,6 +72,8 @@ pub async fn handle(
|
|||
add_reaction.message_id.to_string(),
|
||||
add_reaction.user_id.unwrap_or_default().to_string()
|
||||
);
|
||||
|
||||
block_reaction::handle(ctx, add_reaction, data).await?;
|
||||
delete_on_reaction::handle(ctx, add_reaction).await?;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue