new plugin expand.lua

This commit is contained in:
Akamaru 2015-08-19 15:14:30 +02:00
parent 8430ddd168
commit 3a0b3663a8
1 changed files with 26 additions and 0 deletions

26
plugins/expand.lua Normal file
View File

@ -0,0 +1,26 @@
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
}