修复一些错误

This commit is contained in:
2025-11-06 11:46:54 +08:00
parent 661fcfe255
commit 03ca409317
3 changed files with 20 additions and 2 deletions

View File

@@ -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",

2
PWF

Submodule PWF updated: 63cd095f1b...34da3f8459

View File

@@ -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", "")
@@ -158,6 +159,9 @@ class BasicWPSInterface(PluginInterface):
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:
webhook_url = self.get_webhook_url(message, user_id)
@@ -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()