From 75a4e8e3684ad76e29d08d5bae60663337cde2ee Mon Sep 17 00:00:00 2001 From: PrgmrBill Date: Fri, 10 Apr 2015 22:55:25 -0400 Subject: [PATCH] Fixes #14 - Adds channel whitelist for SpiffyTitles --- README.md | 3 +++ config.py | 4 ++++ plugin.py | 25 +++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66e6103..3bd94ff 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,9 @@ Default: `useBold` - Whether to bold the title. Defaults to `False` +`channelWhitelist` - a comma separated list of channels in which titls should be displayed. If empty, +titles will be shown in all channels. + `ignoredDomainPatterns` - a comma separated list of strings that are regular expressions to match against URLs posted in channels. diff --git a/config.py b/config.py index e8d9360..0f99433 100644 --- a/config.py +++ b/config.py @@ -55,6 +55,10 @@ conf.registerGlobalValue(SpiffyTitles, 'mimeTypes', conf.registerGlobalValue(SpiffyTitles, 'ignoredDomainPatterns', registry.CommaSeparatedListOfStrings([], _("""Domains matching these patterns will be ignored"""))) +# Channel whitelist +conf.registerGlobalValue(SpiffyTitles, 'channelWhitelist', + registry.CommaSeparatedListOfStrings([], _("""Only show titles on these channels, or all if empty"""))) + diff --git a/plugin.py b/plugin.py index 8215da5..986c3f6 100644 --- a/plugin.py +++ b/plugin.py @@ -35,15 +35,23 @@ class SpiffyTitles(callbacks.Plugin): callBefore = ['Web'] def doPrivmsg(self, irc, msg): - channel = msg.args[0] + channel = msg.args[0].lower() is_channel = irc.isChannel(channel) is_ctcp = ircmsgs.isCtcp(msg) message = msg.args[1] if is_channel and not is_ctcp: + channel_whitelist = self.get_channel_whitelist() + url = self.get_url_from_message(message) - if url: + if url: + # If there is a channel whitelist and the origin channel is + # not in the whitelist, bail out. + if len(channel_whitelist) and channel not in channel_whitelist: + self.log.info("SpiffyTitles: ignoring link in %s due to whitelist %s" % (channel, str(channel_whitelist))) + return + info = urlparse(url) if info: @@ -76,6 +84,19 @@ class SpiffyTitles(callbacks.Plugin): irc.reply(formatted_title) + def get_channel_whitelist(self): + white_list = self.registryValue("channelWhitelist") + channels = [] + + if len(white_list): + for channel in white_list: + if channel: + normalized_channel = channel.strip().lower() + + channels.append(normalized_channel) + + return channels + def is_ignored_domain(self, domain): ignored_patterns = self.registryValue("ignoredDomainPatterns") num_patterns = len(ignored_patterns)