Game creation: shuffle players and announce play order

This commit is contained in:
Elnath 2021-06-13 18:40:23 +02:00
parent ef65c2dda6
commit 0792753673
1 changed files with 19 additions and 4 deletions

View File

@ -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 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["game_started"] = True
self.config["player_role"] = player_role.id 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["player_info"] = {str(player): {} for player in self.config["players"]}
self.config["vote"] = None self.config["vote"] = None
self.config["deck"] = [Policy.FASCIST.value] * 11 + [Policy.LIBERAL.value] * 6 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), self.guild.default_role: discord.PermissionOverwrite(send_messages = False),
gm_role: discord.PermissionOverwrite(send_messages = True), 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("announcements", overwrites = perms, position = 1),
game_category.create_text_channel("votes", overwrites = perms, position = 2) game_category.create_text_channel("votes", overwrites = perms, position = 2)
) )
self.config["announce_chan"] = channels[0].id self.config["announce_chan"] = announcements_chan.id
self.config["votes_chan"] = channels[1].id self.config["votes_chan"] = votes_chan.id
logger.debug(f"[{self.guild.name}] Created announcements and votes channels") 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())) tasks.append(asyncio.create_task(create_announcements_and_vote_chans()))
async def create_discussion_chan(): async def create_discussion_chan():