From dfa5637a42a642771d5fc02d9603cc35c7104448 Mon Sep 17 00:00:00 2001 From: Emily Doherty Date: Sat, 14 Dec 2024 20:43:12 -0800 Subject: [PATCH] Log when alerts are being sent for restart safety Maybe we could catch and hold signals here too? --- token_bot/tracker.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/token_bot/tracker.py b/token_bot/tracker.py index 9862ba0..d0f7f7c 100644 --- a/token_bot/tracker.py +++ b/token_bot/tracker.py @@ -77,25 +77,29 @@ class Tracker(Extension): users_alerts[user] = [alert] else: users_alerts[user].append(alert) - for user in users_alerts: - discord_user = await self.bot.fetch_user(user.user_id) - embeds = [ - Embed( - title="GoblinBot Tracker Alert Triggered", - color=0xB10000, - description=f"Hello, you requested to be sent an alert when the price of the World of Warcraft " - f"token reaches a certain value.\n\n" - f"As a reminder, you can remove an alert via ```/remove-alert```\n" - f"or you can remove all alerts and user data via ```/remove-registration```\n\n", - ) - ] - alerts_by_flavor = await gather_alerts_by_flavor(users_alerts[user]) - for flavor in alerts_by_flavor: - embeds.append( - await self._render_alert_flavor(alerts_by_flavor[flavor], user=user) - ) + if users_alerts: + self.bot.logger.log(logging.INFO, "TokenBot Tracker: Processing User Alerts") + for user in users_alerts: + discord_user = await self.bot.fetch_user(user.user_id) + embeds = [ + Embed( + title="GoblinBot Tracker Alert Triggered", + color=0xB10000, + description=f"Hello, you requested to be sent an alert when the price of the World of Warcraft " + f"token reaches a certain value.\n\n" + f"As a reminder, you can remove an alert via ```/remove-alert```\n" + f"or you can remove all alerts and user data via ```/remove-registration```\n\n", + ) + ] + alerts_by_flavor = await gather_alerts_by_flavor(users_alerts[user]) + for flavor in alerts_by_flavor: + embeds.append( + await self._render_alert_flavor(alerts_by_flavor[flavor], user=user) + ) + + await discord_user.send(embeds=embeds) + self.bot.logger.log(logging.INFO, "TokenBot Tracker: Done Processing User Alerts") - await discord_user.send(embeds=embeds) ################################### # Slash Commands #