From 5b850718c139303dce984acd0672021ed7cb7987 Mon Sep 17 00:00:00 2001 From: Abhi <85984486+AbhiTheModder@users.noreply.github.com> Date: Sun, 17 Dec 2023 07:41:17 +0000 Subject: [PATCH] Add: webshot and api installation setup --- install.sh | 6 ++++++ modules/url.py | 53 +++++++++++++++++++++++++++++++++++++++-------- termux-install.sh | 9 +++++++- utils/config.py | 1 + 4 files changed, 59 insertions(+), 10 deletions(-) diff --git a/install.sh b/install.sh index 1f74d3f..a844690 100644 --- a/install.sh +++ b/install.sh @@ -44,6 +44,11 @@ else read -r -p "API_HASH > " api_hash fi +echo +echo "Enter APIFLASH_KEY for webshot plugin" +echo "You can get it here -> https://apiflash.com/dashboard/access_keys" +read -r -p "APIFLASH_KEY > " apiflash_key + echo echo "Choose database type:" echo "[1] MongoDB db_url" @@ -91,6 +96,7 @@ DATABASE_TYPE=${db_type} DATABASE_NAME=${db_name} # only for mongodb DATABASE_URL=${db_url} +APIFLASH_KEY=${apiflash_key} EOL chown -R $SUDO_USER:$SUDO_USER . diff --git a/modules/url.py b/modules/url.py index 6ac209b..c14207a 100644 --- a/modules/url.py +++ b/modules/url.py @@ -21,6 +21,22 @@ import requests from utils.misc import modules_help, prefix from utils.scripts import format_exc +import io +import requests + +from utils.config import apiflash_key + + + +def generate_screenshot(url): + api_url = f'https://api.apiflash.com/v1/urltoimage?access_key={apiflash_key}&url={url}&format=png' + response = requests.get(api_url) + if response.status_code == 200: + return io.BytesIO(response.content) + else: + return None + + http = urllib3.PoolManager() @Client.on_message(filters.command("short", prefix) & filters.me) @@ -123,20 +139,39 @@ async def upload_cmd(_, message: Message): os.remove(file_name) -@Client.on_message(filters.command("webshot", prefix) & filters.me) -async def webshot(client: Client, message: Message): - try: - user_link = message.command[1] - await message.delete() - full_link = f"https://webshot.deam.io/{user_link}/?delay=2000" - await client.send_document(message.chat.id, full_link, caption=f"{user_link}", parse_mode=enums.ParseMode.HTML) - except Exception as e: - await message.edit(format_exc(e), parse_mode=enums.ParseMode.HTML) +@Client.on_message(filters.command(["ws", "webshot"], prefix) & filters.me) +async def webshot(client: Client, message: Message): + if len(message.command) > 1: + url = message.text.split(maxsplit=1)[1] + if not url.startswith("https://"): + await message.edit_text("Invalid URL. Please make sure the URL starts with 'https://'") + return + elif message.reply_to_message: + url = message.reply_to_message.text + if not url.startswith("https://"): + await message.edit_text("Invalid URL. Please make sure the URL starts with 'https://'") + return + else: + await message.edit_text(f"Usage: {prefix}webshot/{prefix}ws [url/reply to url]", parse_mode=enums.ParseMode.HTML) + return + + chat_id = message.chat.id + + try: + screenshot_data = generate_screenshot(url) + if screenshot_data: + await message.delete() + await client.send_photo(chat_id, screenshot_data, caption=f"Screenshot of {url}") + else: + await message.reply_text("Failed to generate screenshot.") + except Exception as e: + await message.reply_text(f"An error occurred: {format_exc(e)}") modules_help["url"] = { "short [url]*": "short url", "urldl [url]*": "download url content", "upload [file|reply]*": "upload file to internet", "webshot [link]*": "Screenshot of web page", + "ws [reply to link]*": "Screenshot of web page", } diff --git a/termux-install.sh b/termux-install.sh index 80bce57..f4219c2 100644 --- a/termux-install.sh +++ b/termux-install.sh @@ -40,6 +40,11 @@ else read -r -p "API_HASH > " api_hash fi +echo +echo "Enter APIFLASH_KEY for webshot plugin" +echo "You can get it here -> https://apiflash.com/dashboard/access_keys" +read -r -p "APIFLASH_KEY > " apiflash_key + echo "Choose database type:" echo "[1] MongoDB (your url)" echo "[2] Sqlite" @@ -67,6 +72,8 @@ DATABASE_NAME=${db_name} # only for mongodb DATABASE_URL=${db_url} + +APIFLASH_KEY=${apiflash_key} EOL python3 install.py 3 || exit 3 @@ -74,5 +81,5 @@ python3 install.py 3 || exit 3 echo echo "============================" echo "Great! Moon-Userbot installed successfully!" -echo "Start with: \"python3 main.py\"" +echo "Start with: \"cd Moon-Userbot && python3 main.py\"" echo "============================" \ No newline at end of file diff --git a/utils/config.py b/utils/config.py index cb7e580..370e0b7 100644 --- a/utils/config.py +++ b/utils/config.py @@ -10,5 +10,6 @@ db_type = env.str("DATABASE_TYPE") db_url = env.str("DATABASE_URL", "") db_name = env.str("DATABASE_NAME") +apiflash_key = env.str("APIFLASH_KEY") test_server = env.bool("TEST_SERVER", False) modules_repo_branch = env.str("MODULES_REPO_BRANCH", "master") \ No newline at end of file