diff --git a/misskaty/helper/html_view.py b/misskaty/helper/html_view.py new file mode 100644 index 00000000..45edccd3 --- /dev/null +++ b/misskaty/helper/html_view.py @@ -0,0 +1,158 @@ +import base64, json, os +from .tools import get_random_string +from .http import http +from misskaty import GH_TOKEN + +hmtl_content = """ + + + + + + {fileName} + + + + + + + +{msg} + + +""" + +html_template = """ + + + + + + {title} + + + + + + + +{msg} + + +""" +async def postToWeb(file, name): + fpath = base64.b64encode(open(file, "rb").read()) + + headers = { + 'Accept': 'application/vnd.github+json', + 'Authorization': f'Bearer {GH_TOKEN}', + 'Content-Type': 'application/x-www-form-urlencoded', + } + + data = {"message":"Added new HTML File","committer":{"name":"Yasir Aris M","email":"mail@yasir.eu.org"},"content": f"{fpath.decode('ascii')}"} + + response = await http.put(f"https://api.github.com/repos/yasirarism/HTMLPaste/contents/{name}", headers=headers, data=json.dumps(data)) + return f"https://yasirarism.github.io/HTMLPaste/{name}" + +async def getMediaWeb(title, text): + msg = "" + fname = get_random_string(7) + msg += '' \ + f'

MediaInfo From {title}

' + msg += '' \ + f'MediaInfo' + msg += '' \ + f"
{text}
" + with open(f"{fname}.html", 'w', encoding='utf-8') as f: + f.write(msg) + res = await postToWeb(f"{fname}.html", fname) + os.remove(f"{fname}.html") + return res diff --git a/misskaty/plugins/genss.py b/misskaty/plugins/genss.py index 33db41ff..6764b6d7 100644 --- a/misskaty/plugins/genss.py +++ b/misskaty/plugins/genss.py @@ -41,11 +41,11 @@ async def genss(client, message): if media is None: return await message.reply("Reply to a Telegram Video or document as video to generate screenshoot!") process = await message.reply_text("`Processing, please wait..`") - if DL_TASK.get(message.from_user.id): - return await process.edit("Sorry to avoid flood and error, bot only process one task at a time.") + if DL_TASK.get(message.from_user.id): + return await process.edit("Sorry to avoid flood and error, bot only process one task per user at a time.") if not DL_TASK.get(message.from_user.id): - DL_TASK[message.from_user.id] = 1 + DL_TASK[message.from_user.id] = True c_time = time.time() the_real_download_location = await replied.download( diff --git a/misskaty/plugins/mediainfo.py b/misskaty/plugins/mediainfo.py index b3b7337e..9d2e31e4 100644 --- a/misskaty/plugins/mediainfo.py +++ b/misskaty/plugins/mediainfo.py @@ -15,7 +15,8 @@ from pyrogram import filters from pyrogram.errors import FloodWait from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup -from misskaty import app, DL_TASK +from misskaty import app, DL_TASK, CUSTOM_VIEW, GH_TOKEN +from misskaty.helper.html_view import getMediaWeb from misskaty.helper.media_helper import post_to_telegraph, runcmd from misskaty.helper.pyro_progress import progress_for_pyrogram from misskaty.vars import COMMAND_HANDLER @@ -29,12 +30,11 @@ async def mediainfo(client, message): file_info = get_file_id(message.reply_to_message) if file_info is None: return await process.edit_text("Balas ke format media yang valid") - async with DL_TASK: - if not DL_TASK.get(message.from_user.id): - DL_TASK[message.from_user.id] = asyncio.Lock() - - if DL_TASK.get(message.from_user.id): - return await process.edit("Sorry to avoid flood and error, bot only process one task at a time.") + + if DL_TASK.get(message.from_user.id): + return await process.edit("Sorry to avoid flood and error, bot only process one task per user at a time.") + if not DL_TASK.get(message.from_user.id): + DL_TASK[message.from_user.id] = 1 c_time = time.time() file_path = await message.reply_to_message.download( @@ -53,7 +53,10 @@ async def mediainfo(client, message): """ title = "MissKaty Bot Mediainfo" text_ = file_info.message_type - link = post_to_telegraph(title, body_text) + if CUSTOM_VIEW and GH_TOKEN is not None: + link = await getMediaWeb(title, body_text) + else: + link = post_to_telegraph(title, body_text) markup = InlineKeyboardMarkup([[InlineKeyboardButton(text=text_, url=link)]]) try: await message.reply("ℹ️ MEDIA INFO", reply_markup=markup, quote=True) @@ -78,12 +81,15 @@ async def mediainfo(client, message):
{output}
""" - tgraph = post_to_telegraph(title, body_text) + if CUSTOM_VIEW and GH_TOKEN is not None: + link = await getMediaWeb(title, body_text) + else: + link = post_to_telegraph(title, body_text) # siteurl = "https://spaceb.in/api/v1/documents/" # response = await http.post(siteurl, data={"content": output, "extension": 'txt'} ) # response = response.json() # spacebin = "https://spaceb.in/"+response['payload']['id'] - markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="💬 Telegraph", url=tgraph)]]) + markup = InlineKeyboardMarkup([[InlineKeyboardButton(text="💬 Telegraph", url=link)]]) with io.BytesIO(str.encode(output)) as out_file: out_file.name = "MissKaty_Mediainfo.txt" await message.reply_document( diff --git a/misskaty/vars.py b/misskaty/vars.py index 49f810eb..c5eb5985 100644 --- a/misskaty/vars.py +++ b/misskaty/vars.py @@ -40,6 +40,8 @@ SUDO = list( ) SUPPORT_CHAT = environ.get("SUPPORT_CHAT", "YasirPediaChannel") NIGHTMODE = environ.get("NIGHTMODE", False) +CUSTOM_VIEW = environ.get("CUSTOM_VIEW", False) +GH_TOKEN = environ.get("GH_TOKEN", None) OPENAI_API = getConfig("OPENAI_API") ## Config For AUtoForwarder