|
1 | 1 | import asyncio |
2 | 2 |
|
| 3 | +from psycopg.errors import UniqueViolation |
| 4 | + |
3 | 5 | from core import EventListener, event, Server, utils, get_translation, Coalition |
4 | 6 | from psycopg.rows import dict_row |
5 | 7 | from typing import TYPE_CHECKING, Optional |
@@ -299,12 +301,15 @@ async def onPlayerChangeSlot(self, server: Server, data: dict) -> None: |
299 | 301 | if cursor.rowcount == 0: |
300 | 302 | config = self.get_config(server) |
301 | 303 | if config.get('auto_join', False): |
302 | | - async with conn.transaction(): |
303 | | - await conn.execute(f""" |
304 | | - INSERT INTO squadron_members (squadron_id, player_ucid) |
305 | | - SELECT squadron_{side} AS squadron_id, '{player.ucid}'::TEXT |
306 | | - FROM tm_matches WHERE match_id = %s |
307 | | - """, (match_id, )) |
| 304 | + try: |
| 305 | + async with conn.transaction(): |
| 306 | + await conn.execute(f""" |
| 307 | + INSERT INTO squadron_members (squadron_id, player_ucid) |
| 308 | + SELECT squadron_{side} AS squadron_id, '{player.ucid}'::TEXT |
| 309 | + FROM tm_matches WHERE match_id = %s |
| 310 | + """, (match_id, )) |
| 311 | + except UniqueViolation: |
| 312 | + await server.kick(player, "You can only be in one squadron at a time!") |
308 | 313 | else: |
309 | 314 | asyncio.create_task(server.kick(player, _("You are not a squadron member.\n" |
310 | 315 | "Please ask your squadron leader to add you."))) |
|
0 commit comments