Implement a geography theme
This commit is contained in:
parent
d8f90517ea
commit
533cae0b79
Binary file not shown.
@ -5,6 +5,7 @@ from lib.quiz_helper import *
|
|||||||
|
|
||||||
class Select(discord.ui.Select):
|
class Select(discord.ui.Select):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.theme = None
|
||||||
options = [
|
options = [
|
||||||
discord.SelectOption(label="History", emoji="1️⃣", description="Do you know your past?"),
|
discord.SelectOption(label="History", emoji="1️⃣", description="Do you know your past?"),
|
||||||
discord.SelectOption(label="Geography", emoji="2️⃣", description="Do you know your geography?"),
|
discord.SelectOption(label="Geography", emoji="2️⃣", description="Do you know your geography?"),
|
||||||
@ -16,10 +17,14 @@ class Select(discord.ui.Select):
|
|||||||
|
|
||||||
async def callback(self, interaction: discord.Interaction):
|
async def callback(self, interaction: discord.Interaction):
|
||||||
if self.values[0] == "History":
|
if self.values[0] == "History":
|
||||||
questions = load_history_questions()
|
self.theme = "History"
|
||||||
for i in range(len(questions)):
|
elif self.values[0] == "Geography":
|
||||||
em = discord.Embed(title=f"Question {i + 1}", description=questions[i])
|
self.theme = "Geography"
|
||||||
await interaction.response.send_message(embed=em, view=load_history_view(i, questions))
|
|
||||||
|
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))
|
||||||
|
|
||||||
class SelectView(discord.ui.View):
|
class SelectView(discord.ui.View):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -5,14 +5,14 @@ client = pymongo.MongoClient(os.getenv('mongo_url'))
|
|||||||
db = client.quiz
|
db = client.quiz
|
||||||
coll = db.leaderboard
|
coll = db.leaderboard
|
||||||
|
|
||||||
def increment_history_correct(user_id):
|
def increment_correct(user_id, theme):
|
||||||
user = coll.find_one({"_id": user_id})
|
user = coll.find_one({"_id": user_id})
|
||||||
|
|
||||||
if user is None:
|
if user is None:
|
||||||
coll.insert_one({"_id": user_id, "amount_correct": 1})
|
coll.insert_one({"_id": user_id, f"{theme}": { "amount_correct": 1}})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
coll.update_one({"_id": user_id}, {"$inc": {"amount_correct": 1}})
|
coll.update_one({"_id": user_id}, {"$inc": {f"{theme}.amount_correct": 1}})
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_correct_answers(user_id):
|
def get_correct_answers(user_id):
|
||||||
|
@ -2,45 +2,85 @@ import discord
|
|||||||
import random
|
import random
|
||||||
from lib.leaderboard_helper import *
|
from lib.leaderboard_helper import *
|
||||||
|
|
||||||
def load_history_questions():
|
def load_questions(theme):
|
||||||
questions = [
|
questions = []
|
||||||
"When did the second world war start (based on allied views)?",
|
if theme == "History":
|
||||||
"When did the second world war end?",
|
questions = [
|
||||||
"Which of these was one of the superpowers in the cold war?",
|
"When did the second world war start (based on allied views)?",
|
||||||
"Who was the loader of North Korea in 1945?",
|
"When did the second world war end?",
|
||||||
"Which country here gained independence between 1945 and 1950?",
|
"Which of these was one of the superpowers in the cold war?",
|
||||||
"When was the first Punic War?",
|
"Who was the loader of North Korea in 1945?",
|
||||||
"Who was the leader of the Soviet Union in 1957?",
|
"Which country here gained independence between 1945 and 1950?",
|
||||||
"Who was the leader of the United States in 1966?",
|
"When was the first Punic War?",
|
||||||
"What combat method was used by the Vietnam in the Vietnam war?",
|
"Who was the leader of the Soviet Union in 1957?",
|
||||||
"What was the 1st Reich?",
|
"Who was the leader of the United States in 1966?",
|
||||||
"Which battle defeated Harald Hardrada of Norway in 1066?",
|
"What combat method was used by the Vietnam in the Vietnam war?",
|
||||||
"Approximately how many people died in World War 2?",
|
"What was the 1st Reich?",
|
||||||
"What ideology was Hungary in 1919?",
|
"Which battle defeated Harald Hardrada of Norway in 1066?",
|
||||||
"Who developed the ideology of Communism?",
|
"Approximately how many people died in World War 2?",
|
||||||
"What happened in Tiananmen Square?"
|
"What ideology was Hungary in 1919?",
|
||||||
]
|
"Who developed the ideology of Communism?",
|
||||||
|
"What happened in Tiananmen Square?"
|
||||||
|
]
|
||||||
|
elif theme == "Geography":
|
||||||
|
questions = [
|
||||||
|
"Name which continent Kenya is on.",
|
||||||
|
"What is an Oxbow lake?",
|
||||||
|
"What happens to the coast when water interacts with it?",
|
||||||
|
"What is the capital of El Salvador?",
|
||||||
|
"What is the longest river in the world?",
|
||||||
|
'What country is known as "Land of a Thousand Lakes"?',
|
||||||
|
"What is the tallest mountain in the world?",
|
||||||
|
"What is the most isolated place on the world called?",
|
||||||
|
"How many bodies of water is the Great Lakes made of?",
|
||||||
|
"What is the 6th most populated country in the world?",
|
||||||
|
"What is the capital city of Malta?",
|
||||||
|
'Which of the following is a "wonder of the world"?',
|
||||||
|
"What is the smallest Country in the world?",
|
||||||
|
"What is the smallest US state?",
|
||||||
|
"What is the most populated city in the world?"
|
||||||
|
]
|
||||||
|
|
||||||
return questions
|
return questions
|
||||||
|
|
||||||
def load_history_answers(question):
|
def load_answers(question, theme):
|
||||||
answers = [
|
answers = []
|
||||||
'0 1939',
|
if theme == "History":
|
||||||
'1 1945',
|
answers = [
|
||||||
'2 USA,USSR',
|
'0 1939',
|
||||||
'3 Terentii Shtykov,Kim Il-Sung',
|
'1 1945',
|
||||||
'4 Vietnam,Indonesia,Philippines,Jordan,India,Pakistan,Myanmar,SriLanka (Ceylon),Israel,Laos,Cambodia,Syria',
|
'2 USA,USSR',
|
||||||
'5 264 BC - 241 BC',
|
'3 Terentii Shtykov,Kim Il-Sung',
|
||||||
'6 Nikita Khrushchev',
|
'4 Vietnam,Indonesia,Philippines,Jordan,India,Pakistan,Myanmar,SriLanka (Ceylon),Israel,Laos,Cambodia,Syria',
|
||||||
'7 Lyndon B Johnson',
|
'5 264 BC - 241 BC',
|
||||||
'8 Guerrilla Warfare',
|
'6 Nikita Khrushchev',
|
||||||
'9 Holy Roman Empire',
|
'7 Lyndon B Johnson',
|
||||||
'10 Battle of Stamford Bridge',
|
'8 Guerrilla Warfare',
|
||||||
'11 70 - 85 million',
|
'9 Holy Roman Empire',
|
||||||
'12 Communist',
|
'10 Battle of Stamford Bridge',
|
||||||
'13 Karl Marx',
|
'11 70 - 85 million',
|
||||||
'14 Nothing,Massacre'
|
'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"
|
||||||
|
]
|
||||||
|
|
||||||
answer = answers[question]
|
answer = answers[question]
|
||||||
if ',' in answer:
|
if ',' in answer:
|
||||||
@ -50,38 +90,59 @@ def load_history_answers(question):
|
|||||||
else:
|
else:
|
||||||
return answer.split(f"{str(question)} ")[1]
|
return answer.split(f"{str(question)} ")[1]
|
||||||
|
|
||||||
def load_history_choices(question):
|
def load_choices(question, theme):
|
||||||
choices = [
|
choices = []
|
||||||
'0 1940,1938,1914',
|
if theme == "History":
|
||||||
'1 1946,1944,1918,1920',
|
choices = [
|
||||||
'2 China,The UK,Germany',
|
'0 1940,1938,1914',
|
||||||
'3 Syngman Rhee,Chiang Kai-shek,Kim Jong Un',
|
'1 1946,1944,1918,1920',
|
||||||
'4 Bahrain,Canada,Australia',
|
'2 China,The UK,Germany',
|
||||||
'5 300 BC - 200 BC,264 BC - 146 BC,120 BC -116 BC',
|
'3 Syngman Rhee,Chiang Kai-shek,Kim Jong Un',
|
||||||
'6 Leonid Brezhnev,Joseph Stalin,Mikhail Gorbachev',
|
'4 Bahrain,Canada,Australia',
|
||||||
'7 John F. Kennedy,Dwight D. Eisenhower,Richard Nixon',
|
'5 300 BC - 200 BC,264 BC - 146 BC,120 BC -116 BC',
|
||||||
'8 Air Strikes,Nuclear Warfare,Hand-to-Hand Combat',
|
'6 Leonid Brezhnev,Joseph Stalin,Mikhail Gorbachev',
|
||||||
'9 Byzantine Empire,Ottoman Empire,Russian Empire',
|
'7 John F. Kennedy,Dwight D. Eisenhower,Richard Nixon',
|
||||||
'10 Battle of Hastings,Battle of Waterloo,Battle of Gettysburg',
|
'8 Air Strikes,Nuclear Warfare,Hand-to-Hand Combat',
|
||||||
'11 100 - 120 million,15 to 30 million,30 to 45 million',
|
'9 Byzantine Empire,Ottoman Empire,Russian Empire',
|
||||||
'12 Capitalist,Monarchist,Fascist',
|
'10 Battle of Hastings,Battle of Waterloo,Battle of Gettysburg',
|
||||||
'13 Vladimir Lenin,Joseph Stalin,Friedrich Engels',
|
'11 100 - 120 million,15 to 30 million,30 to 45 million',
|
||||||
'14 The Fall of the Great Wall of China,A Soccer/Football Match,The signing of the Magna Carta'
|
'12 Capitalist,Monarchist,Fascist',
|
||||||
]
|
'13 Vladimir Lenin,Joseph Stalin,Friedrich Engels',
|
||||||
|
'14 The Fall of the Great Wall of China,A Soccer/Football Match,The signing of the Magna Carta'
|
||||||
|
]
|
||||||
|
elif theme == "Geography":
|
||||||
|
choices = [
|
||||||
|
"0 South America,Europe,Asia",
|
||||||
|
"1 A circular river,A triangle-shaped lake,A square-shaped lake",
|
||||||
|
"2 Freezing,Glaciation,Transpiration",
|
||||||
|
"3 Lima,Caracas,Bogota",
|
||||||
|
"4 Amazon River,Yangtze River,Mississippi River",
|
||||||
|
"5 Norway,Switzerland,Sweden",
|
||||||
|
"6 Mount Fuji,Mount Kilimanjaro,Mount Vesuvius",
|
||||||
|
"7 Bermuda Triangle,South Pole,Loch Ness",
|
||||||
|
"8 7,3,8",
|
||||||
|
"9 South Korea,Russia,Germany",
|
||||||
|
"10 London,Athens,Paris",
|
||||||
|
"11 Eiffel Tower,Statue of Liberty,Big Ben,Sphinx,Red Square",
|
||||||
|
"12 Monaco,Liechtenstein,San Marino,Andorra",
|
||||||
|
"13 Texas,Connecticut,New Jersey",
|
||||||
|
"14 Mexico City,New York,Beijing"
|
||||||
|
]
|
||||||
|
|
||||||
choice = choices[question]
|
choice = choices[question]
|
||||||
only_choice = choice.split(f"{str(question)} ")[1]
|
only_choice = choice.split(f"{str(question)} ")[1]
|
||||||
question_choices = only_choice.split(',')
|
question_choices = only_choice.split(',')
|
||||||
return question_choices
|
return question_choices
|
||||||
|
|
||||||
class load_history_select(discord.ui.Select):
|
class load_select(discord.ui.Select):
|
||||||
def __init__(self, question, questions):
|
def __init__(self, question, questions, theme, correct):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.correct = correct
|
||||||
self.question = question
|
self.question = question
|
||||||
self.questions = questions
|
self.questions = questions
|
||||||
self.answer = load_history_answers(question)
|
self.theme = theme
|
||||||
self.correct = 0
|
self.answer = load_answers(question, self.theme)
|
||||||
choices = load_history_choices(question)
|
choices = load_choices(question, self.theme)
|
||||||
|
|
||||||
options = []
|
options = []
|
||||||
responses = []
|
responses = []
|
||||||
@ -106,10 +167,11 @@ class load_history_select(discord.ui.Select):
|
|||||||
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):
|
||||||
self.correct += 1
|
self.correct += 1
|
||||||
increment_history_correct(interaction.user.id)
|
increment_correct(interaction.user.id, self.theme)
|
||||||
else:
|
else:
|
||||||
if self.values[0] == self.answer:
|
if self.values[0] == self.answer:
|
||||||
increment_history_correct(interaction.user.id)
|
self.correct += 1
|
||||||
|
increment_correct(interaction.user.id, self.theme)
|
||||||
|
|
||||||
await interaction.response.send_message("Answer recorded..")
|
await interaction.response.send_message("Answer recorded..")
|
||||||
|
|
||||||
@ -118,11 +180,11 @@ class load_history_select(discord.ui.Select):
|
|||||||
if next_question_index < len(self.questions):
|
if next_question_index < len(self.questions):
|
||||||
next_question = self.questions[next_question_index]
|
next_question = self.questions[next_question_index]
|
||||||
em = discord.Embed(title=f"Question {next_question_index + 1}", description=next_question)
|
em = discord.Embed(title=f"Question {next_question_index + 1}", description=next_question)
|
||||||
await interaction.followup.send(embed=em, view=load_history_view(next_question_index, self.questions))
|
await interaction.followup.send(embed=em, view=load_view(next_question_index, self.questions, self.theme, self.correct))
|
||||||
else:
|
else:
|
||||||
await interaction.followup.send(f"You finished the quiz. You got {self.correct} answers correct!")
|
await interaction.followup.send(f"You finished the quiz. You got {self.correct} answers correct!")
|
||||||
|
|
||||||
class load_history_view(discord.ui.View):
|
class load_view(discord.ui.View):
|
||||||
def __init__(self, question_index, questions):
|
def __init__(self, question_index, questions, theme, correct = 0):
|
||||||
super().__init__(timeout=None)
|
super().__init__(timeout=None)
|
||||||
self.add_item(load_history_select(question_index, questions))
|
self.add_item(load_select(question_index, questions, theme, correct))
|
Loading…
Reference in New Issue
Block a user