summaryrefslogtreecommitdiffstats
blob: e9f975417357b9220521ea2beef0d335370d578c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function url_grabber(body, muc, nick, message)
	local url = body:match("http://.%S+")
	print("Looking for URL")
	print(url)
	if url then
		print ("found")
		local http = require("socket.http")
		http.TIMEOUT = 5
		--r, c, h = http.request({method = "HEAD", url = url})
		--clen = tonumber(h["content-length"])
		--if clen and clen > 0 and clen < 1024 * 1024 then
			b, c, h = http.request(url)
			local subjectish = b:match("<title>.+</title>")
			print("subjectish")
			print(subjectish)
			if subjectish then 
				local subject = string.gsub(subjectish, "</?title>", "")
				subject = subject:gsub("\n", " | ");
				if subject then
					swiftob_reply_to(message, url..":\n"..subject)
				end
			end
		--else
		--	print("Skipping because missing or too long:")
		--	print(clen)
		--end
	end
end

swiftob_register_listener(url_grabber, false)