From 3a3794f0c1a5ca3b9c27fe486c7fcd9690d34fca Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 28 Jan 2009 18:01:55 +0100 Subject: [PATCH] rss plugin: compact list of rss feeds When lots of rss feeds are defined, the bot will flood the channel on rss list. Fix by showing a compact list when the number of feeds is higher than the maximum output lines. --- data/rbot/plugins/rss.rb | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/data/rbot/plugins/rss.rb b/data/rbot/plugins/rss.rb index 6d8d3c26..18219074 100644 --- a/data/rbot/plugins/rss.rb +++ b/data/rbot/plugins/rss.rb @@ -644,19 +644,34 @@ class RSSFeedsPlugin < Plugin def list_rss(m, params) wanted = params[:handle] - reply = String.new - @feeds.each { |handle, feed| - next if wanted and !handle.match(/#{wanted}/i) - reply << "#{feed.handle}: #{feed.url} (in format: #{feed.type ? feed.type : 'default'})" - (reply << " refreshing every #{Utils.secs_to_string(feed.refresh_rate)}") if feed.refresh_rate - (reply << " (watched)") if feed.watched_by?(m.replyto) - reply << "\n" - } - if reply.empty? + listed = @feeds.keys + if wanted + wanted_rx = Regexp.new(wanted, true) + listed.reject! { |handle| !handle.match(wanted_rx) } + end + listed.sort! + debug listed + if @bot.config['send.max_lines'] > 0 and listed.size > @bot.config['send.max_lines'] + reply = listed.inject([]) do |ar, handle| + feed = @feeds[handle] + string = handle.dup + (string << " (#{feed.type})") if feed.type + (string << " (watched)") if feed.watched_by?(m.replyto) + ar << string + end.join(', ') + elsif listed.size > 0 + reply = listed.inject([]) do |ar, handle| + feed = @feeds[handle] + string = "#{feed.handle}: #{feed.url} (in format: #{feed.type ? feed.type : 'default'})" + (string << " refreshing every #{Utils.secs_to_string(feed.refresh_rate)}") if feed.refresh_rate + (string << " (watched)") if feed.watched_by?(m.replyto) + ar << string + end.join("\n") + else reply = "no feeds found" reply << " matching #{wanted}" if wanted end - m.reply reply, :max_lines => reply.length + m.reply reply, :max_lines => 0 end def watched_rss(m, params) -- 2.32.0.93.g670b81a890