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

51 lines
1.2 KiB
Lua
Raw Normal View History

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
if title == "301 Moved Permanently" or
title == "" or
title == "404 Not Found" or
title == "302 Found" or
title == "Moved Permanently" or
string.match(title, "deviantArt") or
string.match(title, "twitch") or
string.match(title, "eBay</title>") 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-20 18:52:25 +02:00
usage = "Irgendein Link",
patterns = {"(https?://[%w-_%.%?%.:/%+=&]+)$",},
2015-04-14 20:21:23 +02:00
run = run
}
end