4 # :title: 'ri' -- ruby documentation plugin
6 # Author:: Eric Hodel <drbrain@segment7.net> (aka drbrain)
7 # Author:: Michael Brailsford <brailsmt@yahoo.com> aka brailsmt
8 # Author:: dmitry kim <dmitry dot kim at gmail dot com>
9 # Copyright:: (C) 2007, dmitry kim
10 # Copyright:: (C) Eric Hodel
11 # Copyright:: (C) Michael Brailsford
15 class RiPlugin < Plugin
17 RI_COMMAND = %w{ri -f simple -T}
19 BotConfig.register BotConfigIntegerValue.new('ri.max_length',
21 :desc => "Maximum length of ri entry (in bytes) which is ok to be sent to channels or other users")
23 def help(plugin, topic="")
24 "ri <something> => returns ruby documentation for <something>; ri [tell] <whom> [about] <something> => sends the documentation entry about <something> to <whom> using /msg"
31 if params[:who] != m.sourcenick
32 m.reply '"ri tell <who>" syntax is only allowed in public channels'
35 elsif !(tgt = m.channel.users[params[:who]])
36 m.reply "sorry, i don't see user #{params[:who]} here on #{m.channel}"
41 if a = params[:something]
50 ret = Utils.safe_exec(*args)
52 return m.reply("failed to execute ri")
54 ret = ret.gsub(/\t/, " ").split(/\n/).join(" ").gsub(/\s\s+/, ' ')
56 if ret.length > @bot.config['ri.max_length']
57 if !m.private? && tgt.to_s != m.sourcenick
58 return m.reply('entry is too long to send to the channel or to some other user, use /msg to ask me about it')
72 plugin.map 'ri :something', :requirements => {:something => /^((-c)|(\w\S+))$/}
73 plugin.map 'ri [tell] :who [about] :something',
74 :requirements => {:something => /^((-c)|(\w\S+))$/}