| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- """
- MIT License
- Copyright (c) 2023 TheHamkerCat
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
- """
- from asyncio import gather
- from base64 import b64decode
- from io import BytesIO
- from pyrogram import filters
- from pyrogram.types import Message
- from wbb import SUDOERS, USERBOT_PREFIX, app, app2, eor
- from wbb.core.decorators.errors import capture_err
- from wbb.utils.http import post
- async def take_screenshot(url: str, full: bool = False):
- url = "https://" + url if not url.startswith("http") else url
- payload = {
- "url": url,
- "width": 1920,
- "height": 1080,
- "scale": 1,
- "format": "jpeg",
- }
- if full:
- payload["full"] = True
- data = await post(
- "https://webscreenshot.vercel.app/api",
- data=payload,
- )
- if "image" not in data:
- return None
- b = data["image"].replace("data:image/jpeg;base64,", "")
- file = BytesIO(b64decode(b))
- file.name = "webss.jpg"
- return file
- @app2.on_message(filters.command("webss", USERBOT_PREFIX) & SUDOERS)
- @app.on_message(filters.command("webss"))
- @capture_err
- async def take_ss(_, message: Message):
- if len(message.command) < 2:
- return await eor(message, text="Give A Url To Fetch Screenshot.")
- if len(message.command) == 2:
- url = message.text.split(None, 1)[1]
- full = False
- elif len(message.command) == 3:
- url = message.text.split(None, 2)[1]
- full = message.text.split(None, 2)[2].lower().strip() in [
- "yes",
- "y",
- "1",
- "true",
- ]
- else:
- return await eor(message, text="Invalid Command.")
- m = await eor(message, text="Capturing screenshot...")
- try:
- photo = await take_screenshot(url, full)
- if not photo:
- return await m.edit("Failed To Take Screenshot")
- m = await m.edit("Uploading...")
- if not full:
- # Full size images have problem with reply_photo, that's why
- # we need to only use reply_photo if we're not using full size
- await gather(*[message.reply_document(photo), message.reply_photo(photo)])
- else:
- await message.reply_document(photo)
- await m.delete()
- except Exception as e:
- await m.edit(str(e))
|