implement whitelist filters
This commit is contained in:
parent
43ee2992ff
commit
327fa2b215
@ -152,12 +152,18 @@ class TaskCog(commands.Cog):
|
|||||||
log.debug("filter result: %s", "blocked" if blocked else "ok")
|
log.debug("filter result: %s", "blocked" if blocked else "ok")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await api.create_tracked_content(guid=article.guid, title=article.title, url=article.url, subscription=sub_id, blocked=blocked)
|
await api.create_tracked_content(
|
||||||
|
guid=article.guid,
|
||||||
|
title=article.title,
|
||||||
|
url=article.url,
|
||||||
|
subscription=sub_id,
|
||||||
|
blocked=blocked
|
||||||
|
)
|
||||||
log.debug("successfully tracked %s", article.guid)
|
log.debug("successfully tracked %s", article.guid)
|
||||||
except aiohttp.ClientResponseError as error:
|
except aiohttp.ClientResponseError as error:
|
||||||
log.error(error)
|
log.error(error)
|
||||||
|
|
||||||
if error.status == 400:
|
if error.status == 409:
|
||||||
log.debug("It looks like this article already exists, skipping")
|
log.debug("It looks like this article already exists, skipping")
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -176,26 +182,27 @@ class TaskCog(commands.Cog):
|
|||||||
Returns True if article should be ignored due to filters.
|
Returns True if article should be ignored due to filters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
log.debug("trying filter '%s'", _filter["name"])
|
match_found = False # This is the flag to determine if the content should be filtered
|
||||||
|
|
||||||
keywords = _filter["keywords"].split(",")
|
keywords = _filter["keywords"].split(",")
|
||||||
regex_pattern = _filter["regex"]
|
regex_pattern = _filter["regex"]
|
||||||
|
is_whitelist = _filter["whitelist"]
|
||||||
|
|
||||||
|
log.debug(
|
||||||
|
"trying filter '%s', keyword '%s', regex '%s', is whitelist: '%s'",
|
||||||
|
_filter["name"], keywords, regex_pattern, is_whitelist
|
||||||
|
)
|
||||||
|
|
||||||
assert not (keywords and regex_pattern), "Keywords and Regex used, only 1 can be used."
|
assert not (keywords and regex_pattern), "Keywords and Regex used, only 1 can be used."
|
||||||
|
|
||||||
for word in keywords:
|
if any(word in article.title or word in article.description for word in keywords):
|
||||||
if word in article.title or word in article.description:
|
match_found = True
|
||||||
log.debug("keyword '%s' found in title or description", word)
|
|
||||||
return True
|
|
||||||
|
|
||||||
# if any(word in article.title or word in article.description for word in keywords):
|
|
||||||
# return True
|
|
||||||
|
|
||||||
if regex_pattern:
|
if regex_pattern:
|
||||||
regex = re.compile(regex_pattern)
|
regex = re.compile(regex_pattern)
|
||||||
return regex.search(article.title) or regex.search(article.description)
|
match_found = regex.search(article.title) or regex.search(article.description)
|
||||||
|
|
||||||
return False
|
return not match_found if is_whitelist else match_found
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user