Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 63d4faab4f |
71
cogs/quiz.py
71
cogs/quiz.py
@@ -8,13 +8,14 @@ from functions.timer import Timer
|
||||
from data.DatabaseConnection import *
|
||||
from functions import checks
|
||||
|
||||
|
||||
class QuizQuestions(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@commands.group(name="questions",case_insensitive=True, invoke_without_command=True)
|
||||
@commands.group(name="questions", case_insensitive=True, invoke_without_command=True)
|
||||
@commands.check(checks.isModPlus)
|
||||
# /q&a add "What is ...." "Australia"
|
||||
# /q&a add "What is ...." "answer"
|
||||
async def questions(self, ctx, *args):
|
||||
pass
|
||||
|
||||
@@ -26,14 +27,14 @@ class QuizQuestions(commands.Cog):
|
||||
q_id = quizdb.add_question(q, a, reward)
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.green()
|
||||
embed.add_field(name="Success", value=f"Added question with {q_id}", inline=False)
|
||||
embed.add_field(
|
||||
name="Success", value=f"Added question with {q_id}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except:
|
||||
await ctx.send("Something went wrong")
|
||||
finally:
|
||||
quizdb.close()
|
||||
|
||||
|
||||
@questions.command(name="rm")
|
||||
@commands.check(checks.isModPlus)
|
||||
async def rm_question(self, ctx, id):
|
||||
@@ -42,7 +43,8 @@ class QuizQuestions(commands.Cog):
|
||||
quizdb.rm_question(id)
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.green()
|
||||
embed.add_field(name="Success", value=f"Question removed with id {id}", inline=False)
|
||||
embed.add_field(
|
||||
name="Success", value=f"Question removed with id {id}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except QuestionNotFound:
|
||||
await ctx.send("No question found with id " + str(id))
|
||||
@@ -60,7 +62,8 @@ class QuizQuestions(commands.Cog):
|
||||
if len(questions) == 0:
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.red()
|
||||
embed.add_field(name="Questions", value=f"No questions found", inline=False)
|
||||
embed.add_field(name="Questions",
|
||||
value=f"No questions found", inline=False)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
@@ -68,16 +71,15 @@ class QuizQuestions(commands.Cog):
|
||||
embed.set_author(name="Questions")
|
||||
embed.colour = discord.Colour.orange()
|
||||
for q in questions:
|
||||
embed.add_field(name=f"id: {q[0]}", value=f"Question: '{q[1]}'\nAnswer: '{q[2]}'\nReward: {q[3]}\nUsed: {q[4]}", inline=False)
|
||||
embed.add_field(
|
||||
name=f"id: {q[0]}", value=f"Question: '{q[1]}'\nAnswer: '{q[2]}'\nReward: {q[3]}\nUsed: {q[4]}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except:
|
||||
await ctx.send("Something went wrong")
|
||||
finally:
|
||||
quizdb.close()
|
||||
|
||||
|
||||
|
||||
@commands.group(name="wordgame",case_insensitive=True, invoke_without_command=True)
|
||||
@commands.group(name="wordgame", case_insensitive=True, invoke_without_command=True)
|
||||
@commands.check(checks.isModPlus)
|
||||
# /q&a add "What is ...." "Australia"
|
||||
async def wordgame(self, ctx, *args):
|
||||
@@ -91,14 +93,14 @@ class QuizQuestions(commands.Cog):
|
||||
w_id = wordgamedb.add_word(w, reward)
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.green()
|
||||
embed.add_field(name="Success", value=f"Added word with {w_id}", inline=False)
|
||||
embed.add_field(
|
||||
name="Success", value=f"Added word with {w_id}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except:
|
||||
await ctx.send("Something went wrong")
|
||||
finally:
|
||||
wordgamedb.close()
|
||||
|
||||
|
||||
@wordgame.command(name="rm")
|
||||
@commands.check(checks.isModPlus)
|
||||
async def rm_word(self, ctx, id):
|
||||
@@ -107,7 +109,8 @@ class QuizQuestions(commands.Cog):
|
||||
wordgamedb.rm_word(id)
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.green()
|
||||
embed.add_field(name="Success", value=f"Question removed with id {id}", inline=False)
|
||||
embed.add_field(
|
||||
name="Success", value=f"Question removed with id {id}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except QuestionNotFound:
|
||||
await ctx.send("No question found with id " + str(id))
|
||||
@@ -125,7 +128,8 @@ class QuizQuestions(commands.Cog):
|
||||
if len(words) == 0:
|
||||
embed = discord.Embed()
|
||||
embed.colour = discord.Colour.red()
|
||||
embed.add_field(name="Words", value=f"No words found", inline=False)
|
||||
embed.add_field(
|
||||
name="Words", value=f"No words found", inline=False)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
else:
|
||||
@@ -133,13 +137,15 @@ class QuizQuestions(commands.Cog):
|
||||
embed.set_author(name="Words")
|
||||
embed.colour = discord.Colour.orange()
|
||||
for w in words:
|
||||
embed.add_field(name=f"id: {w['id']}", value=f"Word: '{w['word']}'\nReward: {w['reward']}\nUsed: {w['asked']}", inline=False)
|
||||
embed.add_field(
|
||||
name=f"id: {w['id']}", value=f"Word: '{w['word']}'\nReward: {w['reward']}\nUsed: {w['asked']}", inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
except:
|
||||
await ctx.send("Something went wrong")
|
||||
finally:
|
||||
wordgamedb.close()
|
||||
|
||||
|
||||
class Quiz(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
@@ -148,8 +154,7 @@ class Quiz(commands.Cog):
|
||||
self.auto = False
|
||||
self.timeout = 10*60
|
||||
|
||||
|
||||
@commands.group(name="quiz",case_insensitive=True, invoke_without_command=True)
|
||||
@commands.group(name="quiz", case_insensitive=True, invoke_without_command=True)
|
||||
@commands.check(checks.isModPlus)
|
||||
async def quiz(self, ctx, f, *args):
|
||||
pass
|
||||
@@ -165,7 +170,6 @@ class Quiz(commands.Cog):
|
||||
async def auto_quiz(self, ctx):
|
||||
self.auto = False
|
||||
|
||||
|
||||
async def start_auto_quiz(self):
|
||||
while self.auto:
|
||||
await asyncio.sleep(random.randint(self.interval[0], self.interval[1]))
|
||||
@@ -187,29 +191,38 @@ class Quiz(commands.Cog):
|
||||
embed.colour = discord.Colour.orange()
|
||||
|
||||
embed.add_field(name="Question:", value=f"{question}", inline=False)
|
||||
embed.add_field(name="Reward:", value=f"${reward} x streak in game", inline=False)
|
||||
embed.add_field(name="End:", value=f"The quiz will end in 10 minutes!", inline=False)
|
||||
embed.add_field(
|
||||
name="Reward:", value=f"${reward} x streak in game", inline=False)
|
||||
embed.add_field(
|
||||
name="End:", value=f"The quiz will end in 10 minutes!", inline=False)
|
||||
return embed
|
||||
|
||||
def create_answer_embed(self, question, answer, reward, streak=-1, author=None, linked=False, correct=False):
|
||||
embed = discord.Embed()
|
||||
|
||||
embed.add_field(name="Question:", value=f"{question}", inline=False)
|
||||
embed.add_field(name="Reward:", value=f"${reward} in game", inline=False)
|
||||
embed.add_field(
|
||||
name="Reward:", value=f"${reward} in game", inline=False)
|
||||
embed.add_field(name="Answer:", value=f"{answer}", inline=False)
|
||||
|
||||
if correct:
|
||||
embed.colour = discord.Colour.green()
|
||||
if linked:
|
||||
embed.add_field(name="Winner:", value=f"{author.mention} 🎉🎉", inline=False)
|
||||
embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft by using /redeem")
|
||||
embed.add_field(
|
||||
name="Winner:", value=f"{author.mention} 🎉🎉", inline=False)
|
||||
embed.add_field(
|
||||
name="Claim:", value=f"Claim your reward in Minecraft by using /redeem")
|
||||
if streak > 1:
|
||||
embed.add_field(name="Streak:", value=f"{author.mention} has a streak going of {streak}", inline=False)
|
||||
embed.add_field(
|
||||
name="Streak:", value=f"{author.mention} has a streak going of {streak}", inline=False)
|
||||
else:
|
||||
embed.add_field(name="Winner:", value=f"{author.mention} 🎉🎉", inline=False)
|
||||
embed.add_field(name="Claim:", value=f"1. Link your account by using /link <MinecraftName> \n2. Claim your reward in Minecraft by using /redeem", inline=False)
|
||||
embed.add_field(
|
||||
name="Winner:", value=f"{author.mention} 🎉🎉", inline=False)
|
||||
embed.add_field(
|
||||
name="Claim:", value=f"1. Link your account by using /link <MinecraftName> \n2. Claim your reward in Minecraft by using /redeem", inline=False)
|
||||
if streak > 1:
|
||||
embed.add_field(name="Streak:", value=f"{author.mention} has a streak going of {streak}", inline=False)
|
||||
embed.add_field(
|
||||
name="Streak:", value=f"{author.mention} has a streak going of {streak}", inline=False)
|
||||
else:
|
||||
embed.colour = discord.Colour.red()
|
||||
return embed
|
||||
@@ -271,7 +284,6 @@ class Quiz(commands.Cog):
|
||||
await channel.send("Nobody found the correct answer!")
|
||||
await channel.send(embed=self.create_answer_embed(f"Find the word from: {shaken_word}", word["word"], word["reward"]))
|
||||
|
||||
|
||||
def shake_word(self, word):
|
||||
word_list = list(word)
|
||||
random.shuffle(word_list)
|
||||
@@ -312,7 +324,8 @@ class Quiz(commands.Cog):
|
||||
quiz_players_db.reset_streak(previousstreak["discordid"])
|
||||
|
||||
if previousstreak is not None and str(previousstreak["discordid"]) == str(discordid):
|
||||
quiz_players_db.player_won(discordid, reward * (previousstreak["cur_streak"] + 1))
|
||||
quiz_players_db.player_won(
|
||||
discordid, reward * (previousstreak["cur_streak"] + 1))
|
||||
else:
|
||||
quiz_players_db.player_won(discordid, reward)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user