Hilmany / cogs /moderation.py
HilmanBey's picture
Upload 64 files
cbb05ec verified
Raw
History Blame Contribute Delete
28.7 kB
import discord
from discord.ext import commands
from discord import app_commands
import re
from datetime import datetime, timedelta
from database import Database
# Premium HSL Renk Paleti (Embed'ler için)
CYBER_GREEN = discord.Color.from_rgb(46, 204, 113)
CYBER_RED = discord.Color.from_rgb(231, 76, 60)
CYBER_ORANGE = discord.Color.from_rgb(230, 126, 34)
CYBER_BLUE = discord.Color.from_rgb(52, 152, 219)
CYBER_DARK = discord.Color.from_rgb(44, 62, 80)
def parse_duration(duration_str: str) -> timedelta:
"""Süre dizesini ayrıştırır (örn. '10m', '2h', '1d', '30s')"""
match = re.match(r"^(\d+)([smhd])$", duration_str.lower().strip())
if not match:
raise ValueError("Geçersiz süre biçimi. Örnek: 10m, 2h, 1d, 30s")
value, unit = int(match.group(1)), match.group(2)
if unit == 's':
return timedelta(seconds=value)
elif unit == 'm':
return timedelta(minutes=value)
elif unit == 'h':
return timedelta(hours=value)
elif unit == 'd':
return timedelta(days=value)
return timedelta(0)
async def safe_send(ctx, *args, **kwargs):
"""Slash ve prefix komutlarında güvenli mesaj gönderir."""
try:
if ctx.interaction and not ctx.interaction.response.is_done():
return await ctx.send(*args, **kwargs)
elif ctx.interaction and ctx.interaction.response.is_done():
return await ctx.interaction.followup.send(*args, **kwargs)
else:
return await ctx.send(*args, **kwargs)
except Exception:
try:
return await ctx.send(*args, **kwargs)
except Exception:
pass
async def send_dm_notification(member: discord.Member, action_name: str, guild_name: str, reason: str, duration: str = None, warn_count: int = None):
"""Kullanıcıya ceza veya işlem ile ilgili DM kutusuna şık bir bildirim gönderir."""
colors = {
"Yasaklama (Ban)": discord.Color.from_rgb(231, 76, 60),
"Sunucudan Atılma (Kick)": discord.Color.from_rgb(230, 126, 34),
"Susturulma (Mute)": discord.Color.from_rgb(230, 126, 34),
"Susturma Kaldırıldı": discord.Color.from_rgb(46, 204, 113),
"Uyarı": discord.Color.from_rgb(241, 196, 15),
}
color = colors.get(action_name, discord.Color.from_rgb(52, 152, 219))
embed = discord.Embed(
title=f"⚖️ {guild_name} Sunucusunda İşlem Yapıldı",
description=f"Merhaba **{member.name}**, sunucumuzda kurallara uyumu sağlamak amacıyla hesabınıza yönelik bir işlem uygulanmıştır.",
color=color,
timestamp=datetime.now()
)
embed.add_field(name="📌 Uygulanan İşlem", value=f"**{action_name}**", inline=True)
if duration:
embed.add_field(name="⏳ Süre", value=f"`{duration}`", inline=True)
if warn_count is not None:
embed.add_field(name="⚠️ Toplam Uyarı Sayısı", value=f"`{warn_count}`", inline=True)
embed.add_field(name="📝 Sebep", value=f"{reason}", inline=False)
embed.set_footer(text="ArazAI Siber Asayiş ve Güvenlik Sistemi")
try:
await member.send(embed=embed)
return True
except Exception:
return False
class Moderation(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def cog_load(self):
await Database.execute("""
CREATE TABLE IF NOT EXISTS ip_bans (
guild_id INTEGER,
user_id INTEGER,
user_name TEXT,
moderator_id INTEGER,
reason TEXT,
timestamp TEXT,
PRIMARY KEY (guild_id, user_id)
)
""")
@commands.hybrid_command(name="ip-ban", description="Belirtilen üyeyi IP adresi dahil sunucudan tamamen yasaklar.")
@commands.has_permissions(ban_members=True)
@app_commands.describe(member="IP Yasaklanacak üye", reason="Yasaklanma sebebi")
async def ipban(self, ctx: commands.Context, member: discord.Member, *, reason: str = "Belirtilmedi"):
if ctx.interaction:
await ctx.defer()
if member.top_role >= ctx.author.top_role and ctx.author.id != ctx.guild.owner_id:
await safe_send(ctx, "❌ Sizinle aynı veya daha yüksek roldeki birini yasaklayamazsınız!", ephemeral=True)
return
if member.top_role >= ctx.guild.me.top_role:
await safe_send(ctx, "❌ Bu üyeyi yasaklamak için yetkim yetersiz.", ephemeral=True)
return
try:
await send_dm_notification(member, "Yasaklama (Ban)", ctx.guild.name, f"[IP BAN] {reason}")
# Discord bans natively ban by IP
await member.ban(delete_message_days=7, reason=f"IP BAN | Yetkili: {ctx.author} | Sebep: {reason}")
# Save to Database
now_str = datetime.now().isoformat()
await Database.execute(
"INSERT OR REPLACE INTO ip_bans (guild_id, user_id, user_name, moderator_id, reason, timestamp) VALUES (?, ?, ?, ?, ?, ?)",
(ctx.guild.id, member.id, str(member), ctx.author.id, reason, now_str)
)
embed = discord.Embed(
title="🛡️ IP Yasaklaması Uygulandı",
description=f"**Kullanıcı:** {member.mention} ({member.id})\n**Yetkili:** {ctx.author.mention}\n**Sebep:** {reason}\n*Not: Kullanıcının hesabı ve IP adresi Discord sunucusundan tamamen engellenmiştir.*",
color=CYBER_RED,
timestamp=datetime.now()
)
embed.set_thumbnail(url=member.display_avatar.url)
await safe_send(ctx, embed=embed)
except Exception as e:
await safe_send(ctx, f"❌ Üye IP yasaklanırken bir hata oluştu: {e}", ephemeral=True)
@commands.hybrid_command(name="ban", description="Belirtilen üyeyi sunucudan yasaklar.")
@commands.has_permissions(ban_members=True)
@app_commands.describe(member="Yasaklanacak üye", reason="Yasaklanma sebebi")
async def ban(self, ctx: commands.Context, member: discord.Member, *, reason: str = "Belirtilmedi"):
if ctx.interaction:
await ctx.defer()
if member.top_role >= ctx.author.top_role and ctx.author.id != ctx.guild.owner_id:
await safe_send(ctx, "❌ Sizinle aynı veya daha yüksek roldeki birini yasaklayamazsınız!", ephemeral=True)
return
if member.top_role >= ctx.guild.me.top_role:
await safe_send(ctx, "❌ Bu üyeyi yasaklamak için yetkim yetersiz (Rolüm üyenin rolünden düşük).", ephemeral=True)
return
try:
await send_dm_notification(member, "Yasaklama (Ban)", ctx.guild.name, reason)
await member.ban(reason=f"Yetkili: {ctx.author} | Sebep: {reason}")
embed = discord.Embed(
title="🔨 Üye Yasaklandı",
description=f"**Kullanıcı:** {member.mention} ({member.id})\n**Yetkili:** {ctx.author.mention}\n**Sebep:** {reason}",
color=CYBER_RED,
timestamp=datetime.now()
)
embed.set_thumbnail(url=member.display_avatar.url)
await safe_send(ctx, embed=embed)
except Exception as e:
await safe_send(ctx, f"❌ Üye yasaklanırken bir hata oluştu: {e}", ephemeral=True)
@commands.hybrid_command(name="kick", description="Belirtilen üyeyi sunucudan atar.")
@commands.has_permissions(kick_members=True)
@app_commands.describe(member="Atılacak üye", reason="Atılma sebebi")
async def kick(self, ctx: commands.Context, member: discord.Member, *, reason: str = "Belirtilmedi"):
if ctx.interaction:
await ctx.defer()
if member.top_role >= ctx.author.top_role and ctx.author.id != ctx.guild.owner_id:
await safe_send(ctx, "❌ Sizinle aynı veya daha yüksek roldeki birini sunucudan atamazsınız!", ephemeral=True)
return
if member.top_role >= ctx.guild.me.top_role:
await safe_send(ctx, "❌ Bu üyeyi atmak için yetkim yetersiz.", ephemeral=True)
return
try:
await send_dm_notification(member, "Sunucudan Atılma (Kick)", ctx.guild.name, reason)
await member.kick(reason=f"Yetkili: {ctx.author} | Sebep: {reason}")
embed = discord.Embed(
title="👢 Üye Atıldı",
description=f"**Kullanıcı:** {member.mention} ({member.id})\n**Yetkili:** {ctx.author.mention}\n**Sebep:** {reason}",
color=CYBER_ORANGE,
timestamp=datetime.now()
)
embed.set_thumbnail(url=member.display_avatar.url)
await safe_send(ctx, embed=embed)
except Exception as e:
await safe_send(ctx, f"❌ Üye atılırken bir hata oluştu: {e}", ephemeral=True)
@commands.hybrid_command(name="mute", description="Belirtilen üyeyi susturur (Timeout).")
@commands.has_permissions(moderate_members=True)
@app_commands.describe(member="Susturulacak üye", duration="Süre (örn: 10m, 1h, 1d)", reason="Susturulma sebebi")
async def mute(self, ctx: commands.Context, member: discord.Member, duration: str, *, reason: str = "Belirtilmedi"):
if ctx.interaction:
await ctx.defer()
if member.top_role >= ctx.author.top_role and ctx.author.id != ctx.guild.owner_id:
await safe_send(ctx, "❌ Sizinle aynı veya daha yüksek roldeki birini susturamazsınız!", ephemeral=True)
return
if member.top_role >= ctx.guild.me.top_role:
await safe_send(ctx, "❌ Bu üyeyi susturmak için yetkim yetersiz.", ephemeral=True)
return
try:
delta = parse_duration(duration)
if delta.total_seconds() <= 0:
await safe_send(ctx, "❌ Geçersiz süre girdiniz.", ephemeral=True)
return
# Discord'un timeout API'si UTC datetime kabul eder
unmute_time_utc = discord.utils.utcnow() + delta
unmute_time_local = datetime.now() + delta
await send_dm_notification(member, "Susturulma (Mute)", ctx.guild.name, reason, duration=duration)
await member.timeout(unmute_time_utc, reason=f"Yetkili: {ctx.author} | Sebep: {reason}")
await Database.mute_ekle(member.id, ctx.guild.id, unmute_time_local)
embed = discord.Embed(
title="🔇 Üye Susturuldu",
description=f"**Kullanıcı:** {member.mention}\n**Yetkili:** {ctx.author.mention}\n**Süre:** {duration}\n**Açılma Tarihi:** <t:{int(unmute_time_local.timestamp())}:F>\n**Sebep:** {reason}",
color=CYBER_ORANGE,
timestamp=datetime.now()
)
embed.set_thumbnail(url=member.display_avatar.url)
await safe_send(ctx, embed=embed)
except ValueError as ve:
await safe_send(ctx, f"❌ Hata: {ve}", ephemeral=True)
except Exception as e:
await safe_send(ctx, f"❌ Susturma işlemi başarısız oldu: {e}", ephemeral=True)
@commands.hybrid_command(name="unmute", description="Belirtilen üyenin susturmasını kaldırır.")
@commands.has_permissions(moderate_members=True)
@app_commands.describe(member="Susturması kaldırılacak üye")
async def unmute(self, ctx: commands.Context, member: discord.Member):
if ctx.interaction:
await ctx.defer()
try:
await member.timeout(None, reason=f"Susturma kaldırıldı: {ctx.author}")
await Database.mute_kaldir(member.id, ctx.guild.id)
await send_dm_notification(member, "Susturma Kaldırıldı", ctx.guild.name, f"Yetkili: {ctx.author}")
embed = discord.Embed(
title="🔊 Susturma Kaldırıldı",
description=f"**Kullanıcı:** {member.mention}\n**Yetkili:** {ctx.author.mention}",
color=CYBER_GREEN,
timestamp=datetime.now()
)
embed.set_thumbnail(url=member.display_avatar.url)
await safe_send(ctx, embed=embed)
except Exception as e:
await safe_send(ctx, f"❌ Susturma kaldırılamadı: {e}", ephemeral=True)
@commands.hybrid_command(name="warn", description="Belirtilen üyeye uyarı ekler.")
@commands.has_permissions(manage_messages=True)
@app_commands.describe(member="Uyarılacak üye", reason="Uyarı sebebi")
async def warn(self, ctx: commands.Context, member: discord.Member, *, reason: str):
if ctx.interaction:
await ctx.defer()
if member.top_role >= ctx.author.top_role and ctx.author.id != ctx.guild.owner_id:
await safe_send(ctx, "❌ Sizinle aynı veya daha yüksek roldeki birini uyaramazsınız!", ephemeral=True)
return
try:
warn_id = await Database.uyari_ekle(member.id, ctx.guild.id, ctx.author.id, reason)
warns = await Database.uyarilari_getir(member.id, ctx.guild.id)
warn_count = len(warns)
await send_dm_notification(member, "Uyarı", ctx.guild.name, reason, warn_count=warn_count)
embed = discord.Embed(
title="⚠️ Üye Uyarıldı",
description=f"**Kullanıcı:** {member.mention}\n**Yetkili:** {ctx.author.mention}\n**Uyarı ID:** `{warn_id}`\n**Sebep:** {reason}\n**Toplam Uyarı Sayısı:** `{warn_count}`",
color=CYBER_ORANGE,
timestamp=datetime.now()
)
embed.set_thumbnail(url=member.display_avatar.url)
await safe_send(ctx, embed=embed)
# Otomatik cezalar
if warn_count >= 5:
await ctx.channel.send(f"⚠️ {member.mention} 5 uyarı sınırına ulaştığı için sunucudan **atılıyor**.")
await send_dm_notification(member, "Sunucudan Atılma (Kick)", ctx.guild.name, "5 Uyarı sınırına ulaşıldı (Otomatik).")
await member.kick(reason="5 Uyarı sınırına ulaşıldı.")
elif warn_count >= 3:
await ctx.channel.send(f"⚠️ {member.mention} 3 uyarı sınırına ulaştığı için **1 saat** susturuluyor.")
delta = timedelta(hours=1)
unmute_time_utc = discord.utils.utcnow() + delta
await send_dm_notification(member, "Susturulma (Mute)", ctx.guild.name, "3 Uyarı sınırına ulaşıldı (Otomatik 1 Saat Mute).", duration="1 Saat")
await member.timeout(unmute_time_utc, reason="3 Uyarı sınırına ulaşıldı (Otomatik 1 Saat Mute).")
await Database.mute_ekle(member.id, ctx.guild.id, datetime.now() + delta)
except Exception as e:
await safe_send(ctx, f"❌ Uyarı eklenemedi: {e}", ephemeral=True)
@commands.hybrid_command(name="warns", description="Belirtilen üyenin tüm uyarılarını listeler.")
@commands.has_permissions(manage_messages=True)
@app_commands.describe(member="Uyarıları görüntülenecek üye")
async def warns(self, ctx: commands.Context, member: discord.Member):
if ctx.interaction:
await ctx.defer()
try:
records = await Database.uyarilari_getir(member.id, ctx.guild.id)
if not records:
await safe_send(ctx, f"ℹ️ {member.mention} kullanıcısının geçmiş uyarısı bulunmamaktadır.")
return
embed = discord.Embed(
title=f"📋 Uyarı Geçmişi - {member.display_name}",
description=f"{member.mention} kullanıcısının toplam `{len(records)}` uyarısı var.",
color=CYBER_BLUE,
timestamp=datetime.now()
)
embed.set_thumbnail(url=member.display_avatar.url)
for record in records[:10]:
moderator = ctx.guild.get_member(record['moderator_id'])
mod_name = moderator.mention if moderator else f"ID: {record['moderator_id']}"
tarih_dt = datetime.fromisoformat(record['tarih'])
tarih_stamp = f"<t:{int(tarih_dt.timestamp())}:f>"
embed.add_field(
name=f"Uyarı ID: #{record['id']}",
value=f"**Yetkili:** {mod_name}\n**Tarih:** {tarih_stamp}\n**Sebep:** {record['sebep']}",
inline=False
)
await safe_send(ctx, embed=embed)
except Exception as e:
await safe_send(ctx, f"❌ Uyarılar listelenemedi: {e}", ephemeral=True)
@commands.hybrid_command(name="warn-sil", description="ID bazlı olarak tek bir uyarıyı siler.")
@commands.has_permissions(manage_messages=True)
@app_commands.describe(warn_id="Silinecek uyarının sayısal benzersiz ID'si")
async def warn_sil(self, ctx: commands.Context, warn_id: int):
if ctx.interaction:
await ctx.defer()
try:
rows_deleted = await Database.uyari_sil(warn_id, ctx.guild.id)
if rows_deleted > 0:
await safe_send(ctx, f"✅ #{warn_id} ID'li uyarı başarıyla silindi.")
else:
await safe_send(ctx, "❌ Belirtilen ID'ye sahip bir uyarı bu sunucuda bulunamadı.", ephemeral=True)
except Exception as e:
await safe_send(ctx, f"❌ Uyarı silinirken hata: {e}", ephemeral=True)
@commands.hybrid_command(name="warn-temizle", description="Bir üyenin tüm uyarılarını temizler.")
@commands.has_permissions(administrator=True)
@app_commands.describe(member="Uyarıları sıfırlanacak üye")
async def warn_temizle(self, ctx: commands.Context, member: discord.Member):
if ctx.interaction:
await ctx.defer()
try:
rows_deleted = await Database.uyarilari_temizle(member.id, ctx.guild.id)
await safe_send(ctx, f"✅ {member.mention} kullanıcısının tüm uyarıları sıfırlandı. Toplam `{rows_deleted}` uyarı silindi.")
except Exception as e:
await safe_send(ctx, f"❌ Uyarılar silinirken hata: {e}", ephemeral=True)
# --- EKSTRA GÜVENLİK VE MODERASYON KOMUTLARI ---
@commands.hybrid_command(name="unban", description="Belirtilen kullanıcının yasaklamasını kaldırır.")
@commands.has_permissions(ban_members=True)
@app_commands.describe(user_id="Yasağı kaldırılacak kullanıcının ID'si (Sayısal)")
async def unban(self, ctx: commands.Context, user_id: str):
if ctx.interaction:
await ctx.defer()
try:
uid = int(user_id)
user = await self.bot.fetch_user(uid)
if not user:
await safe_send(ctx, "❌ Belirtilen ID'ye sahip bir Discord kullanıcısı bulunamadı.", ephemeral=True)
return
await ctx.guild.unban(user, reason=f"Yasağı kaldıran yetkili: {ctx.author}")
embed = discord.Embed(
title="🔓 Yasak Kaldırıldı",
description=f"**Kullanıcı:** {user.name} ({user.id})\n**Yetkili:** {ctx.author.mention}",
color=CYBER_GREEN,
timestamp=datetime.now()
)
await safe_send(ctx, embed=embed)
except ValueError:
await safe_send(ctx, "❌ Geçersiz kullanıcı ID'si. Sadece rakamlardan oluşmalıdır.", ephemeral=True)
except discord.NotFound:
await safe_send(ctx, "❌ Bu kullanıcı zaten sunucuda yasaklı değil.", ephemeral=True)
except Exception as e:
await safe_send(ctx, f"❌ İşlem başarısız: {e}", ephemeral=True)
@commands.hybrid_command(name="clear", description="Belirtilen miktarda mesajı kanaldan temizler.")
@commands.has_permissions(manage_messages=True)
@app_commands.describe(amount="Temizlenecek mesaj sayısı (1-100)")
async def clear(self, ctx: commands.Context, amount: int):
if amount < 1 or amount > 100:
await safe_send(ctx, "❌ Lütfen 1 ile 100 arasında bir sayı giriniz.", ephemeral=True)
return
try:
if ctx.interaction:
await ctx.defer(ephemeral=True)
deleted = await ctx.channel.purge(limit=amount)
if ctx.interaction:
await ctx.interaction.followup.send(content=f"✅ Başarıyla `{len(deleted)}` mesaj temizlendi.", ephemeral=True)
else:
await ctx.send(f"✅ Başarıyla `{len(deleted)}` mesaj temizlendi.", delete_after=5)
except Exception as e:
await safe_send(ctx, f"❌ Temizleme işlemi başarısız oldu: {e}", ephemeral=True)
@commands.hybrid_command(name="slowmode", description="Kanal için yavaş mod süresini ayarlar.")
@commands.has_permissions(manage_channels=True)
@app_commands.describe(seconds="Saniye cinsinden yavaş mod süresi (0 kapatır)")
async def slowmode(self, ctx: commands.Context, seconds: int):
if ctx.interaction:
await ctx.defer()
if seconds < 0 or seconds > 21600:
await safe_send(ctx, "❌ Yavaş mod süresi 0 ile 21600 saniye (6 saat) arasında olmalıdır.", ephemeral=True)
return
try:
await ctx.channel.edit(slowmode_delay=seconds)
if seconds == 0:
await safe_send(ctx, "✅ Yavaş mod bu kanal için kapatıldı.")
else:
await safe_send(ctx, f"✅ Yavaş mod bu kanal için `{seconds}` saniye olarak ayarlandı.")
except Exception as e:
await safe_send(ctx, f"❌ İşlem başarısız: {e}", ephemeral=True)
@commands.hybrid_command(name="lock", description="Kanalı @everyone rolüne karşı mesaj gönderimine kapatır.")
@commands.has_permissions(manage_channels=True)
async def lock(self, ctx: commands.Context):
if ctx.interaction:
await ctx.defer()
try:
overwrite = ctx.channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = False
await ctx.channel.set_permissions(ctx.guild.default_role, overwrite=overwrite, reason=f"Kanal kilitlendi: {ctx.author}")
await safe_send(ctx, "🔒 Kanal başarıyla yazıma **kilitlendi**.")
except Exception as e:
await safe_send(ctx, f"❌ Kanal kilitlenemedi: {e}", ephemeral=True)
@commands.hybrid_command(name="unlock", description="Kilitlenmiş kanalın kilidini açar.")
@commands.has_permissions(manage_channels=True)
async def unlock(self, ctx: commands.Context):
if ctx.interaction:
await ctx.defer()
try:
overwrite = ctx.channel.overwrites_for(ctx.guild.default_role)
overwrite.send_messages = None
await ctx.channel.set_permissions(ctx.guild.default_role, overwrite=overwrite, reason=f"Kanal kilidi açıldı: {ctx.author}")
await safe_send(ctx, "🔓 Kanal kilidi başarıyla **açıldı**.")
except Exception as e:
await safe_send(ctx, f"❌ Kanal kilidi açılamadı: {e}", ephemeral=True)
@commands.hybrid_command(name="nuke", description="Kanalı siler ve aynı izinlerle yeniden oluşturur (Tüm mesajlar silinir).")
@commands.has_permissions(administrator=True)
async def nuke(self, ctx: commands.Context):
if ctx.interaction:
await ctx.defer(ephemeral=True)
try:
channel = ctx.channel
new_channel = await channel.clone(reason=f"Kanal nuke edildi: {ctx.author}")
await new_channel.edit(position=channel.position)
await channel.delete(reason="Nuke işlemi.")
embed = discord.Embed(
title="💥 Kanal Yeniden Oluşturuldu (Nuke)",
description=f"Bu kanal {ctx.author.mention} tarafından nuke edildi ve tüm mesajlar temizlendi.",
color=CYBER_GREEN,
timestamp=datetime.now()
)
await new_channel.send(embed=embed)
except Exception as e:
try:
await ctx.send(f"❌ Nuke işlemi başarısız: {e}", ephemeral=True)
except Exception:
pass
@commands.hybrid_command(name="banlist", description="Sunucudaki tüm yasaklı kullanıcıları listeler.")
@commands.has_permissions(ban_members=True)
async def banlist(self, ctx: commands.Context):
if ctx.interaction:
await ctx.defer(ephemeral=True)
try:
bans = [entry async for entry in ctx.guild.bans(limit=100)]
if not bans:
await safe_send(ctx, "ℹ️ Sunucuda yasaklı kullanıcı bulunmamaktadır.")
return
embed = discord.Embed(
title=f"🔨 Sunucu Ban Listesi ({len(bans)} kişi)",
color=CYBER_RED,
timestamp=datetime.now()
)
ban_text = ""
for entry in bans[:30]:
ban_text += f"• `{entry.user.name}` ({entry.user.id})\n"
embed.description = ban_text
if len(bans) > 30:
embed.set_footer(text=f"Toplam {len(bans)} yasaklı kullanıcıdan ilk 30 gösteriliyor.")
await safe_send(ctx, embed=embed)
except Exception as e:
await safe_send(ctx, f"❌ Ban listesi alınamadı: {e}", ephemeral=True)
@commands.hybrid_command(name="userinfo", description="Belirtilen üyenin profil bilgilerini gösterir.")
@app_commands.describe(member="Profil bilgisi görüntülenecek üye")
async def userinfo(self, ctx: commands.Context, member: discord.Member = None):
if ctx.interaction:
await ctx.defer()
member = member or ctx.author
try:
created_at = f"<t:{int(member.created_at.timestamp())}:F>"
joined_at = f"<t:{int(member.joined_at.timestamp())}:F>" if member.joined_at else "Bilinmiyor"
roles = [r.mention for r in member.roles if r != ctx.guild.default_role]
embed = discord.Embed(
title=f"👤 Kullanıcı Bilgisi: {member.display_name}",
color=member.color if member.color.value else CYBER_BLUE,
timestamp=datetime.now()
)
embed.set_thumbnail(url=member.display_avatar.url)
embed.add_field(name="Kullanıcı Adı", value=f"`{member.name}`", inline=True)
embed.add_field(name="ID", value=f"`{member.id}`", inline=True)
embed.add_field(name="Bot mu?", value="✅ Evet" if member.bot else "❌ Hayır", inline=True)
embed.add_field(name="Hesap Oluşturulma", value=created_at, inline=False)
embed.add_field(name="Sunucuya Katılma", value=joined_at, inline=False)
embed.add_field(name=f"Roller ({len(roles)})", value=" ".join(roles[:10]) if roles else "Rol yok", inline=False)
await safe_send(ctx, embed=embed)
except Exception as e:
await safe_send(ctx, f"❌ Kullanıcı bilgisi alınamadı: {e}", ephemeral=True)
@commands.hybrid_command(name="serverinfo", description="Sunucu bilgilerini gösterir.")
async def serverinfo(self, ctx: commands.Context):
if ctx.interaction:
await ctx.defer()
try:
guild = ctx.guild
created_at = f"<t:{int(guild.created_at.timestamp())}:F>"
bans_count = guild.me.guild_permissions.ban_members
embed = discord.Embed(
title=f"🏠 Sunucu Bilgisi: {guild.name}",
color=CYBER_BLUE,
timestamp=datetime.now()
)
if guild.icon:
embed.set_thumbnail(url=guild.icon.url)
embed.add_field(name="Sahip", value=guild.owner.mention if guild.owner else "Bilinmiyor", inline=True)
embed.add_field(name="ID", value=f"`{guild.id}`", inline=True)
embed.add_field(name="Üye Sayısı", value=f"`{guild.member_count}`", inline=True)
embed.add_field(name="Kanal Sayısı", value=f"`{len(guild.channels)}`", inline=True)
embed.add_field(name="Rol Sayısı", value=f"`{len(guild.roles)}`", inline=True)
embed.add_field(name="Boost Seviyesi", value=f"`{guild.premium_tier}`", inline=True)
embed.add_field(name="Oluşturulma Tarihi", value=created_at, inline=False)
await safe_send(ctx, embed=embed)
except Exception as e:
await safe_send(ctx, f"❌ Sunucu bilgisi alınamadı: {e}", ephemeral=True)
async def setup(bot):
await bot.add_cog(Moderation(bot))