Cleaned up some code + added redeem
This commit is contained in:
37
cogs/quiz.py
37
cogs/quiz.py
@@ -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()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user