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
1819# TODO: Add support for different years in accordance with AOC changes
1920AOC_URL = "https://adventofcode.com/{year}/day/{day}"
20- LAST_DAY = 25
2121FIRST_YEAR = 2015
2222LAST_YEAR = arrow .get ().year - 1
2323PUBLIC_NAME = "Revival of Code"
@@ -64,8 +64,9 @@ def __init__(self, bot: SirRobin):
6464 self .wait_task : asyncio .Task | None = None
6565 self .loop_task : tasks .Loop | None = None
6666
67- self .is_running = False
67+ self .is_running : bool = False
6868 self .year : int | None = None
69+ self .days_this_year : int | None = None
6970 self .current_day : int | None = None
7071 self .day_interval : int | None = None
7172 self .post_time = 0
@@ -146,6 +147,7 @@ async def start(self, ctx: commands.Context, year: int, day_interval: int, post_
146147
147148 self .is_running = True
148149 self .year = year
150+ self .days_this_year = days_in_year (year )
149151 self .current_day = 1
150152 self .day_interval = day_interval
151153 self .post_time = post_time
@@ -175,8 +177,8 @@ async def force_day(self, ctx: commands.Context, day: int, now: Literal["now"] |
175177 await ctx .send (embed = embed )
176178 return
177179
178- if not 1 <= day <= LAST_DAY :
179- 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" )
180182
181183 log .info (f"Setting the current day of Summer AoC to { day } " )
182184 await self .stop_event ()
@@ -188,7 +190,7 @@ async def force_day(self, ctx: commands.Context, day: int, now: Literal["now"] |
188190
189191 embed = self .get_info_embed ()
190192 if now :
191- if self .current_day > LAST_DAY :
193+ if self .current_day > self . days_this_year :
192194 title = "Puzzle posted and event is now ending"
193195 else :
194196 title = "Puzzle posted and event is now running"
@@ -198,7 +200,7 @@ async def force_day(self, ctx: commands.Context, day: int, now: Literal["now"] |
198200 embed .title = title
199201 embed .color = discord .Color .green ()
200202 await ctx .send (embed = embed )
201- if self .current_day <= LAST_DAY :
203+ if self .current_day <= self . days_this_year :
202204 await self .start_event ()
203205
204206 @summer_aoc_group .command (name = "stop" )
@@ -291,7 +293,7 @@ async def stop_event(self) -> bool:
291293
292294 async def post_puzzle (self ) -> None :
293295 """Create a thread for the current day's puzzle."""
294- if self .current_day > LAST_DAY :
296+ if self .current_day > self . days_this_year :
295297 log .error ("Attempted to post puzzle after last day, stopping event" )
296298 await self .stop_event ()
297299 return
@@ -307,7 +309,7 @@ async def post_puzzle(self) -> None:
307309
308310 self .current_day += 1
309311 await self .save_event_state ()
310- if self .current_day > LAST_DAY :
312+ if self .current_day > self . days_this_year :
311313 await self .stop_event ()
312314
313315 def get_info_embed (self ) -> discord .Embed :
@@ -327,7 +329,7 @@ def get_info_embed(self) -> discord.Embed:
327329
328330 def get_puzzle_embed (self ) -> discord .Embed :
329331 """Generate an embed for the day's puzzle post."""
330- if self .current_day == LAST_DAY :
332+ if self .current_day == self . days_this_year :
331333 next_puzzle_text = LAST_PUZZLE_TEXT .format (timestamp = int (arrow .get (REAL_AOC_START ).timestamp ()))
332334 else :
333335 next_puzzle_text = NEXT_PUZZLE_TEXT .format (
0 commit comments