S72 平台命令别名统一
这个提交存在于:
父节点
3bf4aad1c9
当前提交
7054de3b45
共有 4 个文件被更改,包括 51 次插入 和 9 次删除
33
adapters/chat_commands.py
普通文件
33
adapters/chat_commands.py
普通文件
|
|
@ -0,0 +1,33 @@
|
|||
"""Shared chat command parsing helpers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
|
||||
|
||||
WORKBENCH_ALIASES = frozenset(
|
||||
{
|
||||
"imagestudio",
|
||||
"image studio",
|
||||
"is",
|
||||
"图像工作台",
|
||||
"打开图像工作台",
|
||||
"工作台",
|
||||
"打开工作台",
|
||||
"生图工作台",
|
||||
"打开生图工作台",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def normalize_command_text(text: str) -> str:
|
||||
normalized = str(text or "").replace("/", "/").strip().lower()
|
||||
return re.sub(r"\s+", " ", normalized)
|
||||
|
||||
|
||||
def command_key(text: str) -> str:
|
||||
return normalize_command_text(text).lstrip("/")
|
||||
|
||||
|
||||
def is_workbench_command(text: str) -> bool:
|
||||
return command_key(text) in WORKBENCH_ALIASES
|
||||
|
|
@ -5,12 +5,10 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from adapters.chat_commands import is_workbench_command
|
||||
from backend.services.ui_service import API_BASE
|
||||
|
||||
|
||||
WORKBENCH_COMMANDS = {"imagestudio", "/imagestudio", "图像工作台", "打开图像工作台"}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class OneBotMessage:
|
||||
user_id: str
|
||||
|
|
@ -40,8 +38,7 @@ def normalize_message_event(event: dict[str, Any]) -> OneBotMessage:
|
|||
|
||||
|
||||
def match_workbench_command(message: OneBotMessage) -> bool:
|
||||
text = message.text.strip().lower()
|
||||
return text in WORKBENCH_COMMANDS
|
||||
return is_workbench_command(message.text)
|
||||
|
||||
|
||||
def workbench_reply(api_base: str = API_BASE) -> dict[str, Any]:
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@ from __future__ import annotations
|
|||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from adapters.chat_commands import is_workbench_command
|
||||
from backend.services.ui_service import API_BASE
|
||||
|
||||
|
||||
WORKBENCH_COMMANDS = {"imagestudio", "/imagestudio", "图像工作台", "打开图像工作台"}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class WeChatMessage:
|
||||
user_id: str
|
||||
|
|
@ -36,7 +34,7 @@ def normalize_message_event(event: dict[str, Any]) -> WeChatMessage:
|
|||
|
||||
|
||||
def match_workbench_command(message: WeChatMessage) -> bool:
|
||||
return message.text.strip().lower() in WORKBENCH_COMMANDS
|
||||
return is_workbench_command(message.text)
|
||||
|
||||
|
||||
def workbench_reply(api_base: str = API_BASE) -> dict[str, Any]:
|
||||
|
|
|
|||
|
|
@ -34,6 +34,13 @@ class OneBotAdapterTests(unittest.TestCase):
|
|||
self.assertEqual(result["action"], "open_workbench")
|
||||
self.assertEqual(result["reply"]["url"], "/api/plugin/web")
|
||||
|
||||
def test_workbench_aliases_are_shared(self):
|
||||
for command in ["/is", "image studio", "工作台", "生图工作台"]:
|
||||
with self.subTest(command=command):
|
||||
result = handle_message_event({"user_id": "u1", "raw_message": command}, api_base="/api/plugin")
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(result["action"], "open_workbench")
|
||||
|
||||
def test_ignores_non_commands(self):
|
||||
self.assertIsNone(handle_message_event({"user_id": "u1", "raw_message": "hello"}))
|
||||
|
||||
|
|
@ -59,6 +66,13 @@ class WeChatAdapterTests(unittest.TestCase):
|
|||
self.assertEqual(result["action"], "open_workbench")
|
||||
self.assertEqual(result["reply"]["url"], "/api/plugin/web")
|
||||
|
||||
def test_workbench_aliases_are_shared(self):
|
||||
for command in ["/is", "image studio", "工作台", "生图工作台"]:
|
||||
with self.subTest(command=command):
|
||||
result = handle_wechat_message_event({"from_user": "wx_user", "text": command}, api_base="/api/plugin")
|
||||
self.assertIsNotNone(result)
|
||||
self.assertEqual(result["action"], "open_workbench")
|
||||
|
||||
def test_ignores_non_commands(self):
|
||||
self.assertIsNone(handle_wechat_message_event({"from_user": "wx_user", "text": "hello"}))
|
||||
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用