From a56f75ee3fb4ef0e50e2ec6f9deb3a0fb2ad9467 Mon Sep 17 00:00:00 2001 From: Ridwannurudeen Date: Fri, 27 Feb 2026 08:55:54 +0100 Subject: [PATCH] fix: is_spam always returned None due to missing return statement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit is_spam() built a list of regex patterns for spam detection but never evaluated them — the function fell off the end and implicitly returned None, so spam content was never identified and _should_reply() never penalised it. - Add the missing `return any(re.search(pattern, clean) for pattern in patterns)` - Move `from unicodedata import normalize` to the module-level imports and remove the redundant per-call `import re` / `from unicodedata import normalize` that were shadowing the top-level imports inside the function body Fixes #4 --- agent/engines/twitter/reply_manager.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/agent/engines/twitter/reply_manager.py b/agent/engines/twitter/reply_manager.py index 47b599c2..de42707d 100644 --- a/agent/engines/twitter/reply_manager.py +++ b/agent/engines/twitter/reply_manager.py @@ -3,6 +3,7 @@ import re import time from typing import List, Tuple +from unicodedata import normalize from engines.memory.significance_scorer import SignificanceScorer from engines.twitter.post_maker import PostMaker @@ -89,15 +90,12 @@ def _handle_replies(self, external_context: List[Tuple[str, str]]) -> None: def is_spam(self, content: str) -> bool: """Check if content appears to be spam.""" - import re - from unicodedata import normalize - # Normalize more aggressively: remove all whitespace, symbols, zero-width chars - clean = re.sub(r'[\s\.\-_\|\\/\(\)\[\]\u200b-\u200f\u2060\ufeff]+', '', + clean = re.sub(r'[\s\.\-_\|\\/\(\)\[\]\u200b-\u200f\u2060\ufeff]+', '', normalize('NFKC', content.lower())) patterns = [ - r'[\$\€\¢\£\¥]|(?:usd[t]?|usdc|busd)', + r'[\$\€\¢\£\¥]|(?:usd[t]?|usdc|busd)', r'(?:ca|с[aа]|market.?cap)[:\|/]?(?:\d|soon)', r't[i1І]ck[e3Е]r|symb[o0]l|(?:trading|list).?pairs?', r'p[uüūи][mм]p|рuмр|ⓟⓤⓜⓟ|accumulate', @@ -116,3 +114,4 @@ def is_spam(self, content: str) -> bool: r'(?:early|earlybird|early.?access)', r'(?:t\.me|discord\.gg|dex\.tools)', ] + return any(re.search(pattern, clean) for pattern in patterns)