From dd040f830d15da12111c43a7384b5ec16780b256 Mon Sep 17 00:00:00 2001 From: Daniel Folkinshteyn Date: Sun, 14 Aug 2011 01:42:08 -0400 Subject: [PATCH] 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. --- plugins/RSS/config.py | 8 ++++++++ plugins/RSS/plugin.py | 24 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/RSS/config.py b/plugins/RSS/config.py index 7029f5448..d4c03e8af 100644 --- a/plugins/RSS/config.py +++ b/plugins/RSS/config.py @@ -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', diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index e11e23dbb..53a1ca2b7 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -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: