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:
+33
-38
@@ -1,65 +1,60 @@
|
||||
import asyncio
|
||||
import os
|
||||
from collections import defaultdict
|
||||
|
||||
from pyrogram import Client, filters
|
||||
from pyrogram.errors import (
|
||||
FileReferenceExpired,
|
||||
FileReferenceInvalid,
|
||||
TopicDeleted,
|
||||
TopicClosed,
|
||||
TopicDeleted,
|
||||
)
|
||||
from pyrogram.types import Message
|
||||
from collections import defaultdict
|
||||
|
||||
from utils.db import db
|
||||
from utils.misc import modules_help, prefix
|
||||
|
||||
mlog_enabled = filters.create(lambda _, __, ___: db.get("custom.mlog", "status", False))
|
||||
mlog_enabled = filters.create(lambda _, __, ___: db.get('custom.mlog', 'status', False))
|
||||
|
||||
# Media cache and processing tasks
|
||||
user_media_cache = defaultdict(list)
|
||||
media_processing_tasks = {}
|
||||
|
||||
|
||||
# Helper to get group-specific data
|
||||
def get_group_data(group_id):
|
||||
return db.get(f"custom.mlog", str(group_id), {})
|
||||
return db.get('custom.mlog', str(group_id), {})
|
||||
|
||||
|
||||
# Helper to update group-specific data
|
||||
def update_group_data(group_id, data):
|
||||
db.set(f"custom.mlog", str(group_id), data)
|
||||
db.set('custom.mlog', str(group_id), data)
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["mlog"], prefix) & filters.me)
|
||||
@Client.on_message(filters.command(['mlog'], prefix) & filters.me)
|
||||
async def mlog(_, message: Message):
|
||||
if len(message.command) < 2 or message.command[1].lower() not in ["on", "off"]:
|
||||
return await message.edit(f"<b>Usage:</b> <code>{prefix}mlog [on/off]</code>")
|
||||
if len(message.command) < 2 or message.command[1].lower() not in ['on', 'off']:
|
||||
return await message.edit(f'<b>Usage:</b> <code>{prefix}mlog [on/off]</code>')
|
||||
|
||||
status = message.command[1].lower() == "on"
|
||||
db.set("custom.mlog", "status", status)
|
||||
await message.edit(f"<b>Media logging is now {'enabled' if status else 'disabled'}</b>")
|
||||
status = message.command[1].lower() == 'on'
|
||||
db.set('custom.mlog', 'status', status)
|
||||
await message.edit(f'<b>Media logging is now {"enabled" if status else "disabled"}</b>')
|
||||
|
||||
|
||||
@Client.on_message(filters.command(["msetchat"], prefix) & filters.me)
|
||||
@Client.on_message(filters.command(['msetchat'], prefix) & filters.me)
|
||||
async def set_chat(_, message: Message):
|
||||
if len(message.command) < 2:
|
||||
return await message.edit(f"<b>Usage:</b> <code>{prefix}msetchat [chat_id]</code>")
|
||||
return await message.edit(f'<b>Usage:</b> <code>{prefix}msetchat [chat_id]</code>')
|
||||
|
||||
try:
|
||||
chat_id = message.command[1]
|
||||
chat_id = int("-100" + chat_id if not chat_id.startswith("-100") else chat_id)
|
||||
db.set("custom.mlog", "chat", chat_id)
|
||||
await message.edit(f"<b>Chat ID set to {chat_id}</b>")
|
||||
chat_id = int('-100' + chat_id if not chat_id.startswith('-100') else chat_id)
|
||||
db.set('custom.mlog', 'chat', chat_id)
|
||||
await message.edit(f'<b>Chat ID set to {chat_id}</b>')
|
||||
except ValueError:
|
||||
await message.edit("<b>Invalid chat ID</b>")
|
||||
await message.edit('<b>Invalid chat ID</b>')
|
||||
|
||||
|
||||
@Client.on_message(
|
||||
mlog_enabled
|
||||
& filters.incoming
|
||||
& filters.private
|
||||
& filters.media
|
||||
& ~filters.me
|
||||
& ~filters.bot
|
||||
)
|
||||
@Client.on_message(mlog_enabled & filters.incoming & filters.private & filters.media & ~filters.me & ~filters.bot)
|
||||
async def media_log(client: Client, message: Message):
|
||||
user_id = message.from_user.id
|
||||
user_media_cache[user_id].append(message)
|
||||
@@ -76,26 +71,26 @@ async def process_media(client: Client, user):
|
||||
if user_id == me.id:
|
||||
return
|
||||
|
||||
chat_id = db.get("custom.mlog", "chat")
|
||||
chat_id = db.get('custom.mlog', 'chat')
|
||||
if not chat_id:
|
||||
return await client.send_message(
|
||||
"me",
|
||||
f"Media Logger is on, but no Chat ID is set. Use {prefix}msetchat to set it.",
|
||||
'me',
|
||||
f'Media Logger is on, but no Chat ID is set. Use {prefix}msetchat to set it.',
|
||||
)
|
||||
|
||||
group_data = get_group_data(chat_id)
|
||||
user_topics = group_data.get("user_topics", {})
|
||||
user_topics = group_data.get('user_topics', {})
|
||||
topic_id = user_topics.get(str(user_id)) # Fetch user's topic ID if it exists
|
||||
|
||||
if not topic_id:
|
||||
topic = await client.create_forum_topic(chat_id, user.first_name)
|
||||
topic_id = topic.id
|
||||
user_topics[str(user_id)] = topic_id # Store topic ID for this user
|
||||
update_group_data(chat_id, {"user_topics": user_topics})
|
||||
update_group_data(chat_id, {'user_topics': user_topics})
|
||||
m = await client.send_message(
|
||||
chat_id=chat_id,
|
||||
message_thread_id=topic_id,
|
||||
text=f"<b>Chat Name:</b> {user.full_name}\n<b>User ID:</b> {user_id}\n<b>Username:</b> @{user.username or 'N/A'}\n<b>Phone No:</b> +{user.phone_number or 'N/A'}",
|
||||
text=f'<b>Chat Name:</b> {user.full_name}\n<b>User ID:</b> {user_id}\n<b>Username:</b> @{user.username or "N/A"}\n<b>Phone No:</b> +{user.phone_number or "N/A"}',
|
||||
)
|
||||
await m.pin()
|
||||
|
||||
@@ -111,11 +106,11 @@ async def process_media(client: Client, user):
|
||||
topic = await client.create_forum_topic(chat_id, user.first_name)
|
||||
topic_id = topic.id
|
||||
user_topics[str(user_id)] = topic_id # Update the new topic ID
|
||||
update_group_data(chat_id, {"user_topics": user_topics})
|
||||
update_group_data(chat_id, {'user_topics': user_topics})
|
||||
await client.send_message(
|
||||
chat_id=chat_id,
|
||||
message_thread_id=topic_id,
|
||||
text=f"<b>Chat Name:</b> {user.full_name}\n<b>User ID:</b> {user_id}\n<b>Username:</b> @{user.username or 'N/A'}\n<b>Phone No:</b> +{user.phone_number or 'N/A'}",
|
||||
text=f'<b>Chat Name:</b> {user.full_name}\n<b>User ID:</b> {user_id}\n<b>Username:</b> @{user.username or "N/A"}\n<b>Phone No:</b> +{user.phone_number or "N/A"}',
|
||||
)
|
||||
await handle_self_destruct_media(client, media_message, chat_id, topic_id)
|
||||
except TopicClosed:
|
||||
@@ -135,10 +130,10 @@ async def handle_self_destruct_media(client: Client, message: Message, chat_id:
|
||||
await client.send_video(chat_id, file_path, message_thread_id=topic_id)
|
||||
os.remove(file_path) # Clean up after sending
|
||||
except Exception as e:
|
||||
print(f"Error handling self-destructing media: {e}")
|
||||
print(f'Error handling self-destructing media: {e}')
|
||||
|
||||
|
||||
modules_help["mlog"] = {
|
||||
"mlog [on/off]": "Enable or disable media logging",
|
||||
"msetchat [chat_id]": "Set the chat ID for media logging",
|
||||
modules_help['mlog'] = {
|
||||
'mlog [on/off]': 'Enable or disable media logging',
|
||||
'msetchat [chat_id]': 'Set the chat ID for media logging',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user