From 45afcee8fb330e47ee1dd6d485553da845fe5809 Mon Sep 17 00:00:00 2001 From: Elnath Date: Sun, 20 Jun 2021 21:22:41 +0200 Subject: [PATCH] Added possibility to cancel a running vote --- GameFiles/Game.py | 9 +++++++++ SecretBot.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/GameFiles/Game.py b/GameFiles/Game.py index 81e9491..8229d08 100644 --- a/GameFiles/Game.py +++ b/GameFiles/Game.py @@ -425,6 +425,15 @@ class Game: if not passed: await self.increase_chaos() + @vote_running + @save_on_success + async def cancel_vote(self): + logger.debug(f"[{self.guild.name}] Cancelling the vote") + vote_message_id = self.config["vote"]["message"] + self.config["vote"] = None + if vote_message_id is not None: + await (await self.get_votes_channel().fetch_message(vote_message_id)).edit(content = "~~The vote has been canceled~~") + @game_started @save_on_success async def increase_chaos(self): diff --git a/SecretBot.py b/SecretBot.py index 780932a..4a32863 100755 --- a/SecretBot.py +++ b/SecretBot.py @@ -244,6 +244,24 @@ class SecretBot(commands.Cog): await game.stop_vote() await ctx.message.delete() + @commands.command("CancelVote", help = "Cancel the current vote, applying no consequences") + async def cancel_vote_with_confirmation(self, ctx: commands.Context): + game = await self.get_running_game_or_error_message(ctx) + await self.check_is_administrator_or_gm(ctx) + if game.is_vote_running(): + await self.confirm_action("Do you really want to cancel the vote (applying no consequences)?", ctx.channel, self.cancel_vote(ctx), ctx.message) + else: + await ctx.reply(":x: No vote is running") + + async def cancel_vote(self, ctx: commands.Context): + game = await self.get_running_game_or_error_message(ctx) + await self.check_is_administrator_or_gm(ctx) + if game.is_vote_running(): + await game.cancel_vote() + await ctx.reply(":white_check_mark: The current vote has been canceled.") + else: + await ctx.reply(":x: Not vote is running") + @commands.command("AutoEndVote", help = "Set whether votes of the current game should end automatically when everybody has voted", usage = "true|false|get") async def auto_end_vote(self, ctx: commands.Context, value): game = await self.get_running_game_or_error_message(ctx)