From cff62e0baf1eb3c6105431c695ef3b0e679576db Mon Sep 17 00:00:00 2001 From: "S. Co1" Date: Sat, 30 Nov 2019 15:42:38 -0500 Subject: Fix AOC countdown logic The current time delta until the next AOC event assumes that the next event is next year's. While this is was a safe assumption when written, since the command would not be available until the season is loaded on December 1st, it provides an incorrect answer if the season is loaded prior. The logic has been adjusted to return the closest December 1st that is not in the past. The feedback string has also been adjusted to give hours remaining if we're less than a day away from the event starting. --- bot/seasons/christmas/adventofcode.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 007e4783..bbfe0a69 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() -- cgit v1.2.3 From f0e53739f4db67b8875a780105eb1904a43cb695 Mon Sep 17 00:00:00 2001 From: "S. Co1" Date: Sat, 30 Nov 2019 16:23:24 -0500 Subject: Remove hardcoded date from AOC info link embed If a date is not specified, the AOC site should redirect to the most recent year. --- bot/resources/advent_of_code/about.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') 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 }, { -- cgit v1.2.3 From b6f10e50cadac21ac1f08bc929afd4523ba6f0c4 Mon Sep 17 00:00:00 2001 From: sco1 Date: Mon, 2 Dec 2019 19:41:27 -0500 Subject: Fix Christmas season loading bug The `SeasonBase.is_between_dates()` method assumes that the season's start and end dates are in the same year, which works for every season except for Christmas, since its end date is New Year's Day. To fix this, the christmas.end() method has been overloaded to return the next year instead of the current year. This does not affect checks made on 1 January of the next year, as the season's start date will guard against this. --- bot/seasons/christmas/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'bot') 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) -- cgit v1.2.3