diff options
| author | 2019-07-23 18:07:47 +0100 | |
|---|---|---|
| committer | 2019-07-23 18:07:47 +0100 | |
| commit | 89cb69ed46181820ad1f9fe7012e310cfdd3785d (patch) | |
| tree | 1589652f38ab1838e9eda7b55ffa00d820d0ab19 | |
| parent | add throttle.py (diff) | |
| signature | ||
have !unshorten look back throgh logs for a url
| -rw-r--r-- | modules/shorturl.py | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/modules/shorturl.py b/modules/shorturl.py index 49998ac4..f20c46b7 100644 --- a/modules/shorturl.py +++ b/modules/shorturl.py @@ -56,32 +56,35 @@ class Module(ModuleManager.BaseModule): return page.data["data"]["url"] return None - @utils.hook("received.command.shorten") - def shorten(self, event): - """ - :help: Shorten a given URL - :usage: <url> - """ + def _find_url(self, target, args): url = None - if len(event["args"]) > 0: - url = event["args_split"][0] + if args: + url = args[0] if not re.match(utils.http.REGEX_URL, url): url = "http://%s" % url else: - url = event["target"].buffer.find(utils.http.REGEX_URL) + url = target.buffer.find(utils.http.REGEX_URL) if url: url = re.search(utils.http.REGEX_URL, url.message).group(0) + url = utils.http.url_sanitise(url) if not url: raise utils.EventError("No URL provided/found.") + return url + + @utils.hook("received.command.shorten") + def shorten(self, event): + """ + :help: Shorten a given URL + :usage: <url> + """ + url = self._find_url(event["target"], event["args_split"]) event["stdout"].write("Shortened URL: %s" % self._shorturl( event["server"], url)) - @utils.hook("received.command.unshorten", min_args=1) + @utils.hook("received.command.unshorten") def unshorten(self, event): - url = event["args_split"][0] - if not re.match(utils.http.REGEX_URL, url): - url = "http://%s" % url + url = self._find_url(event["target"], event["args_split"]) try: response = utils.http.request(url, method="HEAD", |
