Implement cheat command to update scores

This commit is contained in:
Yohann D'ANELLO 2021-11-09 00:40:58 +01:00
parent 388c729235
commit 774fec0e32
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 31 additions and 0 deletions

View File

@ -241,6 +241,10 @@ async def open(ctx: commands.Context):
players = list(vote.players) players = list(vote.players)
other_vote = votes[1 - i] other_vote = votes[1 - i]
for j, player in enumerate(players): for j, player in enumerate(players):
if player.score <= 0:
# Player is dead
continue
other_player = players[1 - j] if len(players) == 2 else None other_player = players[1 - j] if len(players) == 2 else None
view = VoteView(timeout=3600) view = VoteView(timeout=3600)
channel_id = player.private_channel_id channel_id = player.private_channel_id
@ -286,6 +290,9 @@ async def close(ctx: commands.Context):
"Rendez-vous dans la salle principale pour découvrir les scores.") "Rendez-vous dans la salle principale pour découvrir les scores.")
if player.score <= 0: if player.score <= 0:
await channel.send("Tiens ! Vous êtes morts :)") await channel.send("Tiens ! Vous êtes morts :)")
elif player.score >= 9:
await channel.send("Vous avez plus de 9 points. Vous pouvez désormais passer la porte 9.\n"
"Mais ... Attendrez-vous vos camarades ?")
await ctx.reply("Les votes ont bien été fermés.") await ctx.reply("Les votes ont bien été fermés.")
game.save('game.save') game.save('game.save')
@ -361,6 +368,30 @@ async def setup(ctx: commands.Context, room: Room):
await ctx.send(f"Attention : **{round_room.vote1.player1.name}** est déjà choisie.") await ctx.send(f"Attention : **{round_room.vote1.player1.name}** est déjà choisie.")
@bot.command(help="Falsification des votes")
@commands.has_permissions(administrator=True)
async def cheat(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.")
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.")
current_round = game.rounds[-1]
for room in current_round.rooms:
for v in room.votes:
if current_player in v.players:
v.vote = vote
game.save('game.save')
await ctx.reply(f"Le vote de **{current_player.name}** a bien été falsifié (nouveau vote : *{vote}**).")
class VoteView(disnake.ui.View): class VoteView(disnake.ui.View):
@disnake.ui.button(label="S'allier", style=disnake.ButtonStyle.green) @disnake.ui.button(label="S'allier", style=disnake.ButtonStyle.green)
async def confirm(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction): async def confirm(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):