# -*- coding: utf-8 -*- import asyncio import os import re from fastapi import FastAPI import uvicorn from playwright.async_api import async_playwright from playwright_stealth import Stealth # --- βš™οΈ TITAN CONFIG --- PULSE_DELAY = 100 TABS_PER_SPACE = 1 app = FastAPI() # πŸ”± FIX: defining both GET and HEAD to ensure 200 OK for UptimeRobot @app.api_route("/", methods=["GET", "HEAD"]) async def health_check(): return {"status": "TITAN_ACTIVE", "monitoring": "ONLINE"} STRIKE_SCRIPT = """ (name, delay) => { const getBlock = () => { const emojis = ["πŸ’™", "❀️", "πŸ’š", "πŸ’›", "πŸ’œ", "πŸ–€", "🀍", "🀎", "🧑", "πŸ’–"]; const currentEmoji = emojis[Math.floor(Math.random() * emojis.length)]; const line = "α΄˜Κ€α΄€α΄›Ιͺα΄‹-ᴠᴇᴇʀ-κœ±α΄œΚ€α΄€α΄Š-Ι΄α΄‡α΄α΄‡κœ±Ιͺπ–˜ πšƒπ™Όπ™Ίπ™² " + currentEmoji + "ΰΌ‹ΰΌ˜ΰΏ"; let text = ""; for(let i = 0; i < 10; i++) { text += line + "\\r\\n\\r\\n\\r\\n\\r\\n"; } return text; } const pulse = () => { const box = document.querySelector('div[role="textbox"], [contenteditable="true"]'); if (box) { const text = getBlock(); // 1. Create a virtual clipboard event const dataTransfer = new DataTransfer(); dataTransfer.setData('text/plain', text); const pasteEvent = new ClipboardEvent('paste', { clipboardData: dataTransfer, bubbles: true, cancelable: true }); // 2. Focus and inject via paste event box.focus(); box.dispatchEvent(pasteEvent); // 3. Trigger input event to update React state box.dispatchEvent(new Event('input', { bubbles: true })); // 4. Trigger send button setTimeout(() => { const sendBtn = Array.from(document.querySelectorAll('div[role="button"], button')).find(el => el.textContent === 'Send' || el.innerText === 'Send' ); if (sendBtn) { sendBtn.click(); } else { const fallbackBtn = document.querySelector('form button[type="button"], div[aria-label="Send"]'); if (fallbackBtn) fallbackBtn.click(); } }, 300); } setTimeout(() => { requestAnimationFrame(pulse); }, delay); } pulse(); } """ async def run_titan(): cookie = os.environ.get("INSTA_COOKIE") target_id = os.environ.get("TARGET_THREAD_ID") target_name = os.environ.get("TARGET_NAME", "TITAN") if not cookie or not target_id: print("❌ MISSING SECRETS") return async with async_playwright() as p: browser = await p.chromium.launch(headless=True, args=[ "--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu", "--js-flags='--max-old-space-size=512'" ]) context = await browser.new_context(user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36") sid = re.search(r'sessionid=([^;]+)', cookie).group(1) if 'sessionid=' in cookie else cookie await context.add_cookies([{'name': 'sessionid', 'value': sid.strip(), 'domain': '.instagram.com', 'path': '/', 'secure': True, 'httpOnly': True}]) while True: pg = await context.new_page() await Stealth().apply_stealth_async(pg) await pg.route("**/*.{png,jpg,jpeg,gif,webp,svg,mp4,woff,woff2,ttf,css}", lambda route: route.abort()) try: await pg.goto("https://www.instagram.com/", wait_until="commit", timeout=30000) await asyncio.sleep(2) await pg.goto(f"https://www.instagram.com/direct/t/{target_id}/", wait_until="load", timeout=90000) await pg.evaluate(STRIKE_SCRIPT, [target_name, PULSE_DELAY]) await asyncio.sleep(600) except Exception as e: print(f"⚠️ Tab Error: {e}") await asyncio.sleep(10) finally: await pg.close() async def start_cluster(): asyncio.create_task(run_titan()) config = uvicorn.Config(app, host="0.0.0.0", port=7860, log_level="info") server = uvicorn.Server(config) await server.serve() if __name__ == "__main__": asyncio.run(start_cluster())