Update app.py
Browse files14 unmodified lines15161718192021222324252627282930313233343536373839406 unmodified lines474849505152535455565758596061626364651 unmodified line6768697071727374757614 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.resources1 unmodified linewith 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()demo.launch(server_name="0.0.0.0", server_port=7860)14 unmodified lines15161718192021222324252627282930313233343536373839404142434445466 unmodified lines5354555657585960616263646566671 unmodified line6970717273747576777814 unmodified linesstate = BotState()def run_bot_engine():# Added no_sandbox and disable_gpu for Docker stabilitywith SB(uc=True, xvfb=True, headless=False, no_sandbox=True, disable_gpu=True) as sb:try:state.status = "๐ Opening Browser..."sb.set_window_size(1280, 720)sb.uc_open_with_reconnect("https://moomoo.io", reconnect_time=7)state.status = "๐ก๏ธ Bypassing Cloudflare..."sb.sleep(5)# Try a stealthy click in the middle of the screen to wake up the JStry:sb.click_active_element()sb.uc_gui_handle_captcha()except:passstate.status = "๐ Entering Name..."sb.type("#nameInput", "Survival_Bot_v1")sb.click("#enterGame")state.active = Truestate.status = "๐ข SURVIVING"while True:# Scrape datagame_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 < 80:sb.press_keys("body", "q")state.last_log = "โค๏ธ Healing"time.sleep(0.1)except Exception as e:state.status = "โ Engine Error"state.last_log = f"Error: {str(e)[:60]}"def get_stats():res = state.resources1 unmodified linewith gr.Blocks() as demo:gr.Markdown("# ๐ฎ Moomoo Survival Bot")display = gr.Markdown("Connecting...")gr.Timer(1.5).tick(get_stats, outputs=display)if __name__ == "__main__":threading.Thread(target=run_bot_engine, daemon=True).start()# server_name="0.0.0.0" is essential for HF to see the appdemo.launch(server_name="0.0.0.0", server_port=7860)
app.py+18-16