From 0d5855dda3cc24454b92fd273bc6cf3302f524b3 Mon Sep 17 00:00:00 2001 From: user Date: Sun, 15 Feb 2026 21:27:03 +0100 Subject: [PATCH] fix: filter alert results to require keyword match in title/URL Search backends return loosely relevant results. Now only announces items where the keyword actually appears in the title or URL (case-insensitive). All results are still marked as seen to prevent re-checking. Co-Authored-By: Claude Opus 4.6 --- plugins/alert.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/alert.py b/plugins/alert.py index 452f8e6..01a0a72 100644 --- a/plugins/alert.py +++ b/plugins/alert.py @@ -282,10 +282,18 @@ async def _poll_once(bot, key: str, announce: bool = True) -> None: seen_list = list(data.get("seen", {}).get(tag, [])) new_items = [item for item in items if item["id"] not in seen_set] - if announce and new_items: + # Filter: only announce results that actually contain the keyword + kw_lower = keyword.lower() + matched = [ + item for item in new_items + if kw_lower in item.get("title", "").lower() + or kw_lower in item.get("url", "").lower() + ] + + if announce and matched: channel = data["channel"] name = data["name"] - shown = new_items[:_MAX_ANNOUNCE] + shown = matched[:_MAX_ANNOUNCE] for item in shown: title = _truncate(item["title"]) if item["title"] else "(no title)" url = item["url"] @@ -293,7 +301,7 @@ async def _poll_once(bot, key: str, announce: bool = True) -> None: if url: line += f" -- {url}" await bot.send(channel, line) - remaining = len(new_items) - len(shown) + remaining = len(matched) - len(shown) if remaining > 0: await bot.send(channel, f"[{name}/{tag}] ... and {remaining} more")