From 0f3e302547363ea237454dda891ddb5de1be4476 Mon Sep 17 00:00:00 2001 From: Tom Gilbert Date: Sat, 9 Oct 2004 01:51:05 +0000 Subject: initial import of rbot --- contrib/plugins/ri.rb | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 contrib/plugins/ri.rb (limited to 'contrib/plugins/ri.rb') diff --git a/contrib/plugins/ri.rb b/contrib/plugins/ri.rb new file mode 100644 index 00000000..99292f1c --- /dev/null +++ b/contrib/plugins/ri.rb @@ -0,0 +1,83 @@ +# Author: Michael Brailsford +# 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") -- cgit v1.2.3