diff options
| author | 2019-12-20 02:15:32 -0300 | |
|---|---|---|
| committer | 2019-12-20 02:15:32 -0300 | |
| commit | e9ed6442e01f78f27ec7404759bb45999d8b8104 (patch) | |
| tree | 33b6dfca75926f2d8a092353410ca5be62b4d78b | |
| parent | Make post_infraction try to `post_user` if user doesn't exist (diff) | |
Refactor minor details in `post_infraction`
| -rw-r--r-- | bot/cogs/moderation/utils.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/bot/cogs/moderation/utils.py b/bot/cogs/moderation/utils.py index 994bdeaa3..1b683b4a3 100644 --- a/bot/cogs/moderation/utils.py +++ b/bot/cogs/moderation/utils.py @@ -108,13 +108,14 @@ async def post_infraction( payload['expires_at'] = expires_at.isoformat() # Try to apply the infraction. If it fails because the user doesn't exist, try to add it. - for attempt in range(2): + for should_post_user in (True, False): try: response = await ctx.bot.api_client.post('bot/infractions', json=payload) + return response except ResponseCodeError as exp: if exp.status == 400 and 'user'in exp.response_json: - # Only once attempt to try to add the user to the database, not two: - if attempt > 0 or await post_user(ctx, user) is None: + # Only one attempt to add the user to the database, not two: + if not should_post_user or await post_user(ctx, user) is None: return else: log.exception("An unexpected ResponseCodeError occurred while adding an infraction:") @@ -123,8 +124,6 @@ async def post_infraction( else: break - return response - async def has_active_infraction(ctx: Context, user: MemberObject, infr_type: str) -> bool: """Checks if a user already has an active infraction of the given type.""" |