aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar PureFunctor <[email protected]>2020-09-24 17:11:21 +0800
committerGravatar PureFunctor <[email protected]>2020-09-24 17:11:21 +0800
commit1ab0084581859a0d8e938b9292bdb86ce9caf523 (patch)
tree12bbd3461493254fddd845ae61aa40b8940da4d1
parentAdd get_latest_infraction utility function (diff)
Refactor routine for obtaining latest infraction
-rw-r--r--bot/exts/moderation/infraction/management.py36
1 files changed, 14 insertions, 22 deletions
diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py
index 7596d2ec1..b841b11c3 100644
--- a/bot/exts/moderation/infraction/management.py
+++ b/bot/exts/moderation/infraction/management.py
@@ -74,20 +74,16 @@ class ModManagement(commands.Cog):
timestamp can be provided for the duration.
"""
if isinstance(infraction_id, str):
- params = {
- "actor__id": ctx.author.id,
- "ordering": "-inserted_at"
- }
- infractions = await self.bot.api_client.get("bot/infractions", params=params)
-
- if infractions:
- old_infraction = infractions[0]
- infraction_id = old_infraction["id"]
- else:
- await ctx.send(
+ old_infraction = await self.get_latest_infraction(ctx.author.id)
+
+ if old_infraction is None:
+ ctx.send(
":x: Couldn't find most recent infraction; you have never given an infraction."
)
return
+
+ infraction_id = old_infraction["id"]
+
else:
old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}")
@@ -129,20 +125,16 @@ class ModManagement(commands.Cog):
# Retrieve the previous infraction for its information.
if isinstance(infraction_id, str):
- params = {
- "actor__id": ctx.author.id,
- "ordering": "-inserted_at"
- }
- infractions = await self.bot.api_client.get("bot/infractions", params=params)
-
- if infractions:
- old_infraction = infractions[0]
- infraction_id = old_infraction["id"]
- else:
- await ctx.send(
+ old_infraction = await self.get_latest_infraction(ctx.author.id)
+
+ if old_infraction is None:
+ ctx.send(
":x: Couldn't find most recent infraction; you have never given an infraction."
)
return
+
+ infraction_id = old_infraction["id"]
+
else:
old_infraction = await self.bot.api_client.get(f"bot/infractions/{infraction_id}")