Muttered3 commited on
Commit
fda2731
Β·
verified Β·
1 Parent(s): 935b8a6

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +34 -19
bot.py CHANGED
@@ -3,6 +3,7 @@ import re
3
  import time
4
  import io
5
  import asyncio
 
6
  from pyrogram import Client, filters
7
  from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
8
  from pyrogram.errors import MessageNotModified
@@ -10,7 +11,6 @@ from pyrogram.errors import MessageNotModified
10
  from state import state
11
  from logger import get_logger
12
  import scraper
13
- from curl_cffi.requests import AsyncSession
14
 
15
  log = get_logger()
16
 
@@ -82,17 +82,19 @@ def generate_status_msg():
82
  f"πŸ”¨ Auction : `{state.counts.get('auction', 0):,}`\n"
83
  f"βœ… Available : `{state.counts.get('available', 0):,}`\n"
84
  f"πŸ›’ Sold : `{state.counts.get('sold', 0):,}`\n"
 
85
  )
86
 
87
- # --- PROXY TESTER ---
88
  async def test_proxy(proxy_url):
89
- proxies = {"http": proxy_url, "https": proxy_url}
90
  start = time.time()
 
91
  try:
92
- async with AsyncSession(impersonate="chrome120", proxies=proxies) as session:
93
- resp = await session.get("https://fragment.com/", timeout=10)
94
- if resp.status_code == 200:
95
- return proxy_url, round((time.time() - start) * 1000)
 
96
  except Exception:
97
  pass
98
  return proxy_url, None
@@ -116,7 +118,7 @@ async def proxy_cmd(client, message):
116
  os.remove(file_path)
117
  if not raw_proxies: return await msg.edit_text("⚠️ No proxies found in file.")
118
 
119
- await msg.edit_text(f"πŸ” Testing **{len(raw_proxies)}** proxies concurrently...")
120
 
121
  tasks = [test_proxy(p) for p in raw_proxies]
122
  results = await asyncio.gather(*tasks)
@@ -124,11 +126,22 @@ async def proxy_cmd(client, message):
124
  working = [p for p, lat in results if lat is not None]
125
  state.proxies = working # Save to memory
126
 
127
- await msg.edit_text(f"βœ… Saved **{len(working)}** working proxies to memory.", reply_markup=get_dynamic_menu())
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  @app.on_message(filters.command("upload") & is_admin)
130
  async def upload_cmd(client, message):
131
- # Support both replying to a file, OR sending the file with the command as a caption
132
  target_message = message if message.document else message.reply_to_message
133
 
134
  if not target_message or not target_message.document:
@@ -137,10 +150,8 @@ async def upload_cmd(client, message):
137
  msg = await message.reply_text("⏳ Downloading `words.txt`...")
138
 
139
  try:
140
- # Pyrogram downloads to a hidden folder. We capture the exact path.
141
  file_path = await target_message.download()
142
 
143
- # Move it to the root directory where the bot is looking for it and overwrite the old one
144
  if os.path.exists("words.txt"):
145
  os.remove("words.txt")
146
  os.replace(file_path, "words.txt")
@@ -186,16 +197,20 @@ async def check_cmd(client, message):
186
  async def html_cmd(client, message):
187
  if len(message.command) < 2: return await message.reply_text("Usage: `/html <word>`")
188
  target = message.command[1].lower()
189
- msg = await message.reply_text(f"πŸ” Fetching raw HTML for `@{target}` via Chrome Impersonation...")
190
 
191
  url = f"https://fragment.com/username/{target}"
 
192
 
193
  try:
194
- async with AsyncSession(impersonate="chrome120") as session:
195
- resp = await session.get(url, timeout=15, allow_redirects=True)
196
- html_text = resp.text
197
- status_code = resp.status_code
198
- final_url = str(resp.url)
 
 
 
199
 
200
  f = io.BytesIO(html_text.encode('utf-8'))
201
  f.name = f"{target}_fragment.html"
@@ -359,7 +374,7 @@ async def button_handler(client, query):
359
  elif data == "export_files":
360
  await query.edit_message_text("⏳ Preparing files from disk...")
361
  exported = 0
362
- for s in ["taken", "unavailable", "sold", "forsale", "auction", "available"]:
363
  if os.path.exists(f"results/{s}.txt"):
364
  await client.send_document(query.message.chat.id, document=f"results/{s}.txt")
365
  exported += 1
 
3
  import time
4
  import io
5
  import asyncio
