diff options
Diffstat (limited to 'Swiftob')
-rw-r--r-- | Swiftob/scripts/urlGrabber.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Swiftob/scripts/urlGrabber.lua b/Swiftob/scripts/urlGrabber.lua new file mode 100644 index 0000000..13fe182 --- /dev/null +++ b/Swiftob/scripts/urlGrabber.lua @@ -0,0 +1,30 @@ +function url_grabber(body, muc, nick, message) + 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) + subjectish = b:match("<title>.+</title>") + print("subjectish") + print(subjectish) + if subjectish then + subject = string.gsub(subjectish, "</?title>", "") + 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) + |