调整代码
This commit is contained in:
@@ -110,18 +110,18 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
# 根据子命令执行相应操作
|
||||
command_handlers = {
|
||||
"列表": self._list_plugins,
|
||||
"启用": lambda w, s, r: self._operate_plugin(plugin_name, w, s, r, self._enable_plugin),
|
||||
"禁用": lambda w, s, r: self._operate_plugin(plugin_name, w, s, r, self._disable_plugin),
|
||||
"重载": lambda w, s, r: self._operate_plugin(plugin_name, w, s, r, self._reload_plugin),
|
||||
"卸载": lambda w, s, r: self._operate_plugin(plugin_name, w, s, r, self._unload_plugin),
|
||||
"启用": lambda s, r: self._operate_plugin(plugin_name, s, r, self._enable_plugin),
|
||||
"禁用": lambda s, r: self._operate_plugin(plugin_name, s, r, self._disable_plugin),
|
||||
"重载": lambda s, r: self._operate_plugin(plugin_name, s, r, self._reload_plugin),
|
||||
"卸载": lambda s, r: self._operate_plugin(plugin_name, s, r, self._unload_plugin),
|
||||
# 修改这一行,使用 lambda 函数而不是直接调用
|
||||
"加载": lambda w, s, r: self._load_plugin(plugin_name, w, s, r),
|
||||
"信息": lambda w, s, r: self._operate_plugin(plugin_name, w, s, r, self._plugin_info)
|
||||
"加载": lambda s, r: self._load_plugin(plugin_name, s, r),
|
||||
"信息": lambda s, r: self._operate_plugin(plugin_name, s, r, self._plugin_info)
|
||||
}
|
||||
|
||||
handler = command_handlers.get(sub_command)
|
||||
if handler and (sub_command == "列表" or plugin_name):
|
||||
return handler(wcf, sender, roomid)
|
||||
return handler(sender, roomid)
|
||||
else:
|
||||
self.message_util.send_text(f"❌未知命令或缺少参数!\n{self.command_format}", target, sender)
|
||||
return True, "未知命令"
|
||||
@@ -154,7 +154,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
self.message_util.send_text(message, target, sender)
|
||||
return True, "列出插件成功"
|
||||
|
||||
def _operate_plugin(self, plugin_name: str, wcf, sender: str, roomid: str,
|
||||
def _operate_plugin(self, plugin_name: str, sender: str, roomid: str,
|
||||
operation_func) -> Tuple[bool, str]:
|
||||
"""通用插件操作函数"""
|
||||
target = roomid if roomid else sender
|
||||
@@ -172,9 +172,9 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
return True, "不能对插件管理插件自身执行此操作"
|
||||
|
||||
# 执行具体操作
|
||||
return operation_func(display_name, wcf, sender, roomid)
|
||||
return operation_func(display_name, sender, roomid)
|
||||
|
||||
def _enable_plugin(self, plugin_name: str, wcf, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
def _enable_plugin(self, plugin_name: str, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
"""启用插件"""
|
||||
target = roomid if roomid else sender
|
||||
plugin = self.plugin_registry.get_plugin(plugin_name)
|
||||
@@ -198,7 +198,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 启用失败", target, sender)
|
||||
return False, f"插件 {plugin_name} 启用失败"
|
||||
|
||||
def _disable_plugin(self, plugin_name: str, wcf, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
def _disable_plugin(self, plugin_name: str, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
"""禁用插件"""
|
||||
target = roomid if roomid else sender
|
||||
plugin = self.plugin_registry.get_plugin(plugin_name)
|
||||
@@ -222,7 +222,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 禁用失败", target, sender)
|
||||
return False, f"插件 {plugin_name} 禁用失败"
|
||||
|
||||
def _reload_plugin(self, plugin_name: str, wcf, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
def _reload_plugin(self, plugin_name: str, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
"""重载插件"""
|
||||
target = roomid if roomid else sender
|
||||
plugin = self.plugin_registry.get_plugin(plugin_name)
|
||||
@@ -247,7 +247,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 重载失败", target, sender)
|
||||
return False, f"插件 {plugin_name} 重载失败"
|
||||
|
||||
def _unload_plugin(self, plugin_name: str, wcf, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
def _unload_plugin(self, plugin_name: str, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
"""卸载插件"""
|
||||
target = roomid if roomid else sender
|
||||
plugin = self.plugin_registry.get_plugin(plugin_name)
|
||||
@@ -267,7 +267,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 卸载失败", target, sender)
|
||||
return False, f"插件 {plugin_name} 卸载失败"
|
||||
|
||||
def _load_plugin(self, plugin_name: str, wcf, sender: str, roomid: str, silent: bool = False) -> Tuple[bool, str]:
|
||||
def _load_plugin(self, plugin_name: str, sender: str, roomid: str, silent: bool = False) -> Tuple[bool, str]:
|
||||
"""加载插件"""
|
||||
# 对于加载操作,我们直接使用目录名作为模块名
|
||||
# 检查插件目录是否存在
|
||||
@@ -275,7 +275,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
if not os.path.exists(plugin_dir):
|
||||
if not silent:
|
||||
self.message_util.send_text(f"❌插件目录 {plugin_dir} 不存在",
|
||||
(roomid if roomid else sender), sender)
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, f"插件目录 {plugin_dir} 不存在"
|
||||
|
||||
# 检查插件是否已加载 - 遍历所有插件查找模块名匹配的
|
||||
@@ -284,7 +284,7 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
if existing_module_name == plugin_name:
|
||||
if not silent:
|
||||
self.message_util.send_text(f"⚠️插件 {existing_plugin.name} (模块名: {plugin_name}) 已经加载",
|
||||
(roomid if roomid else sender), sender)
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"插件 {existing_plugin.name} 已经加载"
|
||||
|
||||
try:
|
||||
@@ -293,34 +293,34 @@ class PluginManagerPlugin(MessagePluginInterface):
|
||||
if plugin:
|
||||
if not silent:
|
||||
self.message_util.send_text(f"✅插件 {plugin.name} 加载成功",
|
||||
(roomid if roomid else sender), sender)
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"插件 {plugin.name} 加载成功"
|
||||
else:
|
||||
if not silent:
|
||||
self.message_util.send_text(f"❌插件 {plugin_name} 加载失败",
|
||||
(roomid if roomid else sender), sender)
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, f"插件 {plugin_name} 加载失败"
|
||||
except Exception as e:
|
||||
self.LOG.error(f"加载插件 {plugin_name} 出错: {e}")
|
||||
if not silent:
|
||||
self.message_util.send_text(f"❌加载插件出错: {str(e)}",
|
||||
(roomid if roomid else sender), sender)
|
||||
(roomid if roomid else sender), sender)
|
||||
return False, f"加载插件出错: {e}"
|
||||
|
||||
def _plugin_info(self, plugin_name: str, wcf, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
def _plugin_info(self, plugin_name: str, sender: str, roomid: str) -> Tuple[bool, str]:
|
||||
"""查看插件详情"""
|
||||
# 查找匹配的插件名称
|
||||
display_name, plugin = self.plugin_manager.find_plugin_by_name(plugin_name)
|
||||
|
||||
if not display_name:
|
||||
self.message_util.send_text(f"❌未找到插件 {plugin_name},请检查名称是否正确",
|
||||
(roomid if roomid else sender), sender)
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"未找到插件 {plugin_name}"
|
||||
|
||||
plugin = self.plugin_registry.get_plugin(display_name)
|
||||
if not plugin:
|
||||
self.message_util.send_text(f"❌插件 {display_name} 不存在",
|
||||
(roomid if roomid else sender), sender)
|
||||
(roomid if roomid else sender), sender)
|
||||
return True, f"插件 {display_name} 不存在"
|
||||
|
||||
# 获取插件模块名
|
||||
|
||||
Reference in New Issue
Block a user