From c6b5589ac915ca5c971fdffe764775722ff4b1c0 Mon Sep 17 00:00:00 2001 From: Liam Goring <4769068+lagliam@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:32:44 -0600 Subject: [PATCH 1/4] Bugfixes - Wording * Updated wording on logs --- app/bot/main_loop.py | 4 ++-- app/commands/start_posting.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/bot/main_loop.py b/app/bot/main_loop.py index 77d6a49..160bb97 100644 --- a/app/bot/main_loop.py +++ b/app/bot/main_loop.py @@ -18,7 +18,7 @@ async def run(self): if not self._restart: sent = await self._send_images(database.get_posting_amount(self._channel_id)) if not sent: - utility.log_event(f'Out of images for {self._guild_id}') + utility.log_event(f'Out of images for guild {self._guild_id}') await self._ctx.send(text.NO_MORE_TO_SEE) database.delete_channel(self._channel_id) break @@ -26,7 +26,7 @@ async def run(self): database.set_last_post_date(self._channel_id, time.time()) self._restart = False await self._wait() - utility.log_event(f'Stopped posting for server {self._guild_id} channel {self._channel_id}') + utility.log_event(f'Stopped posting for guild {self._guild_id} channel {self._channel_id}') async def _send_images(self, post_amount): sender = image_sender.ImageSender(self._ctx, self._guild_id) diff --git a/app/commands/start_posting.py b/app/commands/start_posting.py index 5474b6a..b9fdcea 100644 --- a/app/commands/start_posting.py +++ b/app/commands/start_posting.py @@ -25,12 +25,12 @@ async def run(self): await asyncio.create_task(loop.run()) def _stop_posting(self): - utility.log_event(f'Stop posting called for server {self._guild_id} channel {self._channel_id}') + utility.log_event(f'Stop posting called for guild {self._guild_id} channel {self._channel_id}') database.delete_channel(self._channel_id) def _start_posting(self): database.start_posting_entry(self._channel_id, self._guild_id) - utility.log_event(f'Started posting for server {self._guild_id} channel {self._channel_id}') + utility.log_event(f'Started posting for guild {self._guild_id} channel {self._channel_id}') return MainLoop({ 'ctx': self._ctx.channel, 'guild_id': self._guild_id, From de8a508191fee5212dc344372943d7226dc86781 Mon Sep 17 00:00:00 2001 From: Liam Goring <4769068+lagliam@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:25:47 -0600 Subject: [PATCH 2/4] Bugfixes - Logic * Added trigger time call to account for when the database entry is gone and immediately return a small number to end the loop --- app/bot/main_loop.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/bot/main_loop.py b/app/bot/main_loop.py index 160bb97..d151359 100644 --- a/app/bot/main_loop.py +++ b/app/bot/main_loop.py @@ -39,6 +39,13 @@ async def _send_images(self, post_amount): async def _wait(self): last_post_date = datetime.fromtimestamp(float(database.get_last_post_date(self._channel_id))) start_waiting = (datetime.now() - last_post_date).total_seconds() - while start_waiting < (constants.TRIGGER_DURATION / int(database.get_posting_frequency(self._channel_id))): + while start_waiting < (self._trigger_time()): await asyncio.sleep(constants.POLL_INTERVAL) start_waiting += constants.POLL_INTERVAL + + def _trigger_time(self): + try: + posting_freq = int(database.get_posting_frequency(self._channel_id)) + except TypeError: + return 1 + return constants.TRIGGER_DURATION / posting_freq From 5a3d90b2150f5929115857cf7b5611f3adcc59dc Mon Sep 17 00:00:00 2001 From: Liam Goring <4769068+lagliam@users.noreply.github.com> Date: Thu, 1 Feb 2024 18:42:09 -0600 Subject: [PATCH 3/4] Bugfixes - Logging * Updated logging in some places --- app/app.py | 3 ++- app/bot/main_loop.py | 1 - app/cogs/get_one_image.py | 2 +- app/utilities/utility.py | 2 +- bot.py | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/app.py b/app/app.py index e827df5..11212ca 100644 --- a/app/app.py +++ b/app/app.py @@ -19,7 +19,9 @@ async def run(self): for t in channels: channels_list.append(await self._bot.fetch_channel(t[0])) tasks = self._startup_tasks(channels_list) + utility.log_event(f'Found {len(tasks)} coroutines to start') await asyncio.gather(*tasks) + utility.log_event('Coroutines ended') @staticmethod def _startup_tasks(channels): @@ -37,5 +39,4 @@ def _startup_tasks(channels): } main_loop = MainLoop(params) tasks.append(main_loop.run()) - utility.log_event(f'Found {len(tasks)} coroutines to start') return tasks diff --git a/app/bot/main_loop.py b/app/bot/main_loop.py index d151359..0d71a27 100644 --- a/app/bot/main_loop.py +++ b/app/bot/main_loop.py @@ -18,7 +18,6 @@ async def run(self): if not self._restart: sent = await self._send_images(database.get_posting_amount(self._channel_id)) if not sent: - utility.log_event(f'Out of images for guild {self._guild_id}') await self._ctx.send(text.NO_MORE_TO_SEE) database.delete_channel(self._channel_id) break diff --git a/app/cogs/get_one_image.py b/app/cogs/get_one_image.py index 0bb551e..ac873c8 100644 --- a/app/cogs/get_one_image.py +++ b/app/cogs/get_one_image.py @@ -20,7 +20,7 @@ async def get_one_image(self, ctx): await ctx.respond(text.START_POSTING) sent = await image_sender.send_image() if not sent: - utility.log_event(f'Out of images for {guild_id}') + utility.log_event(f'Unable to send images for {guild_id}') await ctx.send(text.NO_MORE_TO_SEE) diff --git a/app/utilities/utility.py b/app/utilities/utility.py index 164ee52..236ac69 100644 --- a/app/utilities/utility.py +++ b/app/utilities/utility.py @@ -47,7 +47,7 @@ def get_file(file_list): try: filename = file_list.pop(random.randrange(len(file_list))) except ValueError: - log_event('All files are too big to send') + log_event('All files remaining are too big to send') filename = None break return filename diff --git a/bot.py b/bot.py index 406ccbd..94a9df1 100644 --- a/bot.py +++ b/bot.py @@ -34,6 +34,7 @@ async def primary_application_loop(): await bot.wait_until_ready() app = App(bot) await app.run() + log_event('----Primary Application Loop Stopped----') primary_application_loop.start() From 6c7efc5cac27971245feb2599c2a245ca22ff530 Mon Sep 17 00:00:00 2001 From: Liam Goring <4769068+lagliam@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:18:01 -0600 Subject: [PATCH 4/4] Bugfixes - Stability * Updated primary application loop with check to is_ready() to start when bot is ready --- bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 94a9df1..b1fbb6e 100644 --- a/bot.py +++ b/bot.py @@ -2,6 +2,7 @@ # DIP-bot # Author: Liam Goring +import asyncio import os from pathlib import Path @@ -31,7 +32,8 @@ async def on_ready(): @tasks.loop(count=1) async def primary_application_loop(): - await bot.wait_until_ready() + while not bot.is_ready(): + await asyncio.sleep(0.1) app = App(bot) await app.run() log_event('----Primary Application Loop Stopped----')