Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Fun(commands.Cog):

def __init__(self, bot: commands.Bot):
self.bot = bot
self.question_index = 0
self._absolute_template_cache_bytes: Optional[bytes] = None
self._absolute_template_cache_expires_at = 0.0
self._absolute_template_cache_lock = asyncio.Lock()
Expand Down Expand Up @@ -165,6 +166,17 @@ def _build_absolute_gif(cls, template_bytes: bytes, avatar_bytes: bytes, text: s
result.seek(0)
return result

def get_next_question(self) -> dict[str, str]:

if self.question_index >= len(TRIVIA_QUESTIONS):
random.shuffle(TRIVIA_QUESTIONS)
self.question_index = 0

question = TRIVIA_QUESTIONS[self.question_index]
self.question_index += 1

return question

async def _get_absolute_template_bytes(self) -> bytes:
now = time.monotonic()
if self._absolute_template_cache_bytes and now < self._absolute_template_cache_expires_at:
Expand Down Expand Up @@ -268,7 +280,7 @@ async def fortune(self, ctx: commands.Context):
@commands.hybrid_command(name="trivia", help="Answer a programming trivia question")
async def trivia(self, ctx: commands.Context):
"""Start a programming trivia question."""
question_data = random.choice(TRIVIA_QUESTIONS)
question_data = self.get_next_question()

embed = discord.Embed(
title="Programming Trivia",
Expand Down