Update app.py
Browse files9 unmodified lines101112131314151617181918192021222321222324252627282526273028293031323335363435363738394041434243442 unmodified lines47484952505155525354585556575859646061626368646566672 unmodified lines70717277739 unmodified lines self.hp = 100 self.resources = {"Wood": 0, "Stone": 0, "Food": 0} self.active = False self.last_log = "Waiting for game start..." self.last_log = "Waiting..."
state = BotState()
def run_bot_engine(): # Added no_sandbox and disable_gpu for Docker stability with SB(uc=True, xvfb=True, headless=False, no_sandbox=True, disable_gpu=True) as sb: # Fix: Removed 'no_sandbox' from SB() and added it via browser arguments with SB(uc=True, xvfb=True, chromium_arg="--no-sandbox,--disable-dev-shm-usage") 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 = "๐ Connection Stage..." sb.open("https://moomoo.io") sb.sleep(10) # Give ALTCHA time to compute (it's proof-of-work) state.status = "๐ก๏ธ Bypassing Cloudflare..." sb.sleep(5) # Try a stealthy click in the middle of the screen to wake up the JS state.status = "๐ก๏ธ Solving Security..." # Try to force solve the altcha/checkbox try: sb.click_active_element() sb.uc_gui_handle_captcha() sb.click('div[class*="altcha"]') except: pass sb.sleep(5) state.status = "๐ Entering Name..." sb.type("#nameInput", "Survival_Bot_v1") state.status = "๐ Entering Game..." sb.type("#nameInput", "Survival_Bot") sb.click("#enterGame") state.active = True state.status = "๐ข SURVIVING"
while True: # Scrape data game_data = sb.execute_script(""" return { hp: parseInt(document.getElementById('healthBar')?.style.width) || 100,2 unmodified lines stone: 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]}" state.last_log = f"Error: {str(e)[:50]}"
def get_stats(): res = state.resources 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}" return 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 lines
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 app demo.launch(server_name="0.0.0.0", server_port=7860)app.py+15-20