diff --git a/src/extensions/tasks.py b/src/extensions/tasks.py index 28a7fef..cd0aa5d 100644 --- a/src/extensions/tasks.py +++ b/src/extensions/tasks.py @@ -152,12 +152,18 @@ class TaskCog(commands.Cog): log.debug("filter result: %s", "blocked" if blocked else "ok") 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) except aiohttp.ClientResponseError as error: log.error(error) - if error.status == 400: + if error.status == 409: log.debug("It looks like this article already exists, skipping") return @@ -176,26 +182,27 @@ class TaskCog(commands.Cog): 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(",") 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." - for word in keywords: - if word in article.title or word in article.description: - 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 any(word in article.title or word in article.description for word in keywords): + match_found = True if 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): """