aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-11-21 17:09:09 +0100
committerGravatar GitHub <[email protected]>2021-11-21 17:09:09 +0100
commitf5deb3b4d11057311d8aa86723c81a46f47d42c6 (patch)
tree62307f45eeaa5b82d8b3415a1ede310a149346f8
parentMerge pull request #949 from D0rs4n/pr/aochanges (diff)
parentMerge branch 'main' into patch-aocdayandstar (diff)
Merge pull request #954 from D0rs4n/patch-aocdayandstar
Add check to ensure the day-and-star data exists
-rw-r--r--bot/exts/events/advent_of_code/views/dayandstarview.py11
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="",