diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-01-28 18:01:55 +0100 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-01-28 18:01:55 +0100 |
commit | 3a3794f0c1a5ca3b9c27fe486c7fcd9690d34fca (patch) | |
tree | 11735028fc68f89bbf5327d0e7ff37b480e356b9 /data/rbot/plugins | |
parent | 78978a4654ad851b0fa18bcd3d165b9c173f0375 (diff) |
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.
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r-- | data/rbot/plugins/rss.rb | 35 |
1 files 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) |