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
+40 -60
View File
@@ -13,19 +13,17 @@ from pyrogram.types import Message
from utils.misc import modules_help, prefix
from utils.scripts import format_exc, import_library, resize_image
Image = import_library("PIL", "pillow").Image
np = import_library("numpy")
imageio = import_library("imageio")
Image = import_library('PIL', 'pillow').Image
np = import_library('numpy')
imageio = import_library('imageio')
def create_gif(filename: str, offset: int, fps: int = 2, typ: str = "spin"):
img = Image.open(f"downloads/{filename}")
if typ.lower() != "spin":
img = img.resize(
(random.randint(200, 1280), random.randint(200, 1280)), Image.ANTIALIAS
)
def create_gif(filename: str, offset: int, fps: int = 2, typ: str = 'spin'):
img = Image.open(f'downloads/{filename}')
if typ.lower() != 'spin':
img = img.resize((random.randint(200, 1280), random.randint(200, 1280)), Image.ANTIALIAS)
imageio.mimsave(
"downloads/video.gif",
'downloads/video.gif',
[img.rotate(-(i % 360)) for i in range(1, 361, offset)],
fps=fps,
)
@@ -40,9 +38,7 @@ async def quote_cmd(client: Client, message: types.Message):
messages = []
async for msg in client.get_chat_history(
message.chat.id, offset_id=message.reply_to_message.id, reverse=True
):
async for msg in client.get_chat_history(message.chat.id, offset_id=message.reply_to_message.id, reverse=True):
if msg.empty:
continue
if msg.message_id >= message.id:
@@ -57,102 +53,86 @@ async def quote_cmd(client: Client, message: types.Message):
if send_for_me:
await message.delete()
message = await client.send_message(
"me", "<b>Generating...</b>", parse_mode=enums.ParseMode.HTML
)
message = await client.send_message('me', '<b>Generating...</b>', parse_mode=enums.ParseMode.HTML)
else:
await message.edit("<b>Generating...</b>", parse_mode=enums.ParseMode.HTML)
await message.edit('<b>Generating...</b>', parse_mode=enums.ParseMode.HTML)
url = "https://quotes.fl1yd.su/generate"
url = 'https://quotes.fl1yd.su/generate'
params = {
"messages": [
await render_message(client, msg) for msg in messages if not msg.empty
],
"quote_color": "#162330",
"text_color": "#fff",
'messages': [await render_message(client, msg) for msg in messages if not msg.empty],
'quote_color': '#162330',
'text_color': '#fff',
}
response = await aiohttp.ClientSession().post(url, json=params)
if response.status != 200:
return await message.edit(
f"<b>Quotes API error!</b>\n" f"<code>{response.text}</code>",
f'<b>Quotes API error!</b>\n<code>{response.text}</code>',
parse_mode=enums.ParseMode.HTML,
)
resized = resize_image(
BytesIO(await response.read()), img_type="PNG" if is_png else "WEBP"
)
resized = resize_image(BytesIO(await response.read()), img_type='PNG' if is_png else 'WEBP')
return resized, is_png
@Client.on_message(filters.command(["spin", "dspin"], prefix) & filters.me)
@Client.on_message(filters.command(['spin', 'dspin'], prefix) & filters.me)
async def spin_handler(client: Client, message: Message):
if not message.reply_to_message:
await message.edit(
"<b>Reply to a <i>message</i> to spin it!</b>",
'<b>Reply to a <i>message</i> to spin it!</b>',
parse_mode=enums.ParseMode.HTML,
)
await message.edit(
"<b>Downloading sticker...</b>", parse_mode=enums.ParseMode.HTML
)
return await message.edit(
"<b>Invalid file type!</b>", parse_mode=enums.ParseMode.HTML
)
await message.edit('<b>Downloading sticker...</b>', parse_mode=enums.ParseMode.HTML)
return await message.edit('<b>Invalid file type!</b>', parse_mode=enums.ParseMode.HTML)
try:
coro = True
if message.reply_to_message.document:
filename = message.reply_to_message.document.file_name
if (
not filename.endswith(".webp")
and not filename.endswith(".png")
and not filename.endswith(".jpg")
and not filename.endswith(".jpeg")
not filename.endswith('.webp')
and not filename.endswith('.png')
and not filename.endswith('.jpg')
and not filename.endswith('.jpeg')
):
return await message.edit(
"<b>Invalid file type!</b>", parse_mode=enums.ParseMode.HTML
)
return await message.edit('<b>Invalid file type!</b>', parse_mode=enums.ParseMode.HTML)
elif message.reply_to_message.sticker:
if message.reply_to_message.sticker.is_video:
return await message.edit(
"<b>Video stickers not allowed</b>", parse_mode=enums.ParseMode.HTML
)
filename = "sticker.webp"
return await message.edit('<b>Video stickers not allowed</b>', parse_mode=enums.ParseMode.HTML)
filename = 'sticker.webp'
elif message.reply_to_message.text:
result = await quote_cmd(client, message)
if result[1]:
filename = "sticker.png"
filename = 'sticker.png'
else:
filename = "sticker.webp"
open(f"downloads/" + filename, "wb").write(result[0].getbuffer())
filename = 'sticker.webp'
open('downloads/' + filename, 'wb').write(result[0].getbuffer())
coro = False
else:
filename = "photo.jpg"
filename = 'photo.jpg'
if coro:
await message.reply_to_message.download(f"downloads/{filename}")
await message.reply_to_message.download(f'downloads/{filename}')
except Exception as ex:
return await message.edit(
f"<b>Message can not be loaded:</b>\n<code>{format_exc(ex)}</code>",
f'<b>Message can not be loaded:</b>\n<code>{format_exc(ex)}</code>',
parse_mode=enums.ParseMode.HTML,
)
await message.edit("<b>Spinning...</b>", parse_mode=enums.ParseMode.HTML)
await message.edit('<b>Spinning...</b>', parse_mode=enums.ParseMode.HTML)
offset = int(message.command[1]) if len(message.command) > 1 else 10
fps = int(message.command[2]) if len(message.command) > 2 else 30
try:
loop = asyncio.get_event_loop()
await loop.run_in_executor(
None, lambda: create_gif(filename, offset, fps, message.command[0])
)
await loop.run_in_executor(None, lambda: create_gif(filename, offset, fps, message.command[0]))
await message.delete()
return await client.send_animation(
chat_id=message.chat.id,
animation="downloads/video.gif",
animation='downloads/video.gif',
reply_to_message_id=message.reply_to_message.id,
)
except Exception as e:
await message.reply(format_exc(e), parse_mode=enums.ParseMode.HTML)
modules_help["spin"] = {
"spin [offset] [fps]": "Spin message (Reply required)",
"dspin [offset] [fps]": "SHAKAL spin message (Reply required)",
modules_help['spin'] = {
'spin [offset] [fps]': 'Spin message (Reply required)',
'dspin [offset] [fps]': 'SHAKAL spin message (Reply required)',
}