RSS: Allow @announce add to take URLs as feed names.

This commit is contained in:
Valentin Lorentz 2015-10-10 20:40:25 +02:00
parent da8689c320
commit fb52b16429
2 changed files with 25 additions and 1 deletions

View File

@ -465,7 +465,8 @@ class RSS(callbacks.Plugin):
message isn't sent in the channel itself.
"""
plugin = irc.getCallback('RSS')
invalid_feeds = [x for x in feeds if not plugin.get_feed(x)]
invalid_feeds = [x for x in feeds if not plugin.get_feed(x)
and not utils.web.urlRe.match(x)]
if invalid_feeds:
irc.error(format(_('These feeds are unknown: %L'),
invalid_feeds), Raise=True)
@ -477,6 +478,10 @@ class RSS(callbacks.Plugin):
irc.replySuccess()
for name in feeds:
feed = plugin.get_feed(name)
if not feed:
plugin.register_feed_config(name, name)
plugin.register_feed(name, name, True, False)
feed = plugin.get_feed(name)
plugin.announce_feed(feed, True)
add = wrap(add, [('checkChannelCapability', 'op'),
many(first('url', 'feedName'))])

View File

@ -131,6 +131,25 @@ class RSSTestCase(ChannelPluginTestCase):
self._feedMsg('rss remove xkcd')
feedparser._open_resource = old_open
def testAnnounceAnonymous(self):
old_open = feedparser._open_resource
feedparser._open_resource = constant(xkcd_old)
try:
self.assertNotError('rss announce add http://xkcd.com/rss.xml')
self.assertNotError(' ')
with conf.supybot.plugins.RSS.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(' ', 'Chaos')
finally:
self._feedMsg('rss announce remove http://xkcd.com/rss.xml')
self._feedMsg('rss remove http://xkcd.com/rss.xml')
feedparser._open_resource = old_open
def testAnnounceReload(self):
old_open = feedparser._open_resource
feedparser._open_resource = constant(xkcd_old)