Advertisement
disk6969

owner dialogs + @year

Aug 5th, 2023 (edited)
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 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 and not oldest.empty: first = oldest
  16.         else: continue
  17.       if not first.date.year < 2023: continue
  18.       if c.username:
  19.         link = f"https://t.me/{c.username}"
  20.       else:
  21.         link = (await client.get_chat(c.id)).invite_link
  22.       await client.send_message(
  23.         "me",
  24.         f"{c.title} | {first.date.year} | {c.type.value.lower()}\n\n{link}",
  25.         disable_web_page_preview=True,
  26.       )
  27.  
  28. client.start()
  29. client.run(get_owner_dialogs())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement