Fix verification

This commit is contained in:
Zeva Rose 2022-03-23 09:30:45 -06:00
parent dc5919ff86
commit be6d88449e

View file

@ -3,8 +3,8 @@ import asyncio
from random import randint from random import randint
from dis_snek import InteractionContext, Scale, Snake 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.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.command import cooldown
from dis_snek.models.snek.cooldowns import Buckets from dis_snek.models.snek.cooldowns import Buckets
from jarvis_core.db import q from jarvis_core.db import q
@ -41,10 +41,10 @@ class VerifyCog(Scale):
await ctx.defer() await ctx.defer()
role = await Setting.find_one(q(guild=ctx.guild.id, setting="verified")) role = await Setting.find_one(q(guild=ctx.guild.id, setting="verified"))
if not role: 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 return
if await ctx.guild.get_role(role.value) in ctx.author.roles: if await ctx.guild.fetch_role(role.value) in ctx.author.roles:
await ctx.send("You are already verified.", delete_after=5) await ctx.send("You are already verified.", ephemeral=True)
return return
components = create_layout() components = create_layout()
message = await ctx.send( message = await ctx.send(
@ -53,35 +53,39 @@ class VerifyCog(Scale):
) )
try: try:
context = await self.bot.wait_for_component( verified = False
messages=message, check=lambda x: ctx.author.id == x.author.id, timeout=30 while not verified:
) response = await self.bot.wait_for_component(
messages=message,
correct = context.context.custom_id.split("||")[-1] == "yes" check=lambda x: ctx.author.id == x.context.author.id,
if correct: timeout=30,
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,
) )
await context.context.message.delete(delay=5)
else: correct = response.context.custom_id.split("||")[-1] == "yes"
await context.context.edit_origin( if correct:
content=( for row in components:
f"{ctx.author.mention}, incorrect. " for component in row.components:
"Please press the button that says `YES`" 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: except asyncio.TimeoutError:
await message.delete(delay=30) await message.delete(delay=30)