telegraph.py 2.2 KB

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