From 06c200e817964c2d221c62e2d1a2c20e8cd34292 Mon Sep 17 00:00:00 2001 From: karntrehan Date: Fri, 12 Jul 2024 17:17:27 +0530 Subject: [PATCH 1/4] Modify is_active handling for user deletion --- cogs/serverManagement.py | 10 ++++------ helpers/supabaseClient.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cogs/serverManagement.py b/cogs/serverManagement.py index f096c0c..8aaa0ca 100644 --- a/cogs/serverManagement.py +++ b/cogs/serverManagement.py @@ -15,12 +15,10 @@ def __init__(self, bot): def validUser(self, ctx): authorised_users = [ - 1042682119035568178, 1120262151676895274, 1107555866422562926, - 1107555866422562926, - 599878601143222282, - ] # bhavya, devaraj, navaneeth, venkatesh, sukhpreet + 1059343450312544266, + ] # devaraj, venkatesh, karn return ctx.author.id in authorised_users @commands.command(aliaes=["initiate"]) @@ -54,8 +52,8 @@ async def getServerData(self, ctx): print("added chapters") - contributorsGithub = SupabaseClient().read_all("contributors_registration") - contributorsDiscord = SupabaseClient().read_all("contributors_discord") + contributorsGithub = SupabaseClient().read_all_active("contributors_registration") + contributorsDiscord = SupabaseClient().read_all_active("contributors_discord") ## Give contributor role contributorIds = [ diff --git a/helpers/supabaseClient.py b/helpers/supabaseClient.py index 8d16101..7f5fff9 100644 --- a/helpers/supabaseClient.py +++ b/helpers/supabaseClient.py @@ -63,6 +63,10 @@ def read_by_order_limit( def read_all(self, table): data = self.client.table(table).select("*").execute() return data.data + + def read_all_active(self, table): + data = self.client.table(table).select("*").eq('is_active', 'true').execute() + return data.data def update(self, table, update, query_key, query_value): data = ( @@ -137,6 +141,7 @@ def updateContributors(self, contributors: [Member]): "chapter": chapters[0] if chapters else None, "gender": gender, "joined_at": contributor.joined_at.isoformat(), + "is_active": 'true' } ) @@ -149,3 +154,8 @@ def deleteContributorDiscord(self, contributorDiscordIds): table = "contributors_discord" for id in contributorDiscordIds: self.client.table(table).delete().eq("discord_id", id).execute() + + def invalidateContributorDiscord(self, contributorDiscordIds): + table = "contributors_discord" + for id in contributorDiscordIds: + self.client.table(table).update({ 'is_active': 'false' }).eq('discord_id', id).execute() From 8f52a494c358498a3d36c6e68978196e2e0935f5 Mon Sep 17 00:00:00 2001 From: karntrehan Date: Thu, 18 Jul 2024 12:14:30 +0530 Subject: [PATCH 2/4] Invalidate members rather than delete. --- cogs/serverManagement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/serverManagement.py b/cogs/serverManagement.py index 8aaa0ca..fedd54d 100644 --- a/cogs/serverManagement.py +++ b/cogs/serverManagement.py @@ -79,7 +79,7 @@ async def getServerData(self, ctx): currentMembers = [member.id for member in guild.members] membersWhoLeft = list(set(recordedMembers) - set(currentMembers)) print(f"{len(membersWhoLeft)} members left") - SupabaseClient().deleteContributorDiscord(membersWhoLeft) + SupabaseClient().invalidateContributorDiscord(membersWhoLeft) print("Updated Contributors") @tasks.loop(minutes=30) From b9e4e9977c8b0e62d3177361c1e7b4ec88a8e424 Mon Sep 17 00:00:00 2001 From: KDwevedi Date: Thu, 18 Jul 2024 12:40:39 +0530 Subject: [PATCH 3/4] updating invalidating users logic --- cogs/serverManagement.py | 2 +- main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cogs/serverManagement.py b/cogs/serverManagement.py index fedd54d..eafb853 100644 --- a/cogs/serverManagement.py +++ b/cogs/serverManagement.py @@ -52,7 +52,7 @@ async def getServerData(self, ctx): print("added chapters") - contributorsGithub = SupabaseClient().read_all_active("contributors_registration") + contributorsGithub = SupabaseClient().read_all("contributors_registration") contributorsDiscord = SupabaseClient().read_all_active("contributors_discord") ## Give contributor role diff --git a/main.py b/main.py index f7f1142..7f38e29 100644 --- a/main.py +++ b/main.py @@ -112,7 +112,7 @@ def __init__( super().__init__(title=title, timeout=timeout, custom_id=custom_id) async def post_data(self, data): - url = "https://kcavhjwafgtoqkqbbqrd.supabase.co/rest/v1/contributor_names" + url = os.getenv("SUPABASE_URL") headers = { "apikey": f"{os.getenv('SUPABASE_KEY')}", "Authorization": f"Bearer {os.getenv('SUPABASE_KEY')}", From 52e5a4996f32d46efe729da6fd08d1341e46e618 Mon Sep 17 00:00:00 2001 From: KDwevedi Date: Thu, 18 Jul 2024 13:02:16 +0530 Subject: [PATCH 4/4] changed function name to updateServerData --- cogs/serverManagement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/serverManagement.py b/cogs/serverManagement.py index eafb853..76ca419 100644 --- a/cogs/serverManagement.py +++ b/cogs/serverManagement.py @@ -22,7 +22,7 @@ def validUser(self, ctx): return ctx.author.id in authorised_users @commands.command(aliaes=["initiate"]) - async def getServerData(self, ctx): + async def updateServerData(self, ctx): # add all chapters chapterRoles = [] guild = self.bot.get_guild(serverConfig.SERVER)