telegraph.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Written by MaskedVirus | github.com/swatv3nub for William and SupMeta_bot
  2. # Kang with Proper Credits
  3. # Part of Pull Req #2 by @MaskedVirus | github.com/swatv3nub
  4. import os
  5. from pyrogram import filters
  6. from telegraph import upload_file
  7. from wbb import app
  8. from wbb.core.decorators.errors import capture_err
  9. __MODULE__ = "Telegraph"
  10. __HELP__ = """
  11. Paste Photo and Video to Telegraph
  12. Usage:
  13. /tgphoto - reply to a photo
  14. /tgvideo - reply to a Video
  15. """
  16. @app.on_message(filters.command("tgphoto"))
  17. @capture_err
  18. async def tgphoto(client, message):
  19. if not message.reply_to_message:
  20. await message.reply_text("Reply to a photo.")
  21. return
  22. if not message.reply_to_message.photo:
  23. await message.reply_text("Works only for Photos")
  24. return
  25. msg = await message.reply_text("`Uploading to Telegraph...`")
  26. userid = str(message.chat.id)
  27. path = f"./DOWNLOADS/{userid}.jpg"
  28. path = await client.download_media(
  29. message=message.reply_to_message, file_name=path
  30. )
  31. try:
  32. tlink = upload_file(path)
  33. except Exception:
  34. await msg.edit_text("Something went Wrong.")
  35. else:
  36. await msg.edit_text(
  37. f"Successfully Uploaded to [Telegraph](https://telegra.ph{tlink[0]})"
  38. )
  39. os.remove(path)
  40. @app.on_message(filters.command("tgvideo"))
  41. @capture_err
  42. async def tgvideo(client, message):
  43. if not message.reply_to_message:
  44. await message.reply_text("Reply to a Video.")
  45. return
  46. if not message.reply_to_message.video:
  47. await message.reply_text("Works only for Videos")
  48. return
  49. if message.reply_to_message.video.file_size < 5242880:
  50. msg = await message.reply_text("Uploading to Telegraph...")
  51. userid = str(message.chat.id)
  52. vid_path = f"./DOWNLOADS/{userid}.mp4"
  53. vid_path = await client.download_media(
  54. message=message.reply_to_message, file_name=vid_path
  55. )
  56. try:
  57. tlink = upload_file(vid_path)
  58. await msg.edit_text(
  59. f"Successfully Uploaded to [Telegraph](https://telegra.ph{tlink[0]})"
  60. )
  61. os.remove(vid_path)
  62. except Exception:
  63. await msg.edit_text("Something went Wrong.")
  64. else:
  65. await message.reply_text("Size Should Be Less Than 5 mb")