1111
1212from bot .bot import SirRobin
1313from bot .constants import Bot , Channels , Roles
14+ from bot .exts .advent_of_code ._helpers import days_in_year
1415from bot .utils .time import time_until
1516
1617log = logging .get_logger (__name__ )
1718
19+ # TODO: Add support for different years in accordance with AOC changes
1820AOC_URL = "https://adventofcode.com/{year}/day/{day}"
19- LAST_DAY = 25
2021FIRST_YEAR = 2015
2122LAST_YEAR = arrow .get ().year - 1
2223PUBLIC_NAME = "Revival of Code"
@@ -63,8 +64,9 @@ def __init__(self, bot: SirRobin):
6364 self .wait_task : asyncio .Task | None = None
6465 self .loop_task : tasks .Loop | None = None
6566
66- self .is_running = False
67+ self .is_running : bool = False
6768 self .year : int | None = None
69+ self .days_this_year : int | None = None
6870 self .current_day : int | None = None
6971 self .day_interval : int | None = None
7072 self .post_time = 0
@@ -145,6 +147,7 @@ async def start(self, ctx: commands.Context, year: int, day_interval: int, post_
145147
146148 self .is_running = True
147149 self .year = year
150+ self .days_this_year = days_in_year (year )
148151 self .current_day = 1
149152 self .day_interval = day_interval
150153 self .post_time = post_time
@@ -174,8 +177,8 @@ async def force_day(self, ctx: commands.Context, day: int, now: Literal["now"] |
174177 await ctx .send (embed = embed )
175178 return
176179
177- if not 1 <= day <= LAST_DAY :
178- raise commands .BadArgument (f"Start day must be between 1 and { LAST_DAY } , inclusive" )
180+ if not 1 <= day <= self . days_this_year :
181+ raise commands .BadArgument (f"Start day must be between 1 and { self . days_this_year } , inclusive" )
179182
180183 log .info (f"Setting the current day of Summer AoC to { day } " )
181184 await self .stop_event ()
@@ -187,7 +190,7 @@ async def force_day(self, ctx: commands.Context, day: int, now: Literal["now"] |
187190
188191 embed = self .get_info_embed ()
189192 if now :
190- if self .current_day > LAST_DAY :
193+ if self .current_day > self . days_this_year :
191194 title = "Puzzle posted and event is now ending"
192195 else :
193196 title = "Puzzle posted and event is now running"
@@ -197,7 +200,7 @@ async def force_day(self, ctx: commands.Context, day: int, now: Literal["now"] |
197200 embed .title = title
198201 embed .color = discord .Color .green ()
199202 await ctx .send (embed = embed )
200- if self .current_day <= LAST_DAY :
203+ if self .current_day <= self . days_this_year :
201204 await self .start_event ()
202205
203206 @summer_aoc_group .command (name = "stop" )
@@ -290,7 +293,7 @@ async def stop_event(self) -> bool:
290293
291294 async def post_puzzle (self ) -> None :
292295 """Create a thread for the current day's puzzle."""
293- if self .current_day > LAST_DAY :
296+ if self .current_day > self . days_this_year :
294297 log .error ("Attempted to post puzzle after last day, stopping event" )
295298 await self .stop_event ()
296299 return
@@ -306,7 +309,7 @@ async def post_puzzle(self) -> None:
306309
307310 self .current_day += 1
308311 await self .save_event_state ()
309- if self .current_day > LAST_DAY :
312+ if self .current_day > self . days_this_year :
310313 await self .stop_event ()
311314
312315 def get_info_embed (self ) -> discord .Embed :
@@ -326,7 +329,7 @@ def get_info_embed(self) -> discord.Embed:
326329
327330 def get_puzzle_embed (self ) -> discord .Embed :
328331 """Generate an embed for the day's puzzle post."""
329- if self .current_day == LAST_DAY :
332+ if self .current_day == self . days_this_year :
330333 next_puzzle_text = LAST_PUZZLE_TEXT .format (timestamp = int (arrow .get (REAL_AOC_START ).timestamp ()))
331334 else :
332335 next_puzzle_text = NEXT_PUZZLE_TEXT .format (
0 commit comments