aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/api.py22
-rw-r--r--bot/cogs/jams.py17
-rw-r--r--bot/utils/moderation.py2
3 files changed, 31 insertions, 10 deletions
diff --git a/bot/api.py b/bot/api.py
index 36f9cfcd4..9a0ebaa26 100644
--- a/bot/api.py
+++ b/bot/api.py
@@ -1,5 +1,6 @@
import asyncio
import logging
+from typing import Optional
from urllib.parse import quote as quote_url
import aiohttp
@@ -10,13 +11,20 @@ log = logging.getLogger(__name__)
class ResponseCodeError(ValueError):
- def __init__(self, response: aiohttp.ClientResponse, response_data: dict):
+ def __init__(
+ self,
+ response: aiohttp.ClientResponse,
+ response_json: Optional[dict] = None,
+ response_text: str = ""
+ ):
self.status = response.status
- self.response_data = response_data
+ self.response_json = response_json or {}
+ self.response_text = response_text
self.response = response
def __str__(self):
- return f"Status: {self.status} Response: {self.response_data}"
+ response = self.response_json if self.response_json else self.response_text
+ return f"Status: {self.status} Response: {response}"
class APIClient:
@@ -38,8 +46,12 @@ class APIClient:
async def maybe_raise_for_status(self, response: aiohttp.ClientResponse, should_raise: bool):
if should_raise and response.status >= 400:
- response_data = await response.json()
- raise ResponseCodeError(response=response, response_data=response_data)
+ try:
+ response_json = await response.json()
+ raise ResponseCodeError(response=response, response_json=response_json)
+ except aiohttp.ContentTypeError:
+ response_text = await response.text()
+ raise ResponseCodeError(response=response, response_text=response_text)
async def get(self, endpoint: str, *args, raise_for_status: bool = True, **kwargs):
async with self.session.get(self._url_for(endpoint), *args, **kwargs) as resp:
diff --git a/bot/cogs/jams.py b/bot/cogs/jams.py
index 43b31672b..bca1fb607 100644
--- a/bot/cogs/jams.py
+++ b/bot/cogs/jams.py
@@ -2,6 +2,7 @@ import logging
from discord import Member, PermissionOverwrite, utils
from discord.ext import commands
+from more_itertools import unique_everseen
from bot.constants import Roles
from bot.decorators import with_role
@@ -29,15 +30,19 @@ class CodeJams:
The first user passed will always be the team leader.
"""
+ # Ignore duplicate members
+ members = list(unique_everseen(members))
# We had a little issue during Code Jam 4 here, the greedy converter did it's job
# and ignored anything which wasn't a valid argument which left us with teams of
# two members or at some times even 1 member. This fixes that by checking that there
# are always 3 members in the members list.
if len(members) < 3:
- await ctx.send(":no_entry_sign: One of your arguments was invalid - there must be a "
- f"minimum of 3 valid members in your team. Found: {len(members)} "
- "members")
+ await ctx.send(
+ ":no_entry_sign: One of your arguments was invalid\n"
+ f"There must be a minimum of 3 valid members in your team. Found: {len(members)}"
+ " members"
+ )
return
code_jam_category = utils.get(ctx.guild.categories, name="Code Jam")
@@ -102,7 +107,11 @@ class CodeJams:
for member in members:
await member.add_roles(jammer_role)
- await ctx.send(f":ok_hand: Team created: {team_channel.mention}")
+ await ctx.send(
+ f":ok_hand: Team created: {team_channel.mention}\n"
+ f"**Team Leader:** {members[0].mention}\n"
+ f"**Team Members:** {' '.join(member.mention for member in members[1:])}"
+ )
def setup(bot):
diff --git a/bot/utils/moderation.py b/bot/utils/moderation.py
index b295e4649..7860f14a1 100644
--- a/bot/utils/moderation.py
+++ b/bot/utils/moderation.py
@@ -37,7 +37,7 @@ async def post_infraction(
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_data:
+ 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."