From 94d8173f0639d8a1b3c1cc3c2ae9e997c6c13c25 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 12 Nov 2021 14:26:01 +0100 Subject: [PATCH] Implement score override --- orochi/bot.py | 24 +++++++++++++++++++++++- orochi/models.py | 11 +++++++++-- orochi/templates/list.html | 7 ++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/orochi/bot.py b/orochi/bot.py index 32a6159..00c6d47 100644 --- a/orochi/bot.py +++ b/orochi/bot.py @@ -403,7 +403,7 @@ async def vote(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") +@bot.command(help="Échange de vote") @commands.has_any_role('IA', 'Dan') async def swap(ctx: commands.Context, player_name: str): """ @@ -432,6 +432,28 @@ async def swap(ctx: commands.Context, player_name: str): "alors il est de retour à la normale.") +@bot.command(help="Modification du score d'un bracelet") +@commands.has_any_role('IA', 'Dan') +async def override(ctx: commands.Context, player_name: str, target_score: int): + """ + Override the score of a given player. + """ + game: Game = Game.INSTANCE + + 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.") + + game.score_overrides[current_player] = target_score + + game.save('game.save') + await ctx.reply(f"Le score de **{current_player.name}** a bien été modifié. " + f"Il sera maintenant de **{target_score}**.") + + @bot.command(help="Reboot") @commands.has_permissions(administrator=True) async def reboot(ctx: commands.Context): diff --git a/orochi/models.py b/orochi/models.py index 6c50bad..328514e 100644 --- a/orochi/models.py +++ b/orochi/models.py @@ -35,7 +35,7 @@ class Player: yield vote @property - def score(self) -> int: + def calculated_score(self) -> int: s = 3 for vote in self.round_votes: @@ -61,6 +61,12 @@ class Player: return s + @property + def score(self) -> int: + if self in Game.INSTANCE.score_overrides: + return Game.INSTANCE.score_overrides[self] + return self.calculated_score + def __str__(self): return self.name @@ -127,8 +133,9 @@ class Game: state: GameState = GameState.PREPARING rounds: list[Round] = field(default_factory=list) players: dict[str, Player] = field(default_factory=dict) + score_overrides: dict[Player, int] = field(default_factory=dict, init=False) - def __post_init__(self): + def __post_init__(self: "Game") -> None: Game.INSTANCE = self def register_player(self, name: str, vote_channel_id: int) -> Player: diff --git a/orochi/templates/list.html b/orochi/templates/list.html index 67e6066..102b482 100644 --- a/orochi/templates/list.html +++ b/orochi/templates/list.html @@ -24,7 +24,12 @@ {% for player in game.players.values() %} - {{ player.score }}{% if player.score <= 0 %} ☠️ {% elif player.score >= 9 %} 9️⃣ {% endif %} + + {{ player.score }}{% if player.score <= 0 %} ☠️ {% elif player.score >= 9 %} 9️⃣ {% endif %} + {% if admin and player in game.score_overrides %} + Triche + {% endif %} + {% endfor %}