aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Shom770 <[email protected]>2022-01-09 18:26:08 -0500
committerGravatar Shom770 <[email protected]>2022-02-09 18:13:37 -0500
commitb68302524628573ee7e20ccd81db6bb60c05061b (patch)
treecf6b87ddf6f417147a7789ef384ae2cc01a490e4
parentQoL: adding an emoji and the number of people who answered for when the quest... (diff)
fixing .tn next logic
-rw-r--r--bot/exts/events/trivianight/_game.py8
-rw-r--r--bot/exts/events/trivianight/trivianight.py17
2 files changed, 18 insertions, 7 deletions
diff --git a/bot/exts/events/trivianight/_game.py b/bot/exts/events/trivianight/_game.py
index 9d8b98c1..7f667dcf 100644
--- a/bot/exts/events/trivianight/_game.py
+++ b/bot/exts/events/trivianight/_game.py
@@ -33,6 +33,10 @@ class AlreadyUpdated(RuntimeError):
"""Exception raised when the user has already updated their guess once."""
+class AllQuestionsVisited(RuntimeError):
+ """Exception raised when all of the questions have been visited."""
+
+
class Question:
"""Interface for one question in a trivia night game."""
@@ -142,6 +146,8 @@ class TriviaNightGame:
question = [q for q in self._all_questions if q.number == number][0]
except IndexError:
raise ValueError(f"Question number {number} does not exist.")
+ elif len(self._questions) == 0:
+ raise AllQuestionsVisited("All of the questions have been visited.")
else:
question = self._questions.pop(randrange(len(self._questions)))
@@ -161,7 +167,7 @@ class TriviaNightGame:
self.current_question.stop()
self.current_question = None
- def list_questions(self) -> None:
+ def list_questions(self) -> str:
"""
List all the questions.
diff --git a/bot/exts/events/trivianight/trivianight.py b/bot/exts/events/trivianight/trivianight.py
index aa6b8967..af517260 100644
--- a/bot/exts/events/trivianight/trivianight.py
+++ b/bot/exts/events/trivianight/trivianight.py
@@ -9,7 +9,7 @@ from discord.ext import commands
from bot.bot import Bot
from bot.constants import Colours, NEGATIVE_REPLIES, POSITIVE_REPLIES, Roles
-from ._game import TriviaNightGame
+from ._game import AllQuestionsVisited, TriviaNightGame
from ._questions import QuestionView
from ._scoreboard import Scoreboard
@@ -132,7 +132,16 @@ class TriviaNightCog(commands.Cog):
await ctx.send(embed=error_embed)
return
- next_question = self.game.next_question(question_number)
+ try:
+ next_question = self.game.next_question(question_number)
+ except AllQuestionsVisited:
+ error_embed = Embed(
+ title=choice(NEGATIVE_REPLIES),
+ description="All of the questions have been used.",
+ color=Colours.soft_red
+ )
+ await ctx.send(embed=error_embed)
+ return
question_view = QuestionView(next_question)
question_embed = question_view.create_embed()
@@ -196,10 +205,6 @@ class TriviaNightCog(commands.Cog):
return
question_list = self.game.list_questions()
- if isinstance(question_list, Embed):
- await ctx.send(embed=question_list)
- return
-
await ctx.send(question_list)
@trivianight.command()