Advertisement
disk6969

Untitled

Jan 7th, 2024 (edited)
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.06 KB | None | 0 0
  1. from pyrogram import Client, filters
  2. from pyrogram.types import ReplyKeyboardRemove
  3. from pyrogram.utils import get_peer_id
  4.  
  5. from pyrogram.raw.functions.messages import SendMessage
  6. from pyrogram.raw.types import (
  7.   ReplyKeyboardMarkup,
  8.   KeyboardButtonRow as row,
  9.   KeyboardButtonRequestPeer as btn,
  10.   RequestPeerTypeBroadcast as broadcast,
  11.   RequestPeerTypeChat as group,
  12.   RequestPeerTypeUser as user,
  13.   UpdateNewMessage,
  14.   MessageService,
  15.   MessageActionRequestedPeer as action,
  16. )
  17.  
  18. @Client.on_message(filters.private & filters.command("start"))
  19. async def send_button(client, message):
  20.   reply_markup = ReplyKeyboardMarkup(
  21.     rows=[
  22.       row(
  23.         buttons=[
  24.           btn(text="Select Channel", button_id=1, peer_type=broadcast(), max_quantity=1),
  25.           btn(text="Select Group", button_id=2, peer_type=group(), max_quantity=1),
  26.         ]
  27.       ),
  28.       row(
  29.         buttons=[
  30.           btn(text="Select User", button_id=3, peer_type=user(bot=False), max_quantity=1),
  31.           btn(text="Select Bot", button_id=4, peer_type=user(bot=True), max_quantity=1),
  32.         ]
  33.       ),
  34.     ],
  35.     resize=True,
  36.   )
  37.   await client.invoke(
  38.     SendMessage(
  39.       peer=await client.resolve_peer(message.chat.id),
  40.       message="Pick a chat:",
  41.       reply_markup=reply_markup,
  42.       random_id=client.rnd_id(),
  43.     )
  44.   )
  45.  
  46. chat_types = {1: "channel", 2: "group", 3: "user", 4: "bot"}
  47.  
  48. @Client.on_raw_update()
  49. async def get_selected_chat(client, update, _, __):
  50.   if not isinstance(update, UpdateNewMessage):
  51.     return
  52.   if not isinstance(update.message, MessageService):
  53.     return
  54.   if not isinstance(update.message.action, action):
  55.     return
  56.  
  57.   from_user = get_peer_id(update.message.peer_id)
  58.   chat_id, msg_id = get_peer_id(update.message.action.peers[0]), update.message.id
  59.   type = chat_types.get(update.message.action.button_id)
  60.  
  61.   client.loop.create_task(client.delete_messages(from_user, msg_id))
  62.   await client.send_message(
  63.     from_user,
  64.     f"`You have shared a {type} with ID: {chat_id}`",
  65.     reply_markup=ReplyKeyboardRemove(),
  66.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement