aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ionite34 <[email protected]>2022-08-01 01:00:00 -0400
committerGravatar Ionite <[email protected]>2022-08-16 16:38:26 -0400
commit011cfddbbb29a4555c93995ba61ecf6919a4a68e (patch)
treefc02dafa3f033e5ffadd53abc0d8de553e65a9b4
parentAdded microsecond rounding for `humanize_delta` (diff)
Infraction duration fallback if no `last_applied` field
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py8
-rw-r--r--bot/exts/moderation/infraction/_utils.py7
2 files changed, 13 insertions, 2 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index 28aafec2a..cfb585bf5 100644
--- a/bot/exts/moderation/infraction/_scheduler.py
+++ b/bot/exts/moderation/infraction/_scheduler.py
@@ -137,9 +137,15 @@ class InfractionScheduler:
infr_type = infraction["type"]
icon = _utils.INFRACTION_ICONS[infr_type][0]
reason = infraction["reason"]
- expiry = time.format_with_duration(infraction["expires_at"], infraction["last_applied"])
id_ = infraction['id']
+ if "last_applied" in infraction:
+ origin = infraction["last_applied"]
+ else: # Fallback for previous API versions without `last_applied`
+ log.trace(f"No last_applied for infraction {id_}, using inserted_at time.")
+ origin = infraction["inserted_at"]
+ expiry = time.format_with_duration(infraction["expires_at"], origin)
+
if user_reason is None:
user_reason = reason
diff --git a/bot/exts/moderation/infraction/_utils.py b/bot/exts/moderation/infraction/_utils.py
index 23ae517e9..470ce05e1 100644
--- a/bot/exts/moderation/infraction/_utils.py
+++ b/bot/exts/moderation/infraction/_utils.py
@@ -188,7 +188,12 @@ async def notify_infraction(
expires_at = "Never"
duration = "Permanent"
else:
- origin = arrow.get(infraction["last_applied"])
+ if "last_applied" in infraction:
+ origin = infraction["last_applied"]
+ else: # Fallback for previous API versions without `last_applied`
+ log.trace(f"No last_applied for infraction {infraction}, using inserted_at time.")
+ origin = infraction["inserted_at"]
+ origin = arrow.get(origin)
expiry = arrow.get(infraction["expires_at"])
expires_at = time.format_relative(expiry)
duration = time.humanize_delta(origin, expiry, max_units=2)