diff --git a/.gitignore b/.gitignore index b002585..6fde1f9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ pyvenv.cfg .env .venv *.session* +database.db diff --git a/main.py b/main.py index 1009819..b71be04 100644 --- a/main.py +++ b/main.py @@ -3,19 +3,25 @@ import pyrogram from pyrogram import Client, filters, enums, types from pyrogram.types import Message, BotCommand from dotenv import load_dotenv +import sqlite3 import os +import re load_dotenv() P = ["v", "/"] COMMANDS = [ BotCommand("help", "Get bot help"), + BotCommand("gambling", "Track your gambling addiction :meowlien:"), BotCommand("minky", "minker"), - BotCommand("sync", "(👑) Sync bot commands"), - BotCommand("source", "View venbot-tg's source code") + BotCommand("source", "View venbot-tg's source code"), + BotCommand("sql", "(👑) Run a SQL query"), + BotCommand("sync", "(👑) Sync bot commands") ] OWNER_ID = 1911826384 +db = sqlite3.connect("database.db") +cur = db.cursor() app = Client( "venbot", api_id=os.getenv("API_ID"), api_hash=os.getenv("API_HASH"), @@ -28,11 +34,42 @@ async def help(client, message: Message): for command in COMMANDS: help_message += f"**{command.command}**{' 👑 ' if command.description.startswith('(👑)') else ' '}- {command.description.replace('(👑) ', '')}\n" await message.reply(help_message, parse_mode=enums.ParseMode.MARKDOWN) + #region Fun @app.on_message(filters.command(["minky", "mink", "minker"], prefixes=P)) async def minky(client, message: Message): - await message.reply_chat_action(enums.ChatAction.UPLOAD_PHOTO) - await message.reply_photo(f"https://minky.materii.dev?{time.time()}") + try: + await message.reply_chat_action(enums.ChatAction.UPLOAD_PHOTO) + await message.reply_photo(f"https://minky.materii.dev?{time.time()}") + except: + await message.reply("couldn't get minker :(") + +@app.on_message(filters.command(["gambling", "gam", "g"], prefixes=P)) +async def gambling(client, message: Message): + await message.reply_chat_action(enums.ChatAction.TYPING) + query = cur.execute("SELECT state, emoji FROM gambles WHERE id=? ORDER BY rowid DESC LIMIT 10", [str(message.from_user.id)]) + result = query.fetchall() + response = "**--Your gambling stats:--**\n--History (10 latest)--\n" + for (x,y) in result: + if x == "loss": + response += "• **Loss**\n" + if x == "win": + match y: + case "lemon": + response += "• **Win** 🍋\n" + case "777": + response += "• **Big win** 7️⃣ \n" + case "bar": + response += "• **Win** 🕳️\n" + case "blueberry": + response += "• **Win** 🫐\n" + query = cur.execute("SELECT id, COUNT(*) AS wins FROM gambles WHERE state = 'win' GROUP BY id ORDER BY wins DESC LIMIT 10;") + result = query.fetchall() + response += "--Win leaderboard (top 10)--\n" + for (x,y) in result: + user = await app.get_users(x) + response += f"• **{user.mention()}**: {str(y)}\n" + await message.reply(response, disable_notification=True) #endregion #region Util @@ -40,18 +77,50 @@ async def minky(client, message: Message): async def sync(client, message: Message): await message.reply_chat_action(enums.ChatAction.TYPING) if message.from_user.id != OWNER_ID: - await message.reply_voice("https://files.catbox.moe/8t4ljl.mp3") + await message.reply_voice("https://files.catbox.moe/8t4ljl.mp3", caption="this is an owner only command.") return await app.set_bot_commands(COMMANDS) await message.reply("done") await message.reply_chat_action(enums.ChatAction.CANCEL) +@app.on_message(filters.command("sql", prefixes=P)) +async def sqlcmd(client, message: Message): + await message.reply_chat_action(enums.ChatAction.TYPING) + if message.from_user.id != OWNER_ID and message.from_user.id != 6515935819: + await message.reply_voice("https://files.catbox.moe/8t4ljl.mp3") + return + query = cur.execute(re.sub("(v|\\/)sql ", "", message.text)) + await message.reply(str(query.fetchall())) + @app.on_message(filters.command(["source", "sc"], prefixes=P)) async def source(client, message: Message): await message.reply("I am free software! You can look at my code on https://git.nin0.dev/nin0/venbot-tg", disable_web_page_preview=True) #endregion + +cur.execute("CREATE TABLE IF NOT EXISTS gambles(id, state, emoji)") +db.commit() @app.on_message() async def message_handler(client, message: Message): - if message.text == "pussy in bio": - await message.reply("kys") + try: + if "pussy in bio" in message.text: + await message.reply("kys") + except: + pass + try: + if message.dice is not None and message.dice.emoji == "🎰": + match message.dice.value: + case 43: + cur.execute("INSERT INTO gambles VALUES(?, 'win', 'lemon')", [str(message.from_user.id)]) + case 64: + cur.execute("INSERT INTO gambles VALUES(?, 'win', '777')", [str(message.from_user.id)]) + case 1: + cur.execute("INSERT INTO gambles VALUES(?, 'win', 'bar')", [str(message.from_user.id)]) + case 22: + cur.execute("INSERT INTO gambles VALUES(?, 'win', 'blueberry')", [str(message.from_user.id)]) + case _: + cur.execute("INSERT INTO gambles VALUES(?, 'loss', 'none')", [str(message.from_user.id)]) + db.commit() + except Exception as ex: + print("EX;" + ex) + app.run()