Update app.py
Browse files14 unmodified lines1516171818192022212225232724292526313227282930313432333435363741423839406 unmodified lines4748495556575850515253606162545556576458596061696263716465746667767768697079808182838485717273747514 unmodified linesstate = BotState()
def run_bot_engine(): # uc=True + xvfb=True is the ultimate stealth combo with SB(uc=True, xvfb=True, interval=0.05) as sb: try: state.status = "๐ Loading Moomoo.io..." # Open with reconnect to shake off basic bot trackers sb.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 selenium sb.activate_cdp_mode("https://moomoo.io") sb.sleep(2) sb.sleep(5) # This handles the 'I am not a robot' checkbox automatically sb.solve_captcha() try: sb.solve_captcha() except: pass # --- ENTER GAME --- sb.type("#nameInput", "Survival_Bot_v1") sb.click("#enterGame") state.active = True state.status = "๐ข SURVIVING"
while True: # 1. READ GAME STATE (JavaScript Injection) # We pull data directly from the DOM and Game UI game_data = sb.execute_script(""" return { hp: parseInt(document.getElementById('healthBar')?.style.width) || 100,6 unmodified lines state.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 Heal state.last_log = "โ ๏ธ Low HP: Healing used." if state.hp < 70: sb.press_keys("body", "q") state.last_log = "โ ๏ธ Healing active" elif state.resources['Wood'] < 50: sb.press_keys("body", "e") # Toggle Auto-hit state.last_log = "๐ช Farming for survival." elif state.resources['Wood'] < 100: sb.press_keys("body", "e") state.last_log = "๐ช Farming wood" # Prevent CPU overheating on HF Spaces time.sleep(0.1)
except Exception as e: state.status = "โ Fatal Error" state.last_log = f"Error: {str(e)[:100]}" state.last_log = f"Error: {str(e)[:50]}"
# --- GRADIO INTERFACE ---def get_stats(): res = state.resources return f"**Status:** {state.status}\n\n**HP:** {state.hp}%\n**Resources:** ๐ชต {res['Wood']} | ๐ชจ {res['Stone']} | ๐ {res['Food']}\n\n**Log:** {state.last_log}" return 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(title="Moomoo Survival AI") as demo: gr.Markdown("# ๐ฎ Moomoo.io AI Survival Bot")with gr.Blocks() as demo: gr.Markdown("# ๐ฎ Moomoo 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 seconds gr.Timer(1.5).tick(get_stats, outputs=output) 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