Implement score override
This commit is contained in:
parent
881b97218e
commit
94d8173f06
|
@ -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}**).")
|
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')
|
@commands.has_any_role('IA', 'Dan')
|
||||||
async def swap(ctx: commands.Context, player_name: str):
|
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.")
|
"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")
|
@bot.command(help="Reboot")
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def reboot(ctx: commands.Context):
|
async def reboot(ctx: commands.Context):
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Player:
|
||||||
yield vote
|
yield vote
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def score(self) -> int:
|
def calculated_score(self) -> int:
|
||||||
s = 3
|
s = 3
|
||||||
|
|
||||||
for vote in self.round_votes:
|
for vote in self.round_votes:
|
||||||
|
@ -61,6 +61,12 @@ class Player:
|
||||||
|
|
||||||
return s
|
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):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -127,8 +133,9 @@ class Game:
|
||||||
state: GameState = GameState.PREPARING
|
state: GameState = GameState.PREPARING
|
||||||
rounds: list[Round] = field(default_factory=list)
|
rounds: list[Round] = field(default_factory=list)
|
||||||
players: dict[str, Player] = field(default_factory=dict)
|
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
|
Game.INSTANCE = self
|
||||||
|
|
||||||
def register_player(self, name: str, vote_channel_id: int) -> Player:
|
def register_player(self, name: str, vote_channel_id: int) -> Player:
|
||||||
|
|
|
@ -24,7 +24,12 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
{% for player in game.players.values() %}
|
{% for player in game.players.values() %}
|
||||||
<td>{{ player.score }}{% if player.score <= 0 %} ☠️ {% elif player.score >= 9 %} 9️⃣ {% endif %}</td>
|
<td>
|
||||||
|
{{ player.score }}{% if player.score <= 0 %} ☠️ {% elif player.score >= 9 %} 9️⃣ {% endif %}
|
||||||
|
{% if admin and player in game.score_overrides %}
|
||||||
|
<span class="badge bg-danger">Triche</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
Loading…
Reference in New Issue