Spaces:
Paused
Paused
Update bot.py
Browse files
bot.py
CHANGED
|
@@ -3,7 +3,6 @@ import re
|
|
| 3 |
import time
|
| 4 |
import io
|
| 5 |
import asyncio
|
| 6 |
-
import aiohttp
|
| 7 |
from telethon import events, Button
|
| 8 |
import db
|
| 9 |
import scraper
|
|
@@ -104,7 +103,10 @@ def setup_handlers(client):
|
|
| 104 |
def take_screenshot():
|
| 105 |
from html2image import Html2Image
|
| 106 |
# --no-sandbox is critical for Linux servers
|
| 107 |
-
hti = Html2Image(
|
|
|
|
|
|
|
|
|
|
| 108 |
hti.size = (1000, 750)
|
| 109 |
img_name = f"{target}_fragment.png"
|
| 110 |
# Chrome navigates to the URL and renders the exact CSS/HTML
|
|
@@ -121,43 +123,40 @@ def setup_handlers(client):
|
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
try:
|
| 124 |
-
await msg.edit(f"β **Screenshot Error:**\n*(
|
| 125 |
except:
|
| 126 |
pass
|
| 127 |
|
| 128 |
-
# ---
|
| 129 |
@client.on(events.NewMessage(pattern=r'/html\s+([a-zA-Z0-9_]+)'))
|
| 130 |
async def html_cmd(event):
|
| 131 |
if not is_admin(event): return
|
| 132 |
target = event.pattern_match.group(1).lower()
|
| 133 |
-
msg = await event.respond(f"π Fetching raw HTML for `@{target}`...")
|
| 134 |
|
| 135 |
url = f"https://fragment.com/username/{target}"
|
| 136 |
-
headers = {
|
| 137 |
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36"
|
| 138 |
-
}
|
| 139 |
|
| 140 |
try:
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
f = io.BytesIO(html_text.encode('utf-8'))
|
| 148 |
f.name = f"{target}_fragment.html"
|
| 149 |
-
f.seek(0)
|
| 150 |
|
| 151 |
caption = (
|
| 152 |
f"π **Raw Response for** `@{target}`\n"
|
| 153 |
f"**Requested URL:** `{url}`\n"
|
|
|
|
| 154 |
f"**Status Code:** `{status_code}`\n"
|
| 155 |
)
|
| 156 |
|
| 157 |
-
if status_code in [301, 302, 303, 307]:
|
| 158 |
-
caption += f"\n**π¨ FRAGMENT REDIRECTED TO:** `{location}`"
|
| 159 |
-
|
| 160 |
-
# CRITICAL FIX: Send file FIRST, delete message AFTER
|
| 161 |
await client.send_file(event.chat_id, file=f, caption=caption)
|
| 162 |
await msg.delete()
|
| 163 |
|
|
|
|
| 3 |
import time
|
| 4 |
import io
|
| 5 |
import asyncio
|
|
|
|
| 6 |
from telethon import events, Button
|
| 7 |
import db
|
| 8 |
import scraper
|
|
|
|
| 103 |
def take_screenshot():
|
| 104 |
from html2image import Html2Image
|
| 105 |
# --no-sandbox is critical for Linux servers
|
| 106 |
+
hti = Html2Image(
|
| 107 |
+
browser_executable='/usr/bin/chromium',
|
| 108 |
+
custom_flags=['--no-sandbox', '--disable-gpu', '--hide-scrollbars', '--disable-dev-shm-usage']
|
| 109 |
+
)
|
| 110 |
hti.size = (1000, 750)
|
| 111 |
img_name = f"{target}_fragment.png"
|
| 112 |
# Chrome navigates to the URL and renders the exact CSS/HTML
|
|
|
|
| 123 |
|
| 124 |
except Exception as e:
|
| 125 |
try:
|
| 126 |
+
await msg.edit(f"β **Screenshot Error:**\n*(Make sure packages.txt has chromium)*\n`{str(e)}`")
|
| 127 |
except:
|
| 128 |
pass
|
| 129 |
|
| 130 |
+
# --- UPGRADED HTML DEBUG COMMAND (Immune to Shadow Bans) ---
|
| 131 |
@client.on(events.NewMessage(pattern=r'/html\s+([a-zA-Z0-9_]+)'))
|
| 132 |
async def html_cmd(event):
|
| 133 |
if not is_admin(event): return
|
| 134 |
target = event.pattern_match.group(1).lower()
|
| 135 |
+
msg = await event.respond(f"π Fetching raw HTML for `@{target}` via Chrome Impersonation...")
|
| 136 |
|
| 137 |
url = f"https://fragment.com/username/{target}"
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
try:
|
| 140 |
+
from curl_cffi.requests import AsyncSession
|
| 141 |
+
|
| 142 |
+
# Using Chrome impersonation to stop Fragment from faking the redirect
|
| 143 |
+
async with AsyncSession(impersonate="chrome120") as session:
|
| 144 |
+
resp = await session.get(url, timeout=15, allow_redirects=True)
|
| 145 |
+
html_text = resp.text
|
| 146 |
+
status_code = resp.status_code
|
| 147 |
+
final_url = str(resp.url)
|
| 148 |
|
| 149 |
f = io.BytesIO(html_text.encode('utf-8'))
|
| 150 |
f.name = f"{target}_fragment.html"
|
| 151 |
+
f.seek(0)
|
| 152 |
|
| 153 |
caption = (
|
| 154 |
f"π **Raw Response for** `@{target}`\n"
|
| 155 |
f"**Requested URL:** `{url}`\n"
|
| 156 |
+
f"**Final URL:** `{final_url}`\n"
|
| 157 |
f"**Status Code:** `{status_code}`\n"
|
| 158 |
)
|
| 159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
await client.send_file(event.chat_id, file=f, caption=caption)
|
| 161 |
await msg.delete()
|
| 162 |
|