From c106a15bd5b09aa3b88914883c92e8a2d35c2ecc Mon Sep 17 00:00:00 2001 From: Yasir Aris M Date: Wed, 1 Nov 2023 23:05:47 +0700 Subject: [PATCH] tes coba --- misskaty/core/misskaty_patch/bound/message.py | 18 +++++++++---- misskaty/helper/tools.py | 25 +++++++++++++++++++ misskaty/plugins/ytdl_plugins.py | 7 +++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/misskaty/core/misskaty_patch/bound/message.py b/misskaty/core/misskaty_patch/bound/message.py index ab96257f90..87f76e4656 100644 --- a/misskaty/core/misskaty_patch/bound/message.py +++ b/misskaty/core/misskaty_patch/bound/message.py @@ -21,11 +21,18 @@ 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 = ctx.caption if ctx.web_page_preview else ctx.text + if len(m.command) > 1: + return msg.split(None, 1)[1] + return None + +# 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 +# ) async def reply_text( @@ -323,3 +330,4 @@ async def delete(self, revoke: bool = True) -> bool: 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 6f6fc2b88f..7593299939 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/ytdl_plugins.py b/misskaty/plugins/ytdl_plugins.py index 927036a4df..8059850182 100644 --- a/misskaty/plugins/ytdl_plugins.py +++ b/misskaty/plugins/ytdl_plugins.py @@ -27,7 +27,7 @@ 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, is_valid_url from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL, SUDO LOGGER = getLogger("MissKaty") @@ -96,9 +96,10 @@ async def ytdownv2(self, ctx: Message, strings): return await ctx.reply_msg(strings("no_channel")) if ctx.command and len(ctx.command) == 1: return await ctx.reply_msg(strings("invalid_link")) - self.log.info(ctx) - msg = ctx.caption if ctx.web_page_preview else msg.text + msg = ctx.caption if ctx.web_page_preview else ctx.text url = msg.split()[1] + if not is_valid_url(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)