From 5db4e76de8f88706d3d74d2c869e1a550c7a866d Mon Sep 17 00:00:00 2001 From: Emily Doherty Date: Sat, 30 Nov 2024 04:45:36 -0800 Subject: [PATCH] Update to use discord user id instead of member id This is so interactions will work in a DM with the bot as well as in servers where the bot is located --- token_bot/tracker.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/token_bot/tracker.py b/token_bot/tracker.py index 6ea859f..571b338 100644 --- a/token_bot/tracker.py +++ b/token_bot/tracker.py @@ -66,7 +66,10 @@ class Tracker(Extension): for alert in users_alerts[user]: 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" - f"token reaches a certain value. The following alerts have been triggered: {alert_message}") + f"token reaches a certain value.\n\n" + f"As a reminder, you can always 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}") ################################### @@ -94,31 +97,31 @@ class Tracker(Extension): "Please note: \n" "* You can only be registered with one region at a time \n" "* Changing your region will remove all previous alerts you have signed up for") - await self._users.add(ctx.member.id) + await self._users.add(ctx.user.id) await ctx.send(text, components=REGION_MENU, ephemeral=True) @slash_command() async def remove_registration(self, ctx: SlashContext): - await self._users.delete(ctx.member.id) + await self._users.delete(ctx.user.id) await ctx.send("All alert subscriptions and user registration deleted", ephemeral=True) @slash_command() async def delete(self, ctx: SlashContext): - await self._users.delete(ctx.member.id) + await self._users.delete(ctx.user.id) await ctx.send("Deletion Successful", ephemeral=True) @slash_command() async def exists(self, ctx: SlashContext): - await ctx.send(str(await self._users.exists(ctx.member.id)), ephemeral=True) + await ctx.send(str(await self._users.exists(ctx.user.id)), ephemeral=True) @slash_command() async def add_alert(self, ctx: SlashContext): - if not await self._users.exists(ctx.member.id): + if not await self._users.exists(ctx.user.id): await ctx.send("You are not registered with any region\n" "Please register with /register before adding alerts", ephemeral=True) return - user = await self._users.get(ctx.member.id) + user = await self._users.get(ctx.user.id) try: flavor = await self.flavor_select_menu(ctx) @@ -151,7 +154,8 @@ class Tracker(Extension): @slash_command() async def list_alerts(self, ctx: SlashContext): - await ctx.send(str(await self._users.list_alerts(ctx.member.id)), ephemeral=True) + alerts = await self._users.list_alerts(ctx.user.id) + await ctx.send(str(alerts), ephemeral=True) ################################### # Callbacks Commands # @@ -173,7 +177,7 @@ class Tracker(Extension): @component_callback('region_menu') async def region_menu(self, ctx: ComponentContext): - user = User(ctx.member.id, Region(ctx.values[0].lower()), subscribed_alerts=[]) + user = User(ctx.user.id, Region(ctx.values[0].lower()), subscribed_alerts=[]) await self._users.add(user) await ctx.send(f"Successfully registered with the {ctx.values[0]} region", ephemeral=True)