diff options
| author | 2019-04-24 15:36:26 +0100 | |
|---|---|---|
| committer | 2019-04-24 15:36:26 +0100 | |
| commit | 50e3206a9f75ffe23fbb416356eadaaff810cea4 (patch) | |
| tree | 638d838985b8846f241bb5db9a24f5fa9fd65571 /modules/isgd.py | |
| parent | Store full non-hashed auto-title url in setting value (diff) | |
| signature | ||
Aloow !shorten to find the last posted url and shorten it
Diffstat (limited to 'modules/isgd.py')
| -rw-r--r-- | modules/isgd.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/modules/isgd.py b/modules/isgd.py index 7674439c..b4a918fd 100644 --- a/modules/isgd.py +++ b/modules/isgd.py @@ -2,7 +2,7 @@ import re from src import ModuleManager, utils ISGD_API_URL = "https://is.gd/create.php" -REGEX_URL = re.compile("https?://", re.I) +REGEX_URL = re.compile("https?://\S+", re.I) class Module(ModuleManager.BaseModule): def on_load(self): @@ -18,14 +18,23 @@ class Module(ModuleManager.BaseModule): if page and page.data["shorturl"]: return page.data["shorturl"] - @utils.hook("received.command.shorten", min_args=1) + @utils.hook("received.command.shorten") def shorten(self, event): """ :help: Shorten a given URL using the is.gd service :usage: <url> """ - link = self._shortlink(event["args"]) + url = None + if len(event["args"]) > 0: + url = event["args_split"][0] + else: + url = event["target"].buffer.find(REGEX_URL) + if url: + url = re.search(REGEX_URL, url.message).group(0) + if not url: + raise utils.EventError("No URL provided/found.") + if link: - event["stdout"].write("Shortened URL: %s" % link) + event["stdout"].write("Shortened URL: %s" % self._shortlink(url)) else: event["stderr"].write("Unable to shorten that URL.") |
