webss.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. """
  2. MIT License
  3. Copyright (c) 2024 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. from asyncio import gather
  21. from base64 import b64decode
  22. from io import BytesIO
  23. from pyrogram import filters
  24. from pyrogram.types import Message
  25. from wbb import SUDOERS, USERBOT_PREFIX, app, app2, eor
  26. from wbb.core.decorators.errors import capture_err
  27. from wbb.utils.http import post
  28. async def take_screenshot(url: str, full: bool = False):
  29. url = "https://" + url if not url.startswith("http") else url
  30. payload = {
  31. "url": url,
  32. "width": 1920,
  33. "height": 1080,
  34. "scale": 1,
  35. "format": "jpeg",
  36. }
  37. if full:
  38. payload["full"] = True
  39. data = await post(
  40. "https://webscreenshot.vercel.app/api",
  41. data=payload,
  42. )
  43. if "image" not in data:
  44. return None
  45. b = data["image"].replace("data:image/jpeg;base64,", "")
  46. file = BytesIO(b64decode(b))
  47. file.name = "webss.jpg"
  48. return file
  49. @app2.on_message(
  50. filters.command("webss", USERBOT_PREFIX)
  51. & ~filters.forwarded
  52. & ~filters.via_bot
  53. & SUDOERS
  54. )
  55. @app.on_message(filters.command("webss"))
  56. @capture_err
  57. async def take_ss(_, message: Message):
  58. if len(message.command) < 2:
  59. return await eor(message, text="Give A Url To Fetch Screenshot.")
  60. if len(message.command) == 2:
  61. url = message.text.split(None, 1)[1]
  62. full = False
  63. elif len(message.command) == 3:
  64. url = message.text.split(None, 2)[1]
  65. full = message.text.split(None, 2)[2].lower().strip() in [
  66. "yes",
  67. "y",
  68. "1",
  69. "true",
  70. ]
  71. else:
  72. return await eor(message, text="Invalid Command.")
  73. m = await eor(message, text="Capturing screenshot...")
  74. try:
  75. photo = await take_screenshot(url, full)
  76. if not photo:
  77. return await m.edit("Failed To Take Screenshot")
  78. m = await m.edit("Uploading...")
  79. if not full:
  80. # Full size images have problem with reply_photo, that's why
  81. # we need to only use reply_photo if we're not using full size
  82. await gather(
  83. *[message.reply_document(photo), message.reply_photo(photo)]
  84. )
  85. else:
  86. await message.reply_document(photo)
  87. await m.delete()
  88. except Exception as e:
  89. await m.edit(str(e))