mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
RSS: add channel-specific blacklist and whitelist.
also fix bug introduced with the initialannounce feature, which overwrote newheadlines list when doing channel-specific things with it.
This commit is contained in:
parent
3fa45b3b5f
commit
dd040f830d
@ -78,6 +78,14 @@ conf.registerGlobalValue(RSS, 'defaultNumberOfHeadlines',
|
||||
conf.registerChannelValue(RSS, 'initialAnnounceHeadlines',
|
||||
registry.PositiveInteger(5, """Indicates how many headlines an rss feed
|
||||
will output when it is first added to announce for a channel."""))
|
||||
conf.registerChannelValue(RSS, 'keywordWhitelist',
|
||||
registry.SpaceSeparatedSetOfStrings([], """Space separated list of
|
||||
strings, lets you filter headlines to those containing one or more items
|
||||
in this whitelist."""))
|
||||
conf.registerChannelValue(RSS, 'keywordBlacklist',
|
||||
registry.SpaceSeparatedSetOfStrings([], """Space separated list of
|
||||
strings, lets you filter headlines to those not containing any items
|
||||
in this blacklist."""))
|
||||
|
||||
conf.registerGroup(RSS, 'announce')
|
||||
conf.registerChannelValue(RSS.announce, 'showLinks',
|
||||
|
@ -184,9 +184,29 @@ class RSS(callbacks.Plugin):
|
||||
newheadlines[i] = None
|
||||
newheadlines = filter(None, newheadlines) # Removes Nones.
|
||||
if newheadlines:
|
||||
def filter_whitelist(headline):
|
||||
v = False
|
||||
for kw in whitelist:
|
||||
if kw in headline[0] or kw in headline[1]:
|
||||
v = True
|
||||
break
|
||||
return v
|
||||
def filter_blacklist(headline):
|
||||
v = True
|
||||
for kw in blacklist:
|
||||
if kw in headline[0] or kw in headline[1]:
|
||||
v = False
|
||||
break
|
||||
return v
|
||||
for channel in channels:
|
||||
if len(oldheadlines) == 0:
|
||||
newheadlines = newheadlines[:self.registryValue('initialAnnounceHeadlines', channel)]
|
||||
channelnewheadlines = newheadlines[:self.registryValue('initialAnnounceHeadlines', channel)]
|
||||
whitelist = self.registryValue('keywordWhitelist', channel)
|
||||
blacklist = self.registryValue('keywordBlacklist', channel)
|
||||
if len(whitelist) != 0:
|
||||
channelnewheadlines = filter(filter_whitelist, channelnewheadlines)
|
||||
if len(blacklist) != 0:
|
||||
channelnewheadlines = filter(filter_blacklist, channelnewheadlines)
|
||||
bold = self.registryValue('bold', channel)
|
||||
sep = self.registryValue('headlineSeparator', channel)
|
||||
prefix = self.registryValue('announcementPrefix', channel)
|
||||
@ -194,7 +214,7 @@ class RSS(callbacks.Plugin):
|
||||
if bold:
|
||||
pre = ircutils.bold(pre)
|
||||
sep = ircutils.bold(sep)
|
||||
headlines = self.buildHeadlines(newheadlines, channel)
|
||||
headlines = self.buildHeadlines(channelnewheadlines, channel)
|
||||
irc.replies(headlines, prefixer=pre, joiner=sep,
|
||||
to=channel, prefixNick=False, private=True)
|
||||
finally:
|
||||
|
Loading…
Reference in New Issue
Block a user