parse_preview.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. from asyncio import sleep
  2. from pyrogram import filters
  3. from pyrogram.types import Message
  4. from wbb import SUDOERS, USERBOT_PREFIX, app2, eor
  5. from wbb.core.sections import section
  6. @app2.on_message(
  7. filters.command("parse_preview", prefixes=USERBOT_PREFIX)
  8. & filters.user(SUDOERS),
  9. )
  10. async def parse(_, message: Message):
  11. r = message.reply_to_message
  12. has_wpp = False
  13. m_ = await eor(message, text="Parsing...")
  14. if not r:
  15. return await m_.edit("Reply to a message with a webpage")
  16. if not r.web_page:
  17. text = r.text or r.caption
  18. if text:
  19. m = await app2.send_message("me", text)
  20. await sleep(1)
  21. await m.delete()
  22. if m.web_page:
  23. r = m
  24. has_wpp = True
  25. else:
  26. has_wpp = True
  27. if not has_wpp:
  28. return await m_.edit(
  29. "Replied message has no webpage preview.",
  30. )
  31. wpp = r.web_page
  32. body = {
  33. "Title": [wpp.title or "Null"],
  34. "Description": [
  35. (wpp.description[:50] + "...") if wpp.description else "Null"
  36. ],
  37. "URL": [wpp.display_url or "Null"],
  38. "Author": [wpp.author or "Null"],
  39. "Site Name": [wpp.site_name or "Null"],
  40. "Type": wpp.type or "Null",
  41. }
  42. text = section("Preview", body)
  43. t = wpp.type
  44. if t == "photo":
  45. media = wpp.photo
  46. func = app2.send_photo
  47. elif t == "audio":
  48. media = wpp.audio
  49. func = app2.send_audio
  50. elif t == "video":
  51. media = wpp.video
  52. func = app2.send_video
  53. elif t == "document":
  54. media = wpp.document
  55. func = app2.send_document
  56. else:
  57. media = None
  58. func = None
  59. if media and func:
  60. await m_.delete()
  61. return await func(
  62. m_.chat.id,
  63. media.file_id,
  64. caption=text,
  65. )
  66. await m_.edit(text, disable_web_page_preview=True)