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/plugins/url_title.lua

119 lines
3.8 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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, "&acute;", "´")
s = string.gsub(s, "&bull;", "")
s = string.gsub(s, "&gt;", ">")
s = string.gsub(s, "&quot;", '"')
s = string.gsub(s, "&lt;", "<")
s = string.gsub(s, "&mdash;", "")
s = string.gsub(s, "&nabla;", "")
s = string.gsub(s, "&ndash;", "")
s = string.gsub(s, "&Psi;", "ψ")
s = string.gsub(s, "&psi;", "ψ")
s = string.gsub(s, "&raquo;", "»")
s = string.gsub(s, "&reg;", "®")
s = string.gsub(s, "&szlig;", "ß")
s = string.gsub(s, "&trade;", "")
s = string.gsub(s, "&#038;", "&")
s = string.gsub(s, "&#039;", "'")
s = string.gsub(s, "&#39;", "'")
s = string.gsub(s, "&#124;", "|")
s = string.gsub(s, "&#160;", " ")
s = string.gsub(s, "&#174;", "®")
s = string.gsub(s, "&#187;", "»")
s = string.gsub(s, "&#223;", "ß")
s = string.gsub(s, "&#8211;", "")
s = string.gsub(s, "&#8217;", "'")
s = string.gsub(s, "&#8220;", "")
s = string.gsub(s, "&#8221;", "")
s = string.gsub(s, "&#8222;", "")
s = string.gsub(s, "&#8249;", "")
s = string.gsub(s, "&#8364;", "")
-- Ä Ö Ü
s = string.gsub(s, "&auml;", "ä")
s = string.gsub(s, "&Auml;", "Ä")
s = string.gsub(s, "&#228;", "ä")
s = string.gsub(s, "&#196;", "Ä")
s = string.gsub(s, "&ouml;", "ö")
s = string.gsub(s, "&Ouml;", "Ö")
s = string.gsub(s, "&#246;", "ö")
s = string.gsub(s, "&#214;", "Ö")
s = string.gsub(s, "&uuml;", "ü")
s = string.gsub(s, "&Uuml;", "Ü")
s = string.gsub(s, "&#252;", "ü")
s = string.gsub(s, "&#220;", "Ü")
-- Put all the tags in lowercase.
s = string.gsub(s, "(<[^ >]+)", string.lower)
s = string.gsub(s, "&amp;", "&") -- 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]
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
title == "Not Found" or
title == "Document Moved" or
title == "521: Web server is down" or
string.match(title, "on Steam") 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, "myanimelist.net/profile/") 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, "openings.moe/%?video") or
string.match(msg.text, "myfigurecollection.net") or
string.match(msg.text, "dropbox.com/s/") or
string.match(msg.text, "nicovideo.jp/watch/sm") or
string.ends(url, ".jpg") or
string.ends(url, ".jpeg") or
string.ends(url, ".gif") or
string.ends(url, ".png") then
print('Ungültig, da "'..title..'"')
else
return title
end
end
return {
description = "Postet den URL-Titel",
usage = {""},
patterns = {"^(https?://[%w-_%.%?%.:,/%+=&#!]+)$"},
run = run
}
end