Update app.py
Browse files9 unmodified lines101112131415161718192021222324252627282930313233343536373839404142434445462 unmodified lines49505152535455565758596061626364656667686970712 unmodified lines74757677789 unmodified linesself.hp = 100self.resources = {"Wood": 0, "Stone": 0, "Food": 0}self.active = Falseself.last_log = "Waiting for game start..."state = 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,2 unmodified linesstone: parseInt(document.getElementById('stoneDisplay')?.innerText) || 0}""")state.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.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")2 unmodified linesif __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)9 unmodified lines10111213141516171819202122232425262728293031323334353637383940414243442 unmodified lines4748495051525354555657585960616263646566672 unmodified lines707172739 unmodified linesself.hp = 100self.resources = {"Wood": 0, "Stone": 0, "Food": 0}self.active = Falseself.last_log = "Waiting..."state = BotState()def run_bot_engine():# Fix: Removed 'no_sandbox' from SB() and added it via browser argumentswith SB(uc=True, xvfb=True, chromium_arg="--no-sandbox,--disable-dev-shm-usage") as sb:try:state.status = "๐ Connection Stage..."sb.open("https://moomoo.io")sb.sleep(10) # Give ALTCHA time to compute (it's proof-of-work)state.status = "๐ก๏ธ Solving Security..."# Try to force solve the altcha/checkboxtry:sb.uc_gui_handle_captcha()sb.click('div[class*="altcha"]')except:passsb.sleep(5)state.status = "๐ Entering Game..."sb.type("#nameInput", "Survival_Bot")sb.click("#enterGame")state.active = Truestate.status = "๐ข SURVIVING"while True:game_data = sb.execute_script("""return {hp: parseInt(document.getElementById('healthBar')?.style.width) || 100,2 unmodified linesstone: parseInt(document.getElementById('stoneDisplay')?.innerText) || 0}""")state.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")time.sleep(0.1)except Exception as e:state.status = "โ Engine 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']}\n\n**Action Log:** {state.last_log}"with gr.Blocks() as demo:gr.Markdown("# ๐ฎ Moomoo Survival Bot")2 unmodified linesif __name__ == "__main__":threading.Thread(target=run_bot_engine, daemon=True).start()demo.launch(server_name="0.0.0.0", server_port=7860)
app.py+15-20