diff --git a/Assets/config.json b/Assets/config.json index 4f61cdc..0df1a71 100644 --- a/Assets/config.json +++ b/Assets/config.json @@ -1,7 +1,11 @@ { "properties": { "debug": true, - "main_webhook_url": "https://xz.wps.cn/api/v1/webhook/send?key=d32b1e6cdb5bb593418aee1638354a56" + "main_webhook_url": "https://xz.wps.cn/api/v1/webhook/send?key=d32b1e6cdb5bb593418aee1638354a56", + "app_config": { + "swagger_js_url": "/static/swagger-ui-bundle.js", + "swagger_css_url": "/static/swagger-ui.css" + } }, "find": { "host": "0.0.0.0", diff --git a/PWF b/PWF index 63cd095..34da3f8 160000 --- a/PWF +++ b/PWF @@ -1 +1 @@ -Subproject commit 63cd095f1b80a7e6758939e3b59ce7ece248b812 +Subproject commit 34da3f8459f548aa0b680e102c143e18ddf882cc diff --git a/Plugins/WPSAPI.py b/Plugins/WPSAPI.py index 9efb14b..9516de0 100644 --- a/Plugins/WPSAPI.py +++ b/Plugins/WPSAPI.py @@ -5,6 +5,7 @@ from PWF.Convention.Runtime.GlobalConfig import ProjectConfig from PWF.Convention.Runtime.Web import ToolURL from PWF.Convention.Runtime.String import LimitStringLength import httpx +import re config = ProjectConfig() MAIN_WEBHOOK_URL = config.FindItem("main_webhook_url", "") @@ -157,6 +158,9 @@ class BasicWPSInterface(PluginInterface): return self.get_message_sender(webhook_url).send_link else: raise ValueError(f"Invalid message sender type: {type}") + + # 机器人名称模式(用于从@消息中提取) + AT_PATTERN = re.compile(r'@[^\s]+\s+(.+)', re.DOTALL) @override async def callback(self, message: str, chat_id: int, user_id: int) -> str|None: @@ -165,6 +169,15 @@ class BasicWPSInterface(PluginInterface): config.Log("Info", f"Webhook URL: {webhook_url}, Message: {LimitStringLength(message)}, User ID: {user_id}") if webhook_url == "" or webhook_url == None: return + + # 去除首尾空格 + message = message.strip() + + # 尝试提取@后的内容 + at_match = BasicWPSInterface.AT_PATTERN.search(message) + if at_match: + message = at_match.group(1).strip() + result = await self.get_message_sender_function(webhook_url, self.get_message_sender_type())(message) config.Log("Info", f"Webhook URL: {webhook_url}, Message: {LimitStringLength(message)}, Result: {result}") return None @@ -188,5 +201,6 @@ class WPSAPI(BasicWPSInterface): def wake_up(self) -> None: config.Log("Info", "WPSAPI核心插件已加载") self.register_plugin("say") + self.register_plugin("说") config.SaveProperties() \ No newline at end of file