perf: 插件处于禁用状态时其所属的函数调用工具不可被启用 #254

This commit is contained in:
Soulter
2025-01-30 00:27:02 +08:00
parent 9abccd63cf
commit 9a7a654596
3 changed files with 13 additions and 3 deletions
+4
View File
@@ -1,3 +1,7 @@
'''
此功能已过时,参考 https://astrbot.app/dev/plugin.html#%E6%B3%A8%E5%86%8C%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE-beta
'''
from typing import Union from typing import Union
import os import os
import json import json
+6 -1
View File
@@ -10,7 +10,7 @@ from astrbot.core.platform.astr_message_event import MessageSesion
from astrbot.core.message.message_event_result import MessageChain from astrbot.core.message.message_event_result import MessageChain
from astrbot.core.provider.manager import ProviderManager from astrbot.core.provider.manager import ProviderManager
from astrbot.core.platform.manager import PlatformManager from astrbot.core.platform.manager import PlatformManager
from .star import star_registry, StarMetadata from .star import star_registry, StarMetadata, star_map
from .star_handler import star_handlers_registry, StarHandlerMetadata, EventType from .star_handler import star_handlers_registry, StarHandlerMetadata, EventType
from .filter.command import CommandFilter from .filter.command import CommandFilter
from .filter.regex import RegexFilter from .filter.regex import RegexFilter
@@ -75,6 +75,11 @@ class Context:
''' '''
func_tool = self.provider_manager.llm_tools.get_func(name) func_tool = self.provider_manager.llm_tools.get_func(name)
if func_tool is not None: if func_tool is not None:
if func_tool.handler_module_path in star_map:
if not star_map[func_tool.handler_module_path].activated:
raise ValueError(f"此函数调用工具所属的插件 {star_map[func_tool.handler_module_path].name} 已被禁用,请先在管理面板启用再激活此工具。")
func_tool.active = True func_tool.active = True
inactivated_llm_tools: list = sp.get("inactivated_llm_tools", []) inactivated_llm_tools: list = sp.get("inactivated_llm_tools", [])
+3 -2
View File
@@ -327,13 +327,14 @@ class PluginManager:
if plugin.module_path not in inactivated_plugins: if plugin.module_path not in inactivated_plugins:
inactivated_plugins.append(plugin.module_path) inactivated_plugins.append(plugin.module_path)
inactivated_llm_tools: list = sp.get("inactivated_llm_tools", []) inactivated_llm_tools: list = list(set(sp.get("inactivated_llm_tools", []))) # 后向兼容
# 禁用插件启用的 llm_tool # 禁用插件启用的 llm_tool
for func_tool in llm_tools.func_list: for func_tool in llm_tools.func_list:
if func_tool.handler_module_path == plugin.module_path: if func_tool.handler_module_path == plugin.module_path:
func_tool.active = False func_tool.active = False
inactivated_llm_tools.append(func_tool.name) if func_tool.name not in inactivated_llm_tools:
inactivated_llm_tools.append(func_tool.name)
sp.put("inactivated_plugins", inactivated_plugins) sp.put("inactivated_plugins", inactivated_plugins)
sp.put("inactivated_llm_tools", inactivated_llm_tools) sp.put("inactivated_llm_tools", inactivated_llm_tools)