This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/pluginsold/expand.lua
2015-06-16 21:40:12 +02:00

27 lines
705 B
Lua

local function run(msg, patterns)
local response_body = {}
local request_constructor = {
url = patterns[1],
method = "HEAD",
sink = ltn12.sink.table(response_body),
headers = {},
redirect = false
}
local ok, response_code, response_headers, response_status_line = http.request(request_constructor)
if ok and response_headers.location then
return " 👍 " .. response_headers.location
else
return "Can't expand the url."
end
end
return {
description = "Expand a shortened URL to the original one.",
usage = "!expand [url]: Return the original URL",
patterns = {
"^!expand (https?://[%w-_%.%?%.:/%+=&]+)$"
},
run = run
}