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/expand.lua
2015-08-19 15:14:30 +02:00

26 lines
696 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 "Fehler beim Erweitern der URL."
end
end
return {
description = "Erweitert eine verkürzte URL",
usage = "/expand [URL]: Erweitert einen verkürzten Link",
patterns = {
"^/expand (https?://[%w-_%.%?%.:/%+=&]+)$"
},
run = run
}