From c5c242de21c5a18ca0aa09ceeb0b72d8904daf29 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Wed, 6 Sep 2023 14:14:33 -0400 Subject: [PATCH 1/5] Correct comparison in get_current_cycle(). --- cogs/loops/daily_loop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/loops/daily_loop.py b/cogs/loops/daily_loop.py index 372f86c..b18046f 100644 --- a/cogs/loops/daily_loop.py +++ b/cogs/loops/daily_loop.py @@ -61,7 +61,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"): for cycle, election in enumerate(config.election_cycles): if ( - today.date() > get_datetime(election.election_start).date() + today.date() >= get_datetime(election.election_start).date() and today.date() < get_datetime(election.term_start).date() ): current_election = ElectionCycle(cycle, config, self.bot.get_guild(config.params.guild_id)) From 2640ebdad1235091d2b6358ddc045888a187d988 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Fri, 8 Sep 2023 11:42:34 -0400 Subject: [PATCH 2/5] Move current_election setting. The bot needs to be ready first. --- cogs/loops/daily_loop.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cogs/loops/daily_loop.py b/cogs/loops/daily_loop.py index b18046f..61cde16 100644 --- a/cogs/loops/daily_loop.py +++ b/cogs/loops/daily_loop.py @@ -19,7 +19,7 @@ class DailyLoop(commands.Cog, name="Daily Loop"): def __init__(self, bot: commands.Bot) -> None: self.bot = bot - self.current_election = self.get_current_cycle() + self.current_election = None @commands.Cog.listener() async def on_ready(self): @@ -27,6 +27,10 @@ class DailyLoop(commands.Cog, name="Daily Loop"): Starts the loop when bot is ready. """ await self.bot.wait_until_ready() + + # wait until the discord bot is all ready. Bot needs to know guilds. + self.current_election = self.get_current_cycle() + # pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop. await self.daily_loop.start() # pylint: disable=no-member From e7cfe8bd4c71cd1818e0ac89f7fcac0b01a33c47 Mon Sep 17 00:00:00 2001 From: imcompiling Date: Fri, 8 Sep 2023 20:07:08 -0400 Subject: [PATCH 3/5] Fix logging issue. --- dakiny_bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dakiny_bot.py b/dakiny_bot.py index 1fa6322..a07dee5 100644 --- a/dakiny_bot.py +++ b/dakiny_bot.py @@ -55,4 +55,6 @@ def main(cfg: DakinyConfig): if __name__ == "__main__": sys.argv.append("hydra.job.chdir=False") - main() + sys.argv.append("hydra/job_logging=none") + sys.argv.append("hydra/hydra_logging=none") + main() # pylint: disable=no-value-for-parameter From 8b831fb6aa59459024ecac6a65639dce4df48eff Mon Sep 17 00:00:00 2001 From: imcompiling Date: Sat, 9 Sep 2023 11:38:03 -0400 Subject: [PATCH 4/5] start loop in init, use before loop, waiting on bot ready, to set up needed data. --- cogs/loops/daily_loop.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cogs/loops/daily_loop.py b/cogs/loops/daily_loop.py index 61cde16..c92ca77 100644 --- a/cogs/loops/daily_loop.py +++ b/cogs/loops/daily_loop.py @@ -21,18 +21,8 @@ class DailyLoop(commands.Cog, name="Daily Loop"): self.bot = bot self.current_election = None - @commands.Cog.listener() - async def on_ready(self): - """ - Starts the loop when bot is ready. - """ - await self.bot.wait_until_ready() - - # wait until the discord bot is all ready. Bot needs to know guilds. - self.current_election = self.get_current_cycle() - - # pylint doesn't recognize that periodic_update_guild_data is subclassed from tasks.loop. - await self.daily_loop.start() # pylint: disable=no-member + # pylint doesn't recognize that daily_loop is subclassed from tasks.loop. + self.daily_loop.start() # pylint: disable=no-member @tasks.loop(time=time(hour=0, tzinfo=timezone("GMT"))) async def daily_loop(self): @@ -50,6 +40,17 @@ class DailyLoop(commands.Cog, name="Daily Loop"): if self.current_election.election_over: self.current_election = None + @daily_loop.before_loop + async def before_loop(self): + """ + 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() + + # Bot needs to know guilds to get the current cycle. + self.current_election = self.get_current_cycle() + def get_current_cycle(self) -> ElectionCycle: """ Creates an object for the current election cycle if one is active. An election is considered active From c278bae49845de6e7f3eddd674ef2d0fdeda9f3d Mon Sep 17 00:00:00 2001 From: imcompiling Date: Sat, 9 Sep 2023 11:38:22 -0400 Subject: [PATCH 5/5] I forgot to give the docker image the message files. --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index c31ecab..e93d2ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ COPY config.py config.py COPY dakiny_bot.py dakiny_bot.py COPY utils.py utils.py +COPY bot_messages bot_messages/ COPY classes classes/ COPY cogs cogs/ COPY database_setup database_setup/