MissKatyPyro/misskaty/plugins/webss.py
deepsource-autofix[bot] 0dbab68a39
Format code with black and isort (#9)
This commit fixes the style issues introduced in 95ecce1 according to the output
from black and isort.

Details: https://deepsource.io/gh/yasirarism/MissKatyPyro/transform/2b5c318f-57d7-4419-8e76-1d6c31d72999/

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2023-01-10 20:20:35 +07:00

41 lines
1.3 KiB
Python

import base64
import os
from asyncio import gather
from io import BytesIO
from PIL import Image
from pyrogram import filters
from misskaty import app
from misskaty.core.decorator.errors import capture_err
from misskaty.helper.http import http
from misskaty.vars import COMMAND_HANDLER
__MODULE__ = "WebSS"
__HELP__ = """
/webss [URL] - Take A Screenshot Of A Webpage.
"""
@app.on_message(filters.command(["webss"], COMMAND_HANDLER))
@capture_err
async def take_ss(_, message):
if len(message.command) == 1:
return await message.reply("Give A Url To Fetch Screenshot.")
url = (
message.command[1]
if message.command[1].startswith("http")
else f"https://{message.command[1]}"
)
filename = f"imageToSave_{message.from_user.id}.png"
m = await message.reply("Capturing screenshot...")
try:
photo = (await http.get(f"https://yasirapi.eu.org/webss?url={url}")).json()
img = Image.open(BytesIO(base64.decodebytes(bytes(photo["result"], "utf-8"))))
img.save(filename)
m = await m.edit("Uploading...")
await gather(*[message.reply_document(filename), message.reply_photo(filename)])
await m.delete()
os.remove(filename)
except Exception as e:
await m.edit(f"Failed To Take Screenshot. {str(e)}")