]> git.0d.be Git - botaradio.git/commitdiff
feat: advanced url processing
authorTerry Geng <gengyanda@gmail.com>
Thu, 12 Mar 2020 12:50:07 +0000 (20:50 +0800)
committerTerry Geng <gengyanda@gmail.com>
Thu, 12 Mar 2020 12:50:07 +0000 (20:50 +0800)
mumbleBot.py
util.py

index 0cb80cb99398df2903ae2b0156eb5837459fc981..72fb15c8cba109913811f8bb4ffe8c1e7b3225db 100644 (file)
@@ -236,7 +236,7 @@ class MumbleBot:
                     return
 
             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:
                     for i in var.db.items("url_ban"):
                         if input_url == i[0]:
diff --git a/util.py b/util.py
index 637e2e6c93e93be39751d080c21f032b5f156882..2192d904ae7456dbcb777e1dda4921e6dfad027c 100644 (file)
--- a/util.py
+++ b/util.py
@@ -295,12 +295,17 @@ class Dir(object):
 
 def get_url_from_input(string):
     string = string.strip()
-    if string.startswith('http'):
-        return string
-    p = re.compile('href="(.+?)"', re.IGNORECASE)
-    res = re.search(p, string)
-    if res:
-        return res.group(1)
+    if not (string.startswith("http") or string.startswith("HTTP")):
+        res = re.search('href="(.+?)"', string, flags=re.IGNORECASE)
+        if res:
+            string = res.group(1)
+        else:
+            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:
         return False