diff --git a/otouto/plugins/amazon_cleaner.lua b/otouto/plugins/amazon_cleaner.lua new file mode 100644 index 0000000..52080fb --- /dev/null +++ b/otouto/plugins/amazon_cleaner.lua @@ -0,0 +1,33 @@ +local cln_amzn = {} + +cln_amzn.triggers = { + 'amazon.(%w+)/gp/product/(.+)/(.+)', + 'amazon.(%w+)/gp/product/(.+)%?(.+)', + 'amazon.(%w+)/dp/(.+)/(.+)', + 'amazon.(%w+)/dp/(.+)%?(.+)', + 'amzn.to/(.+)' +} + +function cln_amzn:action(msg, config, matches) + if #matches == 1 then + local request_constructor = { + url = 'http://amzn.to/'..matches[1], + method = "HEAD", + sink = ltn12.sink.null(), + redirect = false + } + + local ok, response_code, response_headers = http.request(request_constructor) + local long_url = response_headers.location + local domain, product_id = long_url:match('amazon.(%w+)/gp/product/(.+)/(.+)') + utilities.send_reply(msg, 'Ohne Ref: https://amazon.'..domain..'/dp/'..product_id) + return + end + + text = msg.text:lower() + if text:match('tag%=.+') or text:match('linkid%=.+') then + utilities.send_reply(msg, 'Ohne Ref: https://amazon.'..matches[1]..'/dp/'..matches[2]) + end +end + +return cln_amzn \ No newline at end of file diff --git a/otouto/plugins/expand.lua b/otouto/plugins/expand.lua index 9ef395d..d5f9ac5 100644 --- a/otouto/plugins/expand.lua +++ b/otouto/plugins/expand.lua @@ -31,16 +31,14 @@ function expand:inline_callback(inline_query, config, matches) end function expand:url(long_url) - local response_body = {} local request_constructor = { url = long_url, method = "HEAD", - sink = ltn12.sink.table(response_body), - headers = {}, + sink = ltn12.sink.null(), redirect = false } - local ok, response_code, response_headers, response_status_line = http.request(request_constructor) + local ok, response_code, response_headers = http.request(request_constructor) return ok, response_headers end diff --git a/otouto/plugins/github_feed.lua b/otouto/plugins/github_feed.lua index 78a2d98..6c33f68 100644 --- a/otouto/plugins/github_feed.lua +++ b/otouto/plugins/github_feed.lua @@ -47,11 +47,11 @@ end function gh_feed_check_modified(repo, cur_etag, last_date) local url = BASE_URL..'/'..repo - local response_body = {} local request_constructor = { url = url, method = "HEAD", redirect = false, + sink = ltn12.sink.null(), headers = { Authorization = 'token '..token, ["If-None-Match"] = cur_etag