summaryrefslogtreecommitdiff
path: root/data/rbot/contrib/plugins/ri.rb
diff options
context:
space:
mode:
authorTom Gilbert <tom@linuxbrit.co.uk>2005-07-27 15:59:13 +0000
committerTom Gilbert <tom@linuxbrit.co.uk>2005-07-27 15:59:13 +0000
commit21949774b91eaec6ecde4eaa8ad121e2c0a36b87 (patch)
tree41a7601e168018ac203bad7ca8d7f9f82515bc28 /data/rbot/contrib/plugins/ri.rb
parent51cf09ec02d089bfdd80e5f728cfc92a234dc437 (diff)
rearrange repo for packaging
Diffstat (limited to 'data/rbot/contrib/plugins/ri.rb')
-rw-r--r--data/rbot/contrib/plugins/ri.rb83
1 files changed, 83 insertions, 0 deletions
diff --git a/data/rbot/contrib/plugins/ri.rb b/data/rbot/contrib/plugins/ri.rb
new file mode 100644
index 00000000..99292f1c
--- /dev/null
+++ b/data/rbot/contrib/plugins/ri.rb
@@ -0,0 +1,83 @@
+# Author: Michael Brailsford <brailsmt@yahoo.com>
+# aka brailsmt
+# Purpose: To respond to requests for information from the ri command line
+# utility.
+
+class RiPlugin < Plugin
+
+ @@handlers = {
+ "ri" => "ri_handler",
+ "msgri" => "msgri_handler"
+ }
+
+ #{{{
+ def initialize
+ super
+ @cache = Hash.new
+ end
+ #}}}
+ #{{{
+ def privmsg(m)
+ if not m.params
+ m.reply "uhmm... whatever"
+ return
+ end
+
+ meth = self.method(@@handlers[m.plugin])
+ meth.call(m)
+ end
+ #}}}
+ #{{{
+ def cleanup
+ @cache = nil
+ end
+ #}}}
+ #{{{
+ def ri_handler(m)
+ response = ""
+ if @cache[m.params]
+ response = @cache[m.params]
+ else
+ IO.popen("-") {|p|
+ if(p)
+ response = p.readlines.join "\n"
+ @cache[m.params] = response
+ else
+ $stderr = $stdout
+ exec("ri", m.params)
+ end
+ }
+ @cache[m.params] = response
+ end
+
+ @bot.say m.sourcenick, response
+ m.reply "Finished \"ri #{m.params}\""
+ end
+ #}}}
+ #{{{
+ def msgri_handler(m)
+ response = ""
+ tell_nick, query = m.params.split()
+ if @cache[query]
+ response = @cache[query]
+ else
+ IO.popen("-") {|p|
+ if(p)
+ response = p.readlines.join "\n"
+ @cache[m.params] = response
+ else
+ $stderr = $stdout
+ exec("ri", query)
+ end
+ }
+ @cache[query] = response
+ end
+
+ @bot.say tell_nick, response
+ m.reply "Finished telling #{tell_nick} about \"ri #{query}\""
+ end
+ #}}}
+end
+plugin = RiPlugin.new
+plugin.register("ri")
+plugin.register("msgri")