Skip to content

Commit

Permalink
verified role
Browse files Browse the repository at this point in the history
  • Loading branch information
KDwevedi committed Nov 7, 2023
1 parent 4d691f0 commit 6f6e429
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
39 changes: 39 additions & 0 deletions cogs/listeners.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from discord.ext import commands
import discord
from utils.db import SupabaseInterface

class Listeners(commands.Cog):
def __init__(self, bot) -> None:
super().__init__()
self.bot = bot

async def grantVerifiedRole(self, member: discord.Member):
verifiedContributorRoleID = 1123967402175119482
try:
verifiedContributorRole = member.guild.get_role(verifiedContributorRoleID)
if verifiedContributorRole:
if verifiedContributorRole not in member.roles:
await member.add_roles(verifiedContributorRole, reason="Completed Auth and Introduction")
else:
print("Verified Contributor Role not found")
except Exception as e:
print("Exception while granting Role:", e)

async def isAuthenticated(self, memberID: int) -> bool:
if SupabaseInterface("contributors").read("discord_id", memberID):
return True
else:
return False


@commands.Cog.listener("on_message")
async def listenForIntroduction(self, message: discord.Message):
if message.channel.id == 1107343423167541328: #intro channel
if await self.isAuthenticated(message.author.id):
await self.grantVerifiedRole(message.author)
else:
return


async def setup(bot: commands.Bot):
await bot.add_cog(Listeners(bot))
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"channels": {
"introduction": {
"id": "",
"name": ""
}
},
"roles": [],

"CONTRIBUTOR_ROLE_ID": 973852365188907048,
"INTRODUCTIONS_CHANNEL_ID": 1107343423167541328,
"ERROR_CHANNEL_ID": 0,
Expand Down
29 changes: 27 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
from discord.utils import MISSING
import dotenv, aiohttp, json
from utils.db import SupabaseInterface

#Since there are user defined packages, adding current directory to python path
current_directory = os.getcwd()
Expand Down Expand Up @@ -112,14 +113,38 @@ async def post_data(self, data):

name = discord.ui.TextInput(label='Please Enter Your Name', placeholder='To give you the recognition you deserve, could you please share your full name for the certificates!')
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.send_message("Thanks! Now please select your affiliation!",view=AuthenticationView(interaction.user.id), ephemeral=True)
user = interaction.user
await interaction.response.send_message("Thanks! Now please sign in via Github!",view=AuthenticationView(user.id), ephemeral=True)
await self.post_data(
{
"name": self.name.value,
"discord_id": interaction.user.id
"discord_id": user.id
}
)

verifiedContributorRoleID = 1123967402175119482
print("User:", type(user))
if verifiedContributorRoleID in [role.id for role in user.roles]:
return
else:
async def hasAuthenticated():
print("Checking...")
discordEngagement = SupabaseInterface("contributors").read("discord_id", user.id)
while not discordEngagement:
await asyncio.sleep(30)
print("Found!")
return True
try:
await asyncio.wait_for(hasAuthenticated(), timeout=1000)
verifiedContributorRole = user.guild.get_role(verifiedContributorRoleID)
if verifiedContributorRole:
if verifiedContributorRole not in user.roles:
await user.add_roles(verifiedContributorRole, reason="Completed Auth and Introduction")
except asyncio.TimeoutError:
print("Timed out waiting for authentication")



class RegistrationView(discord.ui.View):
def __init__(self):
super().__init__(timeout = None)
Expand Down

0 comments on commit 6f6e429

Please sign in to comment.