From 3a0b3663a86949a5dac610390c8199918bac1306 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Wed, 19 Aug 2015 15:14:30 +0200 Subject: [PATCH] new plugin expand.lua --- plugins/expand.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 plugins/expand.lua diff --git a/plugins/expand.lua b/plugins/expand.lua new file mode 100644 index 0000000..6feb270 --- /dev/null +++ b/plugins/expand.lua @@ -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 +} \ No newline at end of file