aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar mbaruh <[email protected]>2021-12-02 22:34:06 +0200
committerGravatar mbaruh <[email protected]>2021-12-02 22:34:06 +0200
commit89f991374b1d0e9d9f7312c3c715129a8bba6ac2 (patch)
tree2bb9ed9efab7e7237de3e215d413c9a601ea532e
parentSimplify cache usage (diff)
Update _build_predicate to require a limit
-rw-r--r--bot/exts/moderation/clean.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/bot/exts/moderation/clean.py b/bot/exts/moderation/clean.py
index bb6e44d6f..a08788fd6 100644
--- a/bot/exts/moderation/clean.py
+++ b/bot/exts/moderation/clean.py
@@ -119,11 +119,11 @@ class Clean(Cog):
@staticmethod
def _build_predicate(
+ first_limit: datetime,
+ second_limit: Optional[datetime] = None,
bots_only: bool = False,
users: Optional[list[User]] = None,
regex: Optional[re.Pattern] = None,
- first_limit: Optional[datetime] = None,
- second_limit: Optional[datetime] = None,
) -> Predicate:
"""Return the predicate that decides whether to delete a given message."""
def predicate_bots_only(message: Message) -> bool:
@@ -164,20 +164,18 @@ class Clean(Cog):
predicates = []
# Set up the correct predicate
+ if second_limit:
+ predicates.append(predicate_range) # Delete messages in the specified age range
+ else:
+ predicates.append(predicate_after) # Delete messages older than the specified age
+
if bots_only:
predicates.append(predicate_bots_only) # Delete messages from bots
if users:
predicates.append(predicate_specific_users) # Delete messages from specific user
if regex:
predicates.append(predicate_regex) # Delete messages that match regex
- # Add up to one of the following:
- if second_limit:
- predicates.append(predicate_range) # Delete messages in the specified age range
- elif first_limit:
- predicates.append(predicate_after) # Delete messages older than specific message
- if not predicates:
- return lambda m: True
if len(predicates) == 1:
return predicates[0]
return lambda m: all(pred(m) for pred in predicates)
@@ -383,7 +381,7 @@ class Clean(Cog):
first_limit, second_limit = sorted([first_limit, second_limit])
# Needs to be called after standardizing the input.
- predicate = self._build_predicate(bots_only, users, regex, first_limit, second_limit)
+ predicate = self._build_predicate(first_limit, second_limit, bots_only, users, regex)
# Delete the invocation first
await self._delete_invocation(ctx)