Skip to content

Commit

Permalink
Merge pull request #83 from Code4GovTech/fix/#432/delayed-role-assign…
Browse files Browse the repository at this point in the history
…ment

Fix/#432/delayed role assignment
  • Loading branch information
karntrehan authored Oct 15, 2024
2 parents b7a57db + 643487d commit 46f777e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
21 changes: 12 additions & 9 deletions cogs/userInteractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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")
Expand All @@ -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"])
Expand Down
9 changes: 6 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit 46f777e

Please sign in to comment.