diff --git a/src/teampulse/monitor.py b/src/teampulse/monitor.py index 8cd8c01..c8858cd 100644 --- a/src/teampulse/monitor.py +++ b/src/teampulse/monitor.py @@ -13,8 +13,9 @@ _MSG_SELECTOR = "[data-tid='chat-pane-message']" _SENDER_SELECTOR = "[data-tid='message-author-name']" _PROFILE_EMAIL_SELECTOR = ".lpc_ip_root_class a[href*='mailto:']" -_START_RE = re.compile(r'^!start(?:\s+"([^"]*)")?$', re.IGNORECASE) +_START_RE = re.compile(r'^!start(?:\s+(.+))?$', re.IGNORECASE) _STOP_RE = re.compile(r'^!stop$', re.IGNORECASE) +_QUOTE_CHARS = '"“”' # straight and typographic quotes def parse_trigger(message: ChatMessage, current_user: str) -> tuple[str, str] | None: @@ -25,7 +26,8 @@ def parse_trigger(message: ChatMessage, current_user: str) -> tuple[str, str] | m = _START_RE.match(text) if m: - name = (m.group(1) or "").strip() or "Unbekannter Vortragender" + raw = (m.group(1) or "").strip(_QUOTE_CHARS).strip() + name = raw or "Unbekannter Vortragender" return ("start", name) if _STOP_RE.match(text): diff --git a/tests/test_monitor_triggers.py b/tests/test_monitor_triggers.py index 47eb00b..8f68a19 100644 --- a/tests/test_monitor_triggers.py +++ b/tests/test_monitor_triggers.py @@ -21,6 +21,21 @@ def test_start_with_single_word_name(): assert result == ("start", "Bauer") +def test_start_without_quotes(): + result = parse_trigger(msg(CURRENT_USER, "!start Stephan Rehfeld"), CURRENT_USER) + assert result == ("start", "Stephan Rehfeld") + + +def test_start_with_typographic_quotes(): + result = parse_trigger(msg(CURRENT_USER, "“start” is not this, but: !start “Anna Bauer”"), CURRENT_USER) + assert result is None # not a trigger — just a regular message + + +def test_start_with_smart_quotes_around_name(): + result = parse_trigger(msg(CURRENT_USER, '!start “Anna Bauer”'), CURRENT_USER) + assert result == ("start", "Anna Bauer") + + def test_start_without_name_returns_placeholder(): result = parse_trigger(msg(CURRENT_USER, "!start"), CURRENT_USER) assert result == ("start", "Unbekannter Vortragender")