Skip to content

Commit

Permalink
tes coba
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirarism authored Nov 1, 2023
1 parent 9456cf6 commit c106a15
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
18 changes: 13 additions & 5 deletions misskaty/core/misskaty_patch/bound/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions misskaty/helper/tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import os
import random
import re
import string
import time
from http.cookies import SimpleCookie
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions misskaty/plugins/ytdl_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c106a15

Please sign in to comment.