2015-04-14 20:21:23 +02:00
|
|
|
do
|
|
|
|
|
|
|
|
function getTitle(page)
|
|
|
|
local s = page
|
|
|
|
|
|
|
|
-- Remove optional spaces from the tags.
|
|
|
|
s = string.gsub(s, "\n", " ")
|
|
|
|
s = string.gsub(s, " *< *", "<")
|
|
|
|
s = string.gsub(s, " *> *", ">")
|
|
|
|
|
|
|
|
-- Put all the tags in lowercase.
|
|
|
|
s = string.gsub(s, "(<[^ >]+)", string.lower)
|
|
|
|
|
|
|
|
local i, f, t = string.find(s, "<title>(.+)</title>")
|
|
|
|
return t or ""
|
|
|
|
end
|
|
|
|
|
|
|
|
function string.ends(str, fin)
|
|
|
|
return fin=='' or string.sub(str,-string.len(fin)) == fin
|
|
|
|
end
|
|
|
|
|
|
|
|
function run(msg, matches)
|
|
|
|
local url = matches[1]
|
|
|
|
if string.ends(url, ".jpg") or string.ends(url, ".gif") or string.ends(url, ".png") then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local result = http.request(url)
|
|
|
|
local title = getTitle(result)
|
|
|
|
|
2015-04-20 18:52:25 +02:00
|
|
|
--Ignoring 301, 302, 404 and more
|
2015-04-28 17:49:11 +02:00
|
|
|
if title == "301 Moved Permanently" or
|
2015-04-20 18:52:25 +02:00
|
|
|
title == "" or
|
|
|
|
title == "404 Not Found" or
|
|
|
|
title == "302 Found" or
|
2015-04-22 16:49:24 +02:00
|
|
|
title == "302 Moved" or
|
2015-04-20 18:52:25 +02:00
|
|
|
title == "Moved Permanently" or
|
2015-04-23 17:29:03 +02:00
|
|
|
title == "Redirection" or
|
2015-04-29 21:32:17 +02:00
|
|
|
title == "Object moved" or
|
2015-04-28 19:29:48 +02:00
|
|
|
string.match(title, "521: Web server is down") or
|
2015-04-20 18:52:25 +02:00
|
|
|
string.match(title, "deviantArt") or
|
|
|
|
string.match(title, "twitch") or
|
2015-04-21 15:59:09 +02:00
|
|
|
string.match(title, "eBay</title>") or
|
2015-04-28 17:49:11 +02:00
|
|
|
string.match(title, "Twitch") then
|
2015-04-14 20:21:23 +02:00
|
|
|
print('Invalide, da "'..title..'"')
|
|
|
|
else
|
|
|
|
return title
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
description = "Postet URL-Titel",
|
2015-04-28 17:49:11 +02:00
|
|
|
usage = {"Irgendein Link"},
|
2015-04-21 15:59:09 +02:00
|
|
|
patterns = {"^(https?://[%w-_%.%?%.:,/%+=&]+)$",},
|
2015-04-14 20:21:23 +02:00
|
|
|
run = run
|
|
|
|
}
|
|
|
|
end
|