diff options
Diffstat (limited to 'bot')
-rw-r--r-- | bot/exts/events/trivianight/_scoreboard.py | 7 | ||||
-rw-r--r-- | bot/exts/events/trivianight/trivianight.py | 42 |
2 files changed, 46 insertions, 3 deletions
diff --git a/bot/exts/events/trivianight/_scoreboard.py b/bot/exts/events/trivianight/_scoreboard.py index d0d0a49c..a5a5fcac 100644 --- a/bot/exts/events/trivianight/_scoreboard.py +++ b/bot/exts/events/trivianight/_scoreboard.py @@ -173,11 +173,14 @@ class Scoreboard: self._speed[user_id][0] + 1, self._speed[user_id][1] + speed ] - async def display(self) -> tuple[Embed, View]: + async def display(self, speed_leaderboard: bool = False) -> tuple[Embed, View]: """Returns the embed of the main leaderboard along with the ScoreboardView.""" view = ScoreboardView(self._bot) view.points = dict(sorted(self._points.items(), key=lambda item: item[-1], reverse=True)) view.speed = dict(sorted(self._speed.items(), key=lambda item: item[-1][1] / item[-1][0])) - return await view.create_main_leaderboard(), view + return ( + await view.create_main_leaderboard(), + view if not speed_leaderboard else await view._create_speed_embed() + ) diff --git a/bot/exts/events/trivianight/trivianight.py b/bot/exts/events/trivianight/trivianight.py index 6676a14e..bdcf243a 100644 --- a/bot/exts/events/trivianight/trivianight.py +++ b/bot/exts/events/trivianight/trivianight.py @@ -241,7 +241,7 @@ class TriviaNightCog(commands.Cog): @commands.has_any_role(*TRIVIA_NIGHT_ROLES) async def end(self, ctx: commands.Context) -> None: """ - Ends the trivia night event and displays the scoreboard view. + Displays the scoreboard view. The scoreboard view consists of the two scoreboards with the 30 players who got the highest points and the 30 players who had the fastest average response time to a question where they got the question right. @@ -268,8 +268,48 @@ class TriviaNightCog(commands.Cog): scoreboard_embed, scoreboard_view = await self.scoreboard.display() await ctx.send(embed=scoreboard_embed, view=scoreboard_view) + + @trivianight.command() + @commands.has_any_role(*TRIVIA_NIGHT_ROLES) + async def scoreboard(self, ctx: commands.Context) -> None: + """ + Displays the scoreboard. + + The scoreboard consists of the two scoreboards with the 30 players who got the highest points and the + 30 players who had the fastest average response time to a question where they got the question right. + """ + if self.game is None: + await ctx.send(embed=Embed( + title=choice(NEGATIVE_REPLIES), + description="There is no trivia night running!", + color=Colours.soft_red + )) + return + + if self.game.current_question is not None: + error_embed = Embed( + title=choice(NEGATIVE_REPLIES), + description="You can't end the event while a question is ongoing!", + color=Colours.soft_red + ) + await ctx.send(embed=error_embed) + return + + scoreboard_embed, speed_scoreboard = await self.scoreboard.display(speed_leaderboard=True) + await ctx.send(embeds=(scoreboard_embed, speed_scoreboard)) + + @trivianight.command() + @commands.has_any_role(*TRIVIA_NIGHT_ROLES) + async def end_game(self, ctx: commands.Context) -> None: + """Ends the ongoing game.""" self.game = None + await ctx.send(embed=Embed( + title=choice(POSITIVE_REPLIES), + description="The game has been stopped.", + color=Colours.soft_green + )) + def setup(bot: Bot) -> None: """Load the TriviaNight cog.""" |