Fixes #39 - adds whitelistDomainPattern option
This option allows users to specify which domains they want to show titles for
This commit is contained in:
parent
132a571481
commit
cfc88d89ed
|
|
@ -164,6 +164,8 @@ titles will be shown in all channels. Default value: `""`
|
|||
|
||||
`ignoredDomainPattern` - ignore domains matching this pattern. Default value: `""`
|
||||
|
||||
`whitelistDomainPattern` - ignore any link without a domain matching this pattern. Default value: `""`
|
||||
|
||||
### Tip ###
|
||||
|
||||
You can ignore domains that you know aren't websites. This prevents a request from being made at all.
|
||||
|
|
@ -178,6 +180,10 @@ Ignore `*.tk` and `buzzfeed.com`
|
|||
|
||||
!config supybot.plugins.SpiffyTitles.ignoredDomainPattern (\.tk|buzzfeed\.com)
|
||||
|
||||
Ignore all links except youtube, imgur, and reddit
|
||||
|
||||
!config supybot.plugins.SpiffyTitles.whitelistDomainPattern /(reddit\.com|youtube\.com|youtu\.be|imgur\.com)/
|
||||
|
||||
`userAgents` - A comma separated list of strings of user agents randomly chosen when requesting.
|
||||
|
||||
`urlRegularExpression` - A regular expression used to match URLs. You shouldn't need to change this.
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ conf.registerGlobalValue(SpiffyTitles, 'youtubeDeveloperKey',
|
|||
|
||||
# Link cache lifetime
|
||||
conf.registerGlobalValue(SpiffyTitles, 'linkCacheLifetimeInSeconds',
|
||||
registry.Integer(60, _("""Link cache lifetime in seconds""")))
|
||||
registry.Integer(60, _("""Link cache lifetime in seconds""")))
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
27
plugin.py
27
plugin.py
|
|
@ -116,7 +116,13 @@ class SpiffyTitles(callbacks.Plugin):
|
|||
is_ignored = self.is_ignored_domain(domain)
|
||||
|
||||
if is_ignored:
|
||||
self.log.info("SpiffyTitles: ignoring url due to pattern match: %s" % (url))
|
||||
self.log.info("SpiffyTitles: URL ignored due to domain blacklist match: %s" % url)
|
||||
return
|
||||
|
||||
is_whitelisted_domain = self.is_whitelisted_domain(domain)
|
||||
|
||||
if self.registryValue("whitelistDomainPattern") and not is_whitelisted_domain:
|
||||
self.log.info("SpiffyTitles: URL ignored due to domain whitelist mismatch: %s" % url)
|
||||
return
|
||||
|
||||
"""
|
||||
|
|
@ -263,6 +269,25 @@ class SpiffyTitles(callbacks.Plugin):
|
|||
except re.Error:
|
||||
self.log.error("SpiffyTitles: invalid regular expression: %s" % (pattern))
|
||||
|
||||
def is_whitelisted_domain(self, domain):
|
||||
"""
|
||||
Checks domain against a regular expression
|
||||
"""
|
||||
pattern = self.registryValue("whitelistDomainPattern")
|
||||
|
||||
if pattern:
|
||||
self.log.debug("SpiffyTitles: matching %s against %s" % (domain, str(pattern)))
|
||||
|
||||
try:
|
||||
pattern_search_result = re.search(pattern, domain)
|
||||
|
||||
if pattern_search_result is not None:
|
||||
match = pattern_search_result.group()
|
||||
|
||||
return match
|
||||
except re.Error:
|
||||
self.log.error("SpiffyTitles: invalid regular expression: %s" % (pattern))
|
||||
|
||||
def get_video_id_from_url(self, url, info):
|
||||
"""
|
||||
Get YouTube video ID from URL
|
||||
|
|
|
|||
Loading…
Reference in New Issue