RSS: add 'announce channels' command to list channels a feed is announced to

Closes #1322.
This commit is contained in:
James Lu 2019-10-06 11:42:31 -07:00 committed by Valentin Lorentz
parent ba6878375b
commit 3c23faf1bd
2 changed files with 30 additions and 0 deletions

View File

@ -550,6 +550,30 @@ class RSS(callbacks.Plugin):
remove = wrap(remove, [('checkChannelCapability', 'op'),
many(first('url', 'feedName'))])
@internationalizeDocstring
def channels(self, irc, msg, args, feed):
"""<name|url>
Returns a list of channels that the given feed name or URL is being
announced to.
"""
plugin = irc.getCallback('RSS')
if not plugin.get_feed(feed):
irc.error(_("Unknown feed %s" % feed), Raise=True)
channels = []
for ircnet in world.ircs:
for channel in ircnet.state.channels:
if feed in plugin.registryValue('announce', channel, ircnet.network):
channels.append(ircnet.network + channel)
if channels:
irc.reply(format("%s is announced to %L.", feed, channels))
else:
irc.reply("%s is not announced to any channels." % feed)
channels = wrap(channels, ['feedName'])
@internationalizeDocstring
def rss(self, irc, msg, args, url, n):
"""<name|url> [<number of headlines>]

View File

@ -357,9 +357,15 @@ class RSSTestCase(ChannelPluginTestCase):
timeFastForward(1.1)
self.assertNotError('rss add advogato %s' % url)
self.assertNotError('rss announce add advogato')
self.assertRegexp('rss announce channels advogato', 'advogato is announced to.*%s%s' % (self.irc.network, self.channel))
self.assertNotRegexp('rss announce', r'ValueError')
self.assertNotError('rss announce remove advogato')
self.assertRegexp('rss announce channels advogato', 'advogato is not announced to any channels')
self.assertNotError('rss remove advogato')
self.assertRegexp('rss announce channels advogato', 'Unknown feed')
def testRss(self):
timeFastForward(1.1)