From 5e73471999330b4bfd12437c90ee33c9b0c02656 Mon Sep 17 00:00:00 2001 From: RohanJnr Date: Mon, 7 Oct 2019 21:29:34 +0530 Subject: Corrected a few typos in the json file and also the following refinements for the quiz game: New scoreboard for every game. Store overall score board which refreshs when bot restarts. --- bot/resources/evergreen/trivia_quiz.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bot/resources') diff --git a/bot/resources/evergreen/trivia_quiz.json b/bot/resources/evergreen/trivia_quiz.json index 1ad2a1e1..66df3df7 100644 --- a/bot/resources/evergreen/trivia_quiz.json +++ b/bot/resources/evergreen/trivia_quiz.json @@ -71,6 +71,7 @@ { "id": 106, "question": "Which country is known as the \"Land of Thunderbolt\"?", + "answer": "Bhutan", "info": "Bhutan is known as the \"Land of Thunder Dragon\" or \"Land of Thunderbolt\" due to the violent and large thunderstorms that whip down through the valleys from the Himalayas. The dragon reference was due to people thinking the sparkling light of thunderbolts was the red fire of a dragon." }, { @@ -129,7 +130,7 @@ }, { "id": 116, - "question": "The Vally Of The Kings is located in which country?", + "question": "The Valley Of The Kings is located in which country?", "answer": "Egypt", "info": "The Valley of the Kings, also known as the Valley of the Gates of the Kings, is a valley in Egypt where, for a period of nearly 500 years from the 16th to 11th century BC, rock cut tombs were excavated for the pharaohs and powerful nobles of the New Kingdom (the Eighteenth to the Twentieth Dynasties of Ancient Egypt)." }, -- cgit v1.2.3 From 21fdbdb4ee062e4a7b59320b64da773a42dad6e0 Mon Sep 17 00:00:00 2001 From: RohanJnr Date: Fri, 18 Oct 2019 22:35:24 +0530 Subject: Made some language corrections in the json file and also made seperate functions for the start and end quiz. Added another check to check if the game is still running before sending the answer. --- bot/resources/evergreen/trivia_quiz.json | 4 +-- bot/seasons/evergreen/trivia_quiz.py | 58 ++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 23 deletions(-) (limited to 'bot/resources') diff --git a/bot/resources/evergreen/trivia_quiz.json b/bot/resources/evergreen/trivia_quiz.json index 66df3df7..48ee2ce4 100644 --- a/bot/resources/evergreen/trivia_quiz.json +++ b/bot/resources/evergreen/trivia_quiz.json @@ -113,7 +113,7 @@ { "id": 113, "question": "What's the name of the tallest waterfall in the world.", - "answer": "Angel", + "answer": "Angel Falls", "info": "Angel Falls (Salto Ángel) in Venezuela is the highest waterfall in the world. The falls are 3230 feet in height, with an uninterrupted drop of 2647 feet. Angel Falls is located on a tributary of the Rio Caroni." }, { @@ -143,7 +143,7 @@ { "id": 118, "question": "Where is the \"International Court Of Justice\" located at?", - "answer": "Hague", + "answer": "The Hague", "info": "" }, { diff --git a/bot/seasons/evergreen/trivia_quiz.py b/bot/seasons/evergreen/trivia_quiz.py index d4e582af..efc3cd98 100644 --- a/bot/seasons/evergreen/trivia_quiz.py +++ b/bot/seasons/evergreen/trivia_quiz.py @@ -24,7 +24,6 @@ WRONG_ANS_RESPONSE = [ class TriviaQuiz(commands.Cog): """A cog for all quiz commands.""" - def __init__(self, bot: commands.Bot) -> None: self.bot = bot self.questions = self.load_questions() @@ -66,19 +65,7 @@ class TriviaQuiz(commands.Cog): # Stop game if running. if self.game_status[ctx.channel.id] is True: - # Check if the author is the game starter or a moderator. - if ( - ctx.author == self.game_owners[ctx.channel.id] - or any(Roles.moderator == role.id for role in ctx.author.roles) - ): - await ctx.send("Quiz is no longer running.") - 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] = {} - else: - await ctx.send(f"{ctx.author.mention}, you are not authorised to stop this game :ghost: !") - return + await self.stop_quiz(ctx.author, ctx.channel) category = category.lower() # Send embed showing available categories if inputted category is invalid. @@ -89,15 +76,11 @@ 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 = discord.Embed(colour=discord.Colour.red()) - start_embed.title = "Quiz game Starting!!" - start_embed.description = "Each game consists of 5 questions.\n" - start_embed.description += "**Rules :**\nNo cheating and have fun!" - start_embed.set_footer( - text="Points for a question reduces by 25 after 10s or after a hint. Total time is 30s per question" - ) + start_embed = self.make_start_embed() + await ctx.send(embed=start_embed) # send an embed with the rules await asyncio.sleep(1) @@ -116,8 +99,10 @@ class TriviaQuiz(commands.Cog): 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. if hint_no == 0: + # Select a random question which has not been used yet. while True: question_dict = random.choice(topic) if question_dict["id"] not in done_question: @@ -155,6 +140,8 @@ class TriviaQuiz(commands.Cog): # If hint_no > 2, then it means that all hints/time alerts have been sent. # Also means that the answer is not yet given and the bot sends the answer and the next question. else: + if self.game_status[ctx.channel.id] is False: + break response = random.choice(WRONG_ANS_RESPONSE) expression = random.choice(ANNOYED_EXPRESSIONS) await ctx.send(f"{response} {expression}") @@ -167,6 +154,8 @@ class TriviaQuiz(commands.Cog): await asyncio.sleep(2) 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]: @@ -187,6 +176,33 @@ class TriviaQuiz(commands.Cog): await self.send_score(ctx.channel, self.game_player_scores[ctx.channel.id]) await asyncio.sleep(2) + @staticmethod + def make_start_embed(): + """Generate a starting/introduction embed for the quiz.""" + start_embed = discord.Embed(colour=discord.Colour.red()) + start_embed.title = "Quiz game Starting!!" + start_embed.description = "Each game consists of 5 questions.\n" + start_embed.description += "**Rules :**\nNo cheating and have fun!" + start_embed.set_footer( + text="Points for a question reduces by 25 after 10s or after a hint. Total time is 30s per question" + ) + return start_embed + + async def stop_quiz(self, author, channel): + # Check if the author is the game starter or a moderator. + if ( + author == self.game_owners[channel.id] + or any(Roles.moderator == role.id for role in author.roles) + ): + await channel.send("Quiz is no longer running.") + await self.declare_winner(channel, self.game_player_scores[channel.id]) + self.game_status[channel.id] = False + del self.game_owners[channel.id] + self.game_player_scores[channel.id] = {} + else: + await channel.send(f"{author.mention}, you are not authorised to stop this game :ghost: !") + return + @quiz_game.command(name="leaderboard") async def leaderboard(self, ctx: commands.Context) -> None: """View everyone's score for this bot session.""" -- cgit v1.2.3