Spaces:
Paused
Paused
Update bot.py
Browse files
bot.py
CHANGED
|
@@ -3,6 +3,7 @@ import re
|
|
| 3 |
import time
|
| 4 |
import io
|
| 5 |
import asyncio
|
|
|
|
| 6 |
from telethon import events, Button
|
| 7 |
from PIL import Image, ImageDraw, ImageFont
|
| 8 |
import db
|
|
@@ -143,7 +144,6 @@ def write_file_sync(lines):
|
|
| 143 |
f.write("\n".join(lines))
|
| 144 |
|
| 145 |
def filter_words_sync(chunk, min_length):
|
| 146 |
-
# Dynamically filters words based on the minimum length setting
|
| 147 |
pattern = re.compile(rf'^[a-z0-9_]{{{min_length},32}}$')
|
| 148 |
return {w for w in chunk if pattern.match(w)}
|
| 149 |
|
|
@@ -171,6 +171,37 @@ def setup_handlers(client):
|
|
| 171 |
await msg.delete()
|
| 172 |
await client.send_file(event.chat_id, file=img, caption=f"**Report:** `@{target}`")
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
@client.on(events.NewMessage(pattern='/upload'))
|
| 175 |
async def upload_cmd(event):
|
| 176 |
if not is_admin(event): return
|
|
@@ -253,7 +284,6 @@ def setup_handlers(client):
|
|
| 253 |
if not all_lines:
|
| 254 |
return await event.edit("Empty file.")
|
| 255 |
|
| 256 |
-
# Get minimum word length setting
|
| 257 |
state = await db.get_state()
|
| 258 |
min_length = int(state.get("min_length", 4))
|
| 259 |
|
|
@@ -352,7 +382,6 @@ def setup_handlers(client):
|
|
| 352 |
await client.send_file(event.chat_id, file=f)
|
| 353 |
exported_count += 1
|
| 354 |
|
| 355 |
-
# Export unknown statuses if the file exists
|
| 356 |
if os.path.exists("other.txt"):
|
| 357 |
await client.send_file(event.chat_id, "other.txt", caption="other.txt (Unknown HTML Responses)")
|
| 358 |
exported_count += 1
|
|
@@ -368,3 +397,4 @@ def setup_handlers(client):
|
|
| 368 |
elif data == "reset_do":
|
| 369 |
await db.flush_all()
|
| 370 |
await event.edit("💣 Memory purged successfully.", buttons=get_settings_menu())
|
|
|
|
|
|
| 3 |
import time
|
| 4 |
import io
|
| 5 |
import asyncio
|
| 6 |
+
import aiohttp
|
| 7 |
from telethon import events, Button
|
| 8 |
from PIL import Image, ImageDraw, ImageFont
|
| 9 |
import db
|
|
|
|
| 144 |
f.write("\n".join(lines))
|
| 145 |
|
| 146 |
def filter_words_sync(chunk, min_length):
|
|
|
|
| 147 |
pattern = re.compile(rf'^[a-z0-9_]{{{min_length},32}}$')
|
| 148 |
return {w for w in chunk if pattern.match(w)}
|
| 149 |
|
|
|
|
| 171 |
await msg.delete()
|
| 172 |
await client.send_file(event.chat_id, file=img, caption=f"**Report:** `@{target}`")
|
| 173 |
|
| 174 |
+
# --- NEW HTML DEBUG COMMAND ---
|
| 175 |
+
@client.on(events.NewMessage(pattern=r'/html\s+([a-zA-Z0-9_]+)'))
|
| 176 |
+
async def html_cmd(event):
|
| 177 |
+
if not is_admin(event): return
|
| 178 |
+
target = event.pattern_match.group(1).lower()
|
| 179 |
+
msg = await event.respond(f"🔍 Fetching raw HTML for `@{target}`...")
|
| 180 |
+
|
| 181 |
+
url = f"https://fragment.com/username/{target}"
|
| 182 |
+
headers = {
|
| 183 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36"
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
try:
|
| 187 |
+
async with aiohttp.ClientSession() as session:
|
| 188 |
+
async with session.get(url, headers=headers, allow_redirects=True, timeout=15) as resp:
|
| 189 |
+
html_text = await resp.text()
|
| 190 |
+
status_code = resp.status
|
| 191 |
+
|
| 192 |
+
# Package the long HTML text into a clean file object
|
| 193 |
+
f = io.BytesIO(html_text.encode('utf-8'))
|
| 194 |
+
f.name = f"{target}_fragment.html"
|
| 195 |
+
|
| 196 |
+
await msg.delete()
|
| 197 |
+
await client.send_file(
|
| 198 |
+
event.chat_id,
|
| 199 |
+
file=f,
|
| 200 |
+
caption=f"📄 **Raw HTML Captured for** `@{target}`\n**Status Code:** `{status_code}`"
|
| 201 |
+
)
|
| 202 |
+
except Exception as e:
|
| 203 |
+
await msg.edit(f"❌ **Error fetching HTML:** `{str(e)}`")
|
| 204 |
+
|
| 205 |
@client.on(events.NewMessage(pattern='/upload'))
|
| 206 |
async def upload_cmd(event):
|
| 207 |
if not is_admin(event): return
|
|
|
|
| 284 |
if not all_lines:
|
| 285 |
return await event.edit("Empty file.")
|
| 286 |
|
|
|
|
| 287 |
state = await db.get_state()
|
| 288 |
min_length = int(state.get("min_length", 4))
|
| 289 |
|
|
|
|
| 382 |
await client.send_file(event.chat_id, file=f)
|
| 383 |
exported_count += 1
|
| 384 |
|
|
|
|
| 385 |
if os.path.exists("other.txt"):
|
| 386 |
await client.send_file(event.chat_id, "other.txt", caption="other.txt (Unknown HTML Responses)")
|
| 387 |
exported_count += 1
|
|
|
|
| 397 |
elif data == "reset_do":
|
| 398 |
await db.flush_all()
|
| 399 |
await event.edit("💣 Memory purged successfully.", buttons=get_settings_menu())
|
| 400 |
+
|