diff --git a/orochi/bot.py b/orochi/bot.py index a53d318..32a6159 100644 --- a/orochi/bot.py +++ b/orochi/bot.py @@ -286,6 +286,11 @@ async def close(ctx: commands.Context): vote.vote = Vote.ALLY await ctx.send(f"L'équipe **{' et '.join(player.name for player in vote.players)}** " f"n'a pas voté en salle **{room.room.value}** et s'est alliée par défaut.") + if vote.swapped: + vote.vote = Vote.ALLY if vote.vote == Vote.BETRAY else Vote.BETRAY + await ctx.send(f"L'équipe **{' et '.join(player.name for player in vote.players)}** " + f"en salle **{room.room.value}** a vu son vote échangé. " + f"Nouveau vote : **{vote.vote.value}**") for player in game.players.values(): channel = bot.get_channel(player.private_channel_id) @@ -376,7 +381,7 @@ async def setup(ctx: commands.Context, room: Room): @bot.command(help="Falsification des votes") @commands.has_permissions(administrator=True) -async def cheat(ctx: commands.Context, player_name: str, vote: Vote | None): +async def vote(ctx: commands.Context, player_name: str, vote: Vote | None): game: Game = Game.INSTANCE if game.state != GameState.VOTING: return await ctx.reply("Les votes ne sont pas ouverts.") @@ -398,6 +403,35 @@ async def cheat(ctx: commands.Context, player_name: str, vote: Vote | None): await ctx.reply(f"Le vote de **{current_player.name}** a bien été falsifié (nouveau vote : *{vote}**).") +@bot.command(help="Préparation d'une salle") +@commands.has_any_role('IA', 'Dan') +async def swap(ctx: commands.Context, player_name: str): + """ + Exchange the vote of the given player. + """ + game: Game = Game.INSTANCE + current_round = game.rounds[-1] + + if game.state != GameState.VOTING: + return await ctx.reply("Les votes ne sont pas ouverts.") + + for player in game.players.values(): + if player.name.lower() == player_name.lower(): + current_player = player + break + else: + return await ctx.reply("Le joueur n'existe pas.") + + for room in current_round.rooms: + for v in room.votes: + if current_player in v.players: + v.swapped ^= True + + game.save('game.save') + await ctx.reply(f"Le vote de **{current_player.name}** a bien été inversé. S'il était déjà inversé, " + "alors il est de retour à la normale.") + + @bot.command(help="Reboot") @commands.has_permissions(administrator=True) async def reboot(ctx: commands.Context): @@ -425,7 +459,7 @@ class VoteView(disnake.ui.View): await interaction.response.send_message("Votre vote a bien été pris en compte.", ephemeral=True) - self.vote(interaction, Vote.ALLY) + await self.vote(interaction, Vote.ALLY) @disnake.ui.button(label="Trahir", style=disnake.ButtonStyle.red) async def cancel(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction): @@ -434,9 +468,9 @@ class VoteView(disnake.ui.View): await interaction.response.send_message("Votre vote a bien été pris en compte.", ephemeral=True) - self.vote(interaction, Vote.BETRAY) + await self.vote(interaction, Vote.BETRAY) - def vote(self, interaction: disnake.MessageInteraction, vote: Vote) -> None: + async def vote(self, interaction: disnake.MessageInteraction, vote: Vote) -> None: game = Game.INSTANCE current_round = game.rounds[-1] current_player: Player | None = None diff --git a/orochi/models.py b/orochi/models.py index 00bb82b..6c50bad 100644 --- a/orochi/models.py +++ b/orochi/models.py @@ -70,6 +70,7 @@ class RoundVote: player1: Player | None = None player2: Player | None = None vote: Vote | None = None + swapped: bool = field(default=False, init=False) @property def players(self) -> Iterable[Player]: diff --git a/orochi/templates/list.html b/orochi/templates/list.html index 1bc95d1..67e6066 100644 --- a/orochi/templates/list.html +++ b/orochi/templates/list.html @@ -58,7 +58,12 @@ {% endif %} {{ vote.player1.name|default('personne')|safe }}{% if vote.player2 %}, {{ vote.player2.name }}{% endif %} {% if round.round != game.rounds|length or game.state.value == 2 or admin %} - {{ vote.vote.value|default('Pas de vote')|safe }} + + {{ vote.vote.value|default('Pas de vote')|safe }} + {% if admin and vote.swapped %} + Échange + {% endif %} + {% else %} Vote en cours ... {% endif %}