Spaces:
No application file
No application file
Download wolf.py from Qiajwjjqqwkq/Py: direct link, hf CLI and curl.
- Browser
- Download file 50.5 kB
-
https://huggingface.co/spaces/Qiajwjjqqwkq/Py/resolve/main/wolf.py
- Command line
-
hf download hf://spaces/Qiajwjjqqwkq/Py/wolf.py
-
curl -L -o wolf.py https://huggingface.co/spaces/Qiajwjjqqwkq/Py/resolve/main/wolf.py
50.5 kB
| import logging | |
| import sqlite3 | |
| from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup | |
| from telegram.ext import ( | |
| Application, | |
| CommandHandler, | |
| MessageHandler, | |
| CallbackQueryHandler, | |
| ContextTypes, | |
| filters, | |
| ConversationHandler, | |
| ) | |
| # --- تنظیمات پایه اختصاصی شما --- | |
| TOKEN = "8905666777:AAHWwfAS1b3AA4vAqJ4yyniSH2YDT6x5DJc" | |
| SUPER_ADMIN_ID = 6108337537 | |
| SECOND_ADMIN_ID = 8340592079 | |
| CARD_NUMBER = "5022291546267327" | |
| CARD_NAME = "هداوند" | |
| REQUIRED_CHANNEL = "@Wolfsho" | |
| PANEL_URL = "https://heroic-liger-811624.netlify.app/" | |
| # مراحل گفتوگو (Conversation States) | |
| ( | |
| START_STAGE, | |
| BUY_VOLUME_CUSTOM, | |
| GET_RECEIPT, | |
| SUPPORT_MSG, | |
| ADMIN_REPLY, | |
| ADD_CONFIG, | |
| CREATE_BTN_NAME, | |
| CREATE_BTN_TEXT, | |
| CHARGE_WALLET_AMOUNT, | |
| GET_WALLET_RECEIPT, | |
| BC_MSG, | |
| ADD_ADMIN_ID, | |
| MANAGE_ADD_BALANCE_ID, | |
| MANAGE_ADD_BALANCE_AMOUNT, | |
| MANAGE_SUB_BALANCE_ID, | |
| MANAGE_SUB_BALANCE_AMOUNT, | |
| BAN_USER_ID, | |
| UNBAN_USER_ID, | |
| USER_INFO_ID, | |
| CLEAR_BALANCE_ID | |
| ) = range(20) | |
| logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO) | |
| # --- پایگاه داده پیشرفته --- | |
| def init_db(): | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute('''CREATE TABLE IF NOT EXISTS users | |
| (user_id INTEGER PRIMARY KEY, username TEXT, balance INTEGER DEFAULT 0, accepted_rules INTEGER DEFAULT 0)''') | |
| cursor.execute('''CREATE TABLE IF NOT EXISTS repo | |
| (id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, config TEXT, is_used INTEGER DEFAULT 0)''') | |
| cursor.execute('''CREATE TABLE IF NOT EXISTS tx | |
| (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER, type TEXT, details TEXT, amount INTEGER DEFAULT 0, status TEXT)''') | |
| cursor.execute('''CREATE TABLE IF NOT EXISTS custom_buttons | |
| (id INTEGER PRIMARY KEY AUTOINCREMENT, btn_name TEXT, btn_text TEXT)''') | |
| cursor.execute('''CREATE TABLE IF NOT EXISTS admins (user_id INTEGER PRIMARY KEY)''') | |
| cursor.execute('''CREATE TABLE IF NOT EXISTS banned_users (user_id INTEGER PRIMARY KEY)''') | |
| cursor.execute('''CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT)''') | |
| cursor.execute("INSERT OR IGNORE INTO admins (user_id) VALUES (?)", (SUPER_ADMIN_ID,)) | |
| cursor.execute("INSERT OR IGNORE INTO admins (user_id) VALUES (?)", (SECOND_ADMIN_ID,)) | |
| cursor.execute("INSERT OR IGNORE INTO settings (key, value) VALUES ('maintenance', '0')") | |
| conn.commit() | |
| conn.close() | |
| init_db() | |
| def is_admin(user_id: int) -> bool: | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT 1 FROM admins WHERE user_id = ?", (user_id,)) | |
| res = cursor.fetchone() | |
| conn.close() | |
| return True if res or user_id in [SUPER_ADMIN_ID, SECOND_ADMIN_ID] else False | |
| def is_banned(user_id: int) -> bool: | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT 1 FROM banned_users WHERE user_id = ?", (user_id,)) | |
| res = cursor.fetchone() | |
| conn.close() | |
| return True if res else False | |
| def is_maintenance() -> bool: | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT value FROM settings WHERE key = 'maintenance'") | |
| res = cursor.fetchone() | |
| conn.close() | |
| return True if res and res[0] == '1' else False | |
| async def send_to_all_admins(context: ContextTypes.DEFAULT_TYPE, text: str, reply_markup=None, photo=None): | |
| admins = [SUPER_ADMIN_ID, SECOND_ADMIN_ID] | |
| for adm in admins: | |
| try: | |
| if photo: | |
| await context.bot.send_photo(chat_id=adm, photo=photo, caption=text, reply_markup=reply_markup, parse_mode="Markdown") | |
| else: | |
| await context.bot.send_message(chat_id=adm, text=text, reply_markup=reply_markup, parse_mode="Markdown") | |
| except: | |
| pass | |
| async def is_joined(user_id: int, context: ContextTypes.DEFAULT_TYPE) -> bool: | |
| if is_admin(user_id): | |
| return True | |
| try: | |
| member = await context.bot.get_chat_member(chat_id=REQUIRED_CHANNEL, user_id=user_id) | |
| return member.status in ['member', 'administrator', 'creator'] | |
| except: | |
| return False | |
| def get_main_menu_keyboard(user_id: int): | |
| keyboard = [ | |
| [ | |
| InlineKeyboardButton("⚡ خرید سرویس حجمی", callback_data="menu_volume_packages"), | |
| InlineKeyboardButton("♾ خرید سرویس نامحدود", callback_data="menu_unlimited_packages") | |
| ], | |
| [ | |
| InlineKeyboardButton("🎁 تست رایگان", callback_data="menu_test"), | |
| InlineKeyboardButton("👨💻 پشتیبانی آنلاین", callback_data="menu_support") | |
| ], | |
| [ | |
| InlineKeyboardButton("💰 شارژ کیف پول", callback_data="menu_charge_wallet"), | |
| InlineKeyboardButton("👤 پروفایل کاربری", callback_data="menu_profile") | |
| ], | |
| [ | |
| InlineKeyboardButton("📚 راهنمای اتصال", callback_data="menu_guide") | |
| ] | |
| ] | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT id, btn_name FROM custom_buttons") | |
| custom_btns = cursor.fetchall() | |
| conn.close() | |
| for btn in custom_btns: | |
| keyboard.append([InlineKeyboardButton(f"✨ {btn[1]}", callback_data=f"custom_btn_{btn[0]}")]) | |
| if is_admin(user_id): | |
| keyboard.append([InlineKeyboardButton("⚙️ ورود به پنل مدیریت", callback_data="admin_panel")]) | |
| return InlineKeyboardMarkup(keyboard) | |
| async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| user_id = update.effective_user.id | |
| username = update.effective_user.username or "نامشخص" | |
| if is_banned(user_id): | |
| await update.message.reply_text("❌ حساب کاربری شما به دلیل تخلف از قوانین ربات مسدود شده است.") | |
| return ConversationHandler.END | |
| if is_maintenance() and not is_admin(user_id): | |
| await update.message.reply_text("🛠 ربات در حال حاضر جهت بروزرسانی و تعمیرات موقتاً غیرفعال است. لطفا بعداً تلاش کنید.") | |
| return ConversationHandler.END | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("INSERT OR IGNORE INTO users (user_id, username) VALUES (?, ?)", (user_id, username)) | |
| cursor.execute("SELECT accepted_rules FROM users WHERE user_id = ?", (user_id,)) | |
| accepted = cursor.fetchone()[0] | |
| conn.commit() | |
| conn.close() | |
| if not await is_joined(user_id, context): | |
| kb = [ | |
| [InlineKeyboardButton("📢 عضویت در کانال", url=f"https://t.me/{REQUIRED_CHANNEL[1:]}")], | |
| [InlineKeyboardButton("✅ بررسی عضویت", callback_data="sub_check")] | |
| ] | |
| await update.message.reply_text("🤖 **جهت استفاده از خدمات ربات، لطفا ابتدا در کانال ما عضو شوید:**", reply_markup=InlineKeyboardMarkup(kb), parse_mode="Markdown") | |
| return START_STAGE | |
| if accepted == 0 and not is_admin(user_id): | |
| rules = ( | |
| "👋 **به ربات فروش کانفیگ VPN خوش آمدید**\n\n" | |
| "📜 **قوانین و شرایط استفاده:**\n" | |
| "1️⃣ سرویس های حجم نامحدود ما هیچ محدودیت مصرفی ندارند.\n" | |
| "2️⃣ سرویسهای حجم دلخواه تا زمانی که حجم خریداریشده کاملاً مصرف نشود، فعال میمانند.\n" | |
| "3️⃣ لطفا از ارسال هرگونه رسید پرداخت جعلی خودداری کنید.\n\n" | |
| "👇 با کلیک روی دکمه زیر، شما قوانین را میپذیرید و وارد دنیای سرعت بالا میشوید:" | |
| ) | |
| kb = [[InlineKeyboardButton("🤝 قبول قوانین و ورود", callback_data="rules_accept")]] | |
| await update.message.reply_text(rules, reply_markup=InlineKeyboardMarkup(kb), parse_mode="Markdown") | |
| return START_STAGE | |
| await update.message.reply_text("📱 **منوی اصلی ربات:**", reply_markup=get_main_menu_keyboard(user_id), parse_mode="Markdown") | |
| return START_STAGE | |
| async def handle_callbacks(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| query = update.callback_query | |
| user_id = query.from_user.id | |
| data = query.data | |
| await query.answer() | |
| if is_banned(user_id): | |
| await query.edit_message_text("❌ حساب کاربری شما مسدود است.") | |
| return START_STAGE | |
| if is_maintenance() and not is_admin(user_id) and data != "sub_check": | |
| await query.edit_message_text("🛠 ربات در وضعیت تعمیرات قرار دارد.") | |
| return START_STAGE | |
| if data == "sub_check": | |
| if await is_joined(user_id, context): | |
| await query.message.delete() | |
| update.message = query.message | |
| return await start(update, context) | |
| else: | |
| await query.edit_message_text("❌ شما هنوز عضو کانال نشدهاید! لطفا ابتدا عضو شوید و سپس دوباره تلاش کنید.") | |
| return START_STAGE | |
| elif data == "rules_accept": | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("UPDATE users SET accepted_rules = 1 WHERE user_id = ?", (user_id,)) | |
| conn.commit() | |
| conn.close() | |
| await query.message.edit_text("🎉 **خوش آمدید!** لطفا سرویس مورد نظر خود را انتخاب کنید:", reply_markup=get_main_menu_keyboard(user_id), parse_mode="Markdown") | |
| return START_STAGE | |
| elif data == "menu_charge_wallet": | |
| await query.message.edit_text("💵 لطفا مبلغی که میخواهید شارژ کنید را به **تومان** وارد کنید (مثال: 50000):") | |
| return CHARGE_WALLET_AMOUNT | |
| elif data == "menu_volume_packages": | |
| kb = [ | |
| [InlineKeyboardButton("📦 10GB - 30,000 T", callback_data="buy_p_10gb")], | |
| [InlineKeyboardButton("📦 20GB - 60,000 T", callback_data="buy_p_20gb")], | |
| [InlineKeyboardButton("📦 30GB - 75,000 T", callback_data="buy_p_30gb")], | |
| [InlineKeyboardButton("📦 40GB - 80,000 T", callback_data="buy_p_40gb")], | |
| [InlineKeyboardButton("📦 50GB - 100,000 T", callback_data="buy_p_50gb")], | |
| [InlineKeyboardButton("📦 100GB - 160,000 T", callback_data="buy_p_100gb")], | |
| [InlineKeyboardButton("✏️ حجم دلخواه (هر گیگ 3,000 T)", callback_data="buy_p_custom")], | |
| [InlineKeyboardButton("🔙 بازگشت به منو", callback_data="back_to_menu")] | |
| ] | |
| await query.message.edit_text("⚡ **لیست بستههای حجمی با بالاترین سرعت:**\n\n💡 حداقل خرید برای حجم دلخواه 10 گیگابایت میباشد.", reply_markup=InlineKeyboardMarkup(kb), parse_mode="Markdown") | |
| return START_STAGE | |
| elif data == "menu_unlimited_packages": | |
| kb = [ | |
| [InlineKeyboardButton("♾ نامحدود 1 ماه - 80,000 T", callback_data="buy_p_unlim_1m")], | |
| [InlineKeyboardButton("♾ نامحدود 2 ماه - 150,000 T", callback_data="buy_p_unlim_2m")], | |
| [InlineKeyboardButton("♾ نامحدود 6 ماه - 350,000 T", callback_data="buy_p_unlim_6m")], | |
| [InlineKeyboardButton("🔙 بازگشت به منو", callback_data="back_to_menu")] | |
| ] | |
| await query.message.edit_text("♾ **بستههای حجم نامحدود واقعی (بدون محدودیت مصرف):**", reply_markup=InlineKeyboardMarkup(kb), parse_mode="Markdown") | |
| return START_STAGE | |
| elif data.startswith("buy_p_"): | |
| pkg_type = data.replace("buy_p_", "") | |
| if pkg_type == "custom": | |
| await query.message.edit_text("✏️ لطفا حجم مورد نظر خود را به **گیگابایت** وارد کنید (فقط عدد و حداقل 10 گیگ، مانند 15):") | |
| return BUY_VOLUME_CUSTOM | |
| packages_info = { | |
| "10gb": (30000, "10gb", "بسته 10 گیگابایت"), | |
| "20gb": (60000, "20gb", "بسته 20 گیگابایت"), | |
| "30gb": (75000, "30gb", "بسته 30 گیگابایت"), | |
| "40gb": (80000, "40gb", "بسته 40 گیگابایت"), | |
| "50gb": (100000, "50gb", "بسته 50 گیگابایت"), | |
| "100gb": (160000, "100gb", "بسته 100 گیگابایت"), | |
| "unlim_1m": (80000, "unlim_1m", "نامحدود 1 ماهه"), | |
| "unlim_2m": (150000, "unlim_2m", "نامحدود 2 ماهه"), | |
| "unlim_6m": (350000, "unlim_6m", "نامحدود 6 ماهه"), | |
| } | |
| price, repo_type, title = packages_info[pkg_type] | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT balance FROM users WHERE user_id = ?", (user_id,)) | |
| balance = cursor.fetchone()[0] | |
| if balance >= price: | |
| cursor.execute("SELECT id, config FROM repo WHERE type = ? AND is_used = 0 LIMIT 1", (repo_type,)) | |
| row = cursor.fetchone() | |
| if row: | |
| cursor.execute("UPDATE repo SET is_used = 1 WHERE id = ?", (row[0],)) | |
| cursor.execute("UPDATE users SET balance = balance - ? WHERE user_id = ?", (price, user_id)) | |
| cursor.execute("INSERT INTO tx (user_id, type, details, amount, status) VALUES (?, ?, ?, ?, 'approved')", (user_id, repo_type, f"خرید {title}", price)) | |
| conn.commit() | |
| panel_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("🌐 ورود به پنل کاربری", url=PANEL_URL)]]) | |
| await query.message.edit_text(f"✅ **خرید با موفقیت انجام شد! مبلغ {price:,} تومان از کیف پول شما کسر گردید.**\n\n🚀 کانفیگ اختصاصی شما:\n\n`{row[1]}`", reply_markup=panel_keyboard, parse_mode="Markdown") | |
| else: | |
| await query.message.edit_text(f"❌ متاسفانه در حال حاضر مخزن سرویس `{title}` خالی است. لطفا به پشتیبانی اطلاع دهید.", reply_markup=get_main_menu_keyboard(user_id)) | |
| else: | |
| await query.message.edit_text(f"❌ **موجودی کیف پول شما کافی نیست!**\n💰 موجودی شما: {balance:,} تومان\n💳 قیمت سرویس: {price:,} تومان\n\n💡 لطفا ابتدا حساب خود را شارژ کنید.", reply_markup=get_main_menu_keyboard(user_id)) | |
| conn.close() | |
| return START_STAGE | |
| elif data == "menu_test": | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT * FROM tx WHERE user_id = ? AND type = 'test'", (user_id,)) | |
| if cursor.fetchone(): | |
| await query.message.edit_text("❌ شما قبلاً سرویس تست رایگان خود را دریافت کردهاید!", reply_markup=get_main_menu_keyboard(user_id)) | |
| else: | |
| cursor.execute("SELECT id, config FROM repo WHERE type = 'test' AND is_used = 0 LIMIT 1") | |
| row = cursor.fetchone() | |
| if row: | |
| cursor.execute("UPDATE repo SET is_used = 1 WHERE id = ?", (row[0],)) | |
| cursor.execute("INSERT INTO tx (user_id, type, details, status) VALUES (?, 'test', 'اکانت تست هدیه', 'approved')", (user_id, )) | |
| conn.commit() | |
| await query.message.edit_text(f"🚀 **سرویس تست با موفقیت برای شما ساخته شد:**\n\n`{row[1]}`", reply_markup=get_main_menu_keyboard(user_id), parse_mode="Markdown") | |
| else: | |
| await query.message.edit_text("❌ مخزن اکانتهای تست در حال حاضر خالی است.", reply_markup=get_main_menu_keyboard(user_id)) | |
| conn.close() | |
| return START_STAGE | |
| elif data == "menu_guide": | |
| guide = "📚 **راهنمای اتصال:**\n\n🤖 **اندروید:** برنامه v2rayNG را نصب کنید.\n\n🍏 **آیآواس (iOS):** از برنامههای V2Box یا FoXray استفاده کنید." | |
| await query.message.edit_text(guide, reply_markup=get_main_menu_keyboard(user_id), parse_mode="Markdown") | |
| return START_STAGE | |
| elif data == "menu_profile": | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT balance FROM users WHERE user_id = ?", (user_id,)) | |
| bal = cursor.fetchone()[0] | |
| conn.close() | |
| await query.message.edit_text(f"👤 **پروفایل حساب کاربری شما:**\n\n🆔 شناسه کاربری: `{user_id}`\n💰 موجودی کیف پول: {bal:,} تومان", reply_markup=get_main_menu_keyboard(user_id), parse_mode="Markdown") | |
| return START_STAGE | |
| elif data == "menu_support": | |
| await query.message.edit_text("✍️ پیام خود را اینجا بنویسید تا مدیریت بتواند مستقیماً به شما پاسخ دهد:") | |
| return SUPPORT_MSG | |
| elif data.startswith("custom_btn_"): | |
| btn_id = data.split('_')[2] | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT btn_text FROM custom_buttons WHERE id = ?", (btn_id,)) | |
| row = cursor.fetchone() | |
| conn.close() | |
| if row: | |
| await query.message.edit_text(row[0], reply_markup=get_main_menu_keyboard(user_id)) | |
| return START_STAGE | |
| elif data == "back_to_menu": | |
| await query.message.edit_text("📱 منوی اصلی:", reply_markup=get_main_menu_keyboard(user_id)) | |
| return START_STAGE | |
| elif data == "admin_panel" and is_admin(user_id): | |
| adm_kb = [ | |
| [InlineKeyboardButton("📥 افزودن کانفیگ", callback_data="adm_add_config"), InlineKeyboardButton("➕ ساخت دکمه", callback_data="adm_create_btn")], | |
| [InlineKeyboardButton("🗑 حذف دکمهها", callback_data="adm_delete_btn_list"), InlineKeyboardButton("📊 آمار سیستم", callback_data="adm_stats")], | |
| [InlineKeyboardButton("📢 پیام همگانی", callback_data="adm_bc"), InlineKeyboardButton("👮♂️ افزودن ادمین", callback_data="adm_add_new_admin")], | |
| [InlineKeyboardButton("➕ افزایش موجودی دستی", callback_data="adm_add_balance"), InlineKeyboardButton("➖ کسر موجودی دستی", callback_data="adm_sub_balance")], | |
| [InlineKeyboardButton("🚫 بن کردن کاربر", callback_data="adm_ban_user"), InlineKeyboardButton("🔓 رفع بن کاربر", callback_data="adm_unban_user")], | |
| [InlineKeyboardButton("👤 آمار کاربر", callback_data="adm_user_info"), InlineKeyboardButton("📉 صفر کردن موجودی", callback_data="adm_clear_balance")], | |
| [InlineKeyboardButton("🧹 پاکسازی مخزن قدیمی", callback_data="adm_clear_repo"), InlineKeyboardButton("📋 ۵ تراکنش اخیر", callback_data="adm_recent_tx")], | |
| [InlineKeyboardButton("⚙️ وضعیت فعالیت ربات", callback_data="adm_manage_maintenance")], | |
| [InlineKeyboardButton("🚪 خروج", callback_data="back_to_menu")] | |
| ] | |
| await query.message.edit_text("🛠 **به پنل کنترل جامع مدیریت خوش آمدید:**", reply_markup=InlineKeyboardMarkup(adm_kb), parse_mode="Markdown") | |
| return START_STAGE | |
| elif data == "adm_add_config" and is_admin(user_id): | |
| kb = [ | |
| [InlineKeyboardButton("تست", callback_data="type_add_test"), InlineKeyboardButton("حجم دلخواه", callback_data="type_add_custom")], | |
| [InlineKeyboardButton("10GB", callback_data="type_add_10gb"), InlineKeyboardButton("20GB", callback_data="type_add_20gb"), InlineKeyboardButton("30GB", callback_data="type_add_30gb")], | |
| [InlineKeyboardButton("40GB", callback_data="type_add_40gb"), InlineKeyboardButton("50GB", callback_data="type_add_50gb"), InlineKeyboardButton("100GB", callback_data="type_add_100gb")], | |
| [InlineKeyboardButton("نامحدود 1 ماه", callback_data="type_add_unlim_1m"), InlineKeyboardButton("نامحدود 2 ماه", callback_data="type_add_unlim_2m"), InlineKeyboardButton("نامحدود 6 ماه", callback_data="type_add_unlim_6m")], | |
| [InlineKeyboardButton("🔙 بازگشت", callback_data="admin_panel")] | |
| ] | |
| await query.message.edit_text("مخزن هدف را جهت آپلود کانفیگ انتخاب کنید:", reply_markup=InlineKeyboardMarkup(kb)) | |
| return START_STAGE | |
| elif data.startswith("type_add_") and is_admin(user_id): | |
| context.user_data['adm_cfg_type'] = data.replace("type_add_", "") | |
| await query.message.edit_text("📥 کانفیگها را ارسال کنید (هر خط یک کانفیگ):") | |
| return ADD_CONFIG | |
| elif data == "adm_create_btn" and is_admin(user_id): | |
| await query.message.edit_text("✏️ نام دکمه جدید را ارسال کنید:") | |
| return CREATE_BTN_NAME | |
| elif data == "adm_delete_btn_list" and is_admin(user_id): | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT id, btn_name FROM custom_buttons") | |
| btns = cursor.fetchall() | |
| conn.close() | |
| if not btns: | |
| await query.message.edit_text("❌ دکمهای برای حذف وجود ندارد.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("بازگشت", callback_data="admin_panel")]])) | |
| return START_STAGE | |
| kb = [[InlineKeyboardButton(f"❌ حذف {b[1]}", callback_data=f"del_btn_{b[0]}")] for b in btns] | |
| kb.append([InlineKeyboardButton("بازگشت", callback_data="admin_panel")]) | |
| await query.message.edit_text("روی دکمهای که میخواهید حذف شود کلیک کنید:", reply_markup=InlineKeyboardMarkup(kb)) | |
| return START_STAGE | |
| elif data.startswith("del_btn_") and is_admin(user_id): | |
| b_id = data.split('_')[2] | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("DELETE FROM custom_buttons WHERE id = ?", (b_id,)) | |
| conn.commit() | |
| conn.close() | |
| await query.message.edit_text("✅ دکمه انتخاب شده با موفقیت حذف شد.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("بازگشت", callback_data="admin_panel")]])) | |
| return START_STAGE | |
| elif data == "adm_bc" and is_admin(user_id): | |
| await query.message.edit_text("✍️ متن پیام همگانی خود را بفرستید:") | |
| return BC_MSG | |
| elif data == "adm_add_new_admin" and is_admin(user_id): | |
| await query.message.edit_text("🔢 آیدی عددی کاربر جدید را ارسال کنید:") | |
| return ADD_ADMIN_ID | |
| elif data == "adm_add_balance" and is_admin(user_id): | |
| await query.message.edit_text("🔢 جهت افزایش موجودی، آیدی عددی کاربر را بفرستید:") | |
| return MANAGE_ADD_BALANCE_ID | |
| elif data == "adm_sub_balance" and is_admin(user_id): | |
| await query.message.edit_text("🔢 جهت کسر موجودی، آیدی عددی کاربر را بفرستید:") | |
| return MANAGE_SUB_BALANCE_ID | |
| elif data == "adm_ban_user" and is_admin(user_id): | |
| await query.message.edit_text("🚫 آیدی عددی کاربر مورد نظر را جهت بن کردن ارسال کنید:") | |
| return BAN_USER_ID | |
| elif data == "adm_unban_user" and is_admin(user_id): | |
| await query.message.edit_text("🔓 آیدی عددی کاربر مورد نظر را جهت رفع بن ارسال کنید:") | |
| return UNBAN_USER_ID | |
| elif data == "adm_user_info" and is_admin(user_id): | |
| await query.message.edit_text("👤 آیدی عددی کاربر را برای مشاهده اطلاعات بفرستید:") | |
| return USER_INFO_ID | |
| elif data == "adm_clear_balance" and is_admin(user_id): | |
| await query.message.edit_text("📉 آیدی عددی کاربر را جهت صفر کردن موجودی بفرستید:") | |
| return CLEAR_BALANCE_ID | |
| elif data == "adm_clear_repo" and is_admin(user_id): | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("DELETE FROM repo WHERE is_used = 1") | |
| deleted = cursor.rowcount | |
| conn.commit() | |
| conn.close() | |
| await query.message.edit_text(f"🧹 تعداد {deleted} کانفیگ فروخته شده و قدیمی از دیتابیس با موفقیت پاکسازی شد.", reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("بازگشت", callback_data="admin_panel")]])) | |
| return START_STAGE | |
| elif data == "adm_recent_tx" and is_admin(user_id): | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT user_id, details, amount, status FROM tx ORDER BY id DESC LIMIT 5") | |
| rows = cursor.fetchall() | |
| conn.close() | |
| txt = "📋 **لیست ۵ تراکنش اخیر سیستم:**\n\n" | |
| if not rows: | |
| txt += "تراکنشی یافت نشد." | |
| for r in rows: | |
| txt += f"👤 کاربر: `{r[0]}`\n📝 بابت: {r[1]}\n💵 مبلغ: {r[2]:,} ت\nوضعیت: {r[3]}\n📊 -----------\n" | |
| await query.message.edit_text(txt, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("بازگشت", callback_data="admin_panel")]]), parse_mode="Markdown") | |
| return START_STAGE | |
| elif data == "adm_manage_maintenance" and is_admin(user_id): | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT value FROM settings WHERE key = 'maintenance'") | |
| current = cursor.fetchone()[0] | |
| conn.close() | |
| if current == "0": | |
| status_text = "🟢 **ربات در حال حاضر روشن است** و کاربران به آن دسترسی دارند." | |
| action_btn = InlineKeyboardButton("🔴 خاموش کردن ربات (حالت تعمیرات)", callback_data="adm_set_maintenance_1") | |
| else: | |
| status_text = "🔴 **ربات در حال حاضر خاموش است** (کاربران پیام تعمیرات دریافت میکنند)." | |
| action_btn = InlineKeyboardButton("🟢 روشن کردن ربات", callback_data="adm_set_maintenance_0") | |
| kb = [ | |
| [action_btn], | |
| [InlineKeyboardButton("🔙 بازگشت به پنل ادمین", callback_data="admin_panel")] | |
| ] | |
| await query.message.edit_text(status_text, reply_markup=InlineKeyboardMarkup(kb), parse_mode="Markdown") | |
| return START_STAGE | |
| elif data.startswith("adm_set_maintenance_") and is_admin(user_id): | |
| new_val = data.split('_')[3] | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("UPDATE settings SET value = ? WHERE key = 'maintenance'", (new_val,)) | |
| conn.commit() | |
| conn.close() | |
| alert_txt = "🔴 ربات با موفقیت خاموش شد و در وضعیت تعمیرات قرار گرفت." if new_val == "1" else "🟢 ربات با موفقیت روشن شد و برای کاربران در دسترس قرار گرفت." | |
| kb = [[InlineKeyboardButton("🔙 بازگشت", callback_data="admin_panel")]] | |
| await query.message.edit_text(alert_txt, reply_markup=InlineKeyboardMarkup(kb)) | |
| return START_STAGE | |
| elif data == "adm_stats" and is_admin(user_id): | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT COUNT(*) FROM users") | |
| u_count = cursor.fetchone()[0] | |
| cursor.execute("SELECT type, COUNT(*) FROM repo WHERE is_used = 0 GROUP BY type") | |
| repo_info = cursor.fetchall() | |
| conn.close() | |
| info = f"📊 **آمار سیستم:**\n👥 کل کاربران: {u_count}\n\n" | |
| for r in repo_info: info += f"📦 مخزن {r[0]}: {r[1]} عدد موجود\n" | |
| await query.message.edit_text(info, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("بازگشت", callback_data="admin_panel")]])) | |
| return START_STAGE | |
| elif data.startswith("tx_"): | |
| parts = data.split('_') | |
| action, tx_id, target_id = parts[1], int(parts[2]), int(parts[3]) | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| if action == "approve": | |
| cursor.execute("SELECT amount, type FROM tx WHERE id = ?", (tx_id,)) | |
| tx_row = cursor.fetchone() | |
| if tx_row: | |
| amount = tx_row[0] | |
| t_type = tx_row[1] | |
| if t_type == 'charge': | |
| cursor.execute("UPDATE users SET balance = balance + ? WHERE user_id = ?", (amount, target_id)) | |
| cursor.execute("UPDATE tx SET status = 'approved' WHERE id = ?", (tx_id,)) | |
| conn.commit() | |
| try: await context.bot.send_message(chat_id=target_id, text=f"✅ رسید شما تایید شد!\nمبلغ {amount:,} تومان به کیف پول شما اضافه گردید.") | |
| except: pass | |
| current_caption = query.message.caption or "" | |
| await query.edit_message_caption(caption=current_caption + f"\n\n✅ تایید شد. {amount:,} تومان واریز شد.") | |
| else: | |
| cursor.execute("SELECT id, config FROM repo WHERE type = ? AND is_used = 0 LIMIT 1", (t_type,)) | |
| cfg_row = cursor.fetchone() | |
| if cfg_row: | |
| cursor.execute("UPDATE repo SET is_used = 1 WHERE id = ?", (cfg_row[0],)) | |
| cursor.execute("UPDATE tx SET status = 'approved' WHERE id = ?", (tx_id,)) | |
| conn.commit() | |
| text_to_send = f"✅ رسید شما تایید شد! کانفیگ اختصاصی شما:\n\n`{cfg_row[1]}`" | |
| try: await context.bot.send_message(chat_id=target_id, text=text_to_send, parse_mode="Markdown") | |
| except: pass | |
| current_caption = query.message.caption or "" | |
| await query.edit_message_caption(caption=current_caption + "\n\n✅ تایید شد و سرویس ارسال گردید.") | |
| else: | |
| current_caption = query.message.caption or "" | |
| await query.edit_message_caption(caption=current_caption + f"\n\n❌ دستهبندی مخزن `{t_type}` خالی است!") | |
| elif action == "reject": | |
| cursor.execute("UPDATE tx SET status = 'rejected' WHERE id = ?", (tx_id,)) | |
| conn.commit() | |
| try: await context.bot.send_message(chat_id=target_id, text="❌ رسید پرداخت شما توسط مدیریت رد شد.") | |
| except: pass | |
| current_caption = query.message.caption or "" | |
| await query.edit_message_caption(caption=current_caption + "\n\n❌ رسید رد شد.") | |
| conn.close() | |
| return START_STAGE | |
| async def process_charge_amount(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| text = update.message.text | |
| if not text.isdigit(): | |
| await update.message.reply_text("❌ لطفا فقط عدد وارد کنید (به تومان):") | |
| return CHARGE_WALLET_AMOUNT | |
| amount = int(text) | |
| context.user_data['wallet_amount'] = amount | |
| invoice = f"💳 **فاکتور شارژ کیف پول**\n\n💵 مبلغ درخواستی: {amount:,} تومان\n🔢 شماره کارت جهت واریز:\n`{CARD_NUMBER}`\n👤 صاحب حساب: {CARD_NAME}\n\n📥 لطفا پس از تراکنش، اسکرینشات رسید خود را ارسال کنید:" | |
| await update.message.reply_text(invoice, reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton("❌ انصراف", callback_data="back_to_menu")]]), parse_mode="Markdown") | |
| return GET_WALLET_RECEIPT | |
| async def process_wallet_receipt(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| user_id = update.effective_user.id | |
| if not update.message.photo: | |
| await update.message.reply_text("❌ لطفا فایل را به صورت تصویر (رسید) ارسال کنید:") | |
| return GET_WALLET_RECEIPT | |
| photo_id = update.message.photo[-1].file_id | |
| amount = context.user_data.get('wallet_amount') | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("INSERT INTO tx (user_id, type, details, amount, status) VALUES (?, 'charge', 'درخواست شارژ کیف پول', ?, 'pending')", (user_id, amount)) | |
| tx_id = cursor.lastrowid | |
| conn.commit() | |
| conn.close() | |
| adm_kb = [[InlineKeyboardButton("✅ تایید و شارژ", callback_data=f"tx_approve_{tx_id}_{user_id}"), InlineKeyboardButton("❌ رد کردن رسید", callback_data=f"tx_reject_{tx_id}_{user_id}")]] | |
| await send_to_all_admins(context, f"🔔 **درخواست افزایش اعتبار جدید**\n\nکد تراکنش: {tx_id}\nشناسه کاربر: `{user_id}`\nمبلغ درخواستی: {amount:,} تومان", InlineKeyboardMarkup(adm_kb), photo=photo_id) | |
| await update.message.reply_text("⏳ رسید با موفقیت برای مدیریت ارسال شد. کیف پول شما پس از بررسی و تایید شارژ خواهد شد.", reply_markup=get_main_menu_keyboard(user_id)) | |
| return START_STAGE | |
| async def process_volume_custom(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| text = update.message.text | |
| if not text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفا فقط عدد وارد کنید:") | |
| return BUY_VOLUME_CUSTOM | |
| vol = int(text) | |
| if vol < 10: | |
| await update.message.reply_text("❌ خطا: حداقل حجم خرید برای حجم دلخواه 10 گیگابایت است. مجدداً وارد کنید:") | |
| return BUY_VOLUME_CUSTOM | |
| price = vol * 3000 | |
| user_id = update.effective_user.id | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT balance FROM users WHERE user_id = ?", (user_id,)) | |
| balance = cursor.fetchone()[0] | |
| if balance >= price: | |
| cursor.execute("SELECT id, config FROM repo WHERE type = 'custom' AND is_used = 0 LIMIT 1") | |
| row = cursor.fetchone() | |
| if row: | |
| cursor.execute("UPDATE repo SET is_used = 1 WHERE id = ?", (row[0],)) | |
| cursor.execute("UPDATE users SET balance = balance - ? WHERE user_id = ?", (price, user_id)) | |
| cursor.execute("INSERT INTO tx (user_id, type, details, amount, status) VALUES (?, 'custom', ?, ?, 'approved')", (user_id, f"خرید حجم دلخواه {vol} گیگابایت", price)) | |
| conn.commit() | |
| await update.message.reply_text(f"✅ **خرید با موفقیت انجام شد!** مبلغ {price:,} تومان از کیف پول شما کسر گردید.\n\n🚀 کانفیگ اختصاصی شما:\n\n`{row[1]}`", reply_markup=get_main_menu_keyboard(user_id), parse_mode="Markdown") | |
| else: | |
| await update.message.reply_text("❌ مخزن اکانتهای حجم دلخواه در حال حاضر خالی است.", reply_markup=get_main_menu_keyboard(user_id)) | |
| else: | |
| await update.message.reply_text(f"❌ موجودی کافی نیست!\n💳 قیمت سرویس: {price:,} تومان\n💰 موجودی شما: {balance:,} تومان", reply_markup=get_main_menu_keyboard(user_id)) | |
| conn.close() | |
| return START_STAGE | |
| async def process_bc_msg(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| text = update.message.text | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT user_id FROM users") | |
| users = cursor.fetchall() | |
| conn.close() | |
| count = 0 | |
| for u in users: | |
| try: | |
| await context.bot.send_message(chat_id=u[0], text=f"📢 **اطلاعیه مدیریت:**\n\n{text}", parse_mode="Markdown") | |
| count += 1 | |
| except: pass | |
| await update.message.reply_text(f"✅ پیام همگانی با موفقیت به {count} کاربر ارسال شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| return START_STAGE | |
| async def process_add_admin(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| text = update.message.text | |
| if not text.isdigit(): | |
| await update.message.reply_text("❌ خطا: شناسه عددی معتبر وارد کنید:") | |
| return ADD_ADMIN_ID | |
| adm_id = int(text) | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("INSERT OR IGNORE INTO admins (user_id) VALUES (?)", (adm_id,)) | |
| conn.commit() | |
| conn.close() | |
| await update.message.reply_text(f"👮♂️ کاربر {adm_id} به لیست مدیران اضافه شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| return START_STAGE | |
| async def process_add_balance_id(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| if not update.message.text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفاً فقط آیدی عددی معتبر وارد کنید:") | |
| return MANAGE_ADD_BALANCE_ID | |
| context.user_data['target_bal_id'] = int(update.message.text) | |
| await update.message.reply_text("💵 مبلغی که میخواهید **اضافه** کنید را به تومان وارد کنید:") | |
| return MANAGE_ADD_BALANCE_AMOUNT | |
| async def process_add_balance_amount(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| if not update.message.text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفاً مبلغ را به صورت عددی وارد کنید:") | |
| return MANAGE_ADD_BALANCE_AMOUNT | |
| amount = int(update.message.text) | |
| target = context.user_data.get('target_bal_id') | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("UPDATE users SET balance = balance + ? WHERE user_id = ?", (amount, target)) | |
| conn.commit() | |
| conn.close() | |
| await update.message.reply_text(f"✅ مبلغ {amount:,} تومان با موفقیت به حساب کاربر {target} اضافه شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| try: await context.bot.send_message(chat_id=target, text=f"💰 مبلغ {amount:,} تومان توسط مدیریت به حساب شما افزوده شد.") | |
| except: pass | |
| return START_STAGE | |
| async def process_sub_balance_id(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| if not update.message.text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفاً فقط آیدی عددی معتبر وارد کنید:") | |
| return MANAGE_SUB_BALANCE_ID | |
| context.user_data['target_sub_id'] = int(update.message.text) | |
| await update.message.reply_text("💵 مبلغی که میخواهید **کسر** کنید را به تومان وارد کنید:") | |
| return MANAGE_SUB_BALANCE_AMOUNT | |
| async def process_sub_balance_amount(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| if not update.message.text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفاً مبلغ را به صورت عددی وارد کنید:") | |
| return MANAGE_SUB_BALANCE_AMOUNT | |
| amount = int(update.message.text) | |
| target = context.user_data.get('target_sub_id') | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("UPDATE users SET balance = MAX(0, balance - ?) WHERE user_id = ?", (amount, target)) | |
| conn.commit() | |
| conn.close() | |
| await update.message.reply_text(f"✅ مبلغ {amount:,} تومان با موفقیت از حساب کاربر {target} کسر شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| try: await context.bot.send_message(chat_id=target, text=f"📉 مبلغ {amount:,} تومان توسط مدیریت از کیف پول شما کسر گردید.") | |
| except: pass | |
| return START_STAGE | |
| async def process_ban_user_id(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| if not update.message.text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفاً فقط آیدی عددی معتبر وارد کنید:") | |
| return BAN_USER_ID | |
| t_id = int(update.message.text) | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("INSERT OR IGNORE INTO banned_users (user_id) VALUES (?)", (t_id,)) | |
| conn.commit() | |
| conn.close() | |
| await update.message.reply_text(f"🚫 کاربر {t_id} با موفقیت مسدود شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| try: await context.bot.send_message(chat_id=t_id, text="❌ حساب کاربری شما به دلیل تخلف مسدود گردید.") | |
| except: pass | |
| return START_STAGE | |
| async def process_unban_user_id(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| if not update.message.text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفاً فقط آیدی عددی معتبر وارد کنید:") | |
| return UNBAN_USER_ID | |
| t_id = int(update.message.text) | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("DELETE FROM banned_users WHERE user_id = ?", (t_id,)) | |
| conn.commit() | |
| conn.close() | |
| await update.message.reply_text(f"🔓 کاربر {t_id} رفع مسدودیت شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| try: await context.bot.send_message(chat_id=t_id, text="🎉 حساب کاربری شما رفع مسدودیت شد.") | |
| except: pass | |
| return START_STAGE | |
| async def process_user_info_id(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| if not update.message.text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفاً فقط آیدی عددی معتبر وارد کنید:") | |
| return USER_INFO_ID | |
| t_id = int(update.message.text) | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("SELECT username, balance FROM users WHERE user_id = ?", (t_id,)) | |
| user_row = cursor.fetchone() | |
| cursor.execute("SELECT COUNT(*) FROM tx WHERE user_id = ? AND status='approved'", (t_id,)) | |
| tx_count = cursor.fetchone()[0] | |
| cursor.execute("SELECT 1 FROM banned_users WHERE user_id = ?", (t_id,)) | |
| ban_status = "🚫 مسدود" if cursor.fetchone() else "🟢 فعال" | |
| conn.close() | |
| if not user_row: | |
| await update.message.reply_text("❌ کاربر یافت نشد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| return START_STAGE | |
| info_txt = f"👤 **اطلاعات کاربر {t_id}**\n\nیوزرنیم: @{user_row[0]}\nموجودی: {user_row[1]:,} تومان\nخرید های موفق: {tx_count} عدد\nوضعیت حساب: {ban_status}" | |
| await update.message.reply_text(info_txt, reply_markup=get_main_menu_keyboard(update.effective_user.id), parse_mode="Markdown") | |
| return START_STAGE | |
| async def process_clear_balance_id(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| if not update.message.text.isdigit(): | |
| await update.message.reply_text("❌ خطا: لطفاً فقط آیدی عددی معتبر وارد کنید:") | |
| return CLEAR_BALANCE_ID | |
| t_id = int(update.message.text) | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("UPDATE users SET balance = 0 WHERE user_id = ?", (t_id,)) | |
| conn.commit() | |
| conn.close() | |
| await update.message.reply_text(f"📉 موجودی کاربر {t_id} با موفقیت صفر شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| return START_STAGE | |
| async def process_support_msg(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| user_id = update.effective_user.id | |
| kb = [[InlineKeyboardButton("✍️ پاسخ دادن", callback_data=f"sp_reply_{user_id}")]] | |
| await send_to_all_admins(context, f"📥 **پیام پشتیبانی جدید**\n🆔 شناسه: {user_id}\n\n📝 متن:\n{update.message.text}", InlineKeyboardMarkup(kb)) | |
| await update.message.reply_text("✅ پیام شما ارسال شد. لطفا منتظر پاسخ بمانید.", reply_markup=get_main_menu_keyboard(user_id)) | |
| return START_STAGE | |
| async def support_reply_callback(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| query = update.callback_query | |
| await query.answer() | |
| context.user_data['reply_target'] = query.data.split('_')[2] | |
| await context.bot.send_message(chat_id=query.from_user.id, text="✍️ پاسخ خود را تایپ کنید:") | |
| return ADMIN_REPLY | |
| async def process_admin_reply(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| target = context.user_data.get('reply_target') | |
| try: | |
| await context.bot.send_message(chat_id=int(target), text=f"👨💻 **پاسخ از طرف مدیریت:**\n\n{update.message.text}") | |
| await update.message.reply_text("✅ با موفقیت برای کاربر ارسال شد.") | |
| except: pass | |
| return START_STAGE | |
| async def process_add_config(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| configs = update.message.text.strip().split('\n') | |
| c_type = context.user_data.get('adm_cfg_type') | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| for cfg in configs: | |
| if cfg.strip(): | |
| cursor.execute("INSERT INTO repo (type, config) VALUES (?, ?)", (c_type, cfg.strip())) | |
| conn.commit() | |
| conn.close() | |
| await update.message.reply_text(f"✅ مخزن نوع `{c_type}` بروزرسانی شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| return START_STAGE | |
| async def process_btn_name(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| context.user_data['new_btn_name'] = update.message.text | |
| await update.message.reply_text("✍️ متن پاسخ این دکمه را ارسال کنید:") | |
| return CREATE_BTN_TEXT | |
| async def process_btn_text(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| b_name = context.user_data.get('new_btn_name') | |
| conn = sqlite3.connect('vpn_ultra.db') | |
| cursor = conn.cursor() | |
| cursor.execute("INSERT INTO custom_buttons (btn_name, btn_text) VALUES (?, ?)", (b_name, update.message.text)) | |
| conn.commit() | |
| conn.close() | |
| await update.message.reply_text(f"✅ دکمه اختصاصی '{b_name}' با موفقیت ساخته شد.", reply_markup=get_main_menu_keyboard(update.effective_user.id)) | |
| return START_STAGE | |
| def main(): | |
| # بهینهسازی کلاینت شبکه برای پلتفرم PythonAnywhere با اضافه کردن مهلت زمانی بیشتر | |
| app = Application.builder().token(TOKEN).connect_timeout(30.0).read_timeout(30.0).build() | |
| handler = ConversationHandler( | |
| entry_points=[CommandHandler("start", start)], | |
| states={ | |
| START_STAGE: [ | |
| CallbackQueryHandler(support_reply_callback, pattern="^sp_reply_"), | |
| CallbackQueryHandler(handle_callbacks) | |
| ], | |
| BUY_VOLUME_CUSTOM: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_volume_custom)], | |
| SUPPORT_MSG: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_support_msg)], | |
| ADMIN_REPLY: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_admin_reply)], | |
| ADD_CONFIG: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_add_config)], | |
| CREATE_BTN_NAME: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_btn_name)], | |
| CREATE_BTN_TEXT: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_btn_text)], | |
| CHARGE_WALLET_AMOUNT: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_charge_amount)], | |
| GET_WALLET_RECEIPT: [ | |
| CallbackQueryHandler(handle_callbacks, pattern="^back_to_menu$"), | |
| MessageHandler(filters.PHOTO, process_wallet_receipt) | |
| ], | |
| BC_MSG: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_bc_msg)], | |
| ADD_ADMIN_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_add_admin)], | |
| MANAGE_ADD_BALANCE_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_add_balance_id)], | |
| MANAGE_ADD_BALANCE_AMOUNT: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_add_balance_amount)], | |
| MANAGE_SUB_BALANCE_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_sub_balance_id)], | |
| MANAGE_SUB_BALANCE_AMOUNT: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_sub_balance_amount)], | |
| BAN_USER_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_ban_user_id)], | |
| UNBAN_USER_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_unban_user_id)], | |
| USER_INFO_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_user_info_id)], | |
| CLEAR_BALANCE_ID: [MessageHandler(filters.TEXT & ~filters.COMMAND, process_clear_balance_id)] | |
| }, | |
| fallbacks=[CommandHandler("start", start)], | |
| allow_reentry=True | |
| ) | |
| app.add_handler(handler) | |
| print("ربات فعال شد. در حال مانیتورینگ شبکه...") | |
| app.run_polling(drop_pending_updates=True, timeout=20) | |
| if __name__ == '__main__': | |
| main() | |