import discord from discord.ext import commands import sqlite3 import locale bot = commands.Bot(command_prefix="!", intents=discord.Intents.all()) conn = sqlite3.connect("discord.db") c = conn.cursor() c.execute("""CREATE TABLE IF NOT EXISTS users ( discord_name TEXT, character_name TEXT, server_name TEXT, balance INTEGER )""") conn.commit() def is_registered(discord_name): c.execute("SELECT * FROM users WHERE discord_name = ?", (discord_name,)) return c.fetchone() is not None def is_admin(ctx): return ctx.message.author.guild_permissions.administrator @bot.command() async def register(ctx, arg): character_name, server_name = arg.split("-") discord_name = ctx.author.name if is_registered(discord_name): await ctx.send(f"{discord_name}, zaten kayıtlısın.") else: c.execute("INSERT INTO users VALUES (?, ?, ?, ?)", (discord_name, character_name, server_name, 0)) conn.commit() await ctx.send(f"{discord_name}, başarıyla kayıt oldun. Karakter adın: {character_name}, sunucu adın: {server_name}, bakiyen: 0.") @bot.command() async def update(ctx, arg): character_name, server_name = arg.split("-") discord_name = ctx.author.name if is_registered(discord_name): c.execute("UPDATE users SET character_name = ?, server_name = ? WHERE discord_name = ?", (character_name, server_name, discord_name)) conn.commit() await ctx.send(f"{discord_name}, verilerin başarıyla güncellendi. Yeni karakter adın: {character_name}, yeni sunucu adın: {server_name}.") else: await ctx.send(f"{discord_name}, henüz kayıtlı değilsin. Lütfen !register - komutunu kullanarak kayıt ol.") def parse_amount(amount): amount = amount.lower() if amount.endswith("k"): amount = float(amount[:-1]) * 1000 elif amount.endswith("m"): amount = float(amount[:-1]) * 1000000 else: amount = float(amount) return amount def format_amount(amount): if amount >= 1000000: return f"{amount/1000000:.1f}m" elif amount >= 1000: return f"{amount/1000:.1f}k" else: return str(amount) @bot.command() @commands.check(is_admin) async def rlpay(ctx, arg, amount): amount = parse_amount(amount) character_name, server_name = arg.split("-") if "-" in arg else (arg, "") voice_channel = discord.utils.get(ctx.guild.voice_channels, name=arg) if voice_channel: members = voice_channel.members for member in members: discord_name = member.name if is_registered(discord_name): formatted_amount = format_amount(amount) c.execute("UPDATE users SET balance = balance + ? WHERE discord_name = ?", (amount, discord_name)) conn.commit() message = f"{character_name}-{server_name} + {formatted_amount}" await ctx.send(message) else: await ctx.send(f"{discord_name}, henüz kayıtlı değilsin. Lütfen !register - komutunu kullanarak kayıt ol.") else: await ctx.send(f"{arg}, böyle bir sesli kanal yok.") @bot.command() @commands.check(is_admin) async def show(ctx): c.execute("SELECT * FROM users") rows = c.fetchall() if rows: message = "```| character_name | server_name | balance\n" for row in rows: formatted_balance = f"{row[3]:,.0f}".replace(",", ".") message += f"| {row[1]} | {row[2]} | {formatted_balance}\n" message += "```" await ctx.send(message) else: await ctx.send("Veritabanında hiç kullanıcı yok.") @bot.command() @commands.check(is_admin) async def payall(ctx): c.execute("UPDATE users SET balance = 0") conn.commit() await ctx.send("Tüm bakiyeler ödendi.") @bot.command() @commands.check(is_admin) async def pay(ctx, arg, amount): character_name, server_name = arg.split("-") amount = parse_amount(amount) discord_name = ctx.author.name if is_registered(discord_name): formatted_amount = format_amount(amount) c.execute("UPDATE users SET balance = balance - ? WHERE discord_name = ? AND character_name = ? AND server_name = ?", (amount, discord_name, character_name, server_name)) conn.commit() await ctx.send(f"{formatted_amount} bakiye ödedin. Karakter adı: {character_name}, sunucu adı: {server_name}.") else: await ctx.send("böyle bir kullanıcı yok.") @bot.command() async def balance(ctx): discord_name = ctx.author.name if is_registered(discord_name): c.execute("SELECT balance FROM users WHERE discord_name = ?", (discord_name,)) balance = c.fetchone()[0] # Binlik gruplara ayırma için locale ayarlarını güncelle locale.setlocale(locale.LC_ALL, '') # Kullanıcının yerel ayarını kullan formatted_balance = f"{balance:,.0f}".replace(",", ".") await ctx.author.send(f"{discord_name}, balance: {formatted_balance}") await ctx.send(f"{ctx.author.mention} Sending a DM.") else: await ctx.author.send(f"{discord_name}, henüz kayıtlı değilsin. Lütfen !register - komutunu kullanarak kayıt ol.") @bot.command() @commands.has_permissions(administrator=True) async def delete(ctx, arg): character_name, server_name = arg.split("-") c.execute("SELECT * FROM users WHERE character_name = ? AND server_name = ?", (character_name, server_name)) result = c.fetchone() if result is None: await ctx.send(f"Verilen karakter adı ve sunucu adıyla kayıt bulunamadı.") else: discord_name = result[0] c.execute("DELETE FROM users WHERE character_name = ? AND server_name = ?", (character_name, server_name)) conn.commit() await ctx.send(f"{discord_name}, başarıyla kayıt silindi. Karakter adı: {character_name}, sunucu adı: {server_name}.") #bot.run('MTEyNjk0OTI0NDg3MjQyOTU2OA.GEMpEr.swROjAvOmO8AryP3lCMHMlr2qzZlhEFTjhH1CA') bot.run('MTA3MzM5ODA3MzY2NzA5NjYyNg.Gy7yvH.0DRMtnpFF-VXpyYkVT61UxwhVq5ZmeN2pWG_uo')