aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2019-06-26 18:09:39 +0100
committerGravatar jesopo2019-06-26 18:09:39 +0100
commit297c403248f026b4dc0c91e56a6f867ae007c1ea (patch)
tree49d330ce1902112f0f6c622507fbfa2e7bcfe6f7 /modules
parentadd CaseInsensitiveDict.__contains__ (diff)
signature
add !unshorten
Diffstat (limited to 'modules')
-rw-r--r--modules/shorturl.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/modules/shorturl.py b/modules/shorturl.py
index 43b57c55..49b9f3cd 100644
--- a/modules/shorturl.py
+++ b/modules/shorturl.py
@@ -70,3 +70,21 @@ class Module(ModuleManager.BaseModule):
event["stdout"].write("Shortened URL: %s" % self._shorturl(
event["server"], url))
+
+ @utils.hook("received.command.unshorten", min_args=1)
+ def unshorten(self, event):
+ url = event["args_split"][0]
+ if not re.match(utils.http.REGEX_URL, url):
+ url = "http://%s" % url
+
+ try:
+ response = utils.http.request(url, method="HEAD",
+ allow_redirects=False)
+ except:
+ response = None
+
+ if response and "location" in response.headers:
+ event["stdout"].write("Unshortened: %s" %
+ response.headers["location"])
+ else:
+ event["stderr"].write("Failed to unshorten URL")