mirror of
https://github.com/progval/Limnoria.git
synced 2025-05-02 16:31:09 -05:00
Improved RSS.announce
This commit is contained in:
parent
9d4b715004
commit
27e3b07119
@ -1,3 +1,7 @@
|
|||||||
|
* Improved the functionality of RSS.announce. Calling it with
|
||||||
|
no arguments now lists the currently announced feeds. Removing
|
||||||
|
feeds is done by specifying the --remove option.
|
||||||
|
|
||||||
* Added a reconnect command to the Owner plugin. It won't work
|
* Added a reconnect command to the Owner plugin. It won't work
|
||||||
for people using asyncoreDrivers, but those people should be few
|
for people using asyncoreDrivers, but those people should be few
|
||||||
and far between these days.
|
and far between these days.
|
||||||
|
@ -39,6 +39,7 @@ import plugins
|
|||||||
|
|
||||||
import sets
|
import sets
|
||||||
import time
|
import time
|
||||||
|
import getopt
|
||||||
import sgmllib
|
import sgmllib
|
||||||
import threading
|
import threading
|
||||||
from itertools import imap
|
from itertools import imap
|
||||||
@ -64,6 +65,10 @@ def configure(advanced):
|
|||||||
url = something('What\'s the URL of the RSS feed?')
|
url = something('What\'s the URL of the RSS feed?')
|
||||||
registerFeed(name, url)
|
registerFeed(name, url)
|
||||||
|
|
||||||
|
class AnnouncedFeeds(registry.SpaceSeparatedListOf):
|
||||||
|
Value = registry.String
|
||||||
|
List = ircutils.IrcSet
|
||||||
|
|
||||||
conf.registerPlugin('RSS')
|
conf.registerPlugin('RSS')
|
||||||
conf.registerChannelValue(conf.supybot.plugins.RSS, 'bold', registry.Boolean(
|
conf.registerChannelValue(conf.supybot.plugins.RSS, 'bold', registry.Boolean(
|
||||||
True, """Determines whether the bot will bold the title of the feed when it
|
True, """Determines whether the bot will bold the title of the feed when it
|
||||||
@ -76,9 +81,9 @@ conf.registerChannelValue(conf.supybot.plugins.RSS, 'announcementPrefix',
|
|||||||
is prepended (if any) to the new news item announcements made in the
|
is prepended (if any) to the new news item announcements made in the
|
||||||
channel."""))
|
channel."""))
|
||||||
conf.registerChannelValue(conf.supybot.plugins.RSS, 'announce',
|
conf.registerChannelValue(conf.supybot.plugins.RSS, 'announce',
|
||||||
registry.SpaceSeparatedListOfStrings([], """Determines which RSS feeds
|
AnnouncedFeeds([], """Determines which RSS feeds should be announced in
|
||||||
should be announced in the channel; valid input is a list of strings
|
the channel; valid input is a list of strings (either registered RSS feeds
|
||||||
(either registered RSS feeds or RSS feed URLs) separated by spaces."""))
|
or RSS feed URLs) separated by spaces."""))
|
||||||
conf.registerGlobalValue(conf.supybot.plugins.RSS, 'waitPeriod',
|
conf.registerGlobalValue(conf.supybot.plugins.RSS, 'waitPeriod',
|
||||||
registry.PositiveInteger(1800, """Indicates how many seconds the bot will
|
registry.PositiveInteger(1800, """Indicates how many seconds the bot will
|
||||||
wait between retrieving RSS feeds; requests made within this period will
|
wait between retrieving RSS feeds; requests made within this period will
|
||||||
@ -89,7 +94,7 @@ the registered feeds for the RSS plugin.""")
|
|||||||
|
|
||||||
def registerFeed(name, url):
|
def registerFeed(name, url):
|
||||||
conf.supybot.plugins.RSS.feeds.register(name, registry.String(url, ''))
|
conf.supybot.plugins.RSS.feeds.register(name, registry.String(url, ''))
|
||||||
|
|
||||||
class RSS(callbacks.Privmsg):
|
class RSS(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -100,7 +105,6 @@ class RSS(callbacks.Privmsg):
|
|||||||
self.cachedFeeds = {}
|
self.cachedFeeds = {}
|
||||||
self.gettingLockLock = threading.Lock()
|
self.gettingLockLock = threading.Lock()
|
||||||
for (name, url) in registry._cache.iteritems():
|
for (name, url) in registry._cache.iteritems():
|
||||||
name = name.lower()
|
|
||||||
if name.startswith('supybot.plugins.rss.feeds.'):
|
if name.startswith('supybot.plugins.rss.feeds.'):
|
||||||
name = rsplit(name, '.', 1)[-1]
|
name = rsplit(name, '.', 1)[-1]
|
||||||
v = registry.String('', 'help is not needed here')
|
v = registry.String('', 'help is not needed here')
|
||||||
@ -114,7 +118,7 @@ class RSS(callbacks.Privmsg):
|
|||||||
L = conf.supybot.plugins.RSS.announce.getValues(fullNames=False)
|
L = conf.supybot.plugins.RSS.announce.getValues(fullNames=False)
|
||||||
newFeeds = {}
|
newFeeds = {}
|
||||||
for (channel, v) in L:
|
for (channel, v) in L:
|
||||||
feeds = v()
|
feeds = v()
|
||||||
for name in feeds:
|
for name in feeds:
|
||||||
commandName = callbacks.canonicalName(name)
|
commandName = callbacks.canonicalName(name)
|
||||||
if self.isCommand(commandName):
|
if self.isCommand(commandName):
|
||||||
@ -178,7 +182,7 @@ class RSS(callbacks.Privmsg):
|
|||||||
to=channel, prefixName=False, private=True)
|
to=channel, prefixName=False, private=True)
|
||||||
finally:
|
finally:
|
||||||
self.releaseLock(url)
|
self.releaseLock(url)
|
||||||
|
|
||||||
def willGetNewFeed(self, url):
|
def willGetNewFeed(self, url):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
wait = self.registryValue('waitPeriod')
|
wait = self.registryValue('waitPeriod')
|
||||||
@ -201,7 +205,7 @@ class RSS(callbacks.Privmsg):
|
|||||||
|
|
||||||
def releaseLock(self, url):
|
def releaseLock(self, url):
|
||||||
self.locks[url].release()
|
self.locks[url].release()
|
||||||
|
|
||||||
def getFeed(self, url):
|
def getFeed(self, url):
|
||||||
try:
|
try:
|
||||||
# This is the most obvious place to acquire the lock, because a
|
# This is the most obvious place to acquire the lock, because a
|
||||||
@ -256,7 +260,7 @@ class RSS(callbacks.Privmsg):
|
|||||||
self.feedNames.add(name)
|
self.feedNames.add(name)
|
||||||
setattr(self.__class__, name, f)
|
setattr(self.__class__, name, f)
|
||||||
registerFeed(name, url)
|
registerFeed(name, url)
|
||||||
|
|
||||||
def add(self, irc, msg, args):
|
def add(self, irc, msg, args):
|
||||||
"""<name> <url>
|
"""<name> <url>
|
||||||
|
|
||||||
@ -290,21 +294,42 @@ class RSS(callbacks.Privmsg):
|
|||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
|
||||||
def announce(self, irc, msg, args, channel):
|
def announce(self, irc, msg, args, channel):
|
||||||
"""[<channel>] [<name|url> ...]
|
"""[<channel>] [--remove] [<name|url> ...]
|
||||||
|
|
||||||
Sets the current list of announced feeds in the channel to the feeds
|
Sets the current list of announced feeds in the channel to the feeds
|
||||||
given. Valid feeds include the names of registered feeds as well as
|
given. Valid feeds include the names of registered feeds as well as
|
||||||
URLs for a RSS feeds. <channel> is only necessary if the message isn't
|
URLs for a RSS feeds. <channel> is only necessary if the message isn't
|
||||||
sent in the channel itself.
|
sent in the channel itself. If no arguments are 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.
|
||||||
"""
|
"""
|
||||||
conf.supybot.plugins.RSS.announce.get(channel).setValue(args)
|
(optlist, rest) = getopt.getopt(args, '', ['remove'])
|
||||||
if not args:
|
remove = False
|
||||||
irc.replySuccess('All previously announced feeds will not be '
|
announce = conf.supybot.plugins.RSS.announce
|
||||||
'announced any longer.')
|
for (option, _) in optlist:
|
||||||
|
if option == '--remove':
|
||||||
|
remove = True
|
||||||
|
if remove:
|
||||||
|
if rest:
|
||||||
|
feeds = announce.get(channel)()
|
||||||
|
for feed in rest:
|
||||||
|
if feed in feeds:
|
||||||
|
feeds.remove(feed)
|
||||||
|
announce.get(channel).setValue(feeds)
|
||||||
|
irc.replySuccess()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise callbacks.ArgumentError
|
||||||
|
elif not rest:
|
||||||
|
feeds = utils.commaAndify(announce.get(channel)())
|
||||||
|
irc.reply(feeds or 'I am currently not announcing any feeds.')
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
|
announce.get(channel).setValue(rest)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
return
|
||||||
announce = privmsgs.checkChannelCapability(announce, 'op')
|
announce = privmsgs.checkChannelCapability(announce, 'op')
|
||||||
|
|
||||||
def rss(self, irc, msg, args):
|
def rss(self, irc, msg, args):
|
||||||
"""<url> [<number of headlines>]
|
"""<url> [<number of headlines>]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user