From 07927536739eb68f978de20fd6dab0ff954ed38b Mon Sep 17 00:00:00 2001 From: Elnath Date: Sun, 13 Jun 2021 18:40:23 +0200 Subject: [PATCH] Game creation: shuffle players and announce play order --- GameFiles/Game.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/GameFiles/Game.py b/GameFiles/Game.py index d6c7f5e..73a7e86 100644 --- a/GameFiles/Game.py +++ b/GameFiles/Game.py @@ -186,7 +186,9 @@ class Game: tasks = [] # Asyncio tasks scheduled to run in parallel (e.g. channel creation), so that we can wait them all at the end of the function self.config["game_started"] = True self.config["player_role"] = player_role.id - self.config["players"] = [member.id for member in player_role.members] + players = [member.id for member in player_role.members] + random.shuffle(players) + self.config["players"] = players self.config["player_info"] = {str(player): {} for player in self.config["players"]} self.config["vote"] = None self.config["deck"] = [Policy.FASCIST.value] * 11 + [Policy.LIBERAL.value] * 6 @@ -227,13 +229,26 @@ class Game: self.guild.default_role: discord.PermissionOverwrite(send_messages = False), gm_role: discord.PermissionOverwrite(send_messages = True), } - channels = await asyncio.gather( + announcements_chan, votes_chan = await asyncio.gather( game_category.create_text_channel("announcements", overwrites = perms, position = 1), game_category.create_text_channel("votes", overwrites = perms, position = 2) ) - self.config["announce_chan"] = channels[0].id - self.config["votes_chan"] = channels[1].id + self.config["announce_chan"] = announcements_chan.id + self.config["votes_chan"] = votes_chan.id logger.debug(f"[{self.guild.name}] Created announcements and votes channels") + + async def announce_game_start(): + message_content = [ + f"<@&{self.get_player_role_id()}> <@&{self.get_gm_role_id()}>", + "**A new game has started!**", + "The turn order is the following:", + ] + message_content.extend([f"ยท <@{player_id}>" for player_id in self.get_players_id()]) + message_content.append("Have a nice game!") + message = await announcements_chan.send("\n".join(message_content), allowed_mentions = discord.AllowedMentions(roles = True)) + await message.pin() + logger.debug(f"[{self.guild.name}] Announced game start in announcements") + asyncio.create_task(announce_game_start()) # We do not add it to the list of tasks to wait before game creation finishes because we do not care if it is executed after a while tasks.append(asyncio.create_task(create_announcements_and_vote_chans())) async def create_discussion_chan():