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-2/otouto/plugins/amazon_cleaner.lua
Andreas Bielawski ff7429363a - NEU: Amazon-Reflink-Entferner
- HEAD-Requests bei Expand und GitHub-Feed ignorieren jetzt den Inhalt
2016-10-02 18:40:05 +02:00

33 lines
951 B
Lua

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