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)