diff options
| author | 2021-11-21 11:20:13 +0100 | |
|---|---|---|
| committer | 2021-11-21 11:20:13 +0100 | |
| commit | 19a21dc6b07a6c7947fbde1de9c6aee21ccc0ef8 (patch) | |
| tree | 62307f45eeaa5b82d8b3415a1ede310a149346f8 /bot | |
| parent | Update Caching logic in AoC helpers (diff) | |
Add check to ensure the day-and-star data exists
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/exts/events/advent_of_code/views/dayandstarview.py | 11 | 
1 files changed, 8 insertions, 3 deletions
| diff --git a/bot/exts/events/advent_of_code/views/dayandstarview.py b/bot/exts/events/advent_of_code/views/dayandstarview.py index 243db32e..a0bfa316 100644 --- a/bot/exts/events/advent_of_code/views/dayandstarview.py +++ b/bot/exts/events/advent_of_code/views/dayandstarview.py @@ -17,14 +17,19 @@ class AoCDropdownView(discord.ui.View):          self.original_author = original_author      def generate_output(self) -> str: -        """Generates a formatted codeblock with AoC statistics based on the currently selected day and star.""" +        """ +        Generates a formatted codeblock with AoC statistics based on the currently selected day and star. + +        Optionally, when the requested day and star data does not exist yet it returns an error message. +        """          header = AOC_DAY_AND_STAR_TEMPLATE.format(              rank="Rank",              name="Name", completion_time="Completion time (UTC)"          )          lines = [f"{header}\n{'-' * (len(header) + 2)}"] - -        for rank, scorer in enumerate(self.data[f"{self.day}-{self.star}"][:self.maximum_scorers]): +        if not (day_and_star_data := self.data.get(f"{self.day}-{self.star}")): +            return ":x: The requested data for the specified day and star does not exist yet." +        for rank, scorer in enumerate(day_and_star_data[:self.maximum_scorers]):              time_data = datetime.fromtimestamp(scorer['completion_time']).strftime("%I:%M:%S %p")              lines.append(AOC_DAY_AND_STAR_TEMPLATE.format(                  datastamp="", | 
