Move REGEX_URL out of isgd.py and title.py in to utils.http
This commit is contained in:
parent
cc9edc6adb
commit
dffee4d223
3 changed files with 8 additions and 10 deletions
|
@ -2,14 +2,13 @@ import re
|
||||||
from src import ModuleManager, utils
|
from src import ModuleManager, utils
|
||||||
|
|
||||||
ISGD_API_URL = "https://is.gd/create.php"
|
ISGD_API_URL = "https://is.gd/create.php"
|
||||||
REGEX_URL = re.compile("https?://\S+", re.I)
|
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
class Module(ModuleManager.BaseModule):
|
||||||
def on_load(self):
|
def on_load(self):
|
||||||
self.exports.add("shortlink", self._shortlink)
|
self.exports.add("shortlink", self._shortlink)
|
||||||
|
|
||||||
def _shortlink(self, url):
|
def _shortlink(self, url):
|
||||||
if not re.match(REGEX_URL, url):
|
if not re.match(utils.http.REGEX_URL, url):
|
||||||
url = "http://%s" % url
|
url = "http://%s" % url
|
||||||
|
|
||||||
page = utils.http.request(ISGD_API_URL, get_params=
|
page = utils.http.request(ISGD_API_URL, get_params=
|
||||||
|
@ -28,9 +27,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
if len(event["args"]) > 0:
|
if len(event["args"]) > 0:
|
||||||
url = event["args_split"][0]
|
url = event["args_split"][0]
|
||||||
else:
|
else:
|
||||||
url = event["target"].buffer.find(REGEX_URL)
|
url = event["target"].buffer.find(utils.http.REGEX_URL)
|
||||||
if 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:
|
if not url:
|
||||||
raise utils.EventError("No URL provided/found.")
|
raise utils.EventError("No URL provided/found.")
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import hashlib, re
|
import hashlib, re
|
||||||
from src import EventManager, ModuleManager, utils
|
from src import EventManager, ModuleManager, utils
|
||||||
|
|
||||||
REGEX_URL = re.compile("https?://\S+", re.I)
|
|
||||||
|
|
||||||
@utils.export("channelset", {"setting": "auto-title",
|
@utils.export("channelset", {"setting": "auto-title",
|
||||||
"help": "Disable/Enable automatically getting info titles from URLs",
|
"help": "Disable/Enable automatically getting info titles from URLs",
|
||||||
"validate": utils.bool_or_none})
|
"validate": utils.bool_or_none})
|
||||||
|
@ -32,7 +30,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
@utils.hook("received.message.channel",
|
@utils.hook("received.message.channel",
|
||||||
priority=EventManager.PRIORITY_MONITOR)
|
priority=EventManager.PRIORITY_MONITOR)
|
||||||
def channel_message(self, event):
|
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):
|
if match and event["channel"].get_setting("auto-title", False):
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
title = self._get_title(match.group(0))
|
title = self._get_title(match.group(0))
|
||||||
|
@ -70,9 +68,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
if len(event["args"]) > 0:
|
if len(event["args"]) > 0:
|
||||||
url = event["args_split"][0]
|
url = event["args_split"][0]
|
||||||
else:
|
else:
|
||||||
url = event["target"].buffer.find(REGEX_URL)
|
url = event["target"].buffer.find(utils.http.REGEX_URL)
|
||||||
if 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:
|
if not url:
|
||||||
raise utils.EventError("No URL provided/found.")
|
raise utils.EventError("No URL provided/found.")
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,10 @@ import json as _json
|
||||||
import bs4, requests
|
import bs4, requests
|
||||||
from src import utils
|
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 "
|
USER_AGENT = ("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 "
|
||||||
"(KHTML, like Gecko) Chrome/49.0.2623.87 Safari/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
|
RESPONSE_MAX = (1024*1024)*100
|
||||||
SOUP_CONTENT_TYPES = ["text/html", "text/xml", "application/xml"]
|
SOUP_CONTENT_TYPES = ["text/html", "text/xml", "application/xml"]
|
||||||
|
|
Loading…
Reference in a new issue