feat: advanced url processing
This commit is contained in:
parent
c1190d6317
commit
2c4e7c3370
@ -236,7 +236,7 @@ class MumbleBot:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if not self.is_admin(user) and parameter:
|
if not self.is_admin(user) and parameter:
|
||||||
input_url = util.get_url_from_input(parameter.lower())
|
input_url = util.get_url_from_input(parameter)
|
||||||
if input_url:
|
if input_url:
|
||||||
for i in var.db.items("url_ban"):
|
for i in var.db.items("url_ban"):
|
||||||
if input_url == i[0]:
|
if input_url == i[0]:
|
||||||
|
17
util.py
17
util.py
@ -295,12 +295,17 @@ class Dir(object):
|
|||||||
|
|
||||||
def get_url_from_input(string):
|
def get_url_from_input(string):
|
||||||
string = string.strip()
|
string = string.strip()
|
||||||
if string.startswith('http'):
|
if not (string.startswith("http") or string.startswith("HTTP")):
|
||||||
return string
|
res = re.search('href="(.+?)"', string, flags=re.IGNORECASE)
|
||||||
p = re.compile('href="(.+?)"', re.IGNORECASE)
|
if res:
|
||||||
res = re.search(p, string)
|
string = res.group(1)
|
||||||
if res:
|
else:
|
||||||
return res.group(1)
|
return False
|
||||||
|
|
||||||
|
match = re.search("(http|https)://(.*)?/(.*)", string, flags=re.IGNORECASE)
|
||||||
|
if match:
|
||||||
|
url = match[1].lower() + "://" + match[2].lower() + "/" + match[3]
|
||||||
|
return url
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user