From 5a2e183ccdad2d6d125f02f35681e0e0fc4b56fa Mon Sep 17 00:00:00 2001 From: Emily Doherty Date: Tue, 3 Dec 2024 02:43:06 -0800 Subject: [PATCH] Clean up alert message, move notification to an embed --- token_bot/persistant_database/alert_schema.py | 3 ++- token_bot/tracker.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/token_bot/persistant_database/alert_schema.py b/token_bot/persistant_database/alert_schema.py index aa8f444..a44866e 100644 --- a/token_bot/persistant_database/alert_schema.py +++ b/token_bot/persistant_database/alert_schema.py @@ -74,7 +74,8 @@ class Alert: if self.alert_type == AlertType.SPECIFIC_PRICE: raise NotImplementedError else: - return f"\n|\tRegion: {self.region.value.upper()}\tFlavor: {self.flavor.name.lower()}\tAlert: {self.alert_type.name.lower()}\t|" + alert_type_str = ' '.join(self.alert_type.name.split("_")) + return f"\n|\tRegion: {self.region.value.upper()}\tFlavor: {self.flavor.name.lower()}\tAlert: {alert_type_str.title()}\t|" async def _lazy_load(self, table: Table, consistent: bool = False) -> None: if consistent or not self._loaded: diff --git a/token_bot/tracker.py b/token_bot/tracker.py index 47c8f3e..3fa4ef3 100644 --- a/token_bot/tracker.py +++ b/token_bot/tracker.py @@ -4,7 +4,7 @@ from typing import Type, Dict, List import aiohttp from interactions import Extension, SlashContext, component_callback, \ - ComponentContext, StringSelectMenu, Message + ComponentContext, StringSelectMenu, Message, Embed from interactions import Task, IntervalTrigger from interactions import slash_command, listen from interactions.api.events import Component @@ -58,11 +58,16 @@ class Tracker(Extension): for alert in users_alerts[user]: if alert.alert_type != AlertType.SPECIFIC_PRICE: alert_message += f"{alert.to_human_string()}" - await discord_user.send(f"Hello, you requested to be sent an alert when the price of the World of Warcraft " + embed = Embed( + title="TokenBot 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 registrations via /remove-registration\n\n" - f"The following alerts have been triggered: {alert_message}") + f"The following alerts have been triggered: {alert_message}", + ) + await discord_user.send(embed=embed) ################################### @@ -144,6 +149,9 @@ class Tracker(Extension): @slash_command() async def list_alerts(self, ctx: SlashContext): alerts = await self._users.list_alerts(ctx.user.id) + alerts_str = str() + for alert in alerts: + alerts_str += f"{alert.to_human_string()}\n" await ctx.send(str(alerts), ephemeral=True) ###################################