feat: 整合开发历史

This commit is contained in:
2026-01-04 19:38:47 +08:00
parent 0965123c1d
commit bbdeecb89b
25 changed files with 2199 additions and 506 deletions

View File

@@ -11,7 +11,9 @@ import pkgutil
import sys
from core.command_manager import matcher
from core.exceptions import SyncHandlerError
from .logger import logger
from .executor import run_in_thread_pool
def load_all_plugins():
@@ -49,6 +51,8 @@ def load_all_plugins():
type_str = "" if is_pkg else "文件"
logger.success(f" [{type_str}] 成功{action}: {module_name}")
except SyncHandlerError as e:
logger.error(f" 插件 {module_name} 加载失败: {e} (跳过此插件)")
except Exception as e:
print(
f" {action if 'action' in locals() else '加载'}插件 {module_name} 失败: {e}"
@@ -75,50 +79,48 @@ class PluginDataManager:
self.plugin_name + ".json",
)
self.data = {}
self.load()
def load(self):
async def load(self):
"""读取配置文件"""
if not os.path.exists(self.data_file):
with open(self.data_file, "w", encoding="utf-8") as f:
self.set(self.plugin_name, [])
await self.set(self.plugin_name, [])
try:
with open(self.data_file, "r", encoding="utf-8") as f:
self.data = json.load(f)
self.data = await run_in_thread_pool(json.load, f)
except json.JSONDecodeError:
self.data = {}
def save(self):
async def save(self):
"""保存配置到文件"""
with open(self.data_file, "w", encoding="utf-8") as f:
json.dump(self.data, f, indent=2, ensure_ascii=False)
await run_in_thread_pool(json.dump, self.data, f, indent=2, ensure_ascii=False)
def get(self, key, default=None):
"""获取配置项"""
return self.data.get(key, default)
def set(self, key, value):
async def set(self, key, value):
"""设置配置项"""
self.data[key] = value
self.save()
await self.save()
def add(self, key, value):
async def add(self, key, value):
"""添加配置项"""
if key not in self.data:
self.data[key] = []
self.data[key].append(value)
self.save()
await self.save()
def remove(self, key):
async def remove(self, key):
"""删除配置项"""
if key in self.data:
del self.data[key]
self.save()
await self.save()
def clear(self):
async def clear(self):
"""清空所有配置"""
self.data.clear()
self.save()
await self.save()
def get_all(self):
return self.data.copy()