Skip to content

Commit fb04f89

Browse files
committed
Persistant verification buttons!
1 parent 03d5ba4 commit fb04f89

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/zorak/cogs/admin/verification_on_verified.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def __init__(self, bot):
2222
def is_verified(self, member):
2323
if "✅" in [role.name for role in member.roles]:
2424
return True
25-
25+
2626
async def send_wrong_button_message(self, guild, member):
2727
button_message = f"""
2828
Hi there, {member.mention}
29-
you have pressed the wrong button to verify yourself.
29+
you have pressed the wrong button to verify yourself.
3030
3131
Make sure you press the **GREEN** button to verify yourself.
3232
Please join the server again and try again.
@@ -46,21 +46,21 @@ async def send_wrong_button_message_and_kick(self, interaction: discord.Interact
4646
await self.send_wrong_button_message(interaction.guild, user)
4747
await user.kick(reason="User failed to verify by pressing red button.")
4848

49-
@discord.ui.button(label="Verify!", row=0, style=discord.ButtonStyle.red)
49+
@discord.ui.button(label="Verify!", row=0, custom_id="Button_1", style=discord.ButtonStyle.red)
5050
async def verify_button_callback_red_1(self, button: discord.ui.Button, interaction: discord.Interaction):
5151
"""
5252
This is a dummy button, if pressed kicks user.
5353
"""
5454
await self.send_wrong_button_message_and_kick(interaction)
5555

56-
@discord.ui.button(label="Verify!", row=0, style=discord.ButtonStyle.red)
56+
@discord.ui.button(label="Verify!", row=0, custom_id="Button_2", style=discord.ButtonStyle.red)
5757
async def verify_button_callback_red_2(self, button: discord.ui.Button, interaction: discord.Interaction):
5858
"""
5959
This is a dummy button, if pressed kicks user.
6060
"""
6161
await self.send_wrong_button_message_and_kick(interaction)
6262

63-
@discord.ui.button(label="Verify!", row=0, style=discord.ButtonStyle.success)
63+
@discord.ui.button(label="Verify!", row=0, custom_id="Button_3", style=discord.ButtonStyle.success)
6464
async def verify_button_callback_green(self, button: discord.ui.Button, interaction: discord.Interaction):
6565
"""
6666
This is the stuff that happens
@@ -75,7 +75,6 @@ async def verify_button_callback_green(self, button: discord.ui.Button, interact
7575

7676
embed = discord.Embed(title="Welcome to Practical Python", color=discord.Color.yellow())
7777
embed.set_thumbnail(url="https://raw.githubusercontent.com/Xarlos89/PracticalPython/main/logo.png")
78-
7978
if not verified:
8079
guild = interaction.guild
8180
roles = guild.roles
@@ -87,27 +86,27 @@ async def verify_button_callback_green(self, button: discord.ui.Button, interact
8786
verified_role = discord.utils.get(roles, id=self.bot.server_settings.verified_role['verified'])
8887
await user.add_roles(verified_role)
8988

89+
9090
log_channels_verification_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["verification_log"])
9191
log_channels_join = await self.bot.fetch_channel(self.bot.server_settings.log_channel["join_log"])
9292

9393
await log_channels_verification_log.send(f"{user.mention} has verified!")
9494
await log_channels_join.send(embed=embed_verified_success(user.mention, user.guild.member_count))
9595

96-
@discord.ui.button(label="Verify!", row=0, style=discord.ButtonStyle.red)
96+
@discord.ui.button(label="Verify!", row=0, custom_id="Button_4", style=discord.ButtonStyle.red)
9797
async def verify_button_callback_red_3(self, button: discord.ui.Button, interaction: discord.Interaction):
9898
"""
9999
This is a dummy button, if pressed kicks user.
100100
"""
101101
await self.send_wrong_button_message_and_kick(interaction)
102102

103-
@discord.ui.button(label="Verify!", row=0, style=discord.ButtonStyle.red)
103+
@discord.ui.button(label="Verify!", row=0, custom_id="Button_5", style=discord.ButtonStyle.red)
104104
async def verify_button_callback_red_4(self, button: discord.ui.Button, interaction: discord.Interaction):
105105
"""
106106
This is a dummy button, if pressed kicks user.
107107
"""
108108
await self.send_wrong_button_message_and_kick(interaction)
109109

110-
111110
class VerifyHelper(commands.Cog):
112111
"""
113112
this adds the button to the #verification channel so that people
@@ -127,9 +126,11 @@ async def add_verify_button(self, ctx):
127126
"please click the **GREEN** 'Verify' button to confirm your identity and gain "
128127
"access to the server. **If you click the RED button you will be kicked!** Feel free to introduce yourself and don't "
129128
"hesitate to ask any questions. Happy coding!")
130-
129+
131130
await ctx.respond(button_message, view=AdminVerification(self.bot))
132131

132+
133+
133134
async def cog_command_error(self, ctx: commands.Context, error: commands.CommandError):
134135
if isinstance(error, commands.MissingPermissions):
135136
await ctx.send(
@@ -140,6 +141,24 @@ async def cog_command_error(self, ctx: commands.Context, error: commands.Command
140141
raise error
141142

142143

144+
class persistantButton(commands.Cog):
145+
"""
146+
Listener for Adding the verification as a persistent listener
147+
"""
148+
149+
def __init__(self, bot):
150+
self.bot = bot
151+
152+
# Registers a View for persistent listening
153+
@commands.Cog.listener()
154+
async def on_ready(self):
155+
self.bot.add_view(AdminVerification(self.bot))
156+
157+
143158
def setup(bot):
144159
"""Required."""
145160
bot.add_cog(VerifyHelper(bot))
161+
bot.add_cog(persistantButton(bot))
162+
163+
164+

0 commit comments

Comments
 (0)