Revert "block_reaction: avoid rate limits"
This reverts commit 3503dda44d
.
This commit is contained in:
parent
84a7cfe151
commit
d25776d45b
1 changed files with 28 additions and 17 deletions
|
@ -1,34 +1,37 @@
|
||||||
use crate::{config::Config, consts::Colors, Data};
|
use crate::{config::Config, consts::Colors, Data};
|
||||||
|
|
||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use eyre::Result;
|
use eyre::{Context as _, Result};
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
use poise::serenity_prelude::{
|
use poise::serenity_prelude::{
|
||||||
Context, CreateEmbed, CreateMessage, Mentionable, Reaction, Timestamp,
|
Context, CreateEmbed, CreateMessage, Mentionable, Message, Reaction, Timestamp, UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
async fn log_old_react(ctx: &Context, config: &Config, reaction: &Reaction) -> Result<()> {
|
async fn log_old_react(
|
||||||
|
ctx: &Context,
|
||||||
|
config: &Config,
|
||||||
|
reactor: &Option<UserId>,
|
||||||
|
message: &Message,
|
||||||
|
) -> Result<()> {
|
||||||
let Some(log_channel) = config.discord.channels.log_channel_id else {
|
let Some(log_channel) = config.discord.channels.log_channel_id else {
|
||||||
debug!("Not logging old reaction; no log channel is set!");
|
debug!("Not logging old reaction; no log channel is set!");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let message_link = reaction
|
|
||||||
.message_id
|
|
||||||
.link(reaction.channel_id, reaction.guild_id);
|
|
||||||
|
|
||||||
let mut embed = CreateEmbed::new()
|
let mut embed = CreateEmbed::new()
|
||||||
.title("Old message reaction!")
|
.title("Old message reaction!")
|
||||||
.color(Colors::Red);
|
.color(Colors::Red);
|
||||||
|
|
||||||
if let Some(reactor) = reaction.user_id {
|
if let Some(reactor) = reactor {
|
||||||
embed = embed.description(format!(
|
embed = embed.description(format!(
|
||||||
"{} just reacted to {message_link}!",
|
"{} just reacted to {}!",
|
||||||
reactor.mention(),
|
reactor.mention(),
|
||||||
|
message.link()
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
embed = embed.description(format!(
|
embed = embed.description(format!(
|
||||||
"Someone (or something...) just reacted to {message_link}!"
|
"Someone (or something...) just reacted to {}!",
|
||||||
|
message.link()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,25 +43,33 @@ async fn log_old_react(ctx: &Context, config: &Config, reaction: &Reaction) -> R
|
||||||
|
|
||||||
pub async fn handle(ctx: &Context, reaction: &Reaction, data: &Data) -> Result<()> {
|
pub async fn handle(ctx: &Context, reaction: &Reaction, data: &Data) -> Result<()> {
|
||||||
let reaction_type = reaction.emoji.clone();
|
let reaction_type = reaction.emoji.clone();
|
||||||
let message_id = reaction.message_id;
|
let reactor = reaction.user_id;
|
||||||
trace!("Checking if we should block reaction on {message_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_id.created_at().to_utc();
|
let time_sent = message.timestamp.to_utc();
|
||||||
let age = Timestamp::now().signed_duration_since(time_sent);
|
let age = Timestamp::now().signed_duration_since(time_sent);
|
||||||
let max_days = Duration::days(data.config.discord.days_to_delete_reaction);
|
let max_days = Duration::days(data.config.discord.days_to_delete_reaction);
|
||||||
|
|
||||||
if age >= max_days {
|
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!(
|
debug!(
|
||||||
"Removing reaction {reaction_type} from message {}",
|
"Removing reaction {reaction_type} from message {}",
|
||||||
message_id
|
message.id
|
||||||
);
|
);
|
||||||
|
message.delete_reaction(ctx, reactor, reaction_type).await?;
|
||||||
|
|
||||||
reaction.delete(ctx).await?;
|
log_old_react(ctx, &data.config, &reactor, &message).await?;
|
||||||
log_old_react(ctx, &data.config, reaction).await?;
|
|
||||||
} else {
|
} else {
|
||||||
trace!(
|
trace!(
|
||||||
"Keeping reaction {reaction_type} for message {}",
|
"Keeping reaction {reaction_type} for message {}",
|
||||||
message_id
|
message.id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue