From be6d88449ee867405a25ae768b8d24ba3738628a Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Wed, 23 Mar 2022 09:30:45 -0600 Subject: [PATCH] Fix verification --- jarvis/cogs/verify.py | 66 +++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/jarvis/cogs/verify.py b/jarvis/cogs/verify.py index 2255623..a4b0647 100644 --- a/jarvis/cogs/verify.py +++ b/jarvis/cogs/verify.py @@ -3,8 +3,8 @@ import asyncio from random import randint from dis_snek import InteractionContext, Scale, Snake -from dis_snek.models.application_commands import slash_command from dis_snek.models.discord.components import Button, ButtonStyles, spread_to_rows +from dis_snek.models.snek.application_commands import slash_command from dis_snek.models.snek.command import cooldown from dis_snek.models.snek.cooldowns import Buckets from jarvis_core.db import q @@ -41,10 +41,10 @@ class VerifyCog(Scale): await ctx.defer() role = await Setting.find_one(q(guild=ctx.guild.id, setting="verified")) if not role: - await ctx.send("This guild has not enabled verification", delete_after=5) + message = await ctx.send("This guild has not enabled verification", ephemeral=True) return - if await ctx.guild.get_role(role.value) in ctx.author.roles: - await ctx.send("You are already verified.", delete_after=5) + if await ctx.guild.fetch_role(role.value) in ctx.author.roles: + await ctx.send("You are already verified.", ephemeral=True) return components = create_layout() message = await ctx.send( @@ -53,35 +53,39 @@ class VerifyCog(Scale): ) try: - context = await self.bot.wait_for_component( - messages=message, check=lambda x: ctx.author.id == x.author.id, timeout=30 - ) - - correct = context.context.custom_id.split("||")[-1] == "yes" - if correct: - for row in components: - for component in row.components: - component.disabled = True - setting = await Setting.find_one(guild=ctx.guild.id, setting="verified") - role = await ctx.guild.get_role(setting.value) - await ctx.author.add_roles(role, reason="Verification passed") - setting = await Setting.find_one(guild=ctx.guild.id, setting="unverified") - if setting: - role = await ctx.guild.get_role(setting.value) - await ctx.author.remove_roles(role, reason="Verification passed") - - await context.context.edit_origin( - content=f"Welcome, {ctx.author.mention}. Please enjoy your stay.", - components=components, + verified = False + while not verified: + response = await self.bot.wait_for_component( + messages=message, + check=lambda x: ctx.author.id == x.context.author.id, + timeout=30, ) - await context.context.message.delete(delay=5) - else: - await context.context.edit_origin( - content=( - f"{ctx.author.mention}, incorrect. " - "Please press the button that says `YES`" + + correct = response.context.custom_id.split("||")[-1] == "yes" + if correct: + for row in components: + for component in row.components: + component.disabled = True + setting = await Setting.find_one(q(guild=ctx.guild.id, setting="verified")) + role = await ctx.guild.fetch_role(setting.value) + await ctx.author.add_role(role, reason="Verification passed") + setting = await Setting.find_one(q(guild=ctx.guild.id, setting="unverified")) + if setting: + role = await ctx.guild.fetch_role(setting.value) + await ctx.author.remove_role(role, reason="Verification passed") + + await response.context.edit_origin( + content=f"Welcome, {ctx.author.mention}. Please enjoy your stay.", + components=components, + ) + await response.context.message.delete(delay=5) + else: + await response.context.edit_origin( + content=( + f"{ctx.author.mention}, incorrect. " + "Please press the button that says `YES`" + ) ) - ) except asyncio.TimeoutError: await message.delete(delay=30)