Make showLinks a ChannelValue specific to RSS.rss and add announce.showLinks

to for RSS.announce
This commit is contained in:
James Vega 2004-09-23 23:53:51 +00:00
parent 3e58419338
commit bbddc4b834
1 changed files with 31 additions and 9 deletions

View File

@ -74,9 +74,6 @@ conf.registerChannelValue(conf.supybot.plugins.RSS, 'announce',
AnnouncedFeeds([], """Determines which RSS feeds should be announced in the AnnouncedFeeds([], """Determines which RSS feeds should be announced in the
channel; valid input is a list of strings (either registered RSS feeds or channel; valid input is a list of strings (either registered RSS feeds or
RSS feed URLs) separated by spaces.""")) RSS feed URLs) separated by spaces."""))
conf.registerGlobalValue(conf.supybot.plugins.RSS, 'showLinks',
registry.Boolean(False, """Determines whether the bot will list the link
along with the title of the feed."""))
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
@ -84,6 +81,17 @@ conf.registerGlobalValue(conf.supybot.plugins.RSS, 'waitPeriod',
conf.registerGlobalValue(conf.supybot.plugins.RSS, 'feeds', conf.registerGlobalValue(conf.supybot.plugins.RSS, 'feeds',
AnnouncedFeeds([], """Determines what feeds should be accessible as AnnouncedFeeds([], """Determines what feeds should be accessible as
commands.""")) commands."""))
conf.registerChannelValue(conf.supybot.plugins.RSS, 'showLinks',
registry.Boolean(False, """Determines whether the bot will list the link
along with the title of the feed when the rss command is called.
supybot.plugins.RSS.announce.showLinks affects whether links will be
listed when a feed is automatically announced."""))
conf.registerGroup(conf.supybot.plugins.RSS, 'announce')
conf.registerChannelValue(conf.supybot.plugins.RSS.announce, 'showLinks',
registry.Boolean(False, """Determines whether the bot will list the link
along with the title of the feed when a feed is automatically
announced."""))
class RSS(callbacks.Privmsg): class RSS(callbacks.Privmsg):
"""This plugin is useful both for announcing updates to RSS feeds in a """This plugin is useful both for announcing updates to RSS feeds in a
@ -143,6 +151,19 @@ class RSS(callbacks.Privmsg):
self.releaseLock(url) self.releaseLock(url)
time.sleep(0.1) # So other threads can run. time.sleep(0.1) # So other threads can run.
def buildHeadlines(self, headlines, channel, config='announce.showLinks'):
newheadlines = []
if self.registryValue('%s' % config, channel):
for headline in headlines:
if headline[1]:
newheadlines.append('%s <%s>' % headline)
else:
newheadlines.append('%s' % headline[0])
else:
for headline in headlines:
newheadlines = ['%s' % h[0] for h in headlines]
return newheadlines
def _newHeadlines(self, irc, channels, name, url): def _newHeadlines(self, irc, channels, name, url):
try: try:
# We acquire the lock here so there's only one announcement thread # We acquire the lock here so there's only one announcement thread
@ -160,7 +181,7 @@ class RSS(callbacks.Privmsg):
newresults = self.getFeed(url) newresults = self.getFeed(url)
newheadlines = self.getHeadlines(newresults) newheadlines = self.getHeadlines(newresults)
def canonicalize(headline): def canonicalize(headline):
return tuple(headline.lower().split()) return (tuple(headline[0].lower().split()), headline[1])
oldheadlines = sets.Set(map(canonicalize, oldheadlines)) oldheadlines = sets.Set(map(canonicalize, oldheadlines))
for (i, headline) in enumerate(newheadlines): for (i, headline) in enumerate(newheadlines):
if canonicalize(headline) in oldheadlines: if canonicalize(headline) in oldheadlines:
@ -175,6 +196,7 @@ class RSS(callbacks.Privmsg):
if bold: if bold:
pre = ircutils.bold(pre) pre = ircutils.bold(pre)
sep = ircutils.bold(sep) sep = ircutils.bold(sep)
newheadlines = self.buildHeadlines(newheadlines, channel)
irc.replies(newheadlines, prefixer=pre, joiner=sep, irc.replies(newheadlines, prefixer=pre, joiner=sep,
to=channel, prefixName=False, private=True) to=channel, prefixName=False, private=True)
finally: finally:
@ -232,15 +254,14 @@ class RSS(callbacks.Privmsg):
def getHeadlines(self, feed): def getHeadlines(self, feed):
headlines = [] headlines = []
showLinks = self.registryValue('showLinks')
for d in feed['items']: for d in feed['items']:
if 'title' in d: if 'title' in d:
title = utils.htmlToText(d['title']).strip() title = utils.htmlToText(d['title']).strip()
link = d.get('link') link = d.get('link')
if link and showLinks: if link:
headlines.append('%s <%s>' % (title, link)) headlines.append((title, link))
else: else:
headlines.append('%s' % title) headlines.append((title, None))
return headlines return headlines
def _validFeedName(self, name): def _validFeedName(self, name):
@ -358,6 +379,7 @@ class RSS(callbacks.Privmsg):
if not headlines: if not headlines:
irc.error('Couldn\'t get RSS feed') irc.error('Couldn\'t get RSS feed')
return return
headlines = self.buildHeadlines(headlines, channel, 'showLinks')
if n: if n:
try: try:
n = int(n) n = int(n)