diff options
| author | 2018-11-21 18:20:51 -0500 | |
|---|---|---|
| committer | 2018-11-22 00:20:51 +0100 | |
| commit | 1fdab40f364416ae6d69afb14fb6658f591aa189 (patch) | |
| tree | d6c8f976bc157a2ee4375ec03b5befbff820f866 /bot/utils/moderation.py | |
| parent | Add note support for bb watch, moderation API call refactor (#201) (diff) | |
Remove duration from JSON payload when not specified (#204)
* Remove duration from JSON payload when not specified
* Drop whitespace.
Diffstat (limited to '')
| -rw-r--r-- | bot/utils/moderation.py | 20 | 
1 files changed, 12 insertions, 8 deletions
| diff --git a/bot/utils/moderation.py b/bot/utils/moderation.py index 1b36b4118..724b455bc 100644 --- a/bot/utils/moderation.py +++ b/bot/utils/moderation.py @@ -15,18 +15,22 @@ HEADERS = {"X-API-KEY": Keys.site_api}  async def post_infraction(      ctx: Context, user: Union[Member, Object, User], type: str, reason: str, duration: str = None, hidden: bool = False  ): + +    payload = { +        "type": type, +        "reason": reason, +        "user_id": str(user.id), +        "actor_id": str(ctx.message.author.id), +        "hidden": hidden +    } +    if duration: +        payload['duration'] = duration +      try:          response = await ctx.bot.http_session.post(              URLs.site_infractions,              headers=HEADERS, -            json={ -                "type": type, -                "reason": reason, -                "duration": duration, -                "user_id": str(user.id), -                "actor_id": str(ctx.message.author.id), -                "hidden": hidden, -            }, +            json=payload          )      except ClientError:          log.exception("There was an error adding an infraction.") | 
