diff --git a/cogs/quiz.py b/cogs/quiz.py index b880960..fa6886c 100644 --- a/cogs/quiz.py +++ b/cogs/quiz.py @@ -169,7 +169,10 @@ class Quiz(commands.Cog): async def start_auto_quiz(self): while self.auto: await asyncio.sleep(random.randint(self.interval[0], self.interval[1])) - if random.random() < 0.4: + perc = random.random() + if perc < 0.5: + await self.guess_the_number() + elif perc < 0.8: await self.start_word_game() else: await self.ask_question() @@ -179,95 +182,87 @@ class Quiz(commands.Cog): self.auto = True asyncio.create_task(self.start_auto_quiz()) - async def ask_question(self): - - question = self.get_random_question() - - self.increment_asked_count(question[0]) - - channel = self.client.get_channel(constants.QuizChannelID) - + def create_question_embed(self, question, reward): embed = discord.Embed() - #embed.set_author(name="Quiz") embed.colour = discord.Colour.orange() - embed.add_field(name="Question:", value=f"{question[1]}", inline=False) - embed.add_field(name="Reward:", value=f"${question[3]} in game", inline=False) + 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="End:", value=f"The quiz will end in 10 minutes!", inline=False) - await channel.send(embed=embed) + return embed + def create_answer_embed(self, question, answer, reward, author=None, linked=False, correct=False): embed = discord.Embed() embed.colour = discord.Colour.orange() - embed.add_field(name="Question:", value=f"{question[1]}", inline=False) - embed.add_field(name="Reward:", value=f"${question[3]} in game", inline=False) - embed.add_field(name="Answer:", value=f"{question[2]}", inline=False) + 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="Answer:", value=f"{answer}", inline=False) - try: - message = await self.client.wait_for("message", check=lambda message: message.content.lower() == question[2].lower(), timeout=self.timeout) - - self.give_reward(message.author.id, question[3]) - playerdblinker = PlayerDBLinker() + if correct: embed.colour = discord.Colour.green() - if playerdblinker.discordidused(message.author.id): - embed.add_field(name="Winner:", value=f"{message.author.mention} 🎉🎉", inline=False) + 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="Claim:", value=f"Claim your reward in Minecraft when the server is online") - await message.channel.send(embed=embed) else: - embed.add_field(name="Winner:", value=f"{message.author.mention} 🎉🎉", 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 \n2. Claim your reward in Minecraft by using /redeem") - #embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft when the server is online") - await message.channel.send(embed=embed) + else: + embed.colour = discord.Colour.red() + return embed + + async def guess_the_number(self): + ranges = {10: 50, 25: 75, 50: 100, 75: 125, 100: 150} + range = random.choice(list(ranges)) + random_number = random.randint(1, range) + channel = self.client.get_channel(constants.QuizChannelID) + await channel.send(embed=self.create_question_embed(f"Guess the number from 1 to {range}", ranges[range])) + await channel.edit(slowmode_delay=1) + try: + message = await self.client.wait_for("message", check=lambda message: message.content.isdigit() and int(message.content) == random_number, timeout=self.timeout) + self.give_reward(message.author.id, ranges[range]) + playerdblinker = PlayerDBLinker() + linked = playerdblinker.discordidused(message.author.id) + await message.channel.send(embed=self.create_answer_embed(f"Guess the number from 1 to {range}", str(random_number), ranges[range], message.author, linked, True)) playerdblinker.close() except asyncio.TimeoutError: await channel.send("Nobody found the correct answer!") - embed.colour = discord.Colour.red() - await channel.send(embed=embed) + await message.channel.send(embed=self.create_answer_embed(f"Guess the number from 1 to {range}", str(random_number), ranges[range])) + await channel.edit(slowmode_delay=10) + + async def ask_question(self): + question = self.get_random_question() + self.increment_asked_count(question[0]) + channel = self.client.get_channel(constants.QuizChannelID) + await channel.send(embed=self.create_question_embed(question[1], question[3])) + try: + message = await self.client.wait_for("message", check=lambda message: message.content.lower() == question[2].lower(), timeout=self.timeout) + self.give_reward(message.author.id, question[3]) + playerdblinker = PlayerDBLinker() + linked = playerdblinker.discordidused(message.author.id) + await message.channel.send(embed=self.create_answer_embed(question[1], question[2], question[3], message.author, linked, True)) + playerdblinker.close() + except asyncio.TimeoutError: + await channel.send("Nobody found the correct answer!") + await message.channel.send(embed=self.create_answer_embed(question[1], question[2], question[3])) async def start_word_game(self): word = self.get_random_word() self.increment_asked_word(int(word["id"])) channel = self.client.get_channel(constants.QuizChannelID) - - embed = discord.Embed() - #embed.set_author(name="Quiz") - embed.colour = discord.Colour.orange() - shaken_word = self.shake_word(word["word"].lower()) - embed.add_field(name="Question:", value=f"Find the word from: {shaken_word}", inline=False) - embed.add_field(name="Reward:", value=f"${word['reward']} in game", inline=False) - embed.add_field(name="End:", value=f"The game will end in 10 minutes!", inline=False) - await channel.send(embed=embed) - - embed = discord.Embed() - embed.colour = discord.Colour.orange() - - embed.add_field(name="Question:", value=f"{shaken_word}", inline=False) - embed.add_field(name="Reward:", value=f"${word['reward']} in game", inline=False) - embed.add_field(name="Answer:", value=f"{word['word']}", inline=False) - + await channel.send(embed=self.create_question_embed(f"Find the word from: {shaken_word}", word['reward'])) try: message = await self.client.wait_for("message", check=lambda message: message.content.lower() == word['word'].lower(), timeout=self.timeout) - self.give_reward(message.author.id, word["reward"]) playerdblinker = PlayerDBLinker() - embed.colour = discord.Colour.green() - if playerdblinker.discordidused(message.author.id): - embed.add_field(name="Winner:", value=f"{message.author.mention} 🎉🎉", inline=False) - embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft by using /redeem") - #embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft when the server is online") - await message.channel.send(embed=embed) - else: - embed.add_field(name="Winner:", value=f"{message.author.mention} 🎉🎉", inline=False) - embed.add_field(name="Claim:", value=f"1. Link your account by using /link \n2. Claim your reward in Minecraft by using /redeem") - #embed.add_field(name="Claim:", value=f"Claim your reward in Minecraft when the server is online") - await message.channel.send(embed=embed) + linked = playerdblinker.discordidused(message.author.id) + await message.channel.send(embed=self.create_answer_embed(f"Find the word from: {shaken_word}", word["word"], word["reward"], message.author, linked, True)) playerdblinker.close() except asyncio.TimeoutError: await channel.send("Nobody found the correct answer!") - embed.colour = discord.Colour.red() - await channel.send(embed=embed) + await message.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) diff --git a/data/constants.py b/data/constants.py index 852da09..b9ea54f 100755 --- a/data/constants.py +++ b/data/constants.py @@ -20,6 +20,7 @@ modPlusRoles = [roleAdmin, roleMod, roleOwner] # Channels ModLogs = 760807882899193867 -#QuizChannelID_dev = 774418250665951232 +# dev +#QuizChannelID = 774418250665951232 QuizChannelID = 775776550871498752 DiscordLinkerID = 776944220119760927