diff --git a/misskaty/__init__.py b/misskaty/__init__.py index daf27c5b..35e66675 100644 --- a/misskaty/__init__.py +++ b/misskaty/__init__.py @@ -42,7 +42,7 @@ MOD_NOLOAD = ["subscene_dl"] HELPABLE = {} cleanmode = {} botStartTime = time.time() -misskaty_version = "v2.11.4 - Stable" +misskaty_version = "v2.12.1 - Stable" uvloop.install() faulthandler_enable() diff --git a/misskaty/__main__.py b/misskaty/__main__.py index 082ea6d9..33580207 100644 --- a/misskaty/__main__.py +++ b/misskaty/__main__.py @@ -85,14 +85,13 @@ if __name__ == "__main__": try: get_event_loop().run_until_complete(start_bot()) app.loop.run_forever() - # loop.run_until_complete(start_bot()) except KeyboardInterrupt: pass except Exception: err = traceback.format_exc() LOGGER.info(err) finally: - loop.stop() + app.loop.stop() LOGGER.info( "------------------------ Stopped Services ------------------------" ) diff --git a/misskaty/core/misskaty_patch/bound/message.py b/misskaty/core/misskaty_patch/bound/message.py index ab96257f..1f57ee1f 100644 --- a/misskaty/core/misskaty_patch/bound/message.py +++ b/misskaty/core/misskaty_patch/bound/message.py @@ -21,11 +21,12 @@ from pyrogram.types import Message LOGGER = getLogger("MissKaty") -Message.input = property( - lambda m: m.text[m.text.find(m.command[0]) + len(m.command[0]) + 1 :] - if len(m.command) > 1 - else None -) +@property +def parse_cmd(m): + msg = m.caption if m.web_page_preview else m.text + if len(m.command) > 1: + return msg.split(None, 1)[1] + return None async def reply_text( @@ -323,3 +324,4 @@ Message.edit_or_send_as_file = edit_or_send_as_file Message.reply_or_send_as_file = reply_or_send_as_file Message.reply_as_file = reply_as_file Message.delete_msg = delete +Message.input = parse_cmd \ No newline at end of file diff --git a/misskaty/helper/tools.py b/misskaty/helper/tools.py index 6f6fc2b8..75932999 100644 --- a/misskaty/helper/tools.py +++ b/misskaty/helper/tools.py @@ -1,6 +1,7 @@ import logging import os import random +import re import string import time from http.cookies import SimpleCookie @@ -151,3 +152,27 @@ async def search_jw(movie_name: str, locale: Union[str, None] = "ID"): m_t_ = m_t_[:-2].strip() break return m_t_ + + +def isValidURL(str): + # Regex to check valid URL + regex = ("((http|https)://)(www.)?" + + "[a-zA-Z0-9@:%._\\+~#?&//=]" + + "{2,256}\\.[a-z]" + + "{2,6}\\b([-a-zA-Z0-9@:%" + + "._\\+~#?&//=]*)") + + # Compile the ReGex + p = re.compile(regex) + + # If the string is empty + # return false + if (str == None): + return False + + # Return if the string + # matched the ReGex + if(re.search(p, str)): + return True + else: + return False \ No newline at end of file diff --git a/misskaty/plugins/dev.py b/misskaty/plugins/dev.py index 34df0297..7a528575 100644 --- a/misskaty/plugins/dev.py +++ b/misskaty/plugins/dev.py @@ -125,11 +125,12 @@ async def log_file(_, ctx: Message, strings): @app.on_message(filters.command(["donate"], COMMAND_HANDLER)) async def donate(self: Client, ctx: Message): - with contextlib.suppress(ChatSendPlainForbidden, ChatSendPhotosForbidden): + try: await ctx.reply_photo( "https://img.yasirweb.eu.org/file/9427d61d6968b8ee4fb2f.jpg", caption=f"Hi {ctx.from_user.mention}, If you find this bot useful, you can make a donation to the account below. Because this bot server uses VPS and is not free. Thank You..\n\nIndonesian Payment:\nQRIS: https://img.yasirweb.eu.org/file/b1c86973ae4e55721983a.jpg (Yasir Store)\nMayar: https://yasirarism.mayar.link/payme\nBank Jago: 109641845083 (Yasir Aris M)\n\nFor international people can use PayPal to support me or via GitHub Sponsor:\nhttps://paypal.me/yasirarism\nhttps://github.com/sponsors/yasirarism\n\nSource: @BeriKopi", ) + except (ChatSendPlainForbidden, ChatSendPhotosForbidden): await self.send_message(LOG_CHANNEL, f"❗️ WARNING\nI'm leaving from {ctx.chat.id} since i didn't have sufficient admin permissions.") await ctx.chat.leave() @@ -400,8 +401,9 @@ async def cmd_eval(self: Client, ctx: Message, strings) -> Optional[str]: if ctx.from_user.is_self else await ctx.reply_msg(strings("run_eval"), quote=True) ) + msg = ctx.caption if ctx.web_page_preview else ctx.text code = ( - ctx.text.split(maxsplit=1)[1] if ctx.command else ctx.text.split("\napp.run()")[0] + msg.split(maxsplit=1)[1] if ctx.command else msg.split("\napp.run()")[0] ) out_buf = io.StringIO() out = "" @@ -435,15 +437,15 @@ async def cmd_eval(self: Client, ctx: Message, strings) -> Optional[str]: "cloudscraper": cloudscraper, "json": json, "aiohttp": aiohttp, - "print": _print, + "p": _print, "send": send, "stdout": out_buf, "traceback": traceback, "fetch": fetch, - "replied": ctx.reply_to_message, + "r": ctx.reply_to_message, "requests": requests, "soup": BeautifulSoup, - "help": _help, + "h": _help, } eval_vars.update(var) eval_vars.update(teskode) diff --git a/misskaty/plugins/imdb_search.py b/misskaty/plugins/imdb_search.py index 21cc8f5a..29686c5c 100644 --- a/misskaty/plugins/imdb_search.py +++ b/misskaty/plugins/imdb_search.py @@ -470,17 +470,17 @@ async def imdb_id_callback(self: Client, query: CallbackQuery): res_str += f"Pemeran: {actor[:-2]}\n\n" if deskripsi := r_json.get("description"): summary = GoogleTranslator("auto", "id").translate(deskripsi) - res_str += f"📜 Plot: {summary}\n\n" + res_str += f"📜 Plot:\n
{summary}
\n\n" if keywd := r_json.get("keywords"): key_ = "".join( f"#{i.replace(' ', '_').replace('-', '_')}, " for i in keywd.split(",") ) - res_str += f"🔥 Kata Kunci: {key_[:-2]} \n" + res_str += f"🔥 Kata Kunci:\n
{key_[:-2]}
\n" if award := sop.select('li[data-testid="award_information"]'): awards = ( award[0].find(class_="ipc-metadata-list-item__list-content-item").text ) - res_str += f"🏆 Penghargaan: {GoogleTranslator('auto', 'id').translate(awards)}\n" + res_str += f"🏆 Penghargaan:\n
{GoogleTranslator('auto', 'id').translate(awards)}
\n" else: res_str += "\n" if ott != "": @@ -633,18 +633,18 @@ async def imdb_en_callback(self: Client, query: CallbackQuery): ) res_str += f"Stars: {actors[:-2]}\n\n" if description := r_json.get("description"): - res_str += f"📜 Summary: {description}\n\n" + res_str += f"📜 Summary:\n
{description}
\n\n" if r_json.get("keywords"): key_ = "".join( f"#{i.replace(' ', '_').replace('-', '_')}, " for i in r_json["keywords"].split(",") ) - res_str += f"🔥 Keywords: {key_[:-2]} \n" + res_str += f"🔥 Keywords:\n
{key_[:-2]}
\n" if award := sop.select('li[data-testid="award_information"]'): awards = ( award[0].find(class_="ipc-metadata-list-item__list-content-item").text ) - res_str += f"🏆 Awards: {awards}\n" + res_str += f"🏆 Awards:\n
{awards}
\n" else: res_str += "\n" if ott != "": diff --git a/misskaty/plugins/inline_search.py b/misskaty/plugins/inline_search.py index c105fb92..f9d83704 100644 --- a/misskaty/plugins/inline_search.py +++ b/misskaty/plugins/inline_search.py @@ -725,20 +725,20 @@ async def imdb_inl(_, query): summary = GoogleTranslator("auto", "id").translate( r_json.get("description") ) - res_str += f"📜 Plot: {summary}\n\n" + res_str += f"📜 Plot:\n
{summary}
\n\n" if r_json.get("keywords"): key_ = "".join( f"#{i.replace(' ', '_').replace('-', '_')}, " for i in r_json["keywords"].split(",") ) - res_str += f"🔥 Kata Kunci: {key_[:-2]} \n" + res_str += f"🔥 Kata Kunci:\n
{key_[:-2]}
\n" if award := sop.select('li[data-testid="award_information"]'): awards = ( award[0] .find(class_="ipc-metadata-list-item__list-content-item") .text ) - res_str += f"🏆 Penghargaan: {GoogleTranslator('auto', 'id').translate(awards)}\n" + res_str += f"🏆 Penghargaan:\n
{GoogleTranslator('auto', 'id').translate(awards)}
\n" else: res_str += "\n" if ott != "": diff --git a/misskaty/plugins/ytdl_plugins.py b/misskaty/plugins/ytdl_plugins.py index 008a4377..9f5a35d8 100644 --- a/misskaty/plugins/ytdl_plugins.py +++ b/misskaty/plugins/ytdl_plugins.py @@ -27,7 +27,7 @@ from pyrogram.types import ( from misskaty import app from misskaty.core import pyro_cooldown from misskaty.core.decorator import capture_err, new_task -from misskaty.helper import fetch, use_chat_lang +from misskaty.helper import fetch, use_chat_lang, isValidURL from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL, SUDO LOGGER = getLogger("MissKaty") @@ -91,12 +91,15 @@ async def ytsearch(_, ctx: Message, strings): ) @capture_err @use_chat_lang() -async def ytdownv2(_, ctx: Message, strings): +async def ytdownv2(self, ctx: Message, strings): if not ctx.from_user: return await ctx.reply_msg(strings("no_channel")) if ctx.command and len(ctx.command) == 1: return await ctx.reply_msg(strings("invalid_link")) - url = ctx.input if ctx.command and len(ctx.command) > 1 else ctx.text + msg = ctx.caption if ctx.web_page_preview else ctx.text + url = msg.split()[1] + if not isValidURL(url): + return await ctx.reply_msg(strings("invalid_link")) async with iYTDL(log_group_id=0, cache_path="cache", silent=True) as ytdl: try: x = await ytdl.parse(url, extract=True)