From 3e6beeff17c11663781672cae48657b6c3686dbb Mon Sep 17 00:00:00 2001 From: karntrehan Date: Tue, 15 Oct 2024 17:43:45 +0530 Subject: [PATCH 1/4] Fix task role assignment --- cogs/userInteractions.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cogs/userInteractions.py b/cogs/userInteractions.py index 5dd58ae..6a5d7ac 100644 --- a/cogs/userInteractions.py +++ b/cogs/userInteractions.py @@ -26,16 +26,19 @@ async def update_contributors(self): contributor_role = guild.get_role(VERIFIED_CONTRIBUTOR_ROLE_ID) for contributor in contributors: discord_id = contributor["discord_id"] - member = guild.get_member(discord_id) - if member: + try: + member = await guild.fetch_member(discord_id) if contributor_role not in member.roles: - await member.add_roles(contributor_role) - print(f"Given {contributor_role.name} Role to {member.name}") + try: + await member.add_roles(contributor_role) + print(f"Gave {contributor_role.name} role to {member.name}") + except Exception as e: + print(f"{member.name} could not be given verified contributor role") else: - print(f"{member.name} is already {contributor_role.name}") - else: - print(f"{discord_id} is not a member on discord") - ## TODO delete from supabase as well? + print(f"{member.name} is already a {contributor_role.name}") + except: + print(f"User with discord_id: {discord_id} is not a member of our server anymore") + # TODO delete from supabase as well? return @commands.command(aliases=["badges"]) From 37247af09819983989afecc47b138aade9efabf0 Mon Sep 17 00:00:00 2001 From: karntrehan Date: Tue, 15 Oct 2024 17:56:34 +0530 Subject: [PATCH 2/4] Fix running of task every 60 mins --- cogs/userInteractions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cogs/userInteractions.py b/cogs/userInteractions.py index 6a5d7ac..40ee38f 100644 --- a/cogs/userInteractions.py +++ b/cogs/userInteractions.py @@ -17,13 +17,15 @@ def __init__(self, bot) -> None: self.bot = bot self.update_contributors.start() - @tasks.loop(minutes=10) + @tasks.loop(minutes=60) async def update_contributors(self): print("update_contributors running") contributors = SupabaseClient().read_all("contributors_registration") print("Contributors in DB: ", len(contributors)) guild = await self.bot.fetch_guild(os.getenv("SERVER_ID")) contributor_role = guild.get_role(VERIFIED_CONTRIBUTOR_ROLE_ID) + # TODO remove before prod + return for contributor in contributors: discord_id = contributor["discord_id"] try: From d75719d2792804e5578d5f74e3fa1b1a7be93a41 Mon Sep 17 00:00:00 2001 From: karntrehan Date: Tue, 15 Oct 2024 17:57:44 +0530 Subject: [PATCH 3/4] Remove hardcoded return --- cogs/userInteractions.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cogs/userInteractions.py b/cogs/userInteractions.py index 40ee38f..115d6b2 100644 --- a/cogs/userInteractions.py +++ b/cogs/userInteractions.py @@ -24,8 +24,6 @@ async def update_contributors(self): print("Contributors in DB: ", len(contributors)) guild = await self.bot.fetch_guild(os.getenv("SERVER_ID")) contributor_role = guild.get_role(VERIFIED_CONTRIBUTOR_ROLE_ID) - # TODO remove before prod - return for contributor in contributors: discord_id = contributor["discord_id"] try: From 643487dff2cbc43ee626e507b27cf433ae9b19d0 Mon Sep 17 00:00:00 2001 From: karntrehan Date: Tue, 15 Oct 2024 18:14:18 +0530 Subject: [PATCH 4/4] Log when db insert fails. --- main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index d4b20f1..8cfe131 100644 --- a/main.py +++ b/main.py @@ -61,9 +61,12 @@ async def on_submit(self, interaction: discord.Interaction): "country": self.country.value } supaClient = SupabaseClient() - response = (supaClient.client.table("contributors_discord") - .upsert(user_data, on_conflict="discord_id").execute()) - print("DB updated for user:", response.data[0]["discord_id"]) + try: + response = (supaClient.client.table("contributors_discord") + .upsert(user_data, on_conflict="discord_id").execute()) + print("DB updated for user:", response.data[0]["discord_id"]) + except Exception as e: + print("Failed to update credentials for user: "+e) verifiedContributorRoleID = int(os.getenv("VERIFIED_ROLE_ID")) if verifiedContributorRoleID in [role.id for role in user.roles]: