Skip to content

Commit 6b991ea

Browse files
authored
Merge pull request #304 from practical-python-org/feature/persistant_verification_button
Feature/ Persistant verification buttons
2 parents 03d5ba4 + 55037db commit 6b991ea

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/zorak/cogs/admin/verification_on_verified.py

Lines changed: 25 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,20 +86,21 @@ 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

90-
log_channels_verification_log = await self.bot.fetch_channel(self.bot.server_settings.log_channel["verification_log"])
89+
log_channels_verification_log = await self.bot.fetch_channel(
90+
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.
@@ -127,7 +127,7 @@ async def add_verify_button(self, ctx):
127127
"please click the **GREEN** 'Verify' button to confirm your identity and gain "
128128
"access to the server. **If you click the RED button you will be kicked!** Feel free to introduce yourself and don't "
129129
"hesitate to ask any questions. Happy coding!")
130-
130+
131131
await ctx.respond(button_message, view=AdminVerification(self.bot))
132132

133133
async def cog_command_error(self, ctx: commands.Context, error: commands.CommandError):
@@ -140,6 +140,21 @@ async def cog_command_error(self, ctx: commands.Context, error: commands.Command
140140
raise error
141141

142142

143+
class PersistentButton(commands.Cog):
144+
"""
145+
Listener for Adding the verification as a persistent listener
146+
"""
147+
148+
def __init__(self, bot):
149+
self.bot = bot
150+
151+
# Registers a View for persistent listening
152+
@commands.Cog.listener()
153+
async def on_ready(self):
154+
self.bot.add_view(AdminVerification(self.bot))
155+
156+
143157
def setup(bot):
144158
"""Required."""
145159
bot.add_cog(VerifyHelper(bot))
160+
bot.add_cog(PersistentButton(bot))

0 commit comments

Comments
 (0)