107 lines
3.3 KiB
Lua
107 lines
3.3 KiB
Lua
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, " *> *", ">")
|
||
|
||
-- Character encoding
|
||
s = string.gsub(s, "´", "´")
|
||
s = string.gsub(s, ">", ">")
|
||
s = string.gsub(s, """, '"')
|
||
s = string.gsub(s, "<", "<")
|
||
s = string.gsub(s, "—", "—")
|
||
s = string.gsub(s, "∇", "∇")
|
||
s = string.gsub(s, "–", "–")
|
||
s = string.gsub(s, "Ψ", "ψ")
|
||
s = string.gsub(s, "ψ", "ψ")
|
||
s = string.gsub(s, "»", "»")
|
||
s = string.gsub(s, "ß", "ß")
|
||
s = string.gsub(s, "™", "™")
|
||
s = string.gsub(s, "'", "'")
|
||
s = string.gsub(s, "|", "|")
|
||
s = string.gsub(s, " ", " ")
|
||
s = string.gsub(s, "»", "»")
|
||
s = string.gsub(s, "ß", "ß")
|
||
s = string.gsub(s, "–", "–")
|
||
s = string.gsub(s, "’", "'")
|
||
s = string.gsub(s, "“", "“")
|
||
s = string.gsub(s, "”", "”")
|
||
s = string.gsub(s, "„", "")
|
||
s = string.gsub(s, "‹", "‹")
|
||
s = string.gsub(s, "€", "€")
|
||
|
||
-- Ä Ö Ü
|
||
s = string.gsub(s, "ä", "ä")
|
||
s = string.gsub(s, "Ä", "Ä")
|
||
s = string.gsub(s, "ä", "ä")
|
||
s = string.gsub(s, "Ä", "Ä")
|
||
s = string.gsub(s, "ö", "ö")
|
||
s = string.gsub(s, "Ö", "Ö")
|
||
s = string.gsub(s, "ö", "ö")
|
||
s = string.gsub(s, "Ö", "Ö")
|
||
s = string.gsub(s, "ü", "ü")
|
||
s = string.gsub(s, "Ü", "Ü")
|
||
s = string.gsub(s, "ü", "ü")
|
||
s = string.gsub(s, "Ü", "Ü")
|
||
|
||
-- Put all the tags in lowercase.
|
||
s = string.gsub(s, "(<[^ >]+)", string.lower)
|
||
s = string.gsub(s, "&", "&") -- Be sure to do this after all others
|
||
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)
|
||
|
||
--Ignoring 301, 302, 404 and more
|
||
if title == "301 Moved Permanently" or
|
||
title == "" or
|
||
title == "404 Not Found" or
|
||
title == "302 Found" or
|
||
title == "302 Moved" or
|
||
title == "Moved Permanently" or
|
||
title == "Redirection" or
|
||
title == "Object moved" or
|
||
title == "Error 404 (Not Found)!!1" or
|
||
title =="Moved Temporarily" or
|
||
string.match(title, "on Steam") or
|
||
string.match(title, "521: Web server is down") or
|
||
string.match(title, "eBay</title>") or
|
||
string.match(msg.text, "twitch.tv") or
|
||
string.match(msg.text, "twitter.com") or
|
||
string.match(msg.text, "steamcommunity.com/app/") or
|
||
string.match(msg.text, "myanimelist.net/anime/") or
|
||
string.match(msg.text, "myanimelist.net/manga/") or
|
||
string.match(msg.text, "deviantart.com") or
|
||
string.match(msg.text, "urbanup.com/") or
|
||
string.match(msg.text, "urbandictionary.com/define.php")or
|
||
string.match(msg.text, "wikia.com") or
|
||
string.match(msg.text, "rule34.xxx/index.php") or
|
||
string.match(msg.text, "dropbox.com/s/") then
|
||
print('Ungültig, da "'..title..'"')
|
||
else
|
||
return title
|
||
end
|
||
end
|
||
|
||
return {
|
||
description = "Postet den URL-Titel",
|
||
usage = {""},
|
||
patterns = {"^(https?://[%w-_%.%?%.:,/%+=&#!]+)$"},
|
||
run = run
|
||
}
|
||
end |