Skip to content

Commit f798be0

Browse files
update summer to get days for year
1 parent a8e9138 commit f798be0

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

bot/exts/summer_aoc.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
from bot.bot import SirRobin
1313
from bot.constants import Bot, Channels, Roles
14+
from bot.exts.advent_of_code._helpers import days_in_year
1415
from bot.utils.time import time_until
1516

1617
log = logging.get_logger(__name__)
1718

1819
# TODO: Add support for different years in accordance with AOC changes
1920
AOC_URL = "https://adventofcode.com/{year}/day/{day}"
20-
LAST_DAY = 25
2121
FIRST_YEAR = 2015
2222
LAST_YEAR = arrow.get().year - 1
2323
PUBLIC_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
@@ -306,7 +308,7 @@ async def post_puzzle(self) -> None:
306308

307309
self.current_day += 1
308310
await self.save_event_state()
309-
if self.current_day > LAST_DAY:
311+
if self.current_day > self.days_this_year:
310312
await self.stop_event()
311313

312314
def get_info_embed(self) -> discord.Embed:
@@ -326,7 +328,7 @@ def get_info_embed(self) -> discord.Embed:
326328

327329
def get_puzzle_embed(self) -> discord.Embed:
328330
"""Generate an embed for the day's puzzle post."""
329-
if self.current_day == LAST_DAY:
331+
if self.current_day == self.days_this_year:
330332
next_puzzle_text = LAST_PUZZLE_TEXT.format(timestamp=int(arrow.get(REAL_AOC_START).timestamp()))
331333
else:
332334
next_puzzle_text = NEXT_PUZZLE_TEXT.format(

0 commit comments

Comments
 (0)