Implement math and riddles theme

This commit is contained in:
TropiiDev 2025-01-31 17:27:14 -05:00
parent ab7b1a74ac
commit 6f6554a488
5 changed files with 207 additions and 78 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@
/.idea /.idea
/commands/__pycache__ /commands/__pycache__
/lib/__pycache__ /lib/__pycache__
.DS_Store

5
bot.py
View File

@ -8,8 +8,6 @@ import asyncio
# sys imports # sys imports
import os import os
import logging
import logging.handlers
load_dotenv() load_dotenv()
@ -36,7 +34,6 @@ intents.members = True
# create the bot # create the bot
class MyBot(commands.Bot): class MyBot(commands.Bot):
def __init__(self): def __init__(self):
# super().__init__(command_prefix=get_server_prefix, intents = intents) - prefix setup
super().__init__(command_prefix="!", intents=intents) super().__init__(command_prefix="!", intents=intents)
self.synced = False self.synced = False
self.remove_command("help") self.remove_command("help")
@ -63,7 +60,7 @@ tree = bot.tree
async def main(): async def main():
async with bot: async with bot:
await bot.load_extensions() await bot.load_extensions()
await bot.start(os.getenv("token")) await bot.start(str(os.getenv("token")))
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
await asyncio.sleep(0.1) await asyncio.sleep(0.1)

View File

@ -2,6 +2,7 @@ import discord
from discord import app_commands from discord import app_commands
from discord.ext import commands from discord.ext import commands
from lib.quiz_helper import * from lib.quiz_helper import *
from lib.leaderboard_helper import *
class Select(discord.ui.Select): class Select(discord.ui.Select):
def __init__(self): def __init__(self):
@ -22,11 +23,48 @@ class Select(discord.ui.Select):
self.theme = "Geography" self.theme = "Geography"
elif self.values[0] == "Pop Culture": elif self.values[0] == "Pop Culture":
self.theme = "Pop Culture" self.theme = "Pop Culture"
elif self.values[0] == "Math":
self.theme = "Math"
elif self.values[0] == "Riddles":
self.theme = "Riddles"
questions = load_questions(self.theme) questions = load_questions(self.theme)
if self.theme != "Riddles":
for i in range(len(questions)): for i in range(len(questions)):
em = discord.Embed(title=f"Question {i + 1}", description=questions[i]) em = discord.Embed(title=f"Question {i + 1}", description=questions[i])
await interaction.response.send_message(embed=em, view=load_view(i, questions, self.theme)) await interaction.response.send_message(embed=em, view=load_view(i, questions, self.theme))
else:
correct = 0
for i in range(len(questions)):
answer = load_answers(i, self.theme)
em = discord.Embed(title=f"Question {i + 1}", description=f"{questions[i]}\nPlease type your answer")
try:
await interaction.response.send_message(embed=em)
except discord.InteractionResponded:
await interaction.followup.send(embed=em)
try:
message = await interaction.client.wait_for(
'message',
timeout=30.0,
check=lambda m: m.author == interaction.user and m.channel == interaction.channel
)
if message.author.bot:
return
# Check if the answer is correct (case-insensitive)
if message.content.lower() == answer.lower():
correct += 1
increment_correct(interaction.user.id, self.theme)
await interaction.followup.send("Answer recorded..")
except TimeoutError:
await interaction.followup.send(f"Time's up! Please try again.\nYou got {correct} answers correct!")
return
if i == len(questions) - 1:
await interaction.followup.send(f"You got {correct} answers correct!")
class SelectView(discord.ui.View): class SelectView(discord.ui.View):
def __init__(self): def __init__(self):

View File

@ -58,6 +58,42 @@ def load_questions(theme):
"Which music artist has the most albums?", "Which music artist has the most albums?",
"Who is top global artist of 2024?" "Who is top global artist of 2024?"
] ]
elif theme == "Math":
questions = [
"What is the Pythagoras theorem rule?",
"What is the answer to (2x5)+5/2?",
"What is the quadratic formula?",
"What is interest?",
"What is √441?",
"Which month is 2 months after August?",
"What is Ѡ equivalent to?",
"What is the longest number with a name?",
"What is the first 6 digits of Pi?",
"What is the longest side of a triangle called?",
"What triangle has the 3 sides equal?",
"How many seconds are in a day?",
"What is the name of a 9 sided shape?",
"What does the internal angles of a triangle add up to?",
"Is 173 a prime number?"
]
elif theme == "Riddles":
questions = [
"What kind of band never plays music?",
"What has a head and a tail but no body?",
"What has four wheels and flies?",
"What would you find in the middle of Toronto?",
"What is 3/7 chicken, 2/3 cat and 2/4 goat?",
"What is so fragile that saying its name breaks it?",
"The more you take, the more you leave behind. What are they?",
"I am always hungry and will die if not fed, but whatever I touch will soon turn red. What am I?",
"The more of this there is, the less you see. What is it?",
"What is black when it's clean and white when it's dirty?",
"What invention lets you look right through a wall?",
"What has hands, but can't clap?",
"What has legs, but doesn't walk?",
"What has a thumb and four fingers, but is not a hand?",
"What building has the most stories?"
]
return questions return questions
@ -117,6 +153,42 @@ def load_answers(question, theme):
"13 Billy Childish", "13 Billy Childish",
"14 Taylor Swift" "14 Taylor Swift"
] ]
elif theme == "Math":
answers = [
"0 a^2+b^2=c^2",
"1 12.5",
"2 x = (-b ± √(b² - 4ac)) / 2a",
"3 P × r × t",
"4 21",
"5 October",
"6 300",
"7 Googleplexian",
"8 3.14159",
"9 Hypotenuse",
"10 Equilateral Triangle",
"11 86400",
"12 Nonagon",
"13 180°",
"14 Yes"
]
elif theme == "Riddles":
answers = [
"0 Rubber Band",
"1 Coin",
"2 Garbage truck",
"3 The letter o",
"4 Chicago",
"5 Silence",
"6 Footsteps",
"7 Fire",
"8 Darkness",
"9 Chalkboard",
"10 Window",
"11 Clock",
"12 Table",
"13 Glove",
"14 Library"
]
answer = answers[question] answer = answers[question]
if ',' in answer: if ',' in answer:
@ -182,6 +254,24 @@ def load_choices(question, theme):
"13 Lady Gaga,Adele,Rihanna", "13 Lady Gaga,Adele,Rihanna",
"14 Billie Eilish,Ariana Grande,Kendrick Lamar" "14 Billie Eilish,Ariana Grande,Kendrick Lamar"
] ]
elif theme == "Math":
choices = [
"0 a^3 + b^3 = c^3,a^2 + b^2 = c^3,a^1 + b^1 = c^2",
"1 15,20,25",
"2 x = (-b ± √(a + c)) / 2a,x = (b ± √(a + c)) / a,x = (b + c) / a",
"3 P + r + t,P × r + t,P ÷ r × t",
"4 20,500,144",
"5 September,July,November",
"6 500,200,1000",
"7 Googol,Centillion,Octillion",
"8 3.14169,3.14559,3.14155",
"9 Diameter,Base,Radius",
"10 Right Angle Triangle,Scalene Triangle,Acute Triangle",
"11 1200,43200,8640",
"12 Decagon,Octagon,Dodecagon",
"13 270°,360°,90°",
"14 No"
]
choice = choices[question] choice = choices[question]
only_choice = choice.split(f"{str(question)} ")[1] only_choice = choice.split(f"{str(question)} ")[1]
@ -196,8 +286,9 @@ class load_select(discord.ui.Select):
self.questions = questions self.questions = questions
self.theme = theme self.theme = theme
self.answer = load_answers(question, self.theme) self.answer = load_answers(question, self.theme)
choices = load_choices(question, self.theme)
if theme != "Riddles":
choices = load_choices(question, self.theme)
options = [] options = []
responses = [] responses = []
@ -217,6 +308,8 @@ class load_select(discord.ui.Select):
self.options = options self.options = options
async def callback(self, interaction: discord.Interaction): async def callback(self, interaction: discord.Interaction):
if isinstance(self.answer, list): if isinstance(self.answer, list):
if any(value in self.answer for value in self.values): if any(value in self.answer for value in self.values):