From ce23fe9bc1f0eed2a8745acb71304b6dfeb20f79 Mon Sep 17 00:00:00 2001 From: 苏向夜 Date: Fri, 15 Mar 2024 14:44:54 +0800 Subject: feat(router): add support for chinese router --- src/infini/router.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/infini/router.py b/src/infini/router.py index 71da44e2..3adc08dd 100644 --- a/src/infini/router.py +++ b/src/infini/router.py @@ -3,7 +3,7 @@ from infini.input import Input class Router: - type: Literal["normal"] = "normal" + type: Literal["text"] = "text" signs: set[str] def __init__(self, sign: str, alias: Sequence[str] = []) -> None: @@ -19,7 +19,7 @@ class Router: class Startswith(Router): - type: Literal["startswith"] = "startswith" + name: Literal["startswith"] = "startswith" def match(self, plain_text: str) -> bool: text = plain_text.strip() @@ -27,14 +27,14 @@ class Startswith(Router): class Contains(Router): - type: Literal["contains"] = "contains" + name: Literal["contains"] = "contains" def match(self, plain_text: str) -> bool: return any([sign in plain_text for sign in self.signs]) class Endswith(Router): - type: Literal["endswith"] = "endswith" + name: Literal["endswith"] = "endswith" def match(self, input: Input) -> bool: text = input.get_plain_text().strip() @@ -42,14 +42,13 @@ class Endswith(Router): class Command(Router): - type: Literal["command"] = "command" - prefix: tuple = (".", "/") + name: Literal["command"] = "command" + prefix: tuple = (".", "/", "。", "!", "!") def match(self, input: Input) -> bool: text = input.get_plain_text().strip() - if text: - if text.startswith(self.prefix): - text = text[1:] - return any([text.startswith(sign) for sign in self.signs]) + if text.startswith(self.prefix): + text = text[1:] + return any([text.startswith(sign) for sign in self.signs]) return False -- cgit v1.2.3-70-g09d2