From 9001d0846be3c466102647fe0dec8905865709ad Mon Sep 17 00:00:00 2001 From: yasir Date: Sun, 8 Jan 2023 21:49:49 +0700 Subject: [PATCH] Some fixes --- misskaty/plugins/dev.py | 67 ++++- misskaty/plugins/json.py | 23 +- misskaty/plugins/misc_tools.py | 4 +- misskaty/plugins/scrapwebsite.py | 402 ++++++++++++++++++++++++++++-- misskaty/plugins/sub_extractor.py | 4 +- 5 files changed, 474 insertions(+), 26 deletions(-) diff --git a/misskaty/plugins/dev.py b/misskaty/plugins/dev.py index 101d256e..9404b796 100644 --- a/misskaty/plugins/dev.py +++ b/misskaty/plugins/dev.py @@ -4,6 +4,7 @@ import os import traceback import asyncio from pyrogram import filters, enums +from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton from misskaty import app from misskaty.vars import COMMAND_HANDLER, SUDO @@ -23,7 +24,20 @@ __HELP__ = """ async def log_file(bot, message): """Send log file""" try: - await message.reply_document("MissKatyLogs.txt", caption="Log Bot MissKatyPyro") + await message.reply_document( + "MissKatyLogs.txt", + caption="Log Bot MissKatyPyro", + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{message.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await message.reply(str(e)) @@ -64,13 +78,37 @@ async def shell(_, m): with open("shell_output.txt", "w") as file: file.write(shell) with open("shell_output.txt", "rb") as doc: - await m.reply_document(document=doc, file_name=doc.name) + await m.reply_document( + document=doc, + file_name=doc.name, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", callback_data=f"close#{m.from_user.id}" + ) + ] + ] + ), + ) try: os.remove("shell_output.txt") except: pass elif len(shell) != 0: - await m.reply(shell, parse_mode=enums.ParseMode.HTML) + await m.reply( + shell, + parse_mode=enums.ParseMode.HTML, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", callback_data=f"close#{m.from_user.id}" + ) + ] + ] + ), + ) else: await m.reply("No Reply") @@ -119,11 +157,32 @@ async def evaluation_cmd_t(_, m): document="MissKatyEval.txt", caption=f"{cmd[: 4096 // 4 - 1]}", disable_notification=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", callback_data=f"close#{m.from_user.id}" + ) + ] + ] + ), ) os.remove("MissKatyEval.txt") await status_message.delete() else: - await status_message.edit(final_output, parse_mode=enums.ParseMode.MARKDOWN) + await status_message.edit( + final_output, + parse_mode=enums.ParseMode.MARKDOWN, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", callback_data=f"close#{m.from_user.id}" + ) + ] + ] + ), + ) async def aexec(code, c, m): diff --git a/misskaty/plugins/json.py b/misskaty/plugins/json.py index 9cff43d7..27a141f3 100644 --- a/misskaty/plugins/json.py +++ b/misskaty/plugins/json.py @@ -8,6 +8,7 @@ import os from pyrogram import filters +from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton from misskaty import app from misskaty.vars import COMMAND_HANDLER @@ -20,7 +21,18 @@ async def jsonify(_, message): the_real_message = message.reply_to_message or message try: - await message.reply_text(f"{the_real_message}") + await message.reply_text( + f"{the_real_message}", + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", callback_data=f"close#{msg.from_user.id}" + ) + ] + ] + ), + ) except Exception as e: with open("json.text", "w+", encoding="utf8") as out_file: out_file.write(str(the_real_message)) @@ -29,5 +41,14 @@ async def jsonify(_, message): caption=f"{str(e)}", disable_notification=True, reply_to_message_id=reply_to_id, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", callback_data=f"close#{msg.from_user.id}" + ) + ] + ] + ), ) os.remove("json.text") diff --git a/misskaty/plugins/misc_tools.py b/misskaty/plugins/misc_tools.py index 6bd96352..cafd6d19 100644 --- a/misskaty/plugins/misc_tools.py +++ b/misskaty/plugins/misc_tools.py @@ -159,8 +159,8 @@ async def translate(client, message): target_lang = message.text.split(None, 2)[1] text = message.text.split(None, 2)[2] msg = await message.reply("Menerjemahkan...") - my_translator = GoogleTranslator(source="auto", target=target_lang) try: + my_translator = GoogleTranslator(source="auto", target=target_lang) result = my_translator.translate(text=text) await msg.edit( f"Translation using source = {my_translator.source} and target = {my_translator.target}\n\n-> {result}" @@ -289,6 +289,8 @@ async def showid(client, message): @app.on_message(filters.command(["info"], COMMAND_HANDLER)) async def who_is(client, message): # https://github.com/SpEcHiDe/PyroGramBot/blob/master/pyrobot/plugins/admemes/whois.py#L19 + if message.sender_chat: + return await message.reply("Not supported channel..") status_message = await message.reply_text("`Fetching user info...`") await status_message.edit("`Processing user info...`") from_user = None diff --git a/misskaty/plugins/scrapwebsite.py b/misskaty/plugins/scrapwebsite.py index 6858a66e..5a638295 100644 --- a/misskaty/plugins/scrapwebsite.py +++ b/misskaty/plugins/scrapwebsite.py @@ -14,6 +14,7 @@ from logging import getLogger from misskaty import app, BOT_USERNAME from pyrogram import filters from pyrogram.errors import MessageTooLong +from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton from misskaty.vars import COMMAND_HANDLER from misskaty.core.decorator.errors import capture_err from misskaty.helper.http import http @@ -77,11 +78,35 @@ async def zonafilm(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{message.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: LOGGER.error(e) await m.delete() @@ -127,6 +152,16 @@ async def nodrakor(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) await asyncio.sleep(2) msgs = "" @@ -161,7 +196,19 @@ async def ngefilm21(_, message): if not data: return await msg.edit("Oops, data film tidak ditemukan.") res = "".join(f"{i['judul']}\n{i['link']}\n" for i in data) - await msg.edit(f"Hasil Scrap dari Ngefilm21:\n{res}") + await msg.edit( + f"Hasil Scrap dari Ngefilm21:\n{res}", + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{message.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await msg.edit(f"ERROR: {str(e)}") @@ -194,6 +241,16 @@ async def movikucc(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) await asyncio.sleep(2) msgs = "" @@ -202,6 +259,16 @@ async def movikucc(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) except Exception as e: LOGGER.error(e) @@ -230,6 +297,16 @@ async def movikucc(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) await asyncio.sleep(2) msgs = "" @@ -238,6 +315,16 @@ async def movikucc(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) except Exception as e: LOGGER.error(e) @@ -278,6 +365,16 @@ async def savefilm21(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) await asyncio.sleep(2) msgs = "" @@ -286,6 +383,16 @@ async def savefilm21(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) else: html = await http.get(SITE, headers=headers) @@ -306,6 +413,16 @@ async def savefilm21(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) await asyncio.sleep(2) msgs = "" @@ -314,6 +431,16 @@ async def savefilm21(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) except Exception as e: await m.delete() @@ -353,11 +480,39 @@ async def melongmovie(_, msg): for c, i in enumerate(data, start=1): msgs += f"{c}. {i['judul']}\nQuality: {i['quality']}\nExtract: /{msg.command[0]}_scrap {i['link']}\n\n" if len(head.encode("utf-8") + msgs.encode("utf-8")) >= 4000: - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await m.delete() LOGGER.error(e) @@ -384,11 +539,39 @@ async def melongmovie(_, msg): for c, i in enumerate(data, start=1): msgs += f"{c}. {i['judul']}\nQuality: {i['quality']}\nExtract: /{msg.command[0]}_scrap {i['link']}\n\n" if len(head.encode("utf-8") + msgs.encode("utf-8")) >= 4000: - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await m.delete() LOGGER.error(e) @@ -420,11 +603,35 @@ async def pahe_scrap(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await m.delete() LOGGER.error(e) @@ -448,11 +655,39 @@ async def terbit21_scrap(_, msg): for c, i in enumerate(res["result"], start=1): msgs += f"{c}. {i['judul']}\nCategory: {i['kategori']}\n💠 Download\n\n" if len(head.encode("utf-8") + msgs.encode("utf-8")) >= 4000: - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await m.delete() LOGGER.error(e) @@ -471,11 +706,39 @@ async def terbit21_scrap(_, msg): for c, i in enumerate(res["result"], start=1): msgs += f"{c}. {i['judul']}\nCategory: {i['kategori']}\n💠 Download\n\n" if len(head.encode("utf-8") + msgs.encode("utf-8")) >= 4000: - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await m.delete() LOGGER.error(e) @@ -502,11 +765,39 @@ async def lk21_scrap(_, msg): for c, i in enumerate(res["result"], start=1): msgs += f"{c}. {i['judul']}\nCategory: {i['kategori']}\n💠 Download\n\n" if len(head.encode("utf-8") + msgs.encode("utf-8")) >= 4000: - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await m.delete() LOGGER.error(e) @@ -528,11 +819,39 @@ async def lk21_scrap(_, msg): for c, i in enumerate(res["result"], start=1): msgs += f"{c}. {i['judul']}\nCategory: {i['kategori']}\n💠 Download\n\n" if len(head.encode("utf-8") + msgs.encode("utf-8")) >= 4000: - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: await m.delete() LOGGER.error(e) @@ -578,11 +897,35 @@ async def gomov_scrap(_, msg): head + msgs, True, disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), ) await asyncio.sleep(2) msgs = "" if msgs != "": - await msg.reply(head + msgs, True, disable_web_page_preview=True) + await msg.reply( + head + msgs, + True, + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{msg.from_user.id}", + ) + ] + ] + ), + ) except Exception as e: LOGGER.error(e) await m.delete() @@ -603,7 +946,18 @@ async def savefilm21_scrap(_, message): res = soup.find_all(class_="button button-shadow") res = "".join(f"{i.text}\n{i['href']}\n\n" for i in res) await message.reply( - f"Hasil Scrap dari {link}:\n\n{res}", disable_web_page_preview=True + f"Hasil Scrap dari {link}:\n\n{res}", + disable_web_page_preview=True, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{message.from_user.id}", + ) + ] + ] + ), ) except IndexError: return await message.reply( @@ -705,7 +1059,19 @@ async def gomov_zonafilm_dl(_, message): title = i.find("a").text link = i.find("a")["href"] hasil += f"\n{title}\n{link}\n" - await message.reply(hasil) + await message.reply( + hasil, + reply_markup=InlineKeyboardMarkup( + [ + [ + InlineKeyboardButton( + text="❌ Close", + callback_data=f"close#{message.from_user.id}", + ) + ] + ] + ), + ) except IndexError: await message.reply( f"Gunakan command /{message.command[0]} [link] untuk scrap link download" diff --git a/misskaty/plugins/sub_extractor.py b/misskaty/plugins/sub_extractor.py index 569d69e0..4a4d6870 100644 --- a/misskaty/plugins/sub_extractor.py +++ b/misskaty/plugins/sub_extractor.py @@ -85,7 +85,7 @@ async def ceksub(_, m): ) end_time = perf_counter() timelog = "{:.2f}".format(end_time - start_time) + " second" - buttons.append([InlineKeyboardButton("Cancel", "cancel")]) + buttons.append([InlineKeyboardButton("❌ Cancel", f"close#{m.from_user.id}")]) await pesan.edit( f"Press the button below to extract subtitles/audio. Only support direct link at this time.\nProcessed in {timelog}", reply_markup=InlineKeyboardMarkup(buttons), @@ -177,4 +177,4 @@ async def stream_extract(bot, update): except: pass except Exception as e: - await update.message.edit(f"Failed extract sub. \n\nERROR: {e}") + await update.message.edit("Failed extract sub, Maybe unsupported format..")