Make RSS.announce a nested plugin

This simplifies the interface for dealing with announced feeds by providing
separate "announce add", "announce remove", "announce list" commands as
opposed to the one "announce" command with confusing syntax.

Signed-off-by: James Vega <jamessan@users.sourceforge.net>
This commit is contained in:
James Vega 2009-02-28 00:10:10 -05:00
parent 0e05fe67c7
commit 62acb0c998
2 changed files with 45 additions and 41 deletions

View File

@ -324,47 +324,51 @@ class RSS(callbacks.Plugin):
irc.replySuccess() irc.replySuccess()
remove = wrap(remove, ['feedName']) remove = wrap(remove, ['feedName'])
def announce(self, irc, msg, args, channel, optlist, rest): class announce(callbacks.Commands):
"""[<channel>] [--remove] [<name|url> ...] def list(self, irc, msg, args, channel):
"""[<channel>]
Adds the list of <name|url> to the current list of announced feeds in Returns the list of feeds announced in <channel>. <channel> is
the channel given. Valid feeds include the names of registered feeds only necessary if the message isn't sent in the channel itself.
as well as URLs for a RSS feeds. <channel> is only necessary if the """
message isn't sent in the channel itself. If no arguments are announce = conf.supybot.plugins.RSS.announce
specified, replies with the current list of feeds to announce. If
--remove is given, the specified feeds will be removed from the list
of feeds to announce.
"""
remove = False
announce = conf.supybot.plugins.RSS.announce
for (option, _) in optlist:
if option == 'remove':
if not rest:
raise callbacks.ArgumentError
remove = True
def addFeed(feed):
if feed not in feeds:
feeds.add(feed)
def removeFeed(feed):
if feed in feeds:
feeds.remove(feed)
if rest:
if remove:
updater = removeFeed
else:
updater = addFeed
feeds = announce.get(channel)()
for feed in rest:
updater(feed)
announce.get(channel).setValue(feeds)
irc.replySuccess()
elif not rest:
feeds = format('%L', list(announce.get(channel)())) feeds = format('%L', list(announce.get(channel)()))
irc.reply(feeds or 'I am currently not announcing any feeds.') irc.reply(feeds or 'I am currently not announcing any feeds.')
return list = wrap(list, [optional('channel')])
announce = wrap(announce, [('checkChannelCapability', 'op'),
getopts({'remove':''}), def add(self, irc, msg, args, channel, feeds):
any(first('url', 'feedName'))]) """[<channel>] <name|url> [<name|url> ...]
Adds the list of feeds to the current list of announced feeds in
<channel>. Valid feeds include the names of registered feeds as
well as URLs for RSS feeds. <channel> is only necessary if the
message isn't sent in the channel itself.
"""
announce = conf.supybot.plugins.RSS.announce
S = announce.get(channel)()
for feed in feeds:
S.add(feed)
announce.get(channel).setValue(S)
irc.replySuccess()
add = wrap(add, [('checkChannelCapability', 'op'),
many(first('url', 'feedName'))])
def remove(self, irc, msg, args, channel, feeds):
"""[<channel>] <name|url> [<name|url> ...]
Removes the list of feeds from the current list of announced feeds
in <channel>. Valid feeds include the names of registered feeds as
well as URLs for RSS feeds. <channel> is only necessary if the
message isn't sent in the channel itself.
"""
announce = conf.supybot.plugins.RSS.announce
S = announce.get(channel)()
for feed in feeds:
S.discard(feed)
announce.get(channel).setValue(S)
irc.replySuccess()
remove = wrap(remove, [('checkChannelCapability', 'op'),
many(first('url', 'feedName'))])
def rss(self, irc, msg, args, url, n): def rss(self, irc, msg, args, url, n):
"""<url> [<number of headlines>] """<url> [<number of headlines>]

View File

@ -1,5 +1,6 @@
### ###
# Copyright (c) 2002-2004, Jeremiah Fincher # Copyright (c) 2002-2004, Jeremiah Fincher
# Copyright (c) 2009, James Vega
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -55,9 +56,9 @@ class RSSTestCase(ChannelPluginTestCase):
def testAnnounce(self): def testAnnounce(self):
self.assertNotError('rss add advogato %s' % url) self.assertNotError('rss add advogato %s' % url)
self.assertNotError('rss announce advogato') self.assertNotError('rss announce add advogato')
self.assertNotRegexp('rss announce', r'ValueError') self.assertNotRegexp('rss announce', r'ValueError')
self.assertNotError('rss announce --remove advogato') self.assertNotError('rss announce remove advogato')
self.assertNotError('rss remove advogato') self.assertNotError('rss remove advogato')
def testRss(self): def testRss(self):
@ -81,4 +82,3 @@ class RSSTestCase(ChannelPluginTestCase):
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: