From 5a8119f5e45170d26696e5d09f3aa779a85147ea Mon Sep 17 00:00:00 2001 From: imcompiling Date: Wed, 19 Mar 2025 21:27:58 -0400 Subject: [PATCH] Add the daily loop for open raid. --- off_cooldown_bot/cogs/loops/daily_loop.py | 24 ++++++++++++++++++++++- off_cooldown_bot/settings.py | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/off_cooldown_bot/cogs/loops/daily_loop.py b/off_cooldown_bot/cogs/loops/daily_loop.py index 6eba47c..2755227 100644 --- a/off_cooldown_bot/cogs/loops/daily_loop.py +++ b/off_cooldown_bot/cogs/loops/daily_loop.py @@ -13,6 +13,7 @@ from off_cooldown_bot.app import birthday_list from off_cooldown_bot.database.db import engine from off_cooldown_bot.database.models import UserBirthday from off_cooldown_bot.logger import ocd_logger +from off_cooldown_bot.open_raid import OpenRaid, build_raid_embed from off_cooldown_bot.settings import settings @@ -25,14 +26,35 @@ class DailyLoop(commands.Cog, name="Daily Loop"): self.update_birthdays() self.daily_loop.start() - @tasks.loop(time=time(hour=0, tzinfo=timezone("UTC"))) + @tasks.loop(time=time(hour=0, tzinfo=UTC)) async def daily_loop(self) -> None: """Run daily repeated functions.""" self.update_birthdays() await self.cakedays() + @tasks.loop(time=time(hour=20, tzinfo=timezone("CST"))) + async def open_raid(self) -> None: + """ + Define the open raid loop. + + Checks daily if it is Thursday and then posts the open raid sign up. + """ + today = datetime.now(timezone("CST")) + if today.day + 2 == 5: + # open raid is on Saturday, post 2 days before + if (guild := self.bot.get_guild(settings.params.guild_id)) is None: + ocd_logger.error("Guild id not correct.") + return + if (channel := guild.get_channel(settings.channel_ids.raid)) is None or not isinstance( + channel, nextcord.TextChannel + ): + ocd_logger.error("Raid channel is not defined or is not a text channel.") + return + await channel.send(embed=build_raid_embed(), view=OpenRaid()) + @daily_loop.before_loop + @open_raid.before_loop async def before_loop(self) -> None: """Actions run before the loop starts. Want to wait for bot to be ready and get the current cycle.""" await self.bot.wait_until_ready() diff --git a/off_cooldown_bot/settings.py b/off_cooldown_bot/settings.py index 43267ea..767781d 100644 --- a/off_cooldown_bot/settings.py +++ b/off_cooldown_bot/settings.py @@ -12,6 +12,7 @@ class ChannelIds: """Class holds all channel ids needed by bot.""" general: int + raid: int @dataclass