File size: 3,040 Bytes
a8e9b84 56b2d03 a8e9b84 56b2d03 a8e9b84 56b2d03 a8e9b84 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
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)
|