diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 68f2d4e9c..b5ee7365c 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -229,6 +229,10 @@ class RSS(callbacks.Plugin): conf.registerChannelValue(feed_group, 'announceFormat', registry.String('', _("""Feed-specific announce format. Defaults to supybot.plugins.RSS.announceFormat if empty."""))) + conf.registerGlobalValue(feed_group, 'waitPeriod', + registry.NonNegativeInteger(0, _("""If set to a non-zero + value, overrides supybot.plugins.RSS.waitPeriod for this + particular feed."""))) def register_feed(self, name, url, initial, plugin_is_loading, announced=[]): @@ -273,7 +277,12 @@ class RSS(callbacks.Plugin): def is_expired(self, feed): assert feed - event_horizon = time.time() - self.registryValue('waitPeriod') + period = self.registryValue('waitPeriod') + if feed.name != feed.url: # Named feed + specific_period = self.registryValue('feeds.%s.waitPeriod' % feed.name) + if specific_period: + period = specific_period + event_horizon = time.time() - period return feed.last_update < event_horizon ############### diff --git a/plugins/RSS/test.py b/plugins/RSS/test.py index ab26d69e8..53b726688 100644 --- a/plugins/RSS/test.py +++ b/plugins/RSS/test.py @@ -163,6 +163,34 @@ class RSSTestCase(ChannelPluginTestCase): self._feedMsg('rss remove xkcdsec') feedparser._open_resource = old_open + def testFeedSpecificWaitPeriod(self): + old_open = feedparser._open_resource + feedparser._open_resource = constant(xkcd_old) + try: + self.assertNotError('rss add xkcd1 http://xkcd.com/rss.xml') + self.assertNotError('rss announce add xkcd1') + self.assertNotError('rss add xkcd2 http://xkcd.com/rss.xml&foo') + self.assertNotError('rss announce add xkcd2') + self.assertNotError(' ') + self.assertNotError(' ') + with conf.supybot.plugins.RSS.feeds.xkcd1.waitPeriod.context(1): + time.sleep(1.1) + self.assertNoResponse(' ') + self.assertNoResponse(' ') + feedparser._open_resource = constant(xkcd_new) + self.assertNoResponse(' ') + time.sleep(1.1) + self.assertRegexp(' ', 'xkcd1.*Chaos') + self.assertNoResponse(' ') + time.sleep(1.1) + self.assertNoResponse(' ') + finally: + self._feedMsg('rss announce remove xkcd1') + self._feedMsg('rss remove xkcd1') + self._feedMsg('rss announce remove xkcd2') + self._feedMsg('rss remove xkcd2') + feedparser._open_resource = old_open + if network: def testRssinfo(self): self.assertNotError('rss info %s' % url)