aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar JackyFWong <[email protected]>2019-07-07 15:40:58 -0400
committerGravatar JackyFWong <[email protected]>2019-07-07 15:40:58 -0400
commitadc6457aa3496c1606b0728231d4f0f5131207ed (patch)
treef5c86ee5b66c2e34db62339f47a0224ff3e6e0f5
parentfix variables and typo (diff)
implemented one-at-a-time execution policy
-rw-r--r--bot/seasons/easter/easter_riddle.py77
1 files changed, 43 insertions, 34 deletions
diff --git a/bot/seasons/easter/easter_riddle.py b/bot/seasons/easter/easter_riddle.py
index 747c6cdc..2cae299a 100644
--- a/bot/seasons/easter/easter_riddle.py
+++ b/bot/seasons/easter/easter_riddle.py
@@ -24,58 +24,67 @@ class EasterRiddle(commands.Cog):
self.bot = bot
self.winners = []
self.correct = ""
+ self.current_channel = None
@commands.command(aliases=["riddlemethis", "riddleme"])
async def riddle(self, ctx):
"""Gives a random riddle questions, then provides 2 hints at 10 second intervals before revealing the answer"""
- random_question = random.choice(RIDDLE_QUESTIONS)
- question = random_question["question"]
- hints = random_question["riddles"]
- self.correct = random_question["correct_answer"]
+ if not self.current_channel:
+ self.current_channel = ctx.message.channel
- description = f"You have {TIMELIMIT} seconds before the first hint.\n\n"
+ random_question = random.choice(RIDDLE_QUESTIONS)
+ question = random_question["question"]
+ hints = random_question["riddles"]
+ self.correct = random_question["correct_answer"]
- q_embed = discord.Embed(title=question, description=description, colour=Colours.pink)
+ description = f"You have {TIMELIMIT} seconds before the first hint.\n\n"
- await ctx.send(embed=q_embed)
- await asyncio.sleep(TIMELIMIT)
+ q_embed = discord.Embed(title=question, description=description, colour=Colours.pink)
- h_embed = discord.Embed(
- title=f"Here's a hint: {hints[0]}!",
- colour=Colours.pink
- )
+ await ctx.send(embed=q_embed)
+ await asyncio.sleep(TIMELIMIT)
- await ctx.send(embed=h_embed)
- await asyncio.sleep(TIMELIMIT)
+ h_embed = discord.Embed(
+ title=f"Here's a hint: {hints[0]}!",
+ colour=Colours.pink
+ )
- h_embed = discord.Embed(
- title=f"Here's a hint: {hints[1]}!",
- colour=Colours.pink
- )
+ await ctx.send(embed=h_embed)
+ await asyncio.sleep(TIMELIMIT)
- await ctx.send(embed=h_embed)
- await asyncio.sleep(TIMELIMIT)
+ h_embed = discord.Embed(
+ title=f"Here's a hint: {hints[1]}!",
+ colour=Colours.pink
+ )
- if self.winners:
- win_list = " ".join(self.winners)
- content = f"Well done {win_list} for getting it correct!"
- self.winners = []
- else:
- content = "Nobody got it right..."
+ await ctx.send(embed=h_embed)
+ await asyncio.sleep(TIMELIMIT)
+
+ if self.winners:
+ win_list = " ".join(self.winners)
+ content = f"Well done {win_list} for getting it correct!"
+ self.winners = []
+ else:
+ content = "Nobody got it right..."
- a_embed = discord.Embed(
- title=f"The answer is: {self.correct}!",
- colour=Colours.pink
- )
+ a_embed = discord.Embed(
+ title=f"The answer is: {self.correct}!",
+ colour=Colours.pink
+ )
- await ctx.send(content, embed=a_embed)
+ await ctx.send(content, embed=a_embed)
+
+ self.current_channel = None
@commands.Cog.listener()
async def on_message(self, message):
"""If a non-bot user enters a correct answer, their username gets added to self.winners"""
- if self.bot.user != message.author:
- if message.content.lower() == self.correct.lower():
- self.winners.append(message.author.mention)
+ if self.current_channel == message.channel:
+ if self.bot.user != message.author:
+ if message.content.lower() == self.correct.lower():
+ self.winners.append(message.author.mention)
+ else:
+ return
def setup(bot):