diff options
| author | 2019-12-17 08:24:34 -0800 | |
|---|---|---|
| committer | 2019-12-17 08:28:56 -0800 | |
| commit | 529fc617dae7636eb5948bc79f51da9afceb1710 (patch) | |
| tree | 48a3a9b40b1f95249c4d4caabd69d38f3972e513 | |
| parent | fixed a indent error (diff) | |
Trivia: space out some of lines of code
| -rw-r--r-- | bot/seasons/evergreen/trivia_quiz.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/bot/seasons/evergreen/trivia_quiz.py b/bot/seasons/evergreen/trivia_quiz.py index fb7c4ba8..2470ec0f 100644 --- a/bot/seasons/evergreen/trivia_quiz.py +++ b/bot/seasons/evergreen/trivia_quiz.py @@ -80,7 +80,6 @@ class TriviaQuiz(commands.Cog): # Start game if not running. if self.game_status[ctx.channel.id] is False: - self.game_owners[ctx.channel.id] = ctx.author self.game_status[ctx.channel.id] = True start_embed = self.make_start_embed() @@ -94,14 +93,15 @@ class TriviaQuiz(commands.Cog): hint_no = 0 answer = None while self.game_status[ctx.channel.id]: - # Exit quiz if number of questions for a round are already sent. if len(done_question) > self.question_limit and hint_no == 0: await ctx.send("The round has ended.") await self.declare_winner(ctx.channel, self.game_player_scores[ctx.channel.id]) + self.game_status[ctx.channel.id] = False del self.game_owners[ctx.channel.id] self.game_player_scores[ctx.channel.id] = {} + break # If no hint has been sent or any time alert. Basically if hint_no = 0 means it is a new question. @@ -112,6 +112,7 @@ class TriviaQuiz(commands.Cog): if question_dict["id"] not in done_question: done_question.append(question_dict["id"]) break + q = question_dict["question"] answer = question_dict["answer"] @@ -124,6 +125,7 @@ class TriviaQuiz(commands.Cog): def check(m: discord.Message) -> bool: ratio = fuzz.ratio(answer.lower(), m.content.lower()) return ratio > 85 and m.channel == ctx.channel + try: msg = await self.bot.wait_for('message', check=check, timeout=10) except asyncio.TimeoutError: @@ -146,6 +148,7 @@ class TriviaQuiz(commands.Cog): else: if self.game_status[ctx.channel.id] is False: break + response = random.choice(WRONG_ANS_RESPONSE) await ctx.send(response) await self.send_answer(ctx.channel, question_dict) @@ -158,6 +161,7 @@ class TriviaQuiz(commands.Cog): else: if self.game_status[ctx.channel.id] is False: break + # Reduce points by 25 for every hint/time alert that has been sent. points = 100 - 25*hint_no if msg.author in self.game_player_scores[ctx.channel.id]: @@ -201,6 +205,7 @@ class TriviaQuiz(commands.Cog): ): await ctx.send("Quiz stopped.") await self.declare_winner(ctx.channel, self.game_player_scores[ctx.channel.id]) + self.game_status[ctx.channel.id] = False del self.game_owners[ctx.channel.id] self.game_player_scores[ctx.channel.id] = {} @@ -220,12 +225,15 @@ class TriviaQuiz(commands.Cog): if len(player_data) == 0: await channel.send("No one has made it onto the leaderboard yet.") return + embed = discord.Embed(colour=discord.Colour.blue()) embed.title = "Score Board" embed.description = "" + sorted_dict = sorted(player_data.items(), key=lambda a: a[1], reverse=True) for item in sorted_dict: embed.description += f"{item[0]} : {item[1]}\n" + await channel.send(embed=embed) @staticmethod @@ -240,10 +248,12 @@ class TriviaQuiz(commands.Cog): word = "You guys" winners = [] points_copy = list(player_data.values()).copy() + for _ in range(no_of_winners): index = points_copy.index(highest_points) winners.append(list(player_data.keys())[index]) points_copy[index] = 0 + winners_mention = None for winner in winners: winners_mention += f"{winner.mention} " @@ -262,10 +272,12 @@ class TriviaQuiz(commands.Cog): """Build an embed showing all available trivia categories.""" embed = discord.Embed(colour=discord.Colour.blue()) embed.title = "The available question categories are:" + embed.set_footer(text="If not category is chosen, then a random one will be selected.") embed.description = "" + for cat, description in self.categories.items(): embed.description += f"**- {cat.capitalize()}**\n{description.capitalize()}\n" - embed.set_footer(text="If not category is chosen, then a random one will be selected.") + return embed @staticmethod @@ -276,8 +288,10 @@ class TriviaQuiz(commands.Cog): embed = discord.Embed(color=discord.Colour.red()) embed.title = f"The correct answer is **{answer}**\n" embed.description = "" + if info != "": embed.description += f"**Information**\n{info}\n\n" + embed.description += "Let's move to the next question.\nRemaining questions: " await channel.send(embed=embed) |