aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/resources/advent_of_code/about.json2
-rw-r--r--bot/seasons/christmas/__init__.py7
-rw-r--r--bot/seasons/christmas/adventofcode.py17
3 files changed, 22 insertions, 4 deletions
diff --git a/bot/resources/advent_of_code/about.json b/bot/resources/advent_of_code/about.json
index 4abf9145..b1d16a93 100644
--- a/bot/resources/advent_of_code/about.json
+++ b/bot/resources/advent_of_code/about.json
@@ -16,7 +16,7 @@
},
{
"name": "How does scoring work?",
- "value": "Getting a star first is worth 100 points, second is 99, and so on down to 1 point at 100th place.\n\nCheck out AoC's [global leaderboard](https://adventofcode.com/2018/leaderboard) to see who's leading this year's event!",
+ "value": "Getting a star first is worth 100 points, second is 99, and so on down to 1 point at 100th place.\n\nCheck out AoC's [global leaderboard](https://adventofcode.com/leaderboard) to see who's leading this year's event!",
"inline": false
},
{
diff --git a/bot/seasons/christmas/__init__.py b/bot/seasons/christmas/__init__.py
index 6f6efe51..4287efb7 100644
--- a/bot/seasons/christmas/__init__.py
+++ b/bot/seasons/christmas/__init__.py
@@ -1,3 +1,5 @@
+import datetime
+
from bot.constants import Colours
from bot.seasons import SeasonBase
@@ -24,3 +26,8 @@ class Christmas(SeasonBase):
icon = (
"/logos/logo_seasonal/christmas/2019/festive_512.gif",
)
+
+ @classmethod
+ def end(cls) -> datetime.datetime:
+ """Overload the `SeasonBase` method to account for the event ending in the next year."""
+ return datetime.datetime.strptime(f"{cls.end_date}/{cls.current_year() + 1}", cls.date_format)
diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py
index b59c4eba..71da8d94 100644
--- a/bot/seasons/christmas/adventofcode.py
+++ b/bot/seasons/christmas/adventofcode.py
@@ -170,10 +170,21 @@ class AdventOfCode(commands.Cog):
"""Return time left until next day."""
if not is_in_advent():
datetime_now = datetime.now(EST)
- december_first = datetime(datetime_now.year + 1, 12, 1, tzinfo=EST)
- delta = december_first - datetime_now
+
+ # Calculate the delta to this & next year's December 1st to see which one is closest and not in the past
+ this_year = datetime(datetime_now.year, 12, 1, tzinfo=EST)
+ next_year = datetime(datetime_now.year + 1, 12, 1, tzinfo=EST)
+ deltas = (dec_first - datetime_now for dec_first in (this_year, next_year))
+ delta = min(delta for delta in deltas if delta >= timedelta()) # timedelta() gives 0 duration delta
+
+ # Add a finer timedelta if there's less than a day left
+ if delta.days == 0:
+ delta_str = f"approximately {delta.seconds // 3600} hours"
+ else:
+ delta_str = f"{delta.days} days"
+
await ctx.send(f"The Advent of Code event is not currently running. "
- f"The next event will start in {delta.days} days.")
+ f"The next event will start in {delta_str}.")
return
tomorrow, time_left = time_left_to_aoc_midnight()