修复一些错误
This commit is contained in:
@@ -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()
|
||||
Reference in New Issue
Block a user