MissKatyPyro/misskaty/plugins/webss.py
yasirarism a7008c664e
Reformat using black (#120)
* ci: Update .deepsource.toml

* ci: Update .deepsource.toml

* style: format code with black and isort

Format code with black and isort

This commit fixes the style issues introduced in 0fb651a according to the output
from Black and isort.

Details: https://app.deepsource.com/gh/yasirarism/MissKatyPyro/transform/d8f2f66e-b496-4686-aca6-9830236eda12/

---------

Co-authored-by: deepsource-io[bot] <42547082+deepsource-io[bot]@users.noreply.github.com>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2023-06-27 11:07:42 +07:00

51 lines
1.7 KiB
Python

# * @author Yasir Aris M <yasiramunandar@gmail.com>
# * @date 2023-06-21 22:12:27
# * @projectName MissKatyPyro
# * Copyright ©YasirPedia All rights reserved
import os
from asyncio import gather
from pyrogram import Client, filters
from pyrogram.types import Message
from pySmartDL import SmartDL
from misskaty import app
from misskaty.core.decorator.errors import capture_err
from misskaty.core.decorator.ratelimiter import ratelimiter
from misskaty.helper.localization import use_chat_lang
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
@ratelimiter
@use_chat_lang()
async def take_ss(self: Client, ctx: Message, strings):
if len(ctx.command) == 1:
return await ctx.reply_msg(strings("no_url"), del_in=6)
url = (
ctx.command[1]
if ctx.command[1].startswith("http")
else f"https://{ctx.command[1]}"
)
download_file_path = os.path.join("downloads/", f"webSS_{ctx.from_user.id}.png")
msg = await ctx.reply_msg(strings("wait_str"))
try:
url = f"https://webss.yasirapi.eu.org/api?url={url}&width=1280&height=720"
downloader = SmartDL(url, download_file_path, progress_bar=False, timeout=10)
downloader.start(blocking=True)
await gather(
*[
ctx.reply_document(download_file_path),
ctx.reply_photo(download_file_path, caption=strings("str_credit")),
]
)
await msg.delete_msg()
os.remove(download_file_path)
except Exception as e:
await msg.edit_msg(strings("ss_failed_str").format(err=str(e)))