telegraph.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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, Client
  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.photo:
  20. await message.reply_text("Works only for Photos")
  21. return
  22. msg = await message.reply_text("`Uploading to Telegraph...`")
  23. userid = str(message.chat.id)
  24. path = (f"./DOWNLOADS/{userid}.jpg")
  25. path = await client.download_media(message=message.reply_to_message, file_name=path)
  26. try:
  27. tlink = upload_file(path)
  28. except:
  29. await msg.edit_text("Something went Wrong.")
  30. else:
  31. await msg.edit_text(f"Successfully Uploaded to [Telegraph](https://telegra.ph{tlink[0]})")
  32. os.remove(path)
  33. @app.on_message(filters.command("tgvideo"))
  34. @capture_err
  35. async def tgvideo(client, message):
  36. if not message.reply_to_message.video:
  37. await message.reply_text("Works only for Videos")
  38. return
  39. if(message.video.file_size < 5242880):
  40. msg = await message.reply_text("Uploading to Telegraph...")
  41. userid = str(message.chat.id)
  42. vid_path = (f"./DOWNLOADS/{userid}.mp4")
  43. vid_path = await client.download_media(message=message.reply_to_message, file_name=vid_path)
  44. try:
  45. tlink = upload_file(vid_path)
  46. await msg.edit_text(f"Successfully Uploaded to [Telegraph](https://telegra.ph{tlink[0]})")
  47. os.remove(vid_path)
  48. except:
  49. await msg.edit_text("Something went Wrong.")
  50. else:
  51. await message.reply_text("Size Should Be Less Than 5 mb")