telegraph.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. return await message.reply_text("Reply to a photo.")
  21. if not message.reply_to_message.photo:
  22. return await message.reply_text("Works only for Photos")
  23. msg = await message.reply_text("`Uploading to Telegraph...`")
  24. userid = str(message.chat.id)
  25. path = f"./DOWNLOADS/{userid}.jpg"
  26. path = await client.download_media(
  27. message=message.reply_to_message, file_name=path
  28. )
  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. return await message.reply_text("Reply to a Video.")
  43. if not message.reply_to_message.video:
  44. return await message.reply_text("Works only for Videos")
  45. if message.reply_to_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(
  50. message=message.reply_to_message, file_name=vid_path
  51. )
  52. try:
  53. tlink = upload_file(vid_path)
  54. await msg.edit_text(
  55. f"Successfully Uploaded to [Telegraph](https://telegra.ph{tlink[0]})"
  56. )
  57. os.remove(vid_path)
  58. except Exception:
  59. await msg.edit_text("Something went Wrong.")
  60. else:
  61. await message.reply_text("Size Should Be Less Than 5 mb")