aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2008-10-11 05:59:13 +0000
committerRobin H. Johnson <robbat2@gentoo.org>2008-10-11 05:59:13 +0000
commit6d6061f1c2a148e6b594039e2b25bff26995942a (patch)
tree01abd50f4a546d21547b40ff445099fd992cfd7d
parentAdd automatic URL listener code. (diff)
downloadrbot-gentoo-6d6061f1c2a148e6b594039e2b25bff26995942a.tar.gz
rbot-gentoo-6d6061f1c2a148e6b594039e2b25bff26995942a.tar.bz2
rbot-gentoo-6d6061f1c2a148e6b594039e2b25bff26995942a.zip
Make it work much similar to the original jeeves functionality. If you want a tinyurl form of the last URL in a channel, just call !lasturl.
-rw-r--r--gentoo-tinyurl.rb31
1 files changed, 28 insertions, 3 deletions
diff --git a/gentoo-tinyurl.rb b/gentoo-tinyurl.rb
index 5bbab71..8a6f6d9 100644
--- a/gentoo-tinyurl.rb
+++ b/gentoo-tinyurl.rb
@@ -2,7 +2,10 @@ require "shorturl"
class GentooShortenURLs < Plugin
def initialize
super
+ @@cached = {}
+ @@cached['lasturl'] = {}
end
+
def lurk?(m)
replyto = nil
replyto = m.replyto.to_s if m.is_a?(Irc::UserMessage)
@@ -11,20 +14,42 @@ class GentooShortenURLs < Plugin
end
def listen(m)
return if m.address?
- return unless lurk?(m)
+ #return unless lurk?(m)
return unless m.message =~ /(\b|^)[a-z]+:\/\/.*($|\s)/i
m.message.split.each do |word|
next unless word =~ /(\b|^)[a-z]+:\/\/.*($|\s)/i
- next unless word.length >= 32
- shrink(m, {:url => word})
+ #next unless word.length >= 32
+ #shrink(m, {:url => word})
+ set_lasturl(m, word)
end
end
def shrink(m, params)
short = ShortURL.shorten(params[:url], :tinyurl)
m.reply short
end
+ def fetch_lasturl(m)
+ address = m.replyto.to_s
+ url = [0, nil]
+ url = @@cached['lasturl'][address] if @@cached['lasturl'].has_key?(address)
+ return url
+ end
+ def set_lasturl(m, url)
+ address = m.replyto.to_s
+ @@cached['lasturl'][address] = [Time.now.tv_sec, url]
+ end
+ def lasturl(m, params)
+ url = fetch_lasturl(m)
+ if url[1]
+ shrink(m, {:url => url})
+ else
+ m.reply "No URL seen yet"
+ end
+ end
end
plugin = GentooShortenURLs.new
plugin.map 't :url',
:action => 'shrink',
:auth_path => 'view'
+plugin.map 'lasturl',
+ :action => 'lasturl',
+ :auth_path => 'view'