X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fri.rb;h=abecb6ec5a5966b57f52e0dd99593ae4d8715053;hb=16336b4a240a4265d1f2df1e30d7b68d3a924287;hp=f55cdf4dd8c0c8047ad6a3ec90507e179de8266f;hpb=620a8f02cb5d0d711b90f75937a8d268750c2715;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/ri.rb b/data/rbot/plugins/ri.rb index f55cdf4d..abecb6ec 100644 --- a/data/rbot/plugins/ri.rb +++ b/data/rbot/plugins/ri.rb @@ -1,16 +1,42 @@ -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") +#-- vim:sw=2:et +#++ +# +# :title: 'ri' -- ruby documentation plugin +# +# 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 +# +class RiPlugin < Plugin RI_COMMAND = %w{ri -f simple -T} + Config.register Config::IntegerValue.new('ri.max_length', + :default => 512, + :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' @@ -23,17 +49,26 @@ 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' + + if ret.length > @bot.config['ri.max_length'] + if !m.private? && tgt.to_s != m.sourcenick + 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 + end + if tgt + @bot.say(tgt, ret) + m.okay + else + m.reply(ret) end - m.reply(ret) return end end + plugin = RiPlugin.new -plugin.map 'ri :something', +plugin.map 'ri :something', :requirements => {:something => /^((-c)|(\w\S+))$/} +plugin.map 'ri [tell] :who [about] :something', :requirements => {:something => /^((-c)|(\w\S+))$/}