X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=data%2Frbot%2Fplugins%2Fbash.rb;h=cb33a4d48353076c75c66a3d9610b0681fc5158c;hb=d432b9e11936eebb379c6f589879dd8d40ac7163;hp=93d9c3f2af77f54844bb77b2edd7b79f3dbd4f79;hpb=109fa2a5b63af113df2c6b21d44135efa0d94d70;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/data/rbot/plugins/bash.rb b/data/rbot/plugins/bash.rb index 93d9c3f2..cb33a4d4 100644 --- a/data/rbot/plugins/bash.rb +++ b/data/rbot/plugins/bash.rb @@ -19,18 +19,40 @@ require 'rexml/document' class ::BashQuote - attr_accessor :num, :text, :vote + attr_accessor :num, :text, :irc_text, :vote def initialize(num, text, vote) @num = num.to_i @text = text @vote = vote + @irc_text = mk_irc_text end def url "http://www.bash.org/?#{@num}" end + private + def mk_irc_text + cur_nick = nil + last_nick = nil + text = String.new + @text.each_line { |l| + debug "line: #{l.inspect}" + cur_nick = l.match(/^\s*(<.*?>|\(.*?\)|.*?:)\s/)[1] rescue nil + debug "nick: #{cur_nick.inspect}; last: #{last_nick.inspect}" + if cur_nick and cur_nick == last_nick + text << l.sub(cur_nick,"") + else + last_nick = cur_nick.dup if cur_nick + text << l + end + } + debug text + # TODO: the gsub of br tags to | should be an ircify_html option + text.gsub(/(?:
\s*)+/, ' | ').ircify_html + end + end class BashPlugin < Plugin @@ -98,8 +120,7 @@ class BashPlugin < Plugin # may want to echo more than one for latest/random quote = quotes.first end - # TODO: the gsub of br tags to | should be an ircify_html option - m.reply "#%d (%d): %s" % [quote.num, quote.vote, quote.text.gsub(/(?:
\s*)+/, ' | ').ircify_html] + m.reply "#%d (%d): %s" % [quote.num, quote.vote, quote.irc_text] end def xml_bash(m, id=nil)