aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2021-10-16 15:38:39 +0100
committerGravatar GitHub <[email protected]>2021-10-16 15:38:39 +0100
commit3589eead93b2c6ef7f8f7287859c934d43730d31 (patch)
tree8a07d86f39fa9c83b2202ecb5af7345d20bbbaae
parentMerge pull request #1872 from python-discord/experiments/isort (diff)
parentMerge branch 'main' into ks123/bugfix/reapply-infraction (diff)
Merge pull request #1875 from python-discord/ks123/bugfix/reapply-infraction
Do not try to calculate expiry if infraction is permanent on reapply
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index 2a1ccb9d4..fc915016c 100644
--- a/bot/exts/moderation/infraction/_scheduler.py
+++ b/bot/exts/moderation/infraction/_scheduler.py
@@ -81,12 +81,16 @@ class InfractionScheduler:
apply_coro: t.Optional[t.Awaitable]
) -> None:
"""Reapply an infraction if it's still active or deactivate it if less than 60 sec left."""
- # Calculate the time remaining, in seconds, for the mute.
- expiry = dateutil.parser.isoparse(infraction["expires_at"]).replace(tzinfo=None)
- delta = (expiry - datetime.utcnow()).total_seconds()
+ if infraction["expires_at"] is not None:
+ # Calculate the time remaining, in seconds, for the mute.
+ expiry = dateutil.parser.isoparse(infraction["expires_at"]).replace(tzinfo=None)
+ delta = (expiry - datetime.utcnow()).total_seconds()
+ else:
+ # If the infraction is permanent, it is not possible to get the time remaining.
+ delta = None
- # Mark as inactive if less than a minute remains.
- if delta < 60:
+ # Mark as inactive if the infraction is not permanent and less than a minute remains.
+ if delta is not None and delta < 60:
log.info(
"Infraction will be deactivated instead of re-applied "
"because less than 1 minute remains."