]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
rss plugin: upper limit for watched feeds
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Fri, 27 Feb 2009 20:40:16 +0000 (21:40 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 28 Feb 2009 01:23:08 +0000 (02:23 +0100)
Config option to set the maximum number of items that will be announced
when a feed updates. 0 means all of them, anything else clips the list
to the latest ones, and also announces that some of the updates will not
be listed.

data/rbot/plugins/rss.rb

index bfc700d3e90a6738b3282e3f662c89fc1dd5c0f6..30d09bd3a3280b7f875e5efa33a84c62e52bb1bd 100644 (file)
@@ -282,6 +282,10 @@ class RSSFeedsPlugin < Plugin
     :default => 0,
     :desc => "Don't announce watched feed if these many seconds elapsed since the last successful update")
 
+  Config.register Config::IntegerValue.new('rss.announce_max',
+    :default => 3,
+    :desc => "Maximum number of new items to announce when a watched feed is updated")
+
   Config.register Config::BooleanValue.new('rss.show_updated',
     :default => true,
     :desc => "Whether feed items for which the description was changed should be shown as new")
@@ -957,7 +961,19 @@ class RSSFeedsPlugin < Plugin
                 }
 
                 if dispItems.length > 0
+                  max = @bot.config['rss.announce_max']
                   debug "Found #{dispItems.length} new items in #{feed}"
+                  if max > 0 and dispItems.length > max
+                    debug "showing only the latest #{dispItems.length}"
+                    feed.watchers.each do |loc|
+                      @bot.say loc, (_("feed %{feed} had %{num} updates, showing the latest %{max}") % {
+                        :feed => feed.handle,
+                        :num => dispItems.length,
+                        :max => max
+                      })
+                    end
+                    dispItems.slice!(max..-1)
+                  end
                   # When displaying watched feeds, publish them from older to newer
                   dispItems.reverse.each { |item|
                     printFormattedRss(feed, item)