refactor: 重构代码结构和导入路径
fix(ws): 修复反向WebSocket管理器中的循环导入问题 docs: 删除不再使用的文档文件 style: 统一模型导入路径为neobot.models chore: 更新配置文件中的API密钥和连接地址
This commit is contained in:
@@ -13,6 +13,7 @@ from .command_manager import CommandManager
|
||||
from ..utils.exceptions import SyncHandlerError, PluginLoadError, PluginReloadError, PluginNotFoundError
|
||||
from ..utils.logger import logger, ModuleLogger
|
||||
from ..utils.singleton import Singleton
|
||||
from .command_manager import matcher as command_manager
|
||||
|
||||
# 确保logger在模块级别可见
|
||||
__all__ = ['PluginManager', 'logger']
|
||||
@@ -29,24 +30,31 @@ class PluginManager(Singleton):
|
||||
"""
|
||||
初始化插件管理器
|
||||
|
||||
:param command_manager: CommandManager的实例
|
||||
:param command_manager: CommandManager 的实例
|
||||
"""
|
||||
# 检查是否已经初始化
|
||||
if hasattr(self, '_command_manager'):
|
||||
if hasattr(self, '_initialized') and self._initialized:
|
||||
return
|
||||
|
||||
# 只有首次初始化时才执行
|
||||
self._initialized = True
|
||||
|
||||
# 始终创建 logger 和 loaded_plugins
|
||||
self.logger = ModuleLogger("PluginManager")
|
||||
self.loaded_plugins: Set[str] = set()
|
||||
|
||||
if command_manager:
|
||||
self._command_manager = command_manager
|
||||
self.loaded_plugins: Set[str] = set()
|
||||
# 创建模块专用日志记录器
|
||||
self.logger = ModuleLogger("PluginManager")
|
||||
else:
|
||||
self._command_manager = None
|
||||
|
||||
@property
|
||||
def command_manager(self):
|
||||
"""
|
||||
获取命令管理器实例
|
||||
"""
|
||||
if not hasattr(self, '_command_manager') or self._command_manager is None:
|
||||
raise AttributeError("'PluginManager' object has no attribute '_command_manager'")
|
||||
return self._command_manager
|
||||
|
||||
def load_all_plugins(self) -> None:
|
||||
@@ -54,20 +62,21 @@ class PluginManager(Singleton):
|
||||
扫描并加载 `plugins` 目录下的所有插件。
|
||||
"""
|
||||
# 使用 pathlib 获取更可靠的路径
|
||||
# 当前文件: core/managers/plugin_manager.py
|
||||
# 目标: plugins/
|
||||
# 当前文件:core/managers/plugin_manager.py
|
||||
# 目标:neobot/plugins/
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
# 回退两级到项目根目录 (core/managers -> core -> root)
|
||||
root_dir = os.path.dirname(os.path.dirname(current_dir))
|
||||
plugin_dir = os.path.join(root_dir, "plugins")
|
||||
|
||||
package_name = "plugins"
|
||||
# 使用完整的包名:neobot.plugins
|
||||
package_name = "neobot.plugins"
|
||||
|
||||
if not os.path.exists(plugin_dir):
|
||||
self.logger.error(f"插件目录不存在: {plugin_dir}")
|
||||
self.logger.error(f"插件目录不存在:{plugin_dir}")
|
||||
return
|
||||
|
||||
self.logger.info(f"正在从 {package_name} 加载插件 (路径: {plugin_dir})...")
|
||||
self.logger.info(f"正在从 {package_name} 加载插件 (路径:{plugin_dir})...")
|
||||
|
||||
for _, module_name, is_pkg in pkgutil.iter_modules([plugin_dir]):
|
||||
full_module_name = f"{package_name}.{module_name}"
|
||||
@@ -148,3 +157,6 @@ class PluginManager(Singleton):
|
||||
)
|
||||
self.logger.exception(f"重载插件 {full_module_name} 时发生错误: {error.message}")
|
||||
self.logger.log_custom_exception(error)
|
||||
|
||||
|
||||
plugin_manager = PluginManager(command_manager=command_manager)
|
||||
|
||||
Reference in New Issue
Block a user