Move REGEX_URL out of isgd.py and title.py in to utils.http

This commit is contained in:
jesopo 2019-04-24 15:46:54 +01:00
parent cc9edc6adb
commit dffee4d223
3 changed files with 8 additions and 10 deletions

View file

@ -2,14 +2,13 @@ import re
from src import ModuleManager, utils
ISGD_API_URL = "https://is.gd/create.php"
REGEX_URL = re.compile("https?://\S+", re.I)
class Module(ModuleManager.BaseModule):
def on_load(self):
self.exports.add("shortlink", self._shortlink)
def _shortlink(self, url):
if not re.match(REGEX_URL, url):
if not re.match(utils.http.REGEX_URL, url):
url = "http://%s" % url
page = utils.http.request(ISGD_API_URL, get_params=
@ -28,9 +27,9 @@ class Module(ModuleManager.BaseModule):
if len(event["args"]) > 0:
url = event["args_split"][0]
else:
url = event["target"].buffer.find(REGEX_URL)
url = event["target"].buffer.find(utils.http.REGEX_URL)
if url:
url = re.search(REGEX_URL, url.message).group(0)
url = re.search(utils.http.REGEX_URL, url.message).group(0)
if not url:
raise utils.EventError("No URL provided/found.")

View file

@ -1,8 +1,6 @@
import hashlib, re
from src import EventManager, ModuleManager, utils
REGEX_URL = re.compile("https?://\S+", re.I)
@utils.export("channelset", {"setting": "auto-title",
"help": "Disable/Enable automatically getting info titles from URLs",
"validate": utils.bool_or_none})
@ -32,7 +30,7 @@ class Module(ModuleManager.BaseModule):
@utils.hook("received.message.channel",
priority=EventManager.PRIORITY_MONITOR)
def channel_message(self, event):
match = re.search(REGEX_URL, event["message"])
match = re.search(utils.http.REGEX_URL, event["message"])
if match and event["channel"].get_setting("auto-title", False):
url = match.group(0)
title = self._get_title(match.group(0))
@ -70,9 +68,9 @@ class Module(ModuleManager.BaseModule):
if len(event["args"]) > 0:
url = event["args_split"][0]
else:
url = event["target"].buffer.find(REGEX_URL)
url = event["target"].buffer.find(utils.http.REGEX_URL)
if url:
url = re.search(REGEX_URL, url.message).group(0)
url = re.search(utils.http.REGEX_URL, url.message).group(0)
if not url:
raise utils.EventError("No URL provided/found.")

View file

@ -3,9 +3,10 @@ import json as _json
import bs4, requests
from src import utils
REGEX_URL = re.compile("https?://\S+", re.I)
USER_AGENT = ("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36")
REGEX_HTTP = re.compile("https?://", re.I)
RESPONSE_MAX = (1024*1024)*100
SOUP_CONTENT_TYPES = ["text/html", "text/xml", "application/xml"]