diff options
author | 2019-07-10 16:53:26 -0400 | |
---|---|---|
committer | 2019-07-10 16:53:26 -0400 | |
commit | 9fb1de91a152bb42b7344e63f2ca6b413b79778c (patch) | |
tree | cb82dcf7d238b633f34f319422a8fa1b0a818f60 /bot | |
parent | Clean up vowel finding logic, update docstrings for new linting rules (diff) | |
parent | implemented one-at-a-time execution policy (diff) |
Merge pull request #202 from JackyFWong/master
Implemented .riddlemethis for the Easter season
Diffstat (limited to 'bot')
-rw-r--r-- | bot/resources/easter/easter_riddle.json | 82 | ||||
-rw-r--r-- | bot/seasons/easter/easter_riddle.py | 93 |
2 files changed, 175 insertions, 0 deletions
diff --git a/bot/resources/easter/easter_riddle.json b/bot/resources/easter/easter_riddle.json new file mode 100644 index 00000000..e93f6dad --- /dev/null +++ b/bot/resources/easter/easter_riddle.json @@ -0,0 +1,82 @@ +[ + { + "question": "What kind of music do bunnies like?", + "riddles": [ + "Two words", + "Jump to the beat" + ], + "correct_answer": "Hip hop" + }, + { + "question": "What kind of jewelry do rabbits wear?", + "riddles": [ + "They can eat it too", + "14 ___ gold" + ], + "correct_answer": "14 carrot gold" + }, + { + "question": "What does the easter bunny get for making a basket?", + "riddles": [ + "KOBE!", + "1+1 = ?" + ], + "correct_answer": "2 points" + }, + { + "question": "Where does the easter bunny eat breakfast?", + "riddles": [ + "No waffles here", + "An international home" + ], + "correct_answer": "IHOP" + }, + { + "question": "What do you call a rabbit with fleas?", + "riddles": [ + "A bit of a looney tune", + "What's up Doc?" + ], + "correct_answer": "Bugs Bunny" + }, + { + "question": "Why was the little girl sad after the race?", + "riddles": [ + "2nd place?", + "Who beat her?" + ], + "correct_answer": "Because an egg beater" + }, + { + "question": "What happened to the Easter Bunny when he misbehaved at school?", + "riddles": [ + "Won't be back anymore", + "Worse than suspension" + ], + "correct_answer": "He was eggspelled" + }, + { + "question": "What kind of bunny can't hop?", + "riddles": [ + "Might melt in the sun", + "Fragile and yummy" + ], + "correct_answer": "A chocolate one" + }, + { + "question": "Where does the Easter Bunny get his eggs?", + "riddles": [ + "Not a bush or tree", + "Emoji for a body part" + ], + "correct_answer": "Eggplants" + }, + { + "question": "Why did the Easter Bunny have to fire the duck?", + "riddles": [ + "Quack", + "MY EGGS!!" + ], + "correct_answer": "He kept quacking the eggs" + } +] diff --git a/bot/seasons/easter/easter_riddle.py b/bot/seasons/easter/easter_riddle.py new file mode 100644 index 00000000..2cae299a --- /dev/null +++ b/bot/seasons/easter/easter_riddle.py @@ -0,0 +1,93 @@ +import asyncio +import logging +import random +from json import load +from pathlib import Path + +import discord +from discord.ext import commands + +from bot.constants import Colours + +log = logging.getLogger(__name__) + +with open(Path('bot', 'resources', 'easter', 'easter_riddle.json'), 'r', encoding="utf8") as f: + RIDDLE_QUESTIONS = load(f) + +TIMELIMIT = 10 + + +class EasterRiddle(commands.Cog): + """This cog contains the command for the Easter quiz!""" + + def __init__(self, bot): + 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""" + if not self.current_channel: + self.current_channel = ctx.message.channel + + random_question = random.choice(RIDDLE_QUESTIONS) + question = random_question["question"] + hints = random_question["riddles"] + self.correct = random_question["correct_answer"] + + description = f"You have {TIMELIMIT} seconds before the first hint.\n\n" + + q_embed = discord.Embed(title=question, description=description, colour=Colours.pink) + + await ctx.send(embed=q_embed) + await asyncio.sleep(TIMELIMIT) + + h_embed = discord.Embed( + title=f"Here's a hint: {hints[0]}!", + colour=Colours.pink + ) + + 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 + ) + + 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 + ) + + 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.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): + """Cog load.""" + bot.add_cog(EasterRiddle(bot)) + log.info("Easter Riddle bot loaded") |