Added possibility to automatically end vote once everybody has voted

This commit is contained in:
Elnath 2021-06-13 19:47:03 +02:00
parent a9b9c4cbe7
commit cc4990093e
2 changed files with 26 additions and 1 deletions

View File

@ -168,6 +168,15 @@ class Game:
vote_count[self.config["vote"][str(player_id)]] += 1 vote_count[self.config["vote"][str(player_id)]] += 1
return vote_count[True] > vote_count[False] return vote_count[True] > vote_count[False]
@game_started
def get_auto_end_vote(self) -> bool:
return self.config["auto_end_vote"]
@game_started
def set_auto_end_vote(self, auto_end_vote: bool):
self.config["auto_end_vote"] = auto_end_vote
self.save_function() # We do not use save_on_success decorator since this is not a coroutine
@game_started @game_started
def get_chaos(self) -> int: def get_chaos(self) -> int:
return self.config["chaos"] return self.config["chaos"]
@ -195,6 +204,7 @@ class Game:
self.config["players"] = 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["auto_end_vote"] = True
self.config["deck"] = [Policy.FASCIST.value] * 11 + [Policy.LIBERAL.value] * 6 self.config["deck"] = [Policy.FASCIST.value] * 11 + [Policy.LIBERAL.value] * 6
random.shuffle(self.config["deck"]) random.shuffle(self.config["deck"])
self.config["discard"] = [] self.config["discard"] = []
@ -340,7 +350,8 @@ class Game:
message_content.append(f":red_square: <@{player_id}> has voted NEIN") message_content.append(f":red_square: <@{player_id}> has voted NEIN")
else: # Player has voted but the vote should not be revealed else: # Player has voted but the vote should not be revealed
message_content.append(f":white_large_square: <@{player_id}> has voted") message_content.append(f":white_large_square: <@{player_id}> has voted")
if self.get_auto_end_vote() and not self.config["vote"]["revealed"]:
message_content.append("The vote will automatically end once everybody has voted")
message_content_str = "\n".join(message_content) message_content_str = "\n".join(message_content)
if self.config["vote"]["message"] is None: if self.config["vote"]["message"] is None:
self.config["vote"]["message"] = (await self.get_votes_channel().send(message_content_str, allowed_mentions = discord.AllowedMentions.none())).id self.config["vote"]["message"] = (await self.get_votes_channel().send(message_content_str, allowed_mentions = discord.AllowedMentions.none())).id
@ -353,6 +364,8 @@ class Game:
logging.debug(f"[{self.guild.name}] Casting vote with value {vote} for user {user.display_name}") logging.debug(f"[{self.guild.name}] Casting vote with value {vote} for user {user.display_name}")
self.config["vote"][str(user.id)] = vote self.config["vote"][str(user.id)] = vote
await self.update_vote_message() await self.update_vote_message()
if self.get_auto_end_vote() and all(self.config["vote"][str(player_id)] is not None for player_id in self.get_players_id()):
asyncio.create_task(self.stop_vote())
@vote_running @vote_running
@save_on_success @save_on_success

View File

@ -244,6 +244,18 @@ class SecretBot(commands.Cog):
await game.stop_vote() await game.stop_vote()
await ctx.message.delete() await ctx.message.delete()
@commands.command("AutoEndVote", help = "Set whether votes of the current game should end automatically when everybody has voted", usage = "true|false|get")
async def auto_end_vote(self, ctx: commands.Context, value):
game = await self.get_running_game_or_error_message(ctx)
await self.check_is_administrator_or_gm(ctx)
if value in ["true", "false"]:
game.set_auto_end_vote(value == "true")
await ctx.reply(":white_check_mark: Done.")
elif value == "get":
await ctx.reply(f"AutoEndVote currently set to {str(game.get_auto_end_vote()).lower()}.")
else:
await ctx.reply(":dizzy_face: You should give either 'true', 'false' or 'get'")
@commands.command("Legislate", help = "Start the legislative session by drawing three policies") @commands.command("Legislate", help = "Start the legislative session by drawing three policies")
async def draw_policies(self, ctx: commands.Context): async def draw_policies(self, ctx: commands.Context):
game = await self.get_running_game_or_error_message(ctx) game = await self.get_running_game_or_error_message(ctx)