Skip to content

Commit c2b5826

Browse files
update aoc to support 12 stars this year rather than all 25
1 parent 89f20b8 commit c2b5826

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

bot/exts/advent_of_code/_helpers.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@
5656
# for each star to compute the rank score.
5757
StarResult = collections.namedtuple("StarResult", "member_id completion_time")
5858

59+
# In 2025, AOC was changed to be held from Dec 1 to 12, with 12 days rather than 25.
60+
# This implementation is done in such a way that any arbitary number of days can be supported.
61+
def days_in_year(year:int | None = None) -> int:
62+
"""Return the number of days in the current Advent of Code year."""
63+
if year is None:
64+
year = AdventOfCode.year
65+
return 25 if year < 2025 else 12
66+
67+
DAYS_THIS_YEAR = days_in_year()
68+
5969

6070
class UnexpectedRedirect(aiohttp.ClientError):
6171
"""Raised when an unexpected redirect was detected."""
@@ -427,13 +437,15 @@ async def get_public_join_code(author: discord.Member) -> str | None:
427437

428438
def is_in_advent() -> bool:
429439
"""
430-
Check if we're currently on an Advent of Code day, excluding 25 December.
440+
Check if we're currently on an Advent of Code day, excluding the final day of AOC for that year.
431441
432442
This helper function is used to check whether or not a feature that prepares
433443
something for the next Advent of Code challenge should run. As the puzzle
434-
published on the 25th is the last puzzle, this check excludes that date.
444+
published on the final day is the last puzzle, this check excludes that date.
435445
"""
436-
return arrow.now(EST).day in range(1, 25) and arrow.now(EST).month == 12
446+
# Advent of Code always begins on December 1st, and runs for one month
447+
now = arrow.now(EST)
448+
return now.month == 12 and now.day in range(1, DAYS_THIS_YEAR)
437449

438450

439451
def time_left_to_est_midnight() -> tuple[datetime.datetime, datetime.timedelta]:
@@ -471,7 +483,7 @@ async def countdown_status(bot: SirRobin) -> None:
471483
# sleeping for the entire year, it will only wait in the currently
472484
# configured year. This means that the task will only start hibernating once
473485
# we start preparing the next event by changing environment variables.
474-
last_challenge = arrow.get(datetime.datetime(AdventOfCode.year, 12, 25, tzinfo=datetime.UTC), EST)
486+
last_challenge = arrow.get(datetime.datetime(AdventOfCode.year, 12, DAYS_THIS_YEAR, tzinfo=datetime.UTC), EST)
475487
end = last_challenge + datetime.timedelta(hours=1)
476488

477489
while arrow.now(EST) < end:
@@ -516,9 +528,8 @@ async def new_puzzle_notification(bot: SirRobin) -> None:
516528
log.error("Could not find the AoC role to announce the daily puzzle")
517529
return
518530

519-
# The last event day is 25 December, so we only have to schedule
520-
# a reminder if the current day is before 25 December.
521-
end = arrow.get(datetime.datetime(AdventOfCode.year, 12, 25, tzinfo=datetime.UTC), EST)
531+
# Only schedule a reminder if the current day is before the final day December.
532+
end = arrow.get(datetime.datetime(AdventOfCode.year, 12, DAYS_THIS_YEAR, tzinfo=datetime.UTC), EST)
522533
while arrow.now(EST) < end:
523534
log.trace("Started puzzle notification loop.")
524535
tomorrow, time_left = time_left_to_est_midnight()

bot/exts/advent_of_code/views/dayandstarview.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import discord
44

5+
from bot.exts.advent_of_code._helpers import DAYS_THIS_YEAR
6+
57
AOC_DAY_AND_STAR_TEMPLATE = "{rank: >4} | {name:25.25} | {completion_time: >10}"
68

79

@@ -52,7 +54,7 @@ async def interaction_check(self, interaction: discord.Interaction) -> bool:
5254

5355
@discord.ui.select(
5456
placeholder="Day",
55-
options=[discord.SelectOption(label=str(i)) for i in range(1, 26)],
57+
options=[discord.SelectOption(label=str(i)) for i in range(1, DAYS_THIS_YEAR + 1)],
5658
custom_id="day_select",
5759
)
5860
async def day_select(self, interaction: discord.Interaction, select: discord.ui.Select) -> None:

bot/exts/summer_aoc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
log = logging.get_logger(__name__)
1717

18+
# TODO: Add support for different years in accordance with AOC changes
1819
AOC_URL = "https://adventofcode.com/{year}/day/{day}"
1920
LAST_DAY = 25
2021
FIRST_YEAR = 2015

0 commit comments

Comments
 (0)