add !unshorten

This commit is contained in:
jesopo 2019-06-26 18:09:39 +01:00
parent 3c3f0449b6
commit 297c403248

View file

@ -70,3 +70,21 @@ class Module(ModuleManager.BaseModule):
event["stdout"].write("Shortened URL: %s" % self._shorturl( event["stdout"].write("Shortened URL: %s" % self._shorturl(
event["server"], url)) 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")