aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Johannes Christ <[email protected]>2019-01-06 17:32:13 +0100
committerGravatar Johannes Christ <[email protected]>2019-01-06 17:32:13 +0100
commit809348d633172c3c2cfd785cd1d6aa0331e48e74 (patch)
tree81a2bf4af6365dd679a5e32534d7d87e6eafc3da
parentRemove unused import, use `tuple`. (diff)
Move note and warning creation to Django API backend.
-rw-r--r--bot/cogs/moderation.py9
-rw-r--r--bot/utils/moderation.py24
2 files changed, 16 insertions, 17 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py
index 7cc2c9b86..d725755cd 100644
--- a/bot/cogs/moderation.py
+++ b/bot/cogs/moderation.py
@@ -87,7 +87,9 @@ class Moderation(Scheduler):
reason=reason
)
- response_object = await post_infraction(ctx, user, type="warning", reason=reason)
+ response_object = await post_infraction(
+ ctx, user, type="warning", reason=reason
+ )
if response_object is None:
return
@@ -386,7 +388,10 @@ class Moderation(Scheduler):
:param reason: The reason for the warning.
"""
- response_object = await post_infraction(ctx, user, type="warning", reason=reason, hidden=True)
+ response_object = await post_infraction(
+ ctx, user, type="warning", reason=reason, hidden=True
+ )
+
if response_object is None:
return
diff --git a/bot/utils/moderation.py b/bot/utils/moderation.py
index 724b455bc..459fe6eb3 100644
--- a/bot/utils/moderation.py
+++ b/bot/utils/moderation.py
@@ -13,33 +13,27 @@ 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
+ ctx: Context, user: Union[Member, Object, User],
+ type: str, reason: str, duration: str = None, hidden: bool = False
):
payload = {
- "type": type,
+ "actor": ctx.message.author.id,
+ "hidden": hidden,
"reason": reason,
- "user_id": str(user.id),
- "actor_id": str(ctx.message.author.id),
- "hidden": hidden
+ "type": type,
+ "user": user.id
}
if duration:
payload['duration'] = duration
try:
- response = await ctx.bot.http_session.post(
- URLs.site_infractions,
- headers=HEADERS,
- json=payload
+ response = await ctx.bot.api_client.post(
+ 'bot/infractions', json=payload
)
except ClientError:
log.exception("There was an error adding an infraction.")
await ctx.send(":x: There was an error adding the infraction.")
return
- response_object = await response.json()
- if "error_code" in response_object:
- await ctx.send(f":x: There was an error adding the infraction: {response_object['error_message']}")
- return
-
- return response_object
+ return response