chore(userbot): apply ruff check --fix and ruff format

- ruff check --fix: 210 auto-fixed errors (import sorting, trailing
  whitespace, unused imports, f-string fixups, deprecated annotations)
- ruff format: 104 files reformatted to consistent style
- 268 non-auto-fixable issues remain (S113 requests timeout, etc.)
This commit is contained in:
2026-06-19 12:19:01 +02:00
parent 95cec59263
commit 7ba6bc44f2
104 changed files with 4338 additions and 5319 deletions
+27 -32
View File
@@ -1,26 +1,27 @@
from utils.misc import modules_help, prefix
import os
import requests
from modules.url import generate_screenshot
from pyrogram import Client, filters
from pyrogram.types import Message
from modules.url import generate_screenshot
import os
from utils.misc import modules_help, prefix
# API endpoints for reverse image search engines
SEARCH_ENGINES = {
"lens": "https://lens.google.com/uploadbyurl?url={image}",
"reverse": "https://www.google.com/searchbyimage?sbisrc=4chanx&image_url={image}&safe=off",
"tineye": "https://www.tineye.com/search?url={image}",
"bing": "https://www.bing.com/images/search?view=detailv2&iss=sbi&form=SBIVSP&sbisrc=UrlPaste&q=imgurl:{image}",
"yandex": "https://yandex.com/images/search?source=collections&&url={image}&rpt=imageview",
"saucenao": "https://saucenao.com/search.php?db=999&url={image}",
'lens': 'https://lens.google.com/uploadbyurl?url={image}',
'reverse': 'https://www.google.com/searchbyimage?sbisrc=4chanx&image_url={image}&safe=off',
'tineye': 'https://www.tineye.com/search?url={image}',
'bing': 'https://www.bing.com/images/search?view=detailv2&iss=sbi&form=SBIVSP&sbisrc=UrlPaste&q=imgurl:{image}',
'yandex': 'https://yandex.com/images/search?source=collections&&url={image}&rpt=imageview',
'saucenao': 'https://saucenao.com/search.php?db=999&url={image}',
}
@Client.on_message(filters.command("risearch", prefix) & filters.reply)
@Client.on_message(filters.command('risearch', prefix) & filters.reply)
async def reverse_image_search(client: Client, message: Message):
if not message.reply_to_message or not message.reply_to_message.photo:
await message.reply_text(
f"Please reply to an image with <code>{prefix}risearch [engine]</code> or <code>{prefix}risearch</code>."
f'Please reply to an image with <code>{prefix}risearch [engine]</code> or <code>{prefix}risearch</code>.'
)
return
@@ -31,16 +32,14 @@ async def reverse_image_search(client: Client, message: Message):
else list(SEARCH_ENGINES.keys())
)
invalid_engines = [
engine for engine in engines_to_use if engine not in SEARCH_ENGINES
]
invalid_engines = [engine for engine in engines_to_use if engine not in SEARCH_ENGINES]
if invalid_engines:
await message.reply_text(
f"Invalid engine(s): {', '.join(invalid_engines)}. Available: {', '.join(SEARCH_ENGINES.keys())}"
f'Invalid engine(s): {", ".join(invalid_engines)}. Available: {", ".join(SEARCH_ENGINES.keys())}'
)
return
processing_message = await message.edit_text("Processing the image...")
processing_message = await message.edit_text('Processing the image...')
try:
# Download and upload the image
@@ -48,7 +47,7 @@ async def reverse_image_search(client: Client, message: Message):
img_url = upload_image(photo_path)
print(img_url)
if not img_url:
await processing_message.edit("Error: Could not upload the image.")
await processing_message.edit('Error: Could not upload the image.')
return
# Perform searches for the selected engines
@@ -56,7 +55,7 @@ async def reverse_image_search(client: Client, message: Message):
search_url = SEARCH_ENGINES[engine].format(image=img_url)
await send_screenshot(client, message, search_url, engine)
except Exception as e:
await processing_message.edit(f"An error occurred: {e}")
await processing_message.edit(f'An error occurred: {e}')
finally:
if photo_path and os.path.exists(photo_path):
os.remove(photo_path)
@@ -65,15 +64,13 @@ async def reverse_image_search(client: Client, message: Message):
def upload_image(photo_path):
"""Uploads an image to tmpfiles.org and returns the direct download URL."""
try:
with open(photo_path, "rb") as image_file:
response = requests.post(
"https://tmpfiles.org/api/v1/upload", files={"file": image_file}
)
with open(photo_path, 'rb') as image_file:
response = requests.post('https://tmpfiles.org/api/v1/upload', files={'file': image_file})
if response.status_code == 200:
data = response.json()
url = data["data"]["url"]
pic_url = url.split("/")[-2] + "/" + url.split("/")[-1]
direct_download_url = url.replace(f"/{pic_url}", f"/dl/{pic_url}")
url = data['data']['url']
pic_url = url.split('/')[-2] + '/' + url.split('/')[-1]
direct_download_url = url.replace(f'/{pic_url}', f'/dl/{pic_url}')
print(direct_download_url)
return direct_download_url
else:
@@ -89,17 +86,15 @@ async def send_screenshot(client, message, url, engine_name):
await client.send_photo(
message.chat.id,
screenshot_data,
caption=f"<b>{engine_name.capitalize()} Result</b>\nURL: <code>{url}</code>",
caption=f'<b>{engine_name.capitalize()} Result</b>\nURL: <code>{url}</code>',
reply_to_message_id=message.id,
)
else:
await message.reply(
f"Failed to take screenshot for {engine_name.capitalize()}."
)
await message.reply(f'Failed to take screenshot for {engine_name.capitalize()}.')
# Add module details to help
modules_help["risearch"] = {
"risearch": f"Reply to a photo with `{prefix}risearch [engine]` (e.g., `{prefix}risearch lens`, `{prefix}risearch bing`) "
f"\nor use `{prefix}risearch` to analyze the image with all engines.",
modules_help['risearch'] = {
'risearch': f'Reply to a photo with `{prefix}risearch [engine]` (e.g., `{prefix}risearch lens`, `{prefix}risearch bing`) '
f'\nor use `{prefix}risearch` to analyze the image with all engines.',
}