diff options
| author | 2021-11-04 13:17:50 -0400 | |
|---|---|---|
| committer | 2022-02-09 18:13:37 -0500 | |
| commit | 1848d0ddd318ff3eee0c9c9efed9fef89f460b21 (patch) | |
| tree | 44a43ed600d0d05e007e3466df7e44bad494bdc8 /bot/exts/events/trivianight/trivianight.py | |
| parent | cog description for .trivianight, and allowing to pick questions that were al... (diff) | |
kahoot style scoring, time limits, and bug fixes
Diffstat (limited to 'bot/exts/events/trivianight/trivianight.py')
| -rw-r--r-- | bot/exts/events/trivianight/trivianight.py | 40 | 
1 files changed, 28 insertions, 12 deletions
| diff --git a/bot/exts/events/trivianight/trivianight.py b/bot/exts/events/trivianight/trivianight.py index 37a29222..9973b6b1 100644 --- a/bot/exts/events/trivianight/trivianight.py +++ b/bot/exts/events/trivianight/trivianight.py @@ -1,3 +1,4 @@ +import asyncio  from json import loads  from random import choice @@ -27,18 +28,19 @@ class TriviaNight(commands.Cog):              for idx, letter in enumerate(text)          ) -    @commands.group() +    @commands.group(aliases=["tn"], invoke_without_command=True)      async def trivianight(self, ctx: commands.Context) -> None:          """No-op subcommand group for organizing different commands.""" -        cog_description = Embed( -            title="What is .trivianight?", -            description=( -                "This 'cog' is for the Python Discord's TriviaNight (date tentative)! Compete against other" -                "players in a trivia about Python!" -            ), -            color=Colours.soft_green -        ) -        await ctx.send(embed=cog_description) +        if ctx.invoked_subcommand is None: +            cog_description = Embed( +                title="What is .trivianight?", +                description=( +                    "This 'cog' is for the Python Discord's TriviaNight (date tentative)! Compete against other" +                    "players in a trivia about Python!" +                ), +                color=Colours.soft_green +            ) +            await ctx.send(embed=cog_description)      @trivianight.command()      async def load(self, ctx: commands.Context) -> None: @@ -79,9 +81,16 @@ class TriviaNight(commands.Cog):              await ctx.send(embed=next_question)              return -        question_embed, question_view = self.questions.current_question() +        (question_embed, time_limit), question_view = self.questions.current_question()          await ctx.send(embed=question_embed, view=question_view) +        for time_remaining in range(time_limit - 1, -1, -1): +            await asyncio.sleep(1) +            if time_remaining % 5 == 0: +                await ctx.send(f"{time_remaining}s remaining") + +        await ctx.send(embed=self.questions.end_question()) +      @trivianight.command()      async def question(self, ctx: commands.Context, question_number: int) -> None:          """Gets a question from the question bank depending on the question number provided.""" @@ -90,9 +99,16 @@ class TriviaNight(commands.Cog):              await ctx.send(embed=question)              return -        question_embed, question_view = self.questions.current_question() +        (question_embed, time_limit), question_view = self.questions.current_question()          await ctx.send(embed=question_embed, view=question_view) +        for time_remaining in range(time_limit - 1, -1, -1): +            await asyncio.sleep(1) +            if time_remaining % 5 == 0: +                await ctx.send(f"{time_remaining}s remaining") + +        await ctx.send(embed=self.questions.end_question()) +      @trivianight.command()      async def list(self, ctx: commands.Context) -> None:          """Displays all the questions from the question bank.""" | 
