# -*- 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__)
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]
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__)
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]