Skip to content

Commit 0b5f875

Browse files
committed
Check the uniqueness of squadron members on auto_join
1 parent 81e3b1f commit 0b5f875

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

plugins/tournament/listener.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
22

3+
from psycopg.errors import UniqueViolation
4+
35
from core import EventListener, event, Server, utils, get_translation, Coalition
46
from psycopg.rows import dict_row
57
from typing import TYPE_CHECKING, Optional
@@ -299,12 +301,15 @@ async def onPlayerChangeSlot(self, server: Server, data: dict) -> None:
299301
if cursor.rowcount == 0:
300302
config = self.get_config(server)
301303
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!")
308313
else:
309314
asyncio.create_task(server.kick(player, _("You are not a squadron member.\n"
310315
"Please ask your squadron leader to add you.")))

0 commit comments

Comments
 (0)