6
+ import aiohttp
7
  from pyrogram import Client, filters
8
  from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
9
  from pyrogram.errors import MessageNotModified
 
11
  from state import state
12
  from logger import get_logger
13
  import scraper
 
14
 
15
  log = get_logger()
16
 
 
82
  f"πŸ”¨ Auction : `{state.counts.get('auction', 0):,}`\n"
83
  f"βœ… Available : `{state.counts.get('available', 0):,}`\n"
84
  f"πŸ›’ Sold : `{state.counts.get('sold', 0):,}`\n"
85
+ f"⚠️ Errors : `{state.counts.get('error', 0):,}`\n"
86
  )
87
 
88
+ # --- PROXY TESTER (aiohttp) ---
89
  async def test_proxy(proxy_url):
 
90
  start = time.time()
91
+ headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36"}
92
  try:
93
+ timeout = aiohttp.ClientTimeout(total=10)
94
+ async with aiohttp.ClientSession(timeout=timeout) as session:
95
+ async with session.get("https://fragment.com/", headers=headers, proxy=proxy_url) as resp:
96
+ if resp.status == 200:
97
+ return proxy_url, round((time.time() - start) * 1000)
98
  except Exception:
99
  pass
100
  return proxy_url, None
 
118
  os.remove(file_path)
119
  if not raw_proxies: return await msg.edit_text("⚠️ No proxies found in file.")
120
 
121
+ await msg.edit_text(f"πŸ” Testing **{len(raw_proxies)}** proxies concurrently via aiohttp...")
122
 
123
  tasks = [test_proxy(p) for p in raw_proxies]
124
  results = await asyncio.gather(*tasks)
 
126
  working = [p for p, lat in results if lat is not None]
127
  state.proxies = working # Save to memory
128
 
129
+ # Format Top 10 Report
130
+ latency_board = sorted([(p, lat) for p, lat in results if lat is not None], key=lambda x: x[1])
131
+ top_str = "\n".join([f"⏱ `{lat}ms` | {url.split('@')[-1] if '@' in url else url}" for url, lat in latency_board[:10]])
132
+
133
+ report = (
134
+ f"βœ… **Proxy Test Complete**\n"
135
+ f"━━━━━━━━━━━━━━━━\n"
136
+ f"**Total Tested:** `{len(raw_proxies)}`\n"
137
+ f"**Working & Saved:** `{len(working)}`\n\n"
138
+ f"πŸ† **Top Fastest Proxies:**\n{top_str if top_str else 'None'}"
139
+ )
140
+
141
+ await msg.edit_text(report, reply_markup=get_dynamic_menu())
142
 
143
  @app.on_message(filters.command("upload") & is_admin)
144
  async def upload_cmd(client, message):
 
145
  target_message = message if message.document else message.reply_to_message
146
 
147
  if not target_message or not target_message.document:
 
150
  msg = await message.reply_text("⏳ Downloading `words.txt`...")
151
 
152
  try:
 
153
  file_path = await target_message.download()
154
 
 
155
  if os.path.exists("words.txt"):
156
  os.remove("words.txt")
157
  os.replace(file_path, "words.txt")
 
197
  async def html_cmd(client, message):
198
  if len(message.command) < 2: return await message.reply_text("Usage: `/html <word>`")
199
  target = message.command[1].lower()
200
+ msg = await message.reply_text(f"πŸ” Fetching raw HTML for `@{target}`...")
201
 
202
  url = f"https://fragment.com/username/{target}"
203
+ headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124.0 Safari/537.36"}
204
 
205
  try:
206
+ proxy = state.proxies[0] if state.proxies else None
207
+
208
+ timeout = aiohttp.ClientTimeout(total=15)
209
+ async with aiohttp.ClientSession(timeout=timeout) as session:
210
+ async with session.get(url, headers=headers, proxy=proxy, allow_redirects=True) as resp:
211
+ html_text = await resp.text()
212
+ status_code = resp.status
213
+ final_url = str(resp.url)
214
 
215
  f = io.BytesIO(html_text.encode('utf-8'))
216
  f.name = f"{target}_fragment.html"
 
374
  elif data == "export_files":
375
  await query.edit_message_text("⏳ Preparing files from disk...")
376
  exported = 0
377
+ for s in ["taken", "unavailable", "sold", "forsale", "auction", "available", "error"]:
378
  if os.path.exists(f"results/{s}.txt"):
379
  await client.send_document(query.message.chat.id, document=f"results/{s}.txt")
380
  exported += 1