Quiz system permissions fix
This commit is contained in:
51
cogs/quiz.py
51
cogs/quiz.py
@@ -6,13 +6,14 @@ import threading
|
||||
import random
|
||||
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="q&a",case_insensitive=True, invoke_without_command=True)
|
||||
@commands.check(checks.isModPlus)
|
||||
# /q&a add "What is ...." "Australia"
|
||||
async def questions(self, ctx, f, *args):
|
||||
if (f == "add"):
|
||||
@@ -75,11 +76,12 @@ class Quiz(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
self.in_progress = False
|
||||
self.interval = (5, 10)
|
||||
#self.interval = (6*60, 30*60)
|
||||
#self.interval = (5, 10)
|
||||
self.interval = (8*60, 30*60)
|
||||
self.auto = False
|
||||
|
||||
@commands.command(name="quiz")
|
||||
@commands.check(checks.isModPlus)
|
||||
async def quiz_bot(self, ctx, f, *args):
|
||||
if (f == "auto" and not self.auto):
|
||||
self.auto = True
|
||||
@@ -105,8 +107,16 @@ class Quiz(commands.Cog):
|
||||
|
||||
channel = self.client.get_channel(constants.QuizChannelID)
|
||||
self.in_progress = True
|
||||
answer_timer = Timer(10, 0)
|
||||
await channel.send(self.question[1])
|
||||
answer_timer = Timer(1, 0)
|
||||
|
||||
embed = discord.Embed()
|
||||
#embed.set_author(name="Quiz")
|
||||
embed.colour = discord.Colour.orange()
|
||||
|
||||
embed.add_field(name="Question:", value=f"{self.question[1]}", inline=False)
|
||||
embed.add_field(name="Reward:", value=f"${self.question[3]}", inline=False)
|
||||
self.embed = embed
|
||||
await channel.send(embed=embed)
|
||||
answer_timer.start()
|
||||
while not answer_timer.ended and self.in_progress:
|
||||
await asyncio.sleep(1)
|
||||
@@ -114,7 +124,9 @@ class Quiz(commands.Cog):
|
||||
answer_timer.stop()
|
||||
else:
|
||||
self.in_progress = False
|
||||
await channel.send("The answer was : " + self.question[2])
|
||||
embed.colour = discord.Colour.red()
|
||||
embed.add_field(name="Answer:", value=f"{self.question[2]}", inline=False)
|
||||
await channel.send(embed=embed)
|
||||
|
||||
|
||||
@commands.Cog.listener()
|
||||
@@ -125,11 +137,23 @@ class Quiz(commands.Cog):
|
||||
if message.content.lower() == self.question[2].lower():
|
||||
self.in_progress = False
|
||||
|
||||
userlinked = self.give_reward(message.author.id, self.question[3])
|
||||
if userlinked:
|
||||
await message.channel.send(f"{message.author.mention} Won 🎉🎉")
|
||||
self.give_reward(message.author.id, self.question[3])
|
||||
|
||||
playerdblinker = PlayerDBLinker()
|
||||
self.embed.colour = discord.Colour.green()
|
||||
if playerdblinker.discordidused(message.author.id):
|
||||
self.embed.add_field(name="Answer:", value=f"{self.question[2]}", inline=False)
|
||||
self.embed.add_field(name="Winner:", value=f"{message.author.mention} 🎉🎉", inline=False)
|
||||
#self.embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft by using /redeem")
|
||||
self.embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft when the server is online")
|
||||
await message.channel.send(embed=self.embed)
|
||||
else:
|
||||
await message.channel.send(f"{message.author.mention} Won 🎉🎉! To claim? Link your minecraft account")
|
||||
self.embed.add_field(name="Answer:", value=f"{self.question[2]}", inline=False)
|
||||
self.embed.add_field(name="Winner:", value=f"{message.author.mention} 🎉🎉", inline=False)
|
||||
#self.embed.add_field(name="Claim:", value=f"1. Link your account by using /link <MinecraftName> \n2. Claim your reward in Minecraft by using /redeem")
|
||||
self.embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft when the server is online")
|
||||
await message.channel.send(embed=self.embed)
|
||||
playerdblinker.close()
|
||||
|
||||
def increment_asked_count(self, q_id):
|
||||
quizdb = QuizDB()
|
||||
@@ -148,13 +172,6 @@ class Quiz(commands.Cog):
|
||||
quiz_players_db.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(QuizQuestions(client))
|
||||
client.add_cog(Quiz(client))
|
||||
|
||||
Reference in New Issue
Block a user