From 121e16053504dfdb21a3d02794409ac63b11152e Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 26 Apr 2026 20:10:49 -0400 Subject: [PATCH] fix: 20q answers truncate at sentence boundary, not mid-word Instead of a raw 6-word slice (which left dangling fragments like 'Partly - Not exclusively American; has'), extract the first complete sentence (up to 10 words). Falls back to the 6-word cap only if no sentence boundary is found in the response. Co-Authored-By: Claude Sonnet 4.6 --- matrixbot/commands.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/matrixbot/commands.py b/matrixbot/commands.py index 7ea62ea..6f408f4 100644 --- a/matrixbot/commands.py +++ b/matrixbot/commands.py @@ -2823,7 +2823,10 @@ async def _answer_20q(thing: str, category: str, question: str) -> str: ) as response: data = await response.json() raw = data.get("message", {}).get("content", "").strip() - # Hard cap at 6 words — enough for a real answer, not enough to name-drop + # Take the first sentence; fall back to a 6-word hard cap + m = re.search(r"^[^.!?\n]+[.!?]", raw) + if m and len(m.group(0).split()) <= 10: + return m.group(0).strip() words = raw.split() return " ".join(words[:6]) if words else "..." except Exception as e: