Update app.py
Browse files14 unmodified lines151617181920212223242526272829303132333435363738394041424344456 unmodified lines5253545556575859606162636465666768697071727374757677787980818283848586878814 unmodified linesstate = BotState()def run_bot_engine():# uc=True + xvfb=True is the ultimate stealth combowith SB(uc=True, xvfb=True, interval=0.05) as sb:try:state.status = "๐ Loading Moomoo.io..."# Open with reconnect to shake off basic bot trackerssb.uc_open_with_reconnect("https://moomoo.io", reconnect_time=5)# --- CAPTCHA BYPASS ---state.status = "๐ก๏ธ Handling Anti-Bot..."# activate_cdp_mode is more stealthy than standard seleniumsb.activate_cdp_mode("https://moomoo.io")sb.sleep(2)# This handles the 'I am not a robot' checkbox automaticallysb.solve_captcha()# --- ENTER GAME ---sb.type("#nameInput", "Survival_Bot_v1")sb.click("#enterGame")state.active = Truestate.status = "๐ข SURVIVING"while True:# 1. READ GAME STATE (JavaScript Injection)# We pull data directly from the DOM and Game UIgame_data = sb.execute_script("""return {hp: parseInt(document.getElementById('healthBar')?.style.width) || 100,6 unmodified linesstate.hp = game_data['hp']state.resources = {"Wood": game_data['wood'], "Stone": game_data['stone'], "Food": game_data['food']}# 2. SURVIVAL HEURISTICS (Based on your strategies)if state.hp < 60:sb.press_keys("body", "q") # Instant Healstate.last_log = "โ ๏ธ Low HP: Healing used."elif state.resources['Wood'] < 50:sb.press_keys("body", "e") # Toggle Auto-hitstate.last_log = "๐ช Farming for survival."# Prevent CPU overheating on HF Spacestime.sleep(0.1)except Exception as e:state.status = "โ Fatal Error"state.last_log = f"Error: {str(e)[:100]}"# --- GRADIO INTERFACE ---def get_stats():res = state.resourcesreturn f"**Status:** {state.status}\n\n**HP:** {state.hp}%\n**Resources:** ๐ชต {res['Wood']} | ๐ชจ {res['Stone']} | ๐ {res['Food']}\n\n**Log:** {state.last_log}"with gr.Blocks(title="Moomoo Survival AI") as demo:gr.Markdown("# ๐ฎ Moomoo.io AI Survival Bot")with gr.Row():with gr.Column():output = gr.Markdown("Loading bot data...")with gr.Column():gr.Image("https://moomoo.io/img/favicon.png", width=100)# Auto-refresh UI every 1.5 secondsgr.Timer(1.5).tick(get_stats, outputs=output)if __name__ == "__main__":threading.Thread(target=run_bot_engine, daemon=True).start()14 unmodified lines15161718192021222324252627282930313233343536373839406 unmodified lines474849505152535455565758596061626364656667686970717273747514 unmodified linesstate = BotState()def run_bot_engine():with SB(uc=True, xvfb=True, interval=0.05) as sb:try:state.status = "๐ Loading Moomoo.io..."sb.uc_open_with_reconnect("https://moomoo.io", reconnect_time=5)state.status = "๐ก๏ธ Handling Anti-Bot..."sb.activate_cdp_mode("https://moomoo.io")sb.sleep(5)try:sb.solve_captcha()except:passsb.type("#nameInput", "Survival_Bot_v1")sb.click("#enterGame")state.active = Truestate.status = "๐ข SURVIVING"while True:game_data = sb.execute_script("""return {hp: parseInt(document.getElementById('healthBar')?.style.width) || 100,6 unmodified linesstate.hp = game_data['hp']state.resources = {"Wood": game_data['wood'], "Stone": game_data['stone'], "Food": game_data['food']}if state.hp < 70:sb.press_keys("body", "q")state.last_log = "โ ๏ธ Healing active"elif state.resources['Wood'] < 100:sb.press_keys("body", "e")state.last_log = "๐ช Farming wood"time.sleep(0.1)except Exception as e:state.status = "โ Fatal Error"state.last_log = f"Error: {str(e)[:50]}"def get_stats():res = state.resourcesreturn f"### ๐ Live Stats\n**Status:** {state.status}\n**HP:** {state.hp}%\n**Wood:** {res['Wood']} | **Stone:** {res['Stone']} | **Food:** {res['Food']}\n\n**Action Log:** {state.last_log}"with gr.Blocks() as demo:gr.Markdown("# ๐ฎ Moomoo Survival Bot")with gr.Row():display = gr.Markdown("Connecting to engine...")gr.Timer(1.5).tick(get_stats, outputs=display)if __name__ == "__main__":threading.Thread(target=run_bot_engine, daemon=True).start()
app.py+17-30