summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-07-28 09:56:04 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-07-28 11:55:02 (GMT)
commitea816801a9d73529bbf9eb3800fef8e85a18d6ca (patch)
tree84949a99765feb853480c0c56f970ec455cb6b61
parentca3044becf1192be24ec7006c9a46040502662fa (diff)
downloadswift-contrib-ea816801a9d73529bbf9eb3800fef8e85a18d6ca.zip
swift-contrib-ea816801a9d73529bbf9eb3800fef8e85a18d6ca.tar.bz2
URL grabber
-rw-r--r--Swiftob/scripts/urlGrabber.lua30
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)
+