diff --git a/.gitignore b/.gitignore index 869f7af..ca512e3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ .env /.idea /commands/__pycache__ -/lib/__pycache__ \ No newline at end of file +/lib/__pycache__ +.DS_Store \ No newline at end of file diff --git a/bot.py b/bot.py index aa0b41a..0382b83 100644 --- a/bot.py +++ b/bot.py @@ -8,8 +8,6 @@ import asyncio # sys imports import os -import logging -import logging.handlers load_dotenv() @@ -36,7 +34,6 @@ intents.members = True # create the bot class MyBot(commands.Bot): def __init__(self): - # super().__init__(command_prefix=get_server_prefix, intents = intents) - prefix setup super().__init__(command_prefix="!", intents=intents) self.synced = False self.remove_command("help") @@ -63,9 +60,9 @@ tree = bot.tree async def main(): async with bot: 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) -asyncio.run(main()) \ No newline at end of file +asyncio.run(main()) diff --git a/commands/quiz.py b/commands/quiz.py index 2667956..86ebf98 100644 --- a/commands/quiz.py +++ b/commands/quiz.py @@ -2,6 +2,7 @@ import discord from discord import app_commands from discord.ext import commands from lib.quiz_helper import * +from lib.leaderboard_helper import * class Select(discord.ui.Select): def __init__(self): @@ -22,11 +23,48 @@ class Select(discord.ui.Select): self.theme = "Geography" elif self.values[0] == "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) - for i in range(len(questions)): - 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)) + if self.theme != "Riddles": + for i in range(len(questions)): + 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)) + 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): def __init__(self): diff --git a/lib/leaderboard_helper.py b/lib/leaderboard_helper.py index 9ddd9c8..1c5b3af 100644 --- a/lib/leaderboard_helper.py +++ b/lib/leaderboard_helper.py @@ -22,4 +22,4 @@ def get_correct_answers(user_id): return 0 correct = int(user["amount_correct"]) - return correct \ No newline at end of file + return correct diff --git a/lib/quiz_helper.py b/lib/quiz_helper.py index 58b4925..b74b470 100644 --- a/lib/quiz_helper.py +++ b/lib/quiz_helper.py @@ -58,66 +58,138 @@ def load_questions(theme): "Which music artist has the most albums?", "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 def load_answers(question, theme): answers = [] if theme == "History": - answers = [ - '0 1939', - '1 1945', - '2 USA,USSR', - '3 Terentii Shtykov,Kim Il-Sung', - '4 Vietnam,Indonesia,Philippines,Jordan,India,Pakistan,Myanmar,SriLanka (Ceylon),Israel,Laos,Cambodia,Syria', - '5 264 BC - 241 BC', - '6 Nikita Khrushchev', - '7 Lyndon B Johnson', - '8 Guerrilla Warfare', - '9 Holy Roman Empire', - '10 Battle of Stamford Bridge', - '11 70 - 85 million', - '12 Communist', - '13 Karl Marx', - '14 Nothing,Massacre' - ] + answers = [ + '0 1939', + '1 1945', + '2 USA,USSR', + '3 Terentii Shtykov,Kim Il-Sung', + '4 Vietnam,Indonesia,Philippines,Jordan,India,Pakistan,Myanmar,SriLanka (Ceylon),Israel,Laos,Cambodia,Syria', + '5 264 BC - 241 BC', + '6 Nikita Khrushchev', + '7 Lyndon B Johnson', + '8 Guerrilla Warfare', + '9 Holy Roman Empire', + '10 Battle of Stamford Bridge', + '11 70 - 85 million', + '12 Communist', + '13 Karl Marx', + '14 Nothing,Massacre' + ] elif theme == "Geography": - answers = [ - "0 Africa", - "1 A curved lake formed from a horseshoe", - "2 Erosion", - "3 San Salvador", - "4 Nile", - "5 Finland", - "6 Mount Everest", - "7 Point Nemo", - "8 5", - "9 Nigeria", - "10 Valletta", - "11 The Great Wall of China,Petra,Christ the Redeemer,Machu Picchu,Chichen Itza,The Colosseum and The Taj Mahal", - "12 Vatican City", - "13 Rhode Island", - "14 Tokyo" - ] + answers = [ + "0 Africa", + "1 A curved lake formed from a horseshoe", + "2 Erosion", + "3 San Salvador", + "4 Nile", + "5 Finland", + "6 Mount Everest", + "7 Point Nemo", + "8 5", + "9 Nigeria", + "10 Valletta", + "11 The Great Wall of China,Petra,Christ the Redeemer,Machu Picchu,Chichen Itza,The Colosseum and The Taj Mahal", + "12 Vatican City", + "13 Rhode Island", + "14 Tokyo" + ] elif theme == "Pop Culture": - answers = [ - "0 Subway Surfers", - "1 Scarface", - "2 Cristiano Ronaldo", - "3 Deadpool and Wolverine", - "4 Space Invaders", - "5 Muggsy Bogues", - "6 Kai Cenat", - "7 William James Sidis", - "8 Elon Musk", - "9 Eve,La La Land,Titanic", - "10 YouTube Rewind 2018: Everyone Controls Rewind", - "11 2016", - "12 CrazyBus", - "13 Billy Childish", - "14 Taylor Swift" - ] - + answers = [ + "0 Subway Surfers", + "1 Scarface", + "2 Cristiano Ronaldo", + "3 Deadpool and Wolverine", + "4 Space Invaders", + "5 Muggsy Bogues", + "6 Kai Cenat", + "7 William James Sidis", + "8 Elon Musk", + "9 Eve,La La Land,Titanic", + "10 YouTube Rewind 2018: Everyone Controls Rewind", + "11 2016", + "12 CrazyBus", + "13 Billy Childish", + "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] if ',' in answer: only_answer = answer.split(f"{str(question)} ")[1] @@ -182,6 +254,24 @@ def load_choices(question, theme): "13 Lady Gaga,Adele,Rihanna", "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] only_choice = choice.split(f"{str(question)} ")[1] @@ -196,26 +286,29 @@ class load_select(discord.ui.Select): self.questions = questions self.theme = theme self.answer = load_answers(question, self.theme) - choices = load_choices(question, self.theme) + + if theme != "Riddles": + choices = load_choices(question, self.theme) + options = [] + responses = [] - options = [] - responses = [] + if isinstance(self.answer, list): + for ans in self.answer: + responses.append(ans) + else: + responses.append(self.answer) - if isinstance(self.answer, list): - for ans in self.answer: - responses.append(ans) - else: - responses.append(self.answer) + for choice in choices: + responses.append(choice) - for choice in choices: - responses.append(choice) + while responses: + response = random.choice(responses) + options.append(discord.SelectOption(label=response)) + responses.remove(response) - while responses: - response = random.choice(responses) - options.append(discord.SelectOption(label=response)) - responses.remove(response) + self.options = options + - self.options = options async def callback(self, interaction: discord.Interaction): if isinstance(self.answer, list): @@ -241,4 +334,4 @@ class load_select(discord.ui.Select): class load_view(discord.ui.View): def __init__(self, question_index, questions, theme, correct = 0): super().__init__(timeout=None) - self.add_item(load_select(question_index, questions, theme, correct)) + self.add_item(load_select(question_index, questions, theme, correct)) \ No newline at end of file