Skip to content

Commit c962588

Browse files
committed
Add role on auto_join
1 parent 0b5f875 commit c962588

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

plugins/tournament/commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ async def create(self, interaction: discord.Interaction, campaign: str):
318318
return
319319

320320
# inform players
321-
channel_id = self.get_config().get('channels', {}).get('info')
322-
if not channel_id:
321+
channel = self.get_info_channel()
322+
if not channel:
323323
return
324324

325325
if not await yn_question(interaction, _("Do you want to inform players about the new tournament now?"),
@@ -329,7 +329,7 @@ async def create(self, interaction: discord.Interaction, campaign: str):
329329

330330
embed = await self.render_info_embed(tournament_id)
331331
# create a persistent message
332-
await self.bot.setEmbed(embed_name=f"tournament_{tournament_id}", embed=embed, channel_id=channel_id)
332+
await self.bot.setEmbed(embed_name=f"tournament_{tournament_id}", embed=embed, channel_id=channel.id)
333333

334334
@tournament.command(description='Finish a tournament')
335335
@app_commands.guild_only()

plugins/tournament/listener.py

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

3+
import discord
34
from psycopg.errors import UniqueViolation
45

56
from core import EventListener, event, Server, utils, get_translation, Coalition
@@ -303,11 +304,21 @@ async def onPlayerChangeSlot(self, server: Server, data: dict) -> None:
303304
if config.get('auto_join', False):
304305
try:
305306
async with conn.transaction():
306-
await conn.execute(f"""
307+
cursor = await conn.execute(f"""
307308
INSERT INTO squadron_members (squadron_id, player_ucid)
308309
SELECT squadron_{side} AS squadron_id, '{player.ucid}'::TEXT
309310
FROM tm_matches WHERE match_id = %s
311+
RETURNING squadron_id
310312
""", (match_id, ))
313+
squadron_id = (await cursor.fetchone())[0]
314+
squadron = utils.get_squadron(self.node, squadron_id=squadron_id)
315+
# we need to give the member the role
316+
if player.member and 'role' in squadron:
317+
try:
318+
await player.member.add_roles(self.bot.get_role(squadron['role']))
319+
except discord.Forbidden:
320+
await self.bot.audit('permission "Manage Roles" missing.',
321+
user=self.bot.member)
311322
except UniqueViolation:
312323
await server.kick(player, "You can only be in one squadron at a time!")
313324
else:

plugins/userstats/commands.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ async def add(self, interaction: discord.Interaction, squadron_id: int,
339339
if self.get_config().get('squadrons', {}).get('persist_list', False):
340340
await self.persist_squadron_list(squadron_id)
341341
except UniqueViolation:
342-
await interaction.followup.send(f"{prefix} is a member of this squadron already!", ephemeral=True)
342+
await interaction.followup.send(f"{prefix} is a member of this or another squadron already!",
343+
phemeral=True)
343344

344345
# check, if the user needs a role
345346
if role:

0 commit comments

Comments
 (0)