diff options
author | Dmitry Kim <dmitry point kim at gmail point com> | 2007-04-06 14:05:53 +0000 |
---|---|---|
committer | Dmitry Kim <dmitry point kim at gmail point com> | 2007-04-06 14:05:53 +0000 |
commit | 620a8f02cb5d0d711b90f75937a8d268750c2715 (patch) | |
tree | b554ca9ff62e8709261d1329d3e555d896e052d5 | |
parent | 3a70c86c98ba9ab8f329e92104a0824f6b1d1f21 (diff) |
+ (plugins/) 'ri' plugin (the same functionality as ruby 'ri' command)
-rw-r--r-- | data/rbot/plugins/ri.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/data/rbot/plugins/ri.rb b/data/rbot/plugins/ri.rb new file mode 100644 index 00000000..f55cdf4d --- /dev/null +++ b/data/rbot/plugins/ri.rb @@ -0,0 +1,39 @@ +class RiPlugin < Plugin + + BotConfig.register BotConfigIntegerValue.new('ri.max_length', + :default => 512, + :desc => "Maximum length of ri entry (in bytes) which is ok to be sent to channels") + + + RI_COMMAND = %w{ri -f simple -T} + + def help(plugin, topic="") + "ri <something> => returns ruby documentation for <something>" + end + def ri(m, params) + args = RI_COMMAND.dup + if a = params[:something] + if a == '-c' + args.push(a) + else + args.push('--') + args.push(a) + end + end + begin + ret = Utils.safe_exec(*args) + rescue + ret = "failed to execute ri" + end + ret = ret.gsub(/\t/, " ").split(/\n/).join(" ").gsub(/\s\s+/, ' ') + + if ret.length > @bot.config['ri.max_length'] && !m.private? + ret = 'entry is too long to send to the channel, use /msg to ask me about it' + end + m.reply(ret) + return + end +end +plugin = RiPlugin.new +plugin.map 'ri :something', + :requirements => {:something => /^((-c)|(\w\S+))$/} |