Cleaned up some code + added redeem

This commit is contained in:
2020-11-10 00:11:52 +01:00
parent 0d8359e9f8
commit 714093fd34
5 changed files with 125 additions and 24 deletions

View File

@@ -18,6 +18,8 @@ class QuizQuestions(commands.Cog):
if (f == "add"):
if (len(args) == 2):
await self.add_question(ctx, args[0], args[1])
elif (len(args) == 3):
await self.add_question(ctx, args[0], args[1], args[2])
else:
await ctx.send("Wrong amount of arguments")
elif (f == "rm"):
@@ -31,13 +33,13 @@ class QuizQuestions(commands.Cog):
else:
await ctx.send("Wrong amount of arguments")
async def add_question(self, ctx, q, a):
async def add_question(self, ctx, q, a, reward=50):
try:
quizdb = QuizDB()
q_id = quizdb.add_question(q, a)
q_id = quizdb.add_question(q, a, reward)
await ctx.send("question id: " + str(q_id))
except:
await ctx.send("Something went wrong")
# except:
# await ctx.send("Something went wrong")
finally:
quizdb.close()
@@ -62,7 +64,7 @@ class QuizQuestions(commands.Cog):
else:
message = ""
for q in questions:
message += f"id: {q[0]}, question: '{q[1]}', answer: '{q[2]}', used: {q[3]}\n"
message += f"id: {q[0]}, question: '{q[1]}', answer: '{q[2]}', reward: {q[3]}, used: {q[4]}\n"
await ctx.send(message)
except:
await ctx.send("Something went wrong")
@@ -123,18 +125,33 @@ class Quiz(commands.Cog):
if message.content.lower() == self.question[2].lower():
self.in_progress = False
quiz_players_db = QuizPlayersDB()
quiz_players_db.player_won(message.author.id, 1)
await message.channel.send(f"{message.author.mention} Won 🎉🎉")
userlinked = self.give_reward(message.author.id, self.question[3])
if userlinked:
await message.channel.send(f"{message.author.mention} Won 🎉🎉")
else:
await message.channel.send(f"{message.author.mention} Won 🎉🎉! To claim? Link your minecraft account")
def increment_asked_count(self, q_id):
quizdb = QuizDB()
quizdb.question_asked_increment(q_id)
quizdb.close()
def get_random_question(self):
quizdb = QuizDB()
return quizdb.get_random_question()
q = quizdb.get_random_question()
quizdb.close()
return q
def give_reward(self, discordid, reward):
quiz_players_db = QuizPlayersDB()
quiz_players_db.player_won(discordid, reward)
quiz_players_db.close()