diff options
| author | 2019-09-13 14:06:30 +0200 | |
|---|---|---|
| committer | 2019-09-13 14:06:30 +0200 | |
| commit | ccb37f310bdf936223a83707c2541f98e0e61354 (patch) | |
| tree | e4b0553d44434651e3e9eaf43f04c2689e06b9a0 /bot/utils/moderation.py | |
| parent | Update bot cog with recent changes. (diff) | |
Fix bugs and inconsistencies in moderation cog
Recent changes and updates to the moderation cog introduced some
inconsistencies that were causing bugs or differences in behavior
between very similar commands.
I've remedied the problems by:
- Consistently making sure we stop if a post_infraction API call fails;
- Factoring out the check for active infractions to a utility function;
- Updating commands that expected a pre-migration API response format.
In addition, I've also added function annotations.
Diffstat (limited to 'bot/utils/moderation.py')
| -rw-r--r-- | bot/utils/moderation.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/bot/utils/moderation.py b/bot/utils/moderation.py index c1eb98dd6..152f9d538 100644 --- a/bot/utils/moderation.py +++ b/bot/utils/moderation.py @@ -44,3 +44,23 @@ async def post_infraction( return return response + + +async def already_has_active_infraction(ctx: Context, user: Union[Member, Object, User], type: str) -> bool: + """Checks if a user already has an active infraction of the given type.""" + active_infractions = await ctx.bot.api_client.get( + 'bot/infractions', + params={ + 'active': 'true', + 'type': type, + 'user__id': str(user.id) + } + ) + if active_infractions: + await ctx.send( + f":x: According to my records, this user already has a {type} infraction. " + f"See infraction **#{active_infractions[0]['id']}**." + ) + return True + else: + return False |