taslim19
fix: Allow owner to use invitelink command and add debug logging
56b2d03
from DragMusic import app
from pyrogram import Client, filters
from pyrogram.errors import ChatIdInvalid
from pyrogram.errors import ChatAdminRequired, ChatNotModified, ChatIdInvalid, FloodWait, InviteHashExpired, UserNotParticipant
import os
import json
from pyrogram.types import Message
from DragMusic.misc import SUDOERS
from config import OWNER_ID
# Command handler for /givelink command
@app.on_message(filters.command("givelink"))
async def give_link_command(client, message):
# Generate an invite link for the chat where the command is used
chat = message.chat.id
link = await app.export_chat_invite_link(chat)
await message.reply_text(f"Here's the invite link for this chat:\n{link}")
@app.on_message(filters.command(["link", "invitelink"], prefixes=["/", "!", "%", ",", "", ".", "@", "#"]) & (SUDOERS | filters.user(OWNER_ID)))
async def link_command_handler(client: Client, message: Message):
print(f"Link command triggered by user {message.from_user.id}")
print(f"User is in SUDOERS: {message.from_user.id in SUDOERS}")
print(f"User is OWNER_ID: {message.from_user.id == OWNER_ID}")
if len(message.command) != 2:
await message.reply("Invalid usage. Correct format: /link group_id")
return
group_id = message.command[1]
file_name = f"group_info_{group_id}.txt"
try:
chat = await client.get_chat(int(group_id))
if chat is None:
await message.reply("Unable to get information for the specified group ID.")
return
try:
invite_link = await client.export_chat_invite_link(chat.id)
except FloodWait as e:
await message.reply(f"FloodWait: {e.x} seconds. Retrying in {e.x} seconds.")
return
group_data = {
"id": chat.id,
"type": str(chat.type),
"title": chat.title,
"members_count": chat.members_count,
"description": chat.description,
"invite_link": invite_link,
"is_verified": chat.is_verified,
"is_restricted": chat.is_restricted,
"is_creator": chat.is_creator,
"is_scam": chat.is_scam,
"is_fake": chat.is_fake,
"dc_id": chat.dc_id,
"has_protected_content": chat.has_protected_content,
}
with open(file_name, "w", encoding="utf-8") as file:
for key, value in group_data.items():
file.write(f"{key}: {value}\n")
await client.send_document(
chat_id=message.chat.id,
document=file_name,
caption=f"๐˜๐˜ฆ๐˜ณ๐˜ฆ ๐˜๐˜ด ๐˜ต๐˜ฉ๐˜ฆ ๐˜๐˜ฏ๐˜ง๐˜ฐ๐˜ณ๐˜ฎ๐˜ข๐˜ต๐˜ช๐˜ฐ๐˜ฏ ๐˜๐˜ฐ๐˜ณ\n{chat.title}\n๐˜›๐˜ฉ๐˜ฆ ๐˜Ž๐˜ณ๐˜ฐ๐˜ถ๐˜ฑ ๐˜๐˜ฏ๐˜ง๐˜ฐ๐˜ณ๐˜ฎ๐˜ข๐˜ต๐˜ช๐˜ฐ๐˜ฏ ๐˜š๐˜ค๐˜ณ๐˜ข๐˜ฑ๐˜ฆ๐˜ฅ ๐˜‰๐˜บ : @{app.username}"
)
except Exception as e:
await message.reply(f"Error: {str(e)}")
finally:
if os.path.exists(file_name):
os.remove(file_name)