From: Thorsten S Date: Wed, 1 May 2019 11:14:29 +0000 (+0200) Subject: move urlresolver to where it should be X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=667f7914814f44d298647fe5d2b895b262efddf3;p=urlbot-v3.git move urlresolver to where it should be --- diff --git a/distbot/plugins/bugtracker.py b/distbot/plugins/bugtracker.py index d9bc5a2..791b09e 100644 --- a/distbot/plugins/bugtracker.py +++ b/distbot/plugins/bugtracker.py @@ -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] diff --git a/distbot/plugins/url.py b/distbot/plugins/url.py index 68e3a37..35f66af 100644 --- a/distbot/plugins/url.py +++ b/distbot/plugins/url.py @@ -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]