-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgetanyid.py
59 lines (42 loc) · 2.52 KB
/
getanyid.py
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
#Copyright ©️ 2022 TeLe TiPs. All Rights Reserved
#You are free to use this code in any of your project, but you MUST include the following in your README.md (Copy & paste)
# ##Credits - [GetAnyID bot by TeLe TiPs] (https://github.com/teletips/GetAnyID-TeLeTiPs)
from pyrogram import Client, filters
from pyrogram.types import Message
import os
GetAnyIDBot=Client(
"GetAnyIDBot",
api_id = int(os.environ["API_ID"]),
api_hash = os.environ["API_HASH"],
bot_token = os.environ["BOT_TOKEN"]
)
@GetAnyIDBot.on_message(filters.command('start') & filters.private)
async def start(client, message):
text = f"""
Heya {message.from_user.mention},
I am here to provide Telegram user and chat ID.
To get ID, simply send the command <code>/id</code> directly to any chat or send it as a reply to any message.
I can also work in group chats.
🏠 | [Home](https://t.me/teletipsofficialchannel)
"""
await GetAnyIDBot.send_message(message.chat.id, text, disable_web_page_preview=True)
@GetAnyIDBot.on_message(filters.command('id'))
async def get_id(client, message):
try:
if (not message.reply_to_message) and (message.chat):
await message.reply(f"User {message.from_user.first_name}'s ID is <code>{message.from_user.id }</code>.\nThis chat's ID is: <code>{message.chat.id}</code>.")
elif not message.reply_to_message:
await message.reply(f"User {message.from_user.first_name}'s ID is <code>{message.from_user.id }</code>.")
elif message.reply_to_message.forward_from_chat:
await message.reply(f"The forwarded {str(message.reply_to_message.forward_from_chat.type)[9:].lower()}, {message.reply_to_message.forward_from_chat.title} has an ID of <code>{message.reply_to_message.forward_from_chat.id}</code>.")
elif message.reply_to_message.forward_from:
await message.reply(f"The forwarded user, {message.reply_to_message.forward_from.first_name} has an ID of <code>{message.reply_to_message.forward_from.id }</code>.")
elif message.reply_to_message.forward_sender_name:
await message.reply("Sorry, you cannot get the forwarded user ID because of their privacy settings")
else:
await message.reply(f"User {message.reply_to_message.from_user.first_name}'s ID is <code>{message.reply_to_message.from_user.id}</code>.")
except Exception:
await message.reply("An error occured while getting the ID.")
print("GetAnyIDBot is alive!")
GetAnyIDBot.run()
#Copyright ©️ 2022 TeLe TiPs. All Rights Reserved