-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverification_system.py
More file actions
171 lines (146 loc) Β· 6.27 KB
/
verification_system.py
File metadata and controls
171 lines (146 loc) Β· 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import discord
from discord.ext import commands
class WelcomeModal(discord.ui.Modal, title="HackUTD2025 - Welcome & Rules Agreement"):
def __init__(self):
super().__init__()
# Text input for agreement
agreement = discord.ui.TextInput(
label="Type 'I AGREE' to accept the rules",
placeholder="Type exactly: I AGREE",
required=True,
max_length=10
)
async def on_submit(self, interaction: discord.Interaction):
if self.agreement.value.upper() == "I AGREE":
# Remove unverified, add verified role
unverified_role = discord.utils.get(interaction.guild.roles, name="Unverified")
verified_role = discord.utils.get(interaction.guild.roles, name="Verified")
if unverified_role:
await interaction.user.remove_roles(unverified_role)
if verified_role:
await interaction.user.add_roles(verified_role)
await interaction.response.send_message(
"π Welcome to HackUTD2025! You now have access to all channels. Let's build something amazing!",
ephemeral=True
)
else:
await interaction.response.send_message(
"β Please type exactly 'I AGREE' to accept the rules.",
ephemeral=True
)
class VerificationView(discord.ui.View):
def __init__(self):
super().__init__(timeout=None) # Persistent view
@discord.ui.button(label="π Read Rules & Verify", style=discord.ButtonStyle.blurple, emoji="β
")
async def verify_button(self, interaction: discord.Interaction, button: discord.ui.Button):
modal = WelcomeModal()
await interaction.response.send_modal(modal)
async def send_welcome_message(channel):
"""Send the welcome embed with rules"""
embed = discord.Embed(
title="π Welcome to HackUTD2025!",
description="Welcome to our official Discord server! Please read our rules below and verify to gain access.",
color=discord.Color.blue()
)
embed.add_field(
name="π Server Rules",
value="""
1. **Be respectful** - Treat everyone with kindness and respect
2. **No spam** - Keep messages relevant and don't flood channels
3. **Stay on topic** - Use appropriate channels for discussions
4. **No NSFW content** - Keep all content appropriate
5. **Ask for help** - Use #help channels when you need assistance
6. **Have fun** - We're here to learn, build, and connect!
""",
inline=False
)
embed.add_field(
name="π― Event Guidelines",
value="""
β’ Form teams respectfully in #team-formation
β’ Share progress in #project-showcase
β’ Mentors are here to help - don't hesitate to ask!
β’ Submission deadline: [DATE] at [TIME]
""",
inline=False
)
embed.set_footer(text="Click the button below to verify and join the hackathon!")
view = VerificationView()
await channel.send(embed=embed, view=view)
async def setup_verification_system(guild):
"""Set up roles, channels, and permissions for verification system"""
print(f"Setting up verification system for {guild.name}...")
# Create Unverified role
unverified_role = discord.utils.get(guild.roles, name="Unverified")
if not unverified_role:
unverified_role = await guild.create_role(
name="Unverified",
color=discord.Color.red(),
reason="Verification system setup"
)
print("Created Unverified role")
# Create Verified role
verified_role = discord.utils.get(guild.roles, name="Verified")
if not verified_role:
verified_role = await guild.create_role(
name="Verified",
color=discord.Color.green(),
reason="Verification system setup"
)
print("Created Verified role")
# Create welcome channel
welcome_channel = discord.utils.get(guild.channels, name="welcome")
if not welcome_channel:
# Create the channel
welcome_channel = await guild.create_text_channel(
"welcome",
topic="Welcome to HackUTD2025! Please verify to gain access to the server.",
reason="Verification system setup"
)
# Set welcome channel permissions
await welcome_channel.set_permissions(
guild.default_role,
view_channel=True,
send_messages=False,
reason="Welcome channel setup"
)
await welcome_channel.set_permissions(
unverified_role,
view_channel=True,
send_messages=False,
reason="Welcome channel setup"
)
await welcome_channel.set_permissions(
verified_role,
view_channel=False,
reason="Welcome channel setup"
)
print("Created welcome channel with permissions")
# Clear any existing messages and send welcome message
await welcome_channel.purge(limit=100)
await send_welcome_message(welcome_channel)
print("Sent welcome message")
print("Verification system setup complete!")
# Event handler for when someone joins
async def handle_member_join(member):
"""Give new members the Unverified role"""
unverified_role = discord.utils.get(member.guild.roles, name="Unverified")
if unverified_role:
await member.add_roles(unverified_role, reason="New member verification")
print(f"Gave {member.display_name} the Unverified role")
# Cog class for easier integration
class VerificationCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_member_join(self, member):
await handle_member_join(member)
@commands.command(name="setup_verification")
@commands.has_permissions(administrator=True)
async def setup_verification_command(self, ctx):
"""Admin command to manually setup verification system"""
await setup_verification_system(ctx.guild)
await ctx.send("β
Verification system has been set up!")
async def setup(bot):
"""Setup function for loading as a cog"""
await bot.add_cog(VerificationCog(bot))