aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Sahran <[email protected]>2024-01-31 20:47:22 +0530
committerGravatar GitHub <[email protected]>2024-01-31 15:17:22 +0000
commit3ba7630d824da67104afc6a3fee9d951b67b3a9e (patch)
tree2419ebbf83c6681366435327d6bee45610fa1263
parentBump pydis-core from 10.5.1 to 10.7.0 (#1442) (diff)
Changed riddle behaviour to match that of trivia (#1440)
* Changed riddle behaviour to match that of trivia. * Changed riddle behaviour to match that of trivia. * Changed riddle behaviour to match that of trivia. * Update bot/exts/holidays/easter/easter_riddle.py Co-authored-by: wookie184 <[email protected]> * Update bot/exts/holidays/easter/easter_riddle.py Co-authored-by: wookie184 <[email protected]> --------- Co-authored-by: wookie184 <[email protected]>
-rw-r--r--bot/exts/holidays/easter/easter_riddle.py74
1 files changed, 30 insertions, 44 deletions
diff --git a/bot/exts/holidays/easter/easter_riddle.py b/bot/exts/holidays/easter/easter_riddle.py
index f9ddc429..a725ccd1 100644
--- a/bot/exts/holidays/easter/easter_riddle.py
+++ b/bot/exts/holidays/easter/easter_riddle.py
@@ -1,4 +1,3 @@
-import asyncio
import random
from json import loads
from pathlib import Path
@@ -22,8 +21,6 @@ class EasterRiddle(commands.Cog):
def __init__(self, bot: Bot):
self.bot = bot
- self.winners = set()
- self.correct = ""
self.current_channel = None
@commands.command(aliases=("riddlemethis", "riddleme"))
@@ -43,7 +40,7 @@ class EasterRiddle(commands.Cog):
embed=discord.Embed(
title=random.choice(NEGATIVE_REPLIES),
description="You can't start riddles in DMs",
- colour=discord.Colour.red()
+ colour=discord.Colour.red(),
)
)
return
@@ -53,59 +50,48 @@ class EasterRiddle(commands.Cog):
random_question = random.choice(RIDDLE_QUESTIONS)
question = random_question["question"]
hints = random_question["riddles"]
- self.correct = random_question["correct_answer"]
+ correct = random_question["correct_answer"]
description = f"You have {TIMELIMIT} seconds before the first hint."
riddle_embed = discord.Embed(title=question, description=description, colour=Colours.pink)
await ctx.send(embed=riddle_embed)
- await asyncio.sleep(TIMELIMIT)
-
- hint_embed = discord.Embed(
- title=f"Here's a hint: {hints[0]}!",
- colour=Colours.pink
- )
-
- await ctx.send(embed=hint_embed)
- await asyncio.sleep(TIMELIMIT)
-
- hint_embed = discord.Embed(
- title=f"Here's a hint: {hints[1]}!",
- colour=Colours.pink
- )
-
- await ctx.send(embed=hint_embed)
- await asyncio.sleep(TIMELIMIT)
-
- if self.winners:
- win_list = " ".join(self.winners)
- content = f"Well done {win_list} for getting it right!"
+ hint_number = 0
+ winner = None
+ while hint_number < 3:
+ try:
+ response = await self.bot.wait_for(
+ "message",
+ check=lambda m: m.channel == ctx.channel
+ and m.author != self.bot.user
+ and m.content.lower() == correct.lower(),
+ timeout=TIMELIMIT,
+ )
+ winner = response.author.mention
+ break
+ except TimeoutError:
+ hint_number += 1
+
+ try:
+ hint_embed = discord.Embed(
+ title=f"Here's a hint: {hints[hint_number-1]}!",
+ colour=Colours.pink,
+ )
+ except IndexError:
+ break
+ await ctx.send(embed=hint_embed)
+
+ if winner:
+ content = f"Well done {winner} for getting it right!"
else:
content = "Nobody got it right..."
- answer_embed = discord.Embed(
- title=f"The answer is: {self.correct}!",
- colour=Colours.pink
- )
+ answer_embed = discord.Embed(title=f"The answer is: {correct}!", colour=Colours.pink)
await ctx.send(content, embed=answer_embed)
-
- self.winners.clear()
self.current_channel = None
- @commands.Cog.listener()
- async def on_message(self, message: discord.Message) -> None:
- """If a non-bot user enters a correct answer, their username gets added to self.winners."""
- if self.current_channel != message.channel:
- return
-
- if self.bot.user == message.author:
- return
-
- if message.content.lower() == self.correct.lower():
- self.winners.add(message.author.mention)
-
async def setup(bot: Bot) -> None:
"""Easter Riddle Cog load."""