summaryrefslogtreecommitdiff
path: root/data/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-08-22 19:57:59 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-08-22 19:57:59 +0000
commit25a834d62139b1be63e94974a9a6fe94b8cd7006 (patch)
treede44bfacc3408e39e8b4ba6ca2d8d6482004291c /data/rbot
parent291d1dc8cbb398e3e62cbf92688e21561a0019f5 (diff)
bash plugin: collapse consecutive lines from the same nick
Diffstat (limited to 'data/rbot')
-rw-r--r--data/rbot/plugins/bash.rb27
1 files changed, 24 insertions, 3 deletions
diff --git a/data/rbot/plugins/bash.rb b/data/rbot/plugins/bash.rb
index 93d9c3f2..d2c3c469 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*(&lt;.*?&gt;|.*?:)/)[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(/(?:<br \/>\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(/(?:<br \/>\s*)+/, ' | ').ircify_html]
+ m.reply "#%d (%d): %s" % [quote.num, quote.vote, quote.irc_text]
end
def xml_bash(m, id=nil)