Bot / demoo.py
warmifans's picture
Rename bot.py to demoo.py
3af05df verified
Raw
History Blame Contribute Delete
4.96 kB
from pyrogram import Client, filters
from pyrogram.types import (
InlineKeyboardMarkup,
InlineKeyboardButton,
ReplyKeyboardMarkup,
KeyboardButton
)
API_ID = 32346503
API_HASH = "391c63b5936e4e717fc7fa19221651de"
BOT_TOKEN = "8966602774:AAFDK_woLHYGpSPxKimun5WUlCwGwpTFFZM"
app = Client("shakti_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
forward_button = ReplyKeyboardMarkup(
[[KeyboardButton("πŸ“¨ Forward Message")]], resize_keyboard=True
)
@app.on_message(filters.command("start"))
async def start(client, message):
user_id = message.from_user.id
text = f"""Hi Welcome To @User1nfo_bot πŸ‘‹
πŸ“š Help : /help
πŸ”” Channel : @iesrl
Your ID : {user_id}"""
buttons = InlineKeyboardMarkup([
[InlineKeyboardButton(f"πŸ“‹ Copy {user_id}", callback_data=f"copy_{user_id}")],
[InlineKeyboardButton("πŸš€ Share ID", switch_inline_query=str(user_id))]
])
await message.reply_text(text, reply_markup=buttons)
await message.reply_text("Tap below button to forward any message:", reply_markup=forward_button)
@app.on_message(filters.command("help"))
async def help_cmd(client, message):
await message.reply_text(
"""πŸ“š HOW TO USE
1️⃣ Tap "Forward Message" button
2️⃣ Forward any message from any user/chat
3️⃣ Bot will show original sender's ID
πŸ”Έ Channel : @iesrl
πŸ”Έ Developer : @dmForbans"""
)
@app.on_message(filters.command("info") & filters.group)
async def info_cmd(client, message):
# Case 1: with username
if len(message.text.split()) > 1:
username = message.text.split(" ", 1)[1]
if username.startswith("@"):
username = username[1:]
try:
user = await client.get_users(username)
user_link = f"https://t.me/{user.username}" if user.username else f"tg://user?id={user.id}"
text = f"""πŸ‘€ User Info
ID: {user.id}
First Name: {user.first_name or '.'}
Last Name: {user.last_name or ''}
Username: @{user.username or 'None'}
πŸ”— User Link: [link]({user_link})"""
await message.reply_text(text, disable_web_page_preview=False) # No parse_mode
return
except Exception as e:
await message.reply_text(f"❌ User not found. Error: {str(e)}")
return
# Case 2: own info
user = message.from_user
user_link = f"https://t.me/{user.username}" if user.username else f"tg://user?id={user.id}"
text = f"""πŸ‘€ π™π™¨π™šπ™§ 𝙄𝙣𝙛𝙀
π™„π˜Ώ: {user.id}
π™π™žπ™§π™¨π™© π™‰π™–π™’π™š: {user.first_name or '.'}
𝙇𝙖𝙨𝙩 π™‰π™–π™’π™š: {user.last_name or ''}
π™π™¨π™šπ™§π™£π™–π™’π™š: @{user.username or 'None'}
πŸ”— User Link: [link]({user_link})"""
await message.reply_text(text, disable_web_page_preview=False)
# Forward handling (same as before)
@app.on_message(filters.text & filters.regex("πŸ“¨ Forward Message"))
async def forward_instruction(client, message):
await message.reply_text(
"πŸ”„ Now forward any message to me\n\n"
"Go to any chat β†’ Press & hold a message β†’ Forward β†’ Select me"
)
@app.on_message(filters.forwarded)
async def get_user_id(client, message):
try:
if message.forward_from:
user = message.forward_from
text = f"""πŸ”Έ Forward detected!
User
π™„π˜Ώ: {user.id}
π™‰π™–π™’π™š: {user.first_name or '.'} {user.last_name or ''}
π™π™¨π™šπ™§π™£π™–π™’π™š: @{user.username if user.username else 'None'}"""
buttons = InlineKeyboardMarkup([
[InlineKeyboardButton(f"πŸ“‹ Copy {user.id}", callback_data=f"copy_{user.id}")],
[InlineKeyboardButton("πŸš€ Share ID", switch_inline_query=str(user.id))]
])
await message.reply_text(text, reply_markup=buttons)
elif message.forward_from_chat:
chat = message.forward_from_chat
text = f"""πŸ”Έ Forward detected!
πŸ“’ Chat/Channel
πŸ†” ID: {chat.id}
πŸ“ Title: {chat.title}
πŸ”— Username: @{chat.username if chat.username else 'None'}"""
buttons = InlineKeyboardMarkup([
[InlineKeyboardButton(f"πŸ“‹ Copy {chat.id}", callback_data=f"copy_{chat.id}")],
[InlineKeyboardButton("πŸš€ Share ID", switch_inline_query=str(chat.id))]
])
await message.reply_text(text, reply_markup=buttons)
except Exception as e:
await message.reply_text(f"❌ Error: {str(e)}")
@app.on_callback_query()
async def handle_callback(client, callback_query):
if callback_query.data.startswith("copy_"):
user_id = callback_query.data.replace("copy_", "")
await callback_query.answer(f"Copied: {user_id}", show_alert=True)
await callback_query.message.edit_text(
callback_query.message.text + f"\n\nβœ… Copied: {user_id}"
)
if __name__ == "__main__":
print("βœ… Bot Started Successfully!")
app.run()