| import discord |
| from discord.ext import commands |
| from discord import app_commands |
| from database import Database |
| import random |
| import string |
|
|
| CYBER_GREEN = discord.Color.from_rgb(46, 204, 113) |
| CYBER_BLUE = discord.Color.from_rgb(52, 152, 219) |
| CYBER_RED = discord.Color.from_rgb(231, 76, 60) |
|
|
| |
| ACTIVE_CAPTCHAS = {} |
|
|
|
|
| class Verification(commands.Cog): |
| def __init__(self, bot): |
| self.bot = bot |
|
|
| @commands.hybrid_command(name="doğrulama-ayarla", description="Doğrulama (captcha) sistemini ayarlar.") |
| @commands.has_permissions(administrator=True) |
| @app_commands.describe( |
| kanal="Doğrulama mesajının gönderileceği kanal", |
| rol="Doğrulayanlara verilecek rol" |
| ) |
| async def dogrulama_ayarla(self, ctx: commands.Context, kanal: discord.TextChannel, rol: discord.Role): |
| if ctx.interaction: |
| await ctx.defer() |
|
|
| await Database.execute( |
| """INSERT OR REPLACE INTO dogrulama_ayarlar (guild_id, kanal_id, rol_id, aktif) |
| VALUES (?, ?, ?, 1)""", |
| (ctx.guild.id, kanal.id, rol.id) |
| ) |
|
|
| embed = discord.Embed( |
| title="✅ Hesabını Doğrula", |
| description=( |
| "Sunucunun tüm içeriklerine erişmek için aşağıdaki **Doğrula** butonuna tıklayın.\n" |
| "Açılan pencerede göreceğiniz kodu yazarak doğrulama işlemini tamamlayabilirsiniz." |
| ), |
| color=CYBER_GREEN, |
| ) |
| embed.set_footer(text="ArazAI Doğrulama Sistemi") |
|
|
| view = discord.ui.View(timeout=None) |
| view.add_item(discord.ui.Button( |
| label="Doğrula", |
| style=discord.ButtonStyle.success, |
| custom_id="verify_btn", |
| emoji="✅" |
| )) |
|
|
| await kanal.send(embed=embed, view=view) |
| await ctx.send(f"✅ Doğrulama sistemi {kanal.mention} kanalında kuruldu. Onaylı rol: {rol.mention}") |
|
|
| @commands.hybrid_command(name="doğrulama-kapat", description="Doğrulama sistemini devre dışı bırakır.") |
| @commands.has_permissions(administrator=True) |
| async def dogrulama_kapat(self, ctx: commands.Context): |
| if ctx.interaction: |
| await ctx.defer() |
| await Database.execute("UPDATE dogrulama_ayarlar SET aktif = 0 WHERE guild_id = ?", (ctx.guild.id,)) |
| await ctx.send("✅ Doğrulama sistemi devre dışı bırakıldı.") |
|
|
| @commands.Cog.listener() |
| async def on_interaction(self, interaction: discord.Interaction): |
| if interaction.type != discord.InteractionType.component: |
| return |
| custom_id = interaction.data.get("custom_id", "") |
| if not custom_id.startswith("verify_btn"): |
| return |
|
|
| if not await Database.modul_aktif_mi(interaction.guild_id, "Verification"): |
| try: |
| await interaction.response.send_message("❌ Doğrulama sistemi şu an devre dışı.", ephemeral=True) |
| except: |
| pass |
| return |
|
|
| cfg = await Database.fetch_one( |
| "SELECT * FROM dogrulama_ayarlar WHERE guild_id = ? AND aktif = 1", |
| (interaction.guild.id,) |
| ) |
| if not cfg: |
| await interaction.response.send_message("❌ Doğrulama sistemi aktif değil.", ephemeral=True) |
| return |
|
|
| |
| code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6)) |
| ACTIVE_CAPTCHAS[interaction.user.id] = code |
|
|
| modal = CaptchaModal(code, cfg['rol_id']) |
| await interaction.response.send_modal(modal) |
|
|
| @commands.Cog.listener() |
| async def on_member_join(self, member: discord.Member): |
| if not await Database.modul_aktif_mi(member.guild.id, "Verification"): |
| return |
| cfg = await Database.fetch_one( |
| "SELECT * FROM dogrulama_ayarlar WHERE guild_id = ? AND aktif = 1", |
| (member.guild.id,) |
| ) |
| if not cfg: |
| return |
|
|
| |
| |
| try: |
| await member.send( |
| f"Merhaba {member.mention}, **{member.guild.name}** sunucusuna hoş geldin!\n" |
| f"Lütfen sunucudaki tüm içeriklere erişebilmek için doğrulama kanalındaki butonu kullanarak hesabını doğrula." |
| ) |
| except: |
| pass |
|
|
|
|
| class CaptchaModal(discord.ui.Modal, title="Hesap Doğrulama - Captcha"): |
| code_input = discord.ui.TextInput( |
| label="Doğrulama Kodu", |
| placeholder="Görseldeki 6 haneli kodu girin ( büyük/küçük farketmez )", |
| required=True, |
| min_length=6, |
| max_length=6 |
| ) |
|
|
| def __init__(self, code, rol_id): |
| super().__init__() |
| self.expected_code = code |
| self.rol_id = rol_id |
|
|
| async def on_submit(self, interaction: discord.Interaction): |
| if self.code_input.value.upper().strip() == self.expected_code: |
| guild = interaction.guild |
| rol = guild.get_role(self.rol_id) if guild else None |
| if rol: |
| try: |
| await interaction.user.add_roles(rol, reason="Doğrulama başarılı") |
| except: |
| pass |
|
|
| ACTIVE_CAPTCHAS.pop(interaction.user.id, None) |
|
|
| await interaction.response.send_message( |
| content=f"✅ Doğrulama başarılı! Hoş geldin {interaction.user.mention}.", |
| ephemeral=True |
| ) |
| else: |
| |
| import random, string |
| new_code = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6)) |
| ACTIVE_CAPTCHAS[interaction.user.id] = new_code |
|
|
| embed = discord.Embed( |
| title="❌ Hatalı Kod!", |
| description=f"Girdiğiniz kod hatalı. Yeni kodunuz: **`{new_code}`**", |
| color=CYBER_RED |
| ) |
| await interaction.response.send_message(embed=embed, ephemeral=True) |
|
|
|
|
| async def setup(bot): |
| await bot.add_cog(Verification(bot)) |
|
|