]> git.aero2k.de Git - urlbot-v3.git/commitdiff
move urlresolver to where it should be
authorThorsten S <mail@aero2k.de>
Wed, 1 May 2019 11:14:29 +0000 (13:14 +0200)
committerThorsten S <mail@aero2k.de>
Wed, 1 May 2019 11:14:29 +0000 (13:14 +0200)
distbot/plugins/bugtracker.py
distbot/plugins/url.py

index d9bc5a21b983a1f95742bf9a80e816d2bfbb36da..791b09eb3ec5c04ea3af3f97a2b5e6e03ddc3e8f 100644 (file)
@@ -1,15 +1,12 @@
 # -*- coding: utf-8 -*-
 
 import logging
-
 import re
 
 from distbot.bot.worker import Worker
 from distbot.common.action import Action
-from distbot.common.config import conf_get
 from distbot.common.utils import extract_title
 
-
 logger = logging.getLogger(__name__)
 
 
@@ -55,44 +52,4 @@ class SecurityTracker(Worker):
         return Action(msg="\n".join(out))
 
 
-class URLResolver(Worker):
-    binding_keys = Worker.CATCH_ALL
-    description = "resolves titles of posted URLs"
-
-    def parse_body(self, msg):
-        user_pref_nospoiler = conf_get('user_pref.spoiler')
-        if user_pref_nospoiler:
-            logger.info('nospoiler in userconf')
-            return
-
-        result = re.findall(r'(https?://[^\s>]+)', msg["body"])
-        if not result:
-            return
-
-        url_blacklist = conf_get('plugins.urlresolve.blacklist').values()
-
-        out = []
-        for url in result[:10]:
-            if any([re.match(b, url) for b in url_blacklist]):
-                logger.info('url blacklist match for ' + url)
-                break
-            # brackets aren't allowed anyways... and repeatedly used.
-            if url.endswith(')'):
-                url = url.rstrip(')')
-            try:
-                title = extract_title(url)
-            except UnicodeError as e:
-                message = 'Bug triggered (%s), invalid URL/domain part: %s' % (str(e), url)
-                logger.warning(message)
-                return {'msg': message}
-
-            if title:
-                title = title.strip()
-                message = 'Title: %s' % title
-                message = message.replace('\n', '\\n')
-                out.append(message)
-
-        return Action(msg="\n".join(out))
-
-
-ALL = [DebianTracker, SecurityTracker, URLResolver]
+ALL = [DebianTracker, SecurityTracker]
index 68e3a3766d91cdc387c472cf4288a0bd9436fe20..35f66afae5e7f59acbae21abdd2fd14237fa7a93 100644 (file)
@@ -3,16 +3,17 @@
 Plugins for user specific functions
 """
 import logging
+import re
 from urllib.parse import urlparse
 
 import requests
 
+from common.utils import extract_title
 from distbot.bot.worker import Worker
 from distbot.common.action import Action
 from distbot.common.config import conf_get, conf_set
 from distbot.common.message import get_nick_from_message, get_words
 
-
 logger = logging.getLogger(__name__)
 
 
@@ -70,4 +71,44 @@ class IsDown(Worker):
             return Action(msg='{}: {} does not exist, you\'re trying to fool me?'.format(sender, url))
 
 
-ALL = [SpoilerSetting, URLBlacklist, IsDown]
+class URLResolver(Worker):
+    binding_keys = Worker.CATCH_ALL
+    description = "resolves titles of posted URLs"
+
+    def parse_body(self, msg):
+        user_pref_nospoiler = conf_get('user_pref.spoiler')
+        if user_pref_nospoiler:
+            logger.info('nospoiler in userconf')
+            return
+
+        result = re.findall(r'(https?://[^\s>]+)', msg["body"])
+        if not result:
+            return
+
+        url_blacklist = conf_get('plugins.urlresolve.blacklist').values()
+
+        out = []
+        for url in result[:10]:
+            if any([re.match(b, url) for b in url_blacklist]):
+                logger.info('url blacklist match for ' + url)
+                break
+            # brackets aren't allowed anyways... and repeatedly used.
+            if url.endswith(')'):
+                url = url.rstrip(')')
+            try:
+                title = extract_title(url)
+            except UnicodeError as e:
+                message = 'Bug triggered (%s), invalid URL/domain part: %s' % (str(e), url)
+                logger.warning(message)
+                return {'msg': message}
+
+            if title:
+                title = title.strip()
+                message = 'Title: %s' % title
+                message = message.replace('\n', '\\n')
+                out.append(message)
+
+        return Action(msg="\n".join(out))
+
+
+ALL = [SpoilerSetting, URLBlacklist, IsDown, URLResolver]