diff options
| author | 2021-10-18 22:53:54 -0400 | |
|---|---|---|
| committer | 2022-02-09 18:13:36 -0500 | |
| commit | e37115a620ff33d4f0aeb9bac3ced3e8578605e0 (patch) | |
| tree | 1fbe72cd5d08892fd311bae9d9106069f07e33a8 /bot/exts | |
| parent | question view shell finished (diff) | |
finished basic question interface
Diffstat (limited to 'bot/exts')
| -rw-r--r-- | bot/exts/events/trivianight/questions.py | 56 | ||||
| -rw-r--r-- | bot/exts/events/trivianight/scoreboard.py | 2 | 
2 files changed, 51 insertions, 7 deletions
| diff --git a/bot/exts/events/trivianight/questions.py b/bot/exts/events/trivianight/questions.py index 21277ce9..2c1dbc81 100644 --- a/bot/exts/events/trivianight/questions.py +++ b/bot/exts/events/trivianight/questions.py @@ -42,12 +42,10 @@ class QuestionButton(Button):  class QuestionView(View):      """View for the questions.""" -    def __init__(self, scoreboard: Scoreboard): -        self.scoreboard = scoreboard +    def __init__(self):          self.current_question = {} -        self._users_picked = {} -    def _create_current_question(self) -> Embed: +    def create_current_question(self) -> Embed:          """Helper function to create the embed for the current question."""          question_embed = Embed(              title=f"Question {self.current_question['number']}", @@ -58,14 +56,60 @@ class QuestionView(View):              question_embed.add_field(name=label, value=answer, inline=False)          self.buttons = [QuestionButton(label) for label in ("A", "B", "C", "D")] +        for button in self.buttons: +            self.add_item(button)          return question_embed -    def end_question(self) -> dict: +    def end_question(self) -> tuple[dict, Embed]:          """Returns the dictionaries from the corresponding buttons for those who got it correct."""          labels = ("A", "B", "C", "D")          label = labels[self.current_question["correct"].index(self.current_question["answers"])]          return_dict = {}          for button in self.buttons:              return_dict.update(button.answer(label)) +            self.remove_item(button) + +        answer_embed = Embed( +            title=f"The correct answer for Question {self.current_question['number']} was", +            color=Colours.grass_green +        ) +        answer_embed.add_field( +            name=label, +            value=self.current_question["correct"].index(self.current_question["answers"]), +            inline=False +        ) + +        return return_dict, answer_embed + + +class Questions: +    """An interface to use from the TriviaNight cog for questions.""" + +    def __init__(self, scoreboard: Scoreboard): +        self.scoreboard = scoreboard +        self.questions = [] +        self._ptr = -1 + +    def set_questions(self, questions: list) -> None: +        """Setting `self.questions` dynamically via a function to set it.""" +        self.questions = questions + +    def next_question(self) -> None: +        """Advances to the next question.""" +        self._ptr += 1 +        if self._ptr < len(self.questions): +            self.questions[self._ptr]["visited"] = True +            self.view.current_question = self.questions[self._ptr] + +    def current_question(self) -> tuple[Embed, QuestionView]: +        """Returns an embed entailing the current question as an embed with a view.""" +        return self.view.create_current_question(), self.view + +    def end_question(self) -> None: +        """Terminates answering of the question and displays the correct answer.""" +        scores, answer_embed = self.view.end_question() +        for user, score in scores.items(): +            self.scoreboard[f"points: {user}"] = score[1] +            self.scoreboard[f"speed: {user}"] = score[2] -        return return_dict +        return answer_embed diff --git a/bot/exts/events/trivianight/scoreboard.py b/bot/exts/events/trivianight/scoreboard.py index 34535690..27a45e30 100644 --- a/bot/exts/events/trivianight/scoreboard.py +++ b/bot/exts/events/trivianight/scoreboard.py @@ -74,7 +74,7 @@ class Scoreboard:          if item.startswith("points: "):              return self.view.points[item.removeprefix("points: ")]          elif item.startswith("speed: "): -            return self.view.speed[item.removepreix("speed: ")] +            return self.view.speed[item.removeprefix("speed: ")]      def display(self) -> Union[Embed, View]:          """Returns the embed of the main leaderboard along with the ScoreboardView.""" | 
