| import discord |
| from discord.ext import commands |
| from discord import app_commands |
| from database import Database |
|
|
| CYBER_BLUE = discord.Color.from_rgb(52, 152, 219) |
| CYBER_GREEN = discord.Color.from_rgb(46, 204, 113) |
| CYBER_RED = discord.Color.from_rgb(231, 76, 60) |
| CYBER_GOLD = discord.Color.from_rgb(241, 196, 15) |
| CYBER_ORANGE = discord.Color.from_rgb(230, 126, 34) |
|
|
|
|
| class Counting(commands.Cog): |
| def __init__(self, bot): |
| self.bot = bot |
|
|
| @commands.hybrid_command(name="sayma-kanal-ayarla", description="Sayı sayma oyunu kanalını ayarlar.") |
| @commands.has_permissions(administrator=True) |
| @app_commands.describe(kanal="Sayı sayma kanalı") |
| async def sayma_kanal_ayarla(self, ctx: commands.Context, kanal: discord.TextChannel): |
| if ctx.interaction: |
| await ctx.defer() |
| await Database.execute( |
| """INSERT OR REPLACE INTO sayi_sayma (guild_id, kanal_id, son_sayi, son_atan, rekor, aktif) |
| VALUES (?, ?, 0, 0, 0, 1)""", |
| (ctx.guild.id, kanal.id) |
| ) |
| await ctx.send(f"✅ Sayı sayma kanalı {kanal.mention} olarak ayarlandı. Sayaç **0**'dan başlıyor!") |
|
|
| @commands.hybrid_command(name="sayma-kapat", description="Sayı sayma oyununu devre dışı bırakır.") |
| @commands.has_permissions(administrator=True) |
| async def sayma_kapat(self, ctx: commands.Context): |
| if ctx.interaction: |
| await ctx.defer() |
| await Database.execute("UPDATE sayi_sayma SET aktif = 0 WHERE guild_id = ?", (ctx.guild.id,)) |
| await ctx.send("✅ Sayı sayma oyunu devre dışı bırakıldı.") |
|
|
| @commands.hybrid_command(name="sayma-sıfırla", description="Sayı sayma sayacını sıfırlar.") |
| @commands.has_permissions(administrator=True) |
| async def sayma_sifirla(self, ctx: commands.Context): |
| if ctx.interaction: |
| await ctx.defer() |
| await Database.execute( |
| "UPDATE sayi_sayma SET son_sayi = 0, son_atan = 0 WHERE guild_id = ?", |
| (ctx.guild.id,) |
| ) |
| await ctx.send("✅ Sayı sayma sayacı sıfırlandı. 0'dan başlayın!") |
|
|
| @commands.Cog.listener() |
| async def on_message(self, message: discord.Message): |
| if message.author.bot or not message.guild: |
| return |
| if not await Database.modul_aktif_mi(message.guild.id, "Counting"): |
| return |
|
|
| cfg = await Database.fetch_one( |
| "SELECT * FROM sayi_sayma WHERE guild_id = ? AND aktif = 1", |
| (message.guild.id,) |
| ) |
| if not cfg: |
| return |
|
|
| if message.channel.id != cfg['kanal_id']: |
| return |
|
|
| |
| content = message.content.strip() |
| if not content.lstrip("-").isdigit(): |
| return |
|
|
| try: |
| num = int(content) |
| except: |
| return |
|
|
| son_sayi = cfg['son_sayi'] |
| son_atan = cfg['son_atan'] |
| rekor = cfg['rekor'] |
|
|
| beklenen = son_sayi + 1 |
| if son_sayi == 0: |
| beklenen = 1 |
|
|
| if num != beklenen: |
| embed = discord.Embed( |
| title="❌ Hatalı Sayı!", |
| description=f"{message.author.mention} yanlış sayı girdi!\nBeklenen: **{beklenen}**, Senin girdiğin: **{num}**\n\n**Sayaç sıfırlandı!** 🔥", |
| color=CYBER_RED, |
| timestamp=discord.utils.utcnow() |
| ) |
| embed.set_footer(text="ArazAI Sayma Oyunu") |
| await message.channel.send(embed=embed) |
|
|
| await Database.execute( |
| "UPDATE sayi_sayma SET son_sayi = 0, son_atan = 0 WHERE guild_id = ?", |
| (message.guild.id,) |
| ) |
| |
| try: |
| await message.add_reaction("❌") |
| except: |
| pass |
| return |
|
|
| if message.author.id == son_atan: |
| embed = discord.Embed( |
| title="⚠️ Ardışık Tespit!", |
| description=f"{message.author.mention}, siz art arda sayamazsınız! Sayaç sıfırlandı.", |
| color=CYBER_ORANGE, |
| timestamp=discord.utils.utcnow() |
| ) |
| await message.channel.send(embed=embed) |
| await Database.execute( |
| "UPDATE sayi_sayma SET son_sayi = 0, son_atan = 0 WHERE guild_id = ?", |
| (message.guild.id,) |
| ) |
| return |
|
|
| |
| yeni_rekor = max(rekor, num) |
| if num > rekor: |
| |
| try: |
| await message.add_reaction("🏆") |
| except: |
| pass |
| else: |
| try: |
| await message.add_reaction("✅") |
| except: |
| pass |
|
|
| await Database.execute( |
| "UPDATE sayi_sayma SET son_sayi = ?, son_atan = ?, rekor = ? WHERE guild_id = ?", |
| (num, message.author.id, yeni_rekor, message.guild.id) |
| ) |
|
|
| @commands.hybrid_command(name="sayma-durum", description="Sayı sayma oyununun mevcut durumunu gösterir.") |
| async def sayma_durum(self, ctx: commands.Context): |
| if ctx.interaction: |
| await ctx.defer() |
| cfg = await Database.fetch_one( |
| "SELECT * FROM sayi_sayma WHERE guild_id = ? AND aktif = 1", |
| (ctx.guild.id,) |
| ) |
| if not cfg: |
| await ctx.send("❌ Sayı sayma oyunu aktif değil.", ephemeral=True) |
| return |
|
|
| embed = discord.Embed(title="🔢 Sayı Sayma Durumu", color=CYBER_BLUE, timestamp=discord.utils.utcnow()) |
| embed.add_field(name="Son Sayı", value=f"**{cfg['son_sayi']}**", inline=True) |
| embed.add_field(name="Rekor", value=f"**{cfg['rekor']}**", inline=True) |
| son_atan_member = ctx.guild.get_member(cfg['son_atan']) |
| son_atan_str = son_atan_member.mention if son_atan_member else "—" |
| embed.add_field(name="Son Atan", value=son_atan_str, inline=True) |
| await ctx.send(embed=embed) |
|
|
|
|
| async def setup(bot): |
| await bot.add_cog(Counting(bot)) |
|
|