diff --git a/common.py b/common.py index af0e9f9..47caf11 100644 --- a/common.py +++ b/common.py @@ -36,6 +36,7 @@ colours = SimpleNamespace( good=0x43B581, neutral=0x7289DA, bad=0xF04747, + timeout=0xF26522, ) # meow @@ -56,10 +57,12 @@ emojis = SimpleNamespace( question="❓", no_entry="⛔", bangbang="‼️", + clock="⏱", a="🇦", b="🇧", c="🇨", d="🇩", + e="🇪", ) paths = SimpleNamespace( diff --git a/exts/study.py b/exts/study.py index d4fc5dc..1739267 100644 --- a/exts/study.py +++ b/exts/study.py @@ -22,7 +22,7 @@ from resources import study class StudyCog(commands.Cog): - choices = {cmn.emojis.a: "A", cmn.emojis.b: "B", cmn.emojis.c: "C", cmn.emojis.d: "D"} + choices = {"A": cmn.emojis.a, "B": cmn.emojis.b, "C": cmn.emojis.c, "D": cmn.emojis.d, "E": cmn.emojis.e} def __init__(self, bot: commands.Bot): self.bot = bot @@ -131,18 +131,22 @@ class StudyCog(commands.Cog): pool_section = random.choice(pool)["sections"] pool_questions = random.choice(pool_section)["questions"] question = random.choice(pool_questions) + answers = question['answers'] + answers_str = "" + answers_str_bolded = "" + for letter, ans in answers.items(): + answers_str += f"{self.choices[letter]} {ans}\n" + if letter == question["answer"]: + answers_str_bolded += f"{self.choices[letter]} **{ans}**\n" + else: + answers_str_bolded += f"{self.choices[letter]} {ans}\n" embed.title = f"{study.pool_emojis[country]} {pool_meta['class']} {question['id']}" embed.description = self.source embed.add_field(name="Question:", value=question["text"], inline=False) - embed.add_field(name="Answers:", - value=(f"**{cmn.emojis.a}** {question['answers']['A']}" - f"\n**{cmn.emojis.b}** {question['answers']['B']}" - f"\n**{cmn.emojis.c}** {question['answers']['C']}" - f"\n**{cmn.emojis.d}** {question['answers']['D']}"), - inline=False) + embed.add_field(name="Answers:", value=answers_str, inline=False) embed.add_field(name="To Answer:", - value=("Answer with reactions below. If not answered within 10 minutes," + value=("Answer with reactions below. If not answered within 5 minutes," " the answer will be revealed."), inline=False) if "image" in question: @@ -151,31 +155,35 @@ class StudyCog(commands.Cog): q_msg = await ctx.send(embed=embed) - await cmn.add_react(q_msg, cmn.emojis.a) - await cmn.add_react(q_msg, cmn.emojis.b) - await cmn.add_react(q_msg, cmn.emojis.c) - await cmn.add_react(q_msg, cmn.emojis.d) + for i in range(len(answers)): + await cmn.add_react(q_msg, list(self.choices.values())[i]) def check(reaction, user): return (user.id != self.bot.user.id and reaction.message.id == q_msg.id - and str(reaction.emoji) in self.choices.keys()) + and str(reaction.emoji) in self.choices.values()) try: - reaction, user = await self.bot.wait_for("reaction_add", timeout=600.0, check=check) + reaction, _ = await self.bot.wait_for("reaction_add", timeout=300.0, check=check) except asyncio.TimeoutError: - embed.remove_field(2) - embed.add_field(name="Answer:", value=f"Timed out! The correct answer was **{question['answer']}**.") + embed.set_field_at(1, name="Answers:", value=answers_str_bolded, inline=False) + embed.set_field_at(2, name="Answer:", + value=(f"{cmn.emojis.clock} " + f"**Timed out!** The correct answer was {self.choices[question['answer']]}")) + embed.colour = cmn.colours.timeout await q_msg.edit(embed=embed) else: - if self.choices[str(reaction.emoji)] == question["answer"]: - embed.remove_field(2) - embed.add_field(name="Answer:", value=f"Correct! The answer was **{question['answer']}**.") + if self.choices[question["answer"]] == str(reaction.emoji): + embed.set_field_at(1, name="Answers:", value=answers_str_bolded, inline=False) + embed.set_field_at(2, name="Answer:", value=(f"{cmn.emojis.check_mark} " + f"**Correct!** The answer was {reaction.emoji}")) embed.colour = cmn.colours.good await q_msg.edit(embed=embed) else: - embed.remove_field(2) - embed.add_field(name="Answer:", value=f"Incorrect! The correct answer was **{question['answer']}**.") + embed.set_field_at(1, name="Answers:", value=answers_str_bolded, inline=False) + embed.set_field_at(2, name="Answer:", + value=(f"{cmn.emojis.x} **Incorrect!** The correct answer was " + f"{self.choices[question['answer']]}, not {reaction.emoji}")) embed.colour = cmn.colours.bad await q_msg.edit(embed=embed)