feat: accept !start name without quotes, strip typographic quotes
This commit is contained in:
parent
e1485e72f0
commit
3ff8381e5a
@ -13,8 +13,9 @@ _MSG_SELECTOR = "[data-tid='chat-pane-message']"
|
|||||||
_SENDER_SELECTOR = "[data-tid='message-author-name']"
|
_SENDER_SELECTOR = "[data-tid='message-author-name']"
|
||||||
_PROFILE_EMAIL_SELECTOR = ".lpc_ip_root_class a[href*='mailto:']"
|
_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)
|
_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:
|
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)
|
m = _START_RE.match(text)
|
||||||
if m:
|
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)
|
return ("start", name)
|
||||||
|
|
||||||
if _STOP_RE.match(text):
|
if _STOP_RE.match(text):
|
||||||
|
|||||||
@ -21,6 +21,21 @@ def test_start_with_single_word_name():
|
|||||||
assert result == ("start", "Bauer")
|
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():
|
def test_start_without_name_returns_placeholder():
|
||||||
result = parse_trigger(msg(CURRENT_USER, "!start"), CURRENT_USER)
|
result = parse_trigger(msg(CURRENT_USER, "!start"), CURRENT_USER)
|
||||||
assert result == ("start", "Unbekannter Vortragender")
|
assert result == ("start", "Unbekannter Vortragender")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user