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 <noreply@anthropic.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user