11import json
2- from datetime import UTC , datetime , timedelta
2+ from datetime import UTC , datetime , time , timedelta
33from pathlib import Path
4+ from zoneinfo import ZoneInfo
45
56import arrow
67import discord
@@ -79,6 +80,9 @@ async def cog_load(self) -> None:
7980 if await _caches .aoc_settings .get (_caches .AoCSettingOption .COMPLETIONIST_ENABLED .value ):
8081 self .completionist_task .start ()
8182
83+ if await _caches .aoc_settings .get (_caches .AoCSettingOption .AUTO_POSTING_ENABLED .value ):
84+ self .daily_posting_task .start ()
85+
8286 @tasks .loop (minutes = 10.0 )
8387 async def completionist_task (self ) -> None :
8488 """
@@ -131,6 +135,29 @@ async def completionist_task(self) -> None:
131135 log .debug (f"Giving completionist role to { member .name } ({ member .mention } )." )
132136 await members .handle_role_change (member , member .add_roles , completionist_role )
133137
138+ @tasks .loop (time = time (0 , 0 , 0 , tzinfo = ZoneInfo (_helpers .EST )))
139+ async def daily_posting_task (self ) -> None :
140+ """
141+ Create a spoilers post for the new puzzle posted at this time.
142+
143+ Runs every day at midnight EST during the event.
144+ """
145+ today = arrow .now (_helpers .EST ).date ()
146+
147+ if not _helpers .is_in_advent ():
148+ log .info ("AoC daily posting is on, but it's not the AoC period. Skipping." )
149+ return
150+
151+ guild = self .bot .get_guild (Bot .guild )
152+ aoc_spoilers_channel : discord .ForumChannel = guild .get_channel (Channels .advent_of_code_spoilers )
153+ if not aoc_spoilers_channel :
154+ log .info ("Couldn't find the AoC spoilers channel. Skipping." )
155+
156+ await aoc_spoilers_channel .create_thread (
157+ name = f"AoC { today .year } | Day { today .day } " ,
158+ content = f"Spoilers discussion for day { today .day } — <{ _helpers .aoc_puzzle_link (today .day )} >" ,
159+ )
160+
134161 @commands .group (name = "adventofcode" , aliases = ("aoc" ,))
135162 async def adventofcode_group (self , ctx : commands .Context ) -> None :
136163 """All of the Advent of Code commands."""
@@ -140,7 +167,7 @@ async def adventofcode_group(self, ctx: commands.Context) -> None:
140167 @with_role (Roles .admins , Roles .events_lead , fail_silently = True )
141168 @adventofcode_group .command (
142169 name = "completionist_toggle" ,
143- aliases = ("ct" , "toggle" ),
170+ aliases = ("ct" ,),
144171 brief = "Toggle whether or not the completionist role is issued to new users." ,
145172 )
146173 async def completionist_toggle (self , ctx : commands .Context ) -> None :
@@ -157,6 +184,38 @@ async def completionist_toggle(self, ctx: commands.Context) -> None:
157184 await _caches .aoc_settings .set (_caches .AoCSettingOption .COMPLETIONIST_ENABLED .value , new_state )
158185 await ctx .send (f":+1: Completionist role issuing is now { state_string } ." )
159186
187+ @with_role (Roles .admins , Roles .events_lead , fail_silently = True )
188+ @adventofcode_group .command (
189+ name = "posting_toggle" ,
190+ aliases = ("pt" ,),
191+ )
192+ async def daily_posting_toggle (self , ctx : commands .Context ) -> None :
193+ """Toggle whether a daily post is to be created every midnight EST throughout the event."""
194+ current_state = await _caches .aoc_settings .get (_caches .AoCSettingOption .AUTO_POSTING_ENABLED .value )
195+ new_state = not current_state
196+ if new_state :
197+ self .daily_posting_task .start ()
198+ state_string = "on"
199+ else :
200+ self .daily_posting_task .cancel ()
201+ state_string = "off"
202+
203+ await _caches .aoc_settings .set (_caches .AoCSettingOption .AUTO_POSTING_ENABLED .value , new_state )
204+ await ctx .send (f":+1: Daily posting is now { state_string } ." )
205+
206+ @with_role (Roles .admins , Roles .events_lead , fail_silently = True )
207+ @adventofcode_group .command ()
208+ async def status (self , ctx : commands .Context ) -> None :
209+ """Show status of the AoC cog."""
210+ completionist_state = await _caches .aoc_settings .get (_caches .AoCSettingOption .COMPLETIONIST_ENABLED .value )
211+ daily_posting_state = await _caches .aoc_settings .get (_caches .AoCSettingOption .AUTO_POSTING_ENABLED .value )
212+
213+ embed = discord .Embed (title = "AoC Cog Status" , colour = discord .Colour .green ())
214+ embed .add_field (name = "Completionist role" , value = "On" if completionist_state else "Off" )
215+ embed .add_field (name = "Daily posting" , value = "On" if daily_posting_state else "Off" )
216+
217+ await ctx .reply (embed = embed )
218+
160219 @with_role (Roles .admins , fail_silently = True )
161220 @adventofcode_group .command (
162221 name = "block" ,
0 commit comments