Spaces:
Paused
Paused
Update Bot.js
Browse files123456789101112131415161718192021222324252627282930313233import express from "express";import puppeteer from "puppeteer"; // Use 'puppeteer', not 'puppeteer-core'import { spawn } from "child_process";const app = express();const PORT = 7860;async function startBot() {console.log(">>> [BOOT]: Launching bot...");// Remove executablePath - Puppeteer will auto-detect its own browserconst browser = await puppeteer.launch({args: ["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage","--disable-gpu"],headless: "new" // Use "new" for 2026 compatibility});const page = await browser.newPage();await page.setViewport({ width: 1280, height: 720 });// ... rest of your FFmpeg and Loop code ...console.log(">>> [SUCCESS]: Browser started!");await page.goto("https://app.apponfly.com/trial", { waitUntil: 'networkidle2' });}app.listen(PORT, "0.0.0.0", () => {startBot().catch(console.error);});123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127import express from "express";import puppeteer from "puppeteer";import { spawn } from "child_process";import https from "https";const app = express();const PORT = 7860;// 🕵️ ZEBBERN INDEX VISION API (Using LLM7 No-Key Endpoint)async function callVision(b64) {return new Promise((resolve) => {const payload = JSON.stringify({model: "gpt-4.1-nano-2025-04-14",messages: [{role: "user",content: [{ type: "text", text: "Locate the Windows Start button or Chrome icon. Output ONLY: CLICK X,Y" },{ type: "image_url", image_url: { url: `data:image/jpeg;base64,${b64}` } }]}]});const req = https.request({hostname: 'api.llm7.io',path: '/v1/chat/completions',method: 'POST',headers: {'Content-Type': 'application/json','Authorization': 'Bearer free'}}, (res) => {let body = '';res.on('data', d => body += d);res.on('end', () => {try {const data = JSON.parse(body);resolve(data.choices[0].message.content.trim());} catch { resolve("WAIT"); }});});req.on('error', () => resolve("WAIT"));req.write(payload); req.end();});}async function startBot() {console.log(">>> [BOOT]: Launching Browser...");const browser = await puppeteer.launch({headless: "new",args: ["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage","--disable-gpu"]});const page = await browser.newPage();await page.setViewport({ width: 1280, height: 720 });// 📺 TWITCH STREAM (Display :99 is standard for HF/Docker)const ffmpeg = spawn("ffmpeg", ["-f", "x11grab", "-s", "1280x720", "-r", "30", "-i", ":99.0","-vcodec", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", "-f", "flv","rtmp://live.twitch.tv/app/live_1469793213_Vb3SfqZyxc5KQugU8fZuMIdITIUwAf"]);ffmpeg.stderr.on('data', (data) => console.log(`[FFMPEG]: ${data}`));// 1️⃣ NAVIGATE TO TRIALconsole.log(">>> [NAVIGATING]: Loading AppOnFly...");await page.goto("https://app.apponfly.com/trial", { waitUntil: 'networkidle2' });// 2️⃣ WAIT FOR REDIRECT (The "Brain" part)// We wait until the URL changes or a specific RDP element appearsconsole.log(">>> [WAITING]: Waiting for Windows Desktop redirect...");try {// AppOnFly usually redirects to a URL containing 'connect' or 'vps'await page.waitForFunction(() =>window.location.href.includes('trial-running') ||document.querySelector('canvas') !== null,{ timeout: 60000 });console.log(">>> [SUCCESS]: Desktop Loaded. Current URL:", page.url());} catch (e) {console.log(">>> [TIMEOUT]: Redirect didn't fire, starting loop anyway.");}// 3️⃣ THE AI LOOPsetInterval(async () => {try {// Check for 'Expired' screen from your uploaded imageconst isExpired = await page.evaluate(() =>document.body.innerText.includes("expired") ||document.body.innerText.includes("Sign in"));if (isExpired) {console.log(">>> [STOP]: Trial Expired. Killing browser.");await browser.close();process.exit(1);}const b64 = await page.screenshot({ encoding: "base64", type: "jpeg", quality: 30 });const decision = await callVision(b64);console.log(">>> [AI]:", decision);if (decision.includes("CLICK")) {const coords = decision.match(/\d+/g);if (coords) await page.mouse.click(parseInt(coords[0]), parseInt(coords[1]));}} catch (err) {console.log(">>> [LOOP ERR]:", err.message);}}, 20000);}// 🌍 HEALTH CHECK (Fixes "Cannot GET /")app.get("/", (req, res) => {res.send("<h1>🤖 Markus Bot Status: ONLINE</h1><p>Scanning AppOnFly Trial...</p>");});app.listen(PORT, "0.0.0.0", () => {console.log(`>>> [SERVER]: Listening on port ${PORT}`);startBot().catch(console.error);});
Bot.js+104-10