From 9efe37db63efbe8c2e360fed93382e59bf1b417b Mon Sep 17 00:00:00 2001 From: Dmitry Kim Date: Fri, 6 Apr 2007 15:42:35 +0000 Subject: + (plugins/ri) "ri [tell] [about] " syntax support + (plugins/ri) add Eric Hodel to the header credits section --- data/rbot/plugins/ri.rb | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'data/rbot/plugins') diff --git a/data/rbot/plugins/ri.rb b/data/rbot/plugins/ri.rb index 5bde894c..472c08e3 100644 --- a/data/rbot/plugins/ri.rb +++ b/data/rbot/plugins/ri.rb @@ -3,9 +3,11 @@ # # :title: 'ri' -- ruby documentation plugin # -# Author: Michael Brailsford aka brailsmt +# Author:: Eric Hodel (aka drbrain) +# Author:: Michael Brailsford aka brailsmt # Author:: dmitry kim # Copyright:: (C) 2007, dmitry kim +# Copyright:: (C) Eric Hodel # Copyright:: (C) Michael Brailsford # License:: MIT # @@ -16,13 +18,25 @@ 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") + :desc => "Maximum length of ri entry (in bytes) which is ok to be sent to channels or other users") def help(plugin, topic="") - "ri => returns ruby documentation for " + "ri => returns ruby documentation for ; ri [tell] [about] => sends the documentation entry about to using /msg" end def ri(m, params) + tgt = nil + if params[:who] + if m.private? + if params[:who] != m.sourcenick + m.reply '"ri tell " syntax is only allowed in public channels' + return + end + elsif !(tgt = m.channel.users[params[:who]]) + m.reply "sorry, i don't see user #{params[:who]} here on #{m.channel}" + return + end + end args = RI_COMMAND.dup if a = params[:something] if a == '-c' @@ -35,17 +49,23 @@ class RiPlugin < Plugin begin ret = Utils.safe_exec(*args) rescue - ret = "failed to execute ri" + return m.reply("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' + return m.reply('entry is too long to send to the channel or to some other user, use /msg to ask me about it') + end + if tgt + @bot.say(tgt, ret) + else + m.reply(ret) end - m.reply(ret) return end end plugin = RiPlugin.new plugin.map 'ri :something', :requirements => {:something => /^((-c)|(\w\S+))$/} +plugin.map 'ri [tell] :who [about] :something', + :requirements => {:something => /^((-c)|(\w\S+))$/} -- cgit v1.2.3