Implement vote closing
This commit is contained in:
parent
8f939e288b
commit
de6dc03dda
|
@ -212,6 +212,7 @@ async def brother(ctx: commands.Context, *, message: str):
|
||||||
|
|
||||||
|
|
||||||
@bot.command(help="Ouvrir les votes")
|
@bot.command(help="Ouvrir les votes")
|
||||||
|
@commands.has_permissions(administrator=True)
|
||||||
async def open(ctx: commands.Context):
|
async def open(ctx: commands.Context):
|
||||||
game: Game = Game.INSTANCE
|
game: Game = Game.INSTANCE
|
||||||
current_round = game.rounds[-1]
|
current_round = game.rounds[-1]
|
||||||
|
@ -258,15 +259,49 @@ async def open(ctx: commands.Context):
|
||||||
await ctx.reply("Les salles de vote sont ouvertes, les joueur⋅se⋅s peuvent désormais voter.")
|
await ctx.reply("Les salles de vote sont ouvertes, les joueur⋅se⋅s peuvent désormais voter.")
|
||||||
|
|
||||||
|
|
||||||
|
@bot.command(help="Fermer les votes")
|
||||||
|
@commands.has_permissions(administrator=True)
|
||||||
|
async def close(ctx: commands.Context):
|
||||||
|
game: Game = Game.INSTANCE
|
||||||
|
if game.state != GameState.VOTING:
|
||||||
|
await ctx.reply("Les votes ne sont pas ouverts.")
|
||||||
|
return
|
||||||
|
|
||||||
|
current_round = game.rounds[-1]
|
||||||
|
for room in current_round.rooms:
|
||||||
|
for vote in room.votes:
|
||||||
|
if vote.vote is None:
|
||||||
|
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.")
|
||||||
|
|
||||||
|
for player in game.players.values():
|
||||||
|
channel = bot.get_channel(player.private_channel_id)
|
||||||
|
await channel.send("Les votes sont à présent clos ! "
|
||||||
|
"Rendez-vous dans la salle principale pour découvrir les scores.")
|
||||||
|
if player.score <= 0:
|
||||||
|
await channel.send("Tiens ! Vous êtes morts :)")
|
||||||
|
|
||||||
|
await ctx.reply("Les votes ont bien été fermés.")
|
||||||
|
game.state = GameState.RESULTS
|
||||||
|
game.save('game.save')
|
||||||
|
|
||||||
|
|
||||||
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):
|
||||||
|
if Game.INSTANCE.state != GameState.VOTING:
|
||||||
|
return await interaction.response.send_message("Les votes ne sont pas ouverts.", ephemeral=True)
|
||||||
|
|
||||||
await interaction.response.send_message("Votre vote a bien été pris en compte.", ephemeral=True)
|
await interaction.response.send_message("Votre vote a bien été pris en compte.", ephemeral=True)
|
||||||
|
|
||||||
self.vote(interaction, Vote.ALLY)
|
self.vote(interaction, Vote.ALLY)
|
||||||
|
|
||||||
@disnake.ui.button(label="Trahir", style=disnake.ButtonStyle.red)
|
@disnake.ui.button(label="Trahir", style=disnake.ButtonStyle.red)
|
||||||
async def cancel(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
|
async def cancel(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
|
||||||
|
if Game.INSTANCE.state != GameState.VOTING:
|
||||||
|
return await interaction.response.send_message("Les votes ne sont pas ouverts.", ephemeral=True)
|
||||||
|
|
||||||
await interaction.response.send_message("Votre vote a bien été pris en compte.", ephemeral=True)
|
await interaction.response.send_message("Votre vote a bien été pris en compte.", ephemeral=True)
|
||||||
|
|
||||||
self.vote(interaction, Vote.BETRAY)
|
self.vote(interaction, Vote.BETRAY)
|
||||||
|
|
|
@ -40,6 +40,10 @@ class Player:
|
||||||
s = 3
|
s = 3
|
||||||
|
|
||||||
for vote in self.round_votes:
|
for vote in self.round_votes:
|
||||||
|
if vote.room.round.round == len(Game.INSTANCE.rounds) and Game.INSTANCE.state != GameState.RESULTS:
|
||||||
|
# Don't compute temporary scores
|
||||||
|
break
|
||||||
|
|
||||||
room = vote.room
|
room = vote.room
|
||||||
other_vote = room.vote1 if room.vote1 is not vote else room.vote2
|
other_vote = room.vote1 if room.vote1 is not vote else room.vote2
|
||||||
match vote.vote, other_vote.vote:
|
match vote.vote, other_vote.vote:
|
||||||
|
@ -52,6 +56,10 @@ class Player:
|
||||||
case Vote.BETRAY, Vote.BETRAY:
|
case Vote.BETRAY, Vote.BETRAY:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if s <= 0:
|
||||||
|
# Player died
|
||||||
|
return s
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,23 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<b>Tour actuel :</b>
|
||||||
|
{{ game.rounds|length }}
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<b>État :</b>
|
||||||
|
{% if game.state.value == 0 %}
|
||||||
|
<span style="color: yellow;">En préparation ...</span>
|
||||||
|
{% elif game.state.value == 1 %}
|
||||||
|
<span style="color: red;">Votes en cours ...</span>
|
||||||
|
{% else %}
|
||||||
|
<span style="color: green;">Résultats du tour</span>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<h2>Récapitulatif par tour</h2>
|
<h2>Récapitulatif par tour</h2>
|
||||||
|
|
||||||
{% for round in game.rounds %}
|
{% for round in game.rounds %}
|
||||||
|
@ -58,7 +75,7 @@
|
||||||
<td rowspan="2">{{ room.room.value }}</td>
|
<td rowspan="2">{{ room.room.value }}</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td>{{ vote.player1.name }}{% if vote.player2 %}, {{ vote.player2.name }}{% endif %}</td>
|
<td>{{ vote.player1.name }}{% if vote.player2 %}, {{ vote.player2.name }}{% endif %}</td>
|
||||||
{% if round.round != game.rounds|length or admin %}
|
{% if round.round != game.rounds|length or game.state.value == 2 or admin %}
|
||||||
<td>{{ vote.vote.value|default('Pas de vote') }}</td>
|
<td>{{ vote.vote.value|default('Pas de vote') }}</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><em>Vote en cours ...</em></td>
|
<td><em>Vote en cours ...</em></td>
|
||||||
|
|
Loading…
Reference in New Issue