From 8aecc5827b82b2632b718a5c70b72b3d64d4196f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 25 Oct 2020 12:15:41 +0000 Subject: [PATCH] Avoid matching hashtags with contains operator --- newsdaemon.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/newsdaemon.py b/newsdaemon.py index eb5b358e..ccc74cb7 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -95,13 +95,17 @@ def hashtagRuleResolve(tree: [], hashtags: [], moderated: bool, if matchStr.startswith('"') and matchStr.endswith('"'): matchStr = matchStr[1:] matchStr = matchStr[:len(matchStr) - 1] - return matchStr.lower() in content + matchStrLower = matchStr.lower() + contentWithoutTags = content.replace('#' + matchStrLower, '') + return matchStrLower in contentWithoutTags elif isinstance(tree[1], list): matchStr = tree[1][0] if matchStr.startswith('"') and matchStr.endswith('"'): matchStr = matchStr[1:] matchStr = matchStr[:len(matchStr) - 1] - return matchStr.lower() in content + matchStrLower = matchStr.lower() + contentWithoutTags = content.replace('#' + matchStrLower, '') + return matchStrLower in contentWithoutTags elif tree[0] == 'from': if len(tree) == 2: if isinstance(tree[1], str):