aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils/moderation.py
diff options
context:
space:
mode:
authorGravatar scragly <[email protected]>2019-10-15 08:37:57 +1000
committerGravatar GitHub <[email protected]>2019-10-15 08:37:57 +1000
commit806c494a9794b7039f06151f5afeaa933382cc5e (patch)
treebc58ef80a3dae6b31832379deb5aa983ed09801f /bot/utils/moderation.py
parentUse `bot.utils.humanize_delta`, tidy bot response, remove stray f from f-string (diff)
parentMerge pull request #503 from avayert/master (diff)
Merge branch 'master' into master
Diffstat (limited to 'bot/utils/moderation.py')
-rw-r--r--bot/utils/moderation.py72
1 files changed, 0 insertions, 72 deletions
diff --git a/bot/utils/moderation.py b/bot/utils/moderation.py
deleted file mode 100644
index 7860f14a1..000000000
--- a/bot/utils/moderation.py
+++ /dev/null
@@ -1,72 +0,0 @@
-import logging
-from datetime import datetime
-from typing import Optional, Union
-
-from discord import Member, Object, User
-from discord.ext.commands import Context
-
-from bot.api import ResponseCodeError
-from bot.constants import Keys
-
-log = logging.getLogger(__name__)
-
-HEADERS = {"X-API-KEY": Keys.site_api}
-
-
-async def post_infraction(
- ctx: Context,
- user: Union[Member, Object, User],
- type: str,
- reason: str,
- expires_at: datetime = None,
- hidden: bool = False,
- active: bool = True,
-) -> Optional[dict]:
- """Posts an infraction to the API."""
- payload = {
- "actor": ctx.message.author.id,
- "hidden": hidden,
- "reason": reason,
- "type": type,
- "user": user.id,
- "active": active
- }
- if expires_at:
- payload['expires_at'] = expires_at.isoformat()
-
- try:
- response = await ctx.bot.api_client.post('bot/infractions', json=payload)
- except ResponseCodeError as exp:
- if exp.status == 400 and 'user' in exp.response_json:
- log.info(
- f"{ctx.author} tried to add a {type} infraction to `{user.id}`, "
- "but that user id was not found in the database."
- )
- await ctx.send(f":x: Cannot add infraction, the specified user is not known to the database.")
- return
- else:
- log.exception("An unexpected ResponseCodeError occurred while adding an infraction:")
- await ctx.send(":x: There was an error adding the 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