aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author苏向夜 <fu050409@163.com>2024-03-15 14:44:54 +0800
committer苏向夜 <fu050409@163.com>2024-03-15 14:44:54 +0800
commitce23fe9bc1f0eed2a8745acb71304b6dfeb20f79 (patch)
tree21e4dc337d00b38c9e77733f8e8d399313092a85
parent70ed526f415db7670b6348173dc9c305ba8eb3da (diff)
downloadinfini-ce23fe9bc1f0eed2a8745acb71304b6dfeb20f79.tar.gz
infini-ce23fe9bc1f0eed2a8745acb71304b6dfeb20f79.zip
feat(router): add support for chinese router
-rw-r--r--src/infini/router.py19
1 files changed, 9 insertions, 10 deletions
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