From d41eb3fc4c52d4ea969f2269dc00220f4724e5c8 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 9 Nov 2021 00:47:49 +0100 Subject: [PATCH] Implement reboot --- .gitignore | 2 +- orochi/bot.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 007b90e..1de6e21 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,5 @@ __pycache__/ venv/ config.yml -game.save +*.save *.log diff --git a/orochi/bot.py b/orochi/bot.py index 788c78b..1d0cd2f 100644 --- a/orochi/bot.py +++ b/orochi/bot.py @@ -1,3 +1,4 @@ +import os from functools import partial import disnake @@ -392,6 +393,25 @@ 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="Reboot") +@commands.has_permissions(administrator=True) +async def reboot(ctx: commands.Context): + game: Game = Game.INSTANCE + for player in game.players.values(): + channel = bot.get_channel(player.private_channel_id) + await channel.send("REB0OT.") + + os.rename('game.save', 'game-prereboot.save') + + game = Game() + for player in bot.config.PLAYERS: + game.register_player(player, bot.config.vote_channels[player.lower()]) + game.rounds.append(game.default_first_round()) + game.save('game.save') + + await ctx.reply("REB0OT.") + + class VoteView(disnake.ui.View): @disnake.ui.button(label="S'allier", style=disnake.ButtonStyle.green) async def confirm(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):