Created streaks
This commit is contained in:
0
cogs/events.py
Normal file → Executable file
0
cogs/events.py
Normal file → Executable file
0
cogs/leaderboards.py
Normal file → Executable file
0
cogs/leaderboards.py
Normal file → Executable file
53
cogs/quiz.py
Normal file → Executable file
53
cogs/quiz.py
Normal file → Executable file
@@ -143,8 +143,8 @@ class QuizQuestions(commands.Cog):
|
||||
class Quiz(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
#self.interval = (5, 10)
|
||||
self.interval = (5*60, 20*60)
|
||||
self.interval = (1, 4)
|
||||
#self.interval = (5*60, 20*60)
|
||||
self.auto = False
|
||||
self.timeout = 10*60
|
||||
|
||||
@@ -187,11 +187,11 @@ 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} in game", 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, author=None, linked=False, correct=False):
|
||||
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)
|
||||
@@ -203,9 +203,13 @@ class Quiz(commands.Cog):
|
||||
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")
|
||||
if streak > 1:
|
||||
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")
|
||||
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)
|
||||
else:
|
||||
embed.colour = discord.Colour.red()
|
||||
return embed
|
||||
@@ -219,12 +223,14 @@ class Quiz(commands.Cog):
|
||||
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])
|
||||
streak = 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))
|
||||
await message.channel.send(embed=self.create_answer_embed(f"Guess the number from 1 to {range}", str(random_number), ranges[range] * streak, streak, message.author, linked, True))
|
||||
|
||||
playerdblinker.close()
|
||||
except asyncio.TimeoutError:
|
||||
self.reset_current_streak()
|
||||
await channel.send("Nobody found the correct answer!")
|
||||
await 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)
|
||||
@@ -236,12 +242,17 @@ class Quiz(commands.Cog):
|
||||
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])
|
||||
streak = 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))
|
||||
await message.channel.send(embed=self.create_answer_embed(question[1], question[2], question[3] * streak, streak, message.author, linked, True))
|
||||
|
||||
if streak > 1:
|
||||
await message.channel.send(f"{message.author.mention} has a streak going of {streak}")
|
||||
|
||||
playerdblinker.close()
|
||||
except asyncio.TimeoutError:
|
||||
self.reset_current_streak()
|
||||
await channel.send("Nobody found the correct answer!")
|
||||
await channel.send(embed=self.create_answer_embed(question[1], question[2], question[3]))
|
||||
|
||||
@@ -253,12 +264,14 @@ class Quiz(commands.Cog):
|
||||
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"])
|
||||
streak = self.give_reward(message.author.id, word["reward"])
|
||||
playerdblinker = PlayerDBLinker()
|
||||
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))
|
||||
await message.channel.send(embed=self.create_answer_embed(f"Find the word from: {shaken_word}", word["word"], word["reward"] * streak, streak, message.author, linked, True))
|
||||
|
||||
playerdblinker.close()
|
||||
except asyncio.TimeoutError:
|
||||
self.reset_current_streak()
|
||||
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"]))
|
||||
|
||||
@@ -290,10 +303,26 @@ class Quiz(commands.Cog):
|
||||
wordgamedb.word_asked_increment(w_id)
|
||||
wordgamedb.close()
|
||||
|
||||
def reset_current_streak(self):
|
||||
quiz_players_db = QuizPlayersDB()
|
||||
current = quiz_players_db.get_current_streak()
|
||||
if current != None:
|
||||
quiz_players_db.reset_streak(current["discordid"])
|
||||
|
||||
def give_reward(self, discordid, reward):
|
||||
quiz_players_db = QuizPlayersDB()
|
||||
quiz_players_db.player_won(discordid, reward)
|
||||
previousstreak = quiz_players_db.get_current_streak()
|
||||
if previousstreak is not None and str(previousstreak["discordid"]) != str(discordid):
|
||||
quiz_players_db.reset_streak(previousstreak["discordid"])
|
||||
|
||||
if previousstreak is not None and previousstreak["discordid"] == discordid:
|
||||
quiz_players_db.player_won(discordid, reward * (previousstreak["cur_streak"] + 1))
|
||||
else:
|
||||
quiz_players_db.player_won(discordid, reward)
|
||||
|
||||
current_streak = quiz_players_db.get_current_streak()
|
||||
quiz_players_db.close()
|
||||
return current_streak["cur_streak"]
|
||||
|
||||
|
||||
def setup(client):
|
||||
|
||||
0
cogs/serverstatus.py
Normal file → Executable file
0
cogs/serverstatus.py
Normal file → Executable file
Reference in New Issue
Block a user