| import discord |
| from discord.ext import commands |
| from discord import app_commands |
| import asyncio |
| from database import Database |
|
|
| CYBER_BLUE = discord.Color.from_rgb(52, 152, 219) |
| CYBER_GREEN = discord.Color.from_rgb(46, 204, 113) |
| CYBER_ORANGE = discord.Color.from_rgb(230, 126, 34) |
|
|
|
|
| class TempChannels(commands.Cog): |
| def __init__(self, bot): |
| self.bot = bot |
|
|
| @commands.hybrid_command(name="geçici-kanal-ayarla", description="Geçici ses kanalı sistemi ayarlar.") |
| @commands.has_permissions(administrator=True) |
| @app_commands.describe( |
| kategori="Geçici kanalların oluşturulacağı kategori", |
| kanal_olusturma_kanali="Kullanıcıların geçici kanal oluşturmak için gireceği ses kanalı" |
| ) |
| async def gecici_kanal_ayarla( |
| self, ctx: commands.Context, |
| kategori: discord.CategoryChannel, |
| kanal_olusturma_kanali: discord.VoiceChannel |
| ): |
| if ctx.interaction: |
| await ctx.defer() |
| await Database.execute( |
| """INSERT OR REPLACE INTO gecici_kanal_ayarlar |
| (guild_id, kategori_id, kanal_olustur_kanal_id, aktif) |
| VALUES (?, ?, ?, 1)""", |
| (ctx.guild.id, kategori.id, kanal_olusturma_kanali.id) |
| ) |
| await ctx.send(f"✅ Geçici kanal sistemi ayarlandı. {kanal_olusturma_kanali.mention} ses kanalına girerek özel geçici kanal oluşturabilirsiniz.") |
|
|
| @commands.hybrid_command(name="geçici-kanal-kapat", description="Geçici kanal sistemini devre dışı bırakır.") |
| @commands.has_permissions(administrator=True) |
| async def gecici_kanal_kapat(self, ctx: commands.Context): |
| if ctx.interaction: |
| await ctx.defer() |
| await Database.execute("UPDATE gecici_kanal_ayarlar SET aktif = 0 WHERE guild_id = ?", (ctx.guild.id,)) |
| await ctx.send("✅ Geçici kanal sistemi devre dışı bırakıldı.") |
|
|
| @commands.Cog.listener() |
| async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): |
| if member.bot or not member.guild: |
| return |
| if not await Database.modul_aktif_mi(member.guild.id, "TempChannels"): |
| return |
|
|
| cfg = await Database.fetch_one( |
| "SELECT * FROM gecici_kanal_ayarlar WHERE guild_id = ? AND aktif = 1", |
| (member.guild.id,) |
| ) |
| if not cfg: |
| return |
|
|
| olustur_kanal_id = cfg.get('kanal_olustur_kanal_id', 0) |
| kategori_id = cfg.get('kategori_id', 0) |
|
|
| |
| if before.channel is None and after.channel is not None and after.channel.id == olustur_kanal_id: |
| kategori = member.guild.get_channel(kategori_id) if kategori_id else None |
| try: |
| overwrites = { |
| member.guild.default_role: discord.PermissionOverwrite(view_channel=False), |
| member: discord.PermissionOverwrite(view_channel=True, send_messages=True, connect=True, manage_channels=True, speak=True, stream=True, use_voice_activation=True), |
| member.guild.me: discord.PermissionOverwrite(view_channel=True, connect=True, manage_channels=True) |
| } |
| new_channel = await member.guild.create_voice_channel( |
| name=f"🔊 {member.display_name} Odası", |
| category=kategori, |
| overwrites=overwrites, |
| reason=f"Geçici kanal: {member}" |
| ) |
| await Database.execute( |
| "INSERT OR REPLACE INTO gecici_kanallar (kanal_id, guild_id, sahip_id) VALUES (?, ?, ?)", |
| (new_channel.id, member.guild.id, member.id) |
| ) |
| await member.move_to(new_channel, reason="Geçici kanala taşınıyor") |
| except Exception as e: |
| print(f"Geçici kanal oluşturma hatası: {e}") |
|
|
| |
| if before.channel is not None and after.channel is None: |
| gecici = await Database.fetch_one( |
| "SELECT * FROM gecici_kanallar WHERE kanal_id = ? AND guild_id = ?", |
| (before.channel.id, member.guild.id) |
| ) |
| if gecici and len(before.channel.members) == 0: |
| try: |
| await before.channel.delete(reason="Geçici kanal boşaldı") |
| except: |
| pass |
| await Database.execute( |
| "DELETE FROM gecici_kanallar WHERE kanal_id = ?", |
| (before.channel.id,) |
| ) |
|
|
| |
| if before.channel is not None and after.channel is not None and before.channel.id != after.channel.id: |
| gecici = await Database.fetch_one( |
| "SELECT * FROM gecici_kanallar WHERE kanal_id = ? AND guild_id = ?", |
| (before.channel.id, member.guild.id) |
| ) |
| if gecici and len(before.channel.members) == 0: |
| try: |
| await before.channel.delete(reason="Geçici kanal boşaldı") |
| except: |
| pass |
| await Database.execute( |
| "DELETE FROM gecici_kanallar WHERE kanal_id = ?", |
| (before.channel.id,) |
| ) |
|
|
|
|
| async def setup(bot): |
| await bot.add_cog(TempChannels(bot)) |
|
|