telegraph.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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(message=message.reply_to_message, file_name=path)
  29. try:
  30. tlink = upload_file(path)
  31. except Exception:
  32. await msg.edit_text("Something went Wrong.")
  33. else:
  34. await msg.edit_text(
  35. f"Successfully Uploaded to [Telegraph](https://telegra.ph{tlink[0]})"
  36. )
  37. os.remove(path)
  38. @app.on_message(filters.command("tgvideo"))
  39. @capture_err
  40. async def tgvideo(client, message):
  41. if not message.reply_to_message:
  42. await message.reply_text("Reply to a Video.")
  43. return
  44. if not message.reply_to_message.video:
  45. await message.reply_text("Works only for Videos")
  46. return
  47. if message.video.file_size < 5242880:
  48. msg = await message.reply_text("Uploading to Telegraph...")
  49. userid = str(message.chat.id)
  50. vid_path = f"./DOWNLOADS/{userid}.mp4"
  51. vid_path = await client.download_media(
  52. message=message.reply_to_message, file_name=vid_path
  53. )
  54. try:
  55. tlink = upload_file(vid_path)
  56. await msg.edit_text(
  57. f"Successfully Uploaded to [Telegraph](https://telegra.ph{tlink[0]})"
  58. )
  59. os.remove(vid_path)
  60. except Exception:
  61. await msg.edit_text("Something went Wrong.")
  62. else:
  63. await message.reply_text("Size Should Be Less Than 5 mb")