修改ProjectConfig生成来源

This commit is contained in:
2025-11-07 23:48:10 +08:00
parent 4d5154a2ac
commit a676533510
4 changed files with 21 additions and 19 deletions

View File

@@ -9,6 +9,10 @@
}
},
"find": {
"max_concurrent_requests": 100,
"database_path": "db.db",
"always_return_ok": true,
"plugin_dir": "Plugins",
"host": "0.0.0.0",
"port": 8000,
"verbose": false

2
PWF

Submodule PWF updated: c49f55808e...9899387697

View File

@@ -7,10 +7,9 @@ from PWF.Convention.Runtime.String import LimitStringLength
import httpx
import re
config = ProjectConfig()
MAIN_WEBHOOK_URL = config.FindItem("main_webhook_url", "")
config.SaveProperties()
logger = ProjectConfig()
MAIN_WEBHOOK_URL = logger.FindItem("main_webhook_url", "")
logger.SaveProperties()
class MessageSender:
@@ -45,14 +44,14 @@ class MessageSender:
response = await client.post(self.webhook_url, json=message)
if response.status_code == 200:
config.Log("Info", f"消息发送成功: {message.get('msgtype')}")
logger.Log("Info", f"消息发送成功: {message.get('msgtype')}")
return True
else:
config.Log("Error", f"消息发送失败: status={response.status_code}, body={response.text}")
logger.Log("Error", f"消息发送失败: status={response.status_code}, body={response.text}")
return False
except Exception as e:
config.Log("Error", f"发送消息异常: {e}")
logger.Log("Error", f"发送消息异常: {e}")
return False
async def send_text(self, content: str, at_user_id: Optional[int] = None) -> bool:
@@ -176,13 +175,13 @@ class BasicWPSInterface(PluginInterface):
async def send_markdown_message(self, message: str, chat_id: int, user_id: int) -> str|None:
webhook_url = self.get_webhook_url(message, user_id)
if get_internal_debug():
config.Log("Info", f"Webhook URL: {webhook_url}, Message: {LimitStringLength(message)}, User ID: {user_id}")
logger.Log("Info", f"Webhook URL: {webhook_url}, Message: {LimitStringLength(message)}, User ID: {user_id}")
if webhook_url == "" or webhook_url == None:
return None
result = await self.get_message_sender_function(webhook_url, self.get_message_sender_type())(message)
if get_internal_verbose():
config.Log("Info", f"Webhook URL: {webhook_url}, Message: {LimitStringLength(message)}, Result: {result}")
logger.Log("Info", f"Webhook URL: {webhook_url}, Message: {LimitStringLength(message)}, Result: {result}")
return None
@override
@@ -197,7 +196,7 @@ class WPSAPI(BasicWPSInterface):
@override
def is_enable_plugin(self) -> bool:
if MAIN_WEBHOOK_URL == "":
config.Log("Error", f"{ConsoleFrontColor.RED}WPSAPI未配置主Webhook URL{ConsoleFrontColor.RESET}")
logger.Log("Error", f"{ConsoleFrontColor.RED}WPSAPI未配置主Webhook URL{ConsoleFrontColor.RESET}")
return MAIN_WEBHOOK_URL != ""
@override
@@ -210,8 +209,8 @@ class WPSAPI(BasicWPSInterface):
@override
def wake_up(self) -> None:
config.Log("Info", f"{ConsoleFrontColor.GREEN}WPSAPI核心插件已加载{ConsoleFrontColor.RESET}")
logger.Log("Info", f"{ConsoleFrontColor.GREEN}WPSAPI核心插件已加载{ConsoleFrontColor.RESET}")
self.register_plugin("say")
self.register_plugin("")
config.SaveProperties()
logger.SaveProperties()

View File

@@ -9,8 +9,9 @@ from PWF.CoreModules.plugin_interface import DatabaseModel, get_db
from .WPSAPI import WPSAPI
config = ProjectConfig()
CHECKIN_POINTS = config.FindItem("checkin_points", 100)
logger = ProjectConfig()
CHECKIN_POINTS = logger.FindItem("checkin_points", 100)
logger.SaveProperties()
class WPSConfigAPI(WPSAPI):
@override
@@ -35,7 +36,7 @@ class WPSConfigAPI(WPSAPI):
@override
def wake_up(self) -> None:
config.Log("Info", f"{ConsoleFrontColor.GREEN}WPSConfigAPI 插件已加载{ConsoleFrontColor.RESET}")
logger.Log("Info", f"{ConsoleFrontColor.GREEN}WPSConfigAPI 插件已加载{ConsoleFrontColor.RESET}")
self.register_plugin("config")
self.register_plugin("cfg")
@@ -201,7 +202,7 @@ class WPSCheckinAPI(WPSAPI):
@override
def wake_up(self) -> None:
config.Log("Info", f"{ConsoleFrontColor.GREEN}WPSCheckinAPI 插件已加载{ConsoleFrontColor.RESET}")
logger.Log("Info", f"{ConsoleFrontColor.GREEN}WPSCheckinAPI 插件已加载{ConsoleFrontColor.RESET}")
self.register_plugin("checkin")
self.register_plugin("签到")
@@ -262,7 +263,5 @@ class WPSCheckinAPI(WPSAPI):
- 今日签到状态: {"已签到" if self._get_today_checkin_status(user_id) else "未签到"}
'''
config.SaveProperties()
__all__ = ["WPSConfigAPI"]