mirror of https://github.com/miaowware/qrm2.git
hamstudy improvements
- added orange colour for timeouts - added emojis in the last field - made the correct answer bold after answering/timeout - minor code optimisations
This commit is contained in:
parent
eb98e295d2
commit
d7e544edcd
|
@ -36,6 +36,7 @@ colours = SimpleNamespace(
|
||||||
good=0x43B581,
|
good=0x43B581,
|
||||||
neutral=0x7289DA,
|
neutral=0x7289DA,
|
||||||
bad=0xF04747,
|
bad=0xF04747,
|
||||||
|
timeout=0xF26522,
|
||||||
)
|
)
|
||||||
|
|
||||||
# meow
|
# meow
|
||||||
|
@ -56,10 +57,12 @@ emojis = SimpleNamespace(
|
||||||
question="❓",
|
question="❓",
|
||||||
no_entry="⛔",
|
no_entry="⛔",
|
||||||
bangbang="‼️",
|
bangbang="‼️",
|
||||||
|
clock="⏱",
|
||||||
a="🇦",
|
a="🇦",
|
||||||
b="🇧",
|
b="🇧",
|
||||||
c="🇨",
|
c="🇨",
|
||||||
d="🇩",
|
d="🇩",
|
||||||
|
e="🇪",
|
||||||
)
|
)
|
||||||
|
|
||||||
paths = SimpleNamespace(
|
paths = SimpleNamespace(
|
||||||
|
|
|
@ -22,7 +22,7 @@ from resources import study
|
||||||
|
|
||||||
|
|
||||||
class StudyCog(commands.Cog):
|
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):
|
def __init__(self, bot: commands.Bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
@ -131,18 +131,22 @@ class StudyCog(commands.Cog):
|
||||||
pool_section = random.choice(pool)["sections"]
|
pool_section = random.choice(pool)["sections"]
|
||||||
pool_questions = random.choice(pool_section)["questions"]
|
pool_questions = random.choice(pool_section)["questions"]
|
||||||
question = random.choice(pool_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.title = f"{study.pool_emojis[country]} {pool_meta['class']} {question['id']}"
|
||||||
embed.description = self.source
|
embed.description = self.source
|
||||||
embed.add_field(name="Question:", value=question["text"], inline=False)
|
embed.add_field(name="Question:", value=question["text"], inline=False)
|
||||||
embed.add_field(name="Answers:",
|
embed.add_field(name="Answers:", value=answers_str, inline=False)
|
||||||
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="To Answer:",
|
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."),
|
" the answer will be revealed."),
|
||||||
inline=False)
|
inline=False)
|
||||||
if "image" in question:
|
if "image" in question:
|
||||||
|
@ -151,31 +155,35 @@ class StudyCog(commands.Cog):
|
||||||
|
|
||||||
q_msg = await ctx.send(embed=embed)
|
q_msg = await ctx.send(embed=embed)
|
||||||
|
|
||||||
await cmn.add_react(q_msg, cmn.emojis.a)
|
for i in range(len(answers)):
|
||||||
await cmn.add_react(q_msg, cmn.emojis.b)
|
await cmn.add_react(q_msg, list(self.choices.values())[i])
|
||||||
await cmn.add_react(q_msg, cmn.emojis.c)
|
|
||||||
await cmn.add_react(q_msg, cmn.emojis.d)
|
|
||||||
|
|
||||||
def check(reaction, user):
|
def check(reaction, user):
|
||||||
return (user.id != self.bot.user.id
|
return (user.id != self.bot.user.id
|
||||||
and reaction.message.id == q_msg.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:
|
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:
|
except asyncio.TimeoutError:
|
||||||
embed.remove_field(2)
|
embed.set_field_at(1, name="Answers:", value=answers_str_bolded, inline=False)
|
||||||
embed.add_field(name="Answer:", value=f"Timed out! The correct answer was **{question['answer']}**.")
|
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)
|
await q_msg.edit(embed=embed)
|
||||||
else:
|
else:
|
||||||
if self.choices[str(reaction.emoji)] == question["answer"]:
|
if self.choices[question["answer"]] == str(reaction.emoji):
|
||||||
embed.remove_field(2)
|
embed.set_field_at(1, name="Answers:", value=answers_str_bolded, inline=False)
|
||||||
embed.add_field(name="Answer:", value=f"Correct! The answer was **{question['answer']}**.")
|
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
|
embed.colour = cmn.colours.good
|
||||||
await q_msg.edit(embed=embed)
|
await q_msg.edit(embed=embed)
|
||||||
else:
|
else:
|
||||||
embed.remove_field(2)
|
embed.set_field_at(1, name="Answers:", value=answers_str_bolded, inline=False)
|
||||||
embed.add_field(name="Answer:", value=f"Incorrect! The correct answer was **{question['answer']}**.")
|
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
|
embed.colour = cmn.colours.bad
|
||||||
await q_msg.edit(embed=embed)
|
await q_msg.edit(embed=embed)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue