disk6969

owner dialogs 2

Aug 5th, 2023 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. from pyrogram import Client
  2. from pyrogram.enums import ChatType
  3.  
  4. client = Client('session_name', api_id, api_hash)
  5.  
  6. async def get_owner_dialogs():
  7.   async for d in client.get_dialogs():
  8.     c = d.chat
  9.     if c.is_creator and c.type in {ChatType.GROUP, ChatType.SUPERGROUP}:
  10.       first = await client.get_messages(c.id, 1)
  11.       if first.empty:
  12.         oldest = await anext(
  13.           client.get_chat_history(c.id, limit=1, offset_id=1, offset=-1), None
  14.         )
  15.         if oldest:
  16.           first = oldest
  17.         else:
  18.           continue
  19.       if not first.date.year < 2023:
  20.         continue
  21.       if c.username:
  22.         link = f"https://t.me/{c.username}"
  23.       else:
  24.         link = (await client.get_chat(c.id)).invite_link
  25.       await client.send_message(
  26.         "me",
  27.         f"{c.title} | {first.date.year} | {c.type.value.lower()}\n\n{link}",
  28.         disable_web_page_preview=True,
  29.       )
  30.  
  31. client.start()
  32. client.run(get_owner_dialogs())
Add Comment
Please, Sign In to add comment