diff options
| author | 2020-09-24 17:05:22 +0800 | |
|---|---|---|
| committer | 2020-09-24 17:07:33 +0800 | |
| commit | f9971be6251dc083332c2adc4bffb746f2c8ccf2 (patch) | |
| tree | 1328f748c28a49216c9a2a510fbdf77348d329f5 | |
| parent | Add append subcommand for infraction group (diff) | |
Add get_latest_infraction utility function
| -rw-r--r-- | bot/exts/moderation/infraction/management.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/bot/exts/moderation/infraction/management.py b/bot/exts/moderation/infraction/management.py index 4e31947d4..7596d2ec1 100644 --- a/bot/exts/moderation/infraction/management.py +++ b/bot/exts/moderation/infraction/management.py @@ -338,6 +338,20 @@ class ModManagement(commands.Cog): return lines.strip() + async def get_latest_infraction(self, actor: int) -> t.Optional[dict]: + """Obtains the latest infraction from an actor.""" + params = { + "actor__id": actor, + "ordering": "-inserted_at" + } + + infractions = await self.bot.api_client.get("bot/infractions", params=params) + + if infractions: + return infractions[0] + + return None + # endregion # This cannot be static (must have a __func__ attribute). |