From 00a4c148ff8754272921527410d35b0c3c27e44c Mon Sep 17 00:00:00 2001 From: ToxicKidz Date: Mon, 17 May 2021 11:17:35 -0400 Subject: fix: Handle a KeyError when using .quiz stop --- bot/exts/evergreen/trivia_quiz.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'bot') diff --git a/bot/exts/evergreen/trivia_quiz.py b/bot/exts/evergreen/trivia_quiz.py index 419126dc..a8d10afd 100644 --- a/bot/exts/evergreen/trivia_quiz.py +++ b/bot/exts/evergreen/trivia_quiz.py @@ -465,22 +465,24 @@ class TriviaQuiz(commands.Cog): Note: Only mods or the owner of the quiz can stop it. """ - if self.game_status[ctx.channel.id] is True: - # Check if the author is the game starter or a moderator. - if ctx.author == self.game_owners[ctx.channel.id] or any( - Roles.moderator == role.id for role in ctx.author.roles - ): - - await ctx.send("Quiz stopped.") - await self.declare_winner(ctx.channel, self.game_player_scores[ctx.channel.id]) - - self.game_status[ctx.channel.id] = False - del self.game_owners[ctx.channel.id] - self.game_player_scores[ctx.channel.id] = {} + try: + if self.game_status[ctx.channel.id]: + # Check if the author is the game starter or a moderator. + if ctx.author == self.game_owners[ctx.channel.id] or any( + Roles.moderator == role.id for role in ctx.author.roles + ): + self.game_status[ctx.channel.id] = False + del self.game_owners[ctx.channel.id] + self.game_player_scores[ctx.channel.id] = {} + + await ctx.send("Quiz stopped.") + await self.declare_winner(ctx.channel, self.game_player_scores[ctx.channel.id]) + else: + await ctx.send(f"{ctx.author.mention}, you are not authorised to stop this game :ghost:!") else: - await ctx.send(f"{ctx.author.mention}, you are not authorised to stop this game :ghost:!") - else: + await ctx.send("No quiz running.") + except KeyError: await ctx.send("No quiz running.") @quiz_game.command(name="leaderboard") -- cgit v1.2.3