Skip to content

Commit

Permalink
safety check to disallow message delete < 14days
Browse files Browse the repository at this point in the history
  • Loading branch information
rtk-rnjn committed Oct 3, 2023
1 parent a8c7db6 commit 03fee06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion cogs/mod/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,15 @@ async def do_removal(
limit = max(1, min(limit or 1, 2000))

passed_before = ctx.message if before is None else discord.Object(id=before)
passed_after = discord.Object(id=after) if after is not None else None
two_weeks_before = ctx.message.created_at - datetime.timedelta(weeks=2)
two_weeks_before_snowflake = discord.utils.time_snowflake(two_weeks_before)

if after:
_after = max(two_weeks_before_snowflake, after)
passed_after = discord.Object(id=_after)
else:
passed_after = None

try:
deleted = await ctx.channel.purge(limit=limit, before=passed_before, after=passed_after, check=predicate)
except discord.HTTPException as e:
Expand Down
2 changes: 1 addition & 1 deletion cogs/mod/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ async def _regex(self, ctx: Context, pattern: str | None = None, search: int | N
pattern = pattern or r".*"

def check(m: discord.Message) -> bool:
return bool(re.match(rf"{pattern}", m.content))
return bool(re.match(rf"{pattern}", m.content)) and m.created_at > arrow.utcnow().shift(days=-14).datetime

await mod_method.do_removal(ctx, search, check)

Expand Down

0 comments on commit 03fee06

Please sign in to comment.