taslim19
commited on
Commit
·
95ec5e4
1
Parent(s):
398389e
feat: Add /id command to get user and group IDs
Browse files
DragMusic/plugins/management/id.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyrogram import filters
|
2 |
+
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
3 |
+
from DragMusic import app
|
4 |
+
|
5 |
+
@app.on_message(filters.command("id") & filters.group)
|
6 |
+
async def id_handler(client, message: Message):
|
7 |
+
group_id = message.chat.id
|
8 |
+
user = None
|
9 |
+
show_group_id = False
|
10 |
+
|
11 |
+
# Case 1: If replied to a user
|
12 |
+
if message.reply_to_message and message.reply_to_message.from_user:
|
13 |
+
user = message.reply_to_message.from_user
|
14 |
+
|
15 |
+
# Case 2: If mentioned user with @username
|
16 |
+
elif len(message.command) > 1:
|
17 |
+
username = message.command[1].replace("@", "")
|
18 |
+
try:
|
19 |
+
user = await client.get_users(username)
|
20 |
+
except Exception:
|
21 |
+
return await message.reply_text("❌ Invalid username or user not found.")
|
22 |
+
|
23 |
+
# Case 3: Just /id → show self and group ID
|
24 |
+
else:
|
25 |
+
user = message.from_user
|
26 |
+
show_group_id = True
|
27 |
+
|
28 |
+
user_id = user.id
|
29 |
+
name = user.first_name or "Unknown"
|
30 |
+
|
31 |
+
# Prepare text and buttons
|
32 |
+
if show_group_id:
|
33 |
+
text = (
|
34 |
+
f"User: {name}\\n"
|
35 |
+
f"User ID: {user_id}\\n"
|
36 |
+
f"Group ID: {group_id}"
|
37 |
+
)
|
38 |
+
buttons = [
|
39 |
+
[
|
40 |
+
InlineKeyboardButton("Copy User ID", switch_inline_query=str(user_id)),
|
41 |
+
InlineKeyboardButton("Copy Group ID", switch_inline_query=str(group_id)),
|
42 |
+
]
|
43 |
+
]
|
44 |
+
else:
|
45 |
+
text = f"User: {name}\\nUser ID: {user_id}"
|
46 |
+
buttons = [[InlineKeyboardButton("Copy User ID", switch_inline_query=str(user_id))]]
|
47 |
+
|
48 |
+
await message.reply_text(text, reply_markup=InlineKeyboardMarkup(buttons))
|