From 9a7a654596ae6d7b6ae3c9dace415539d61aad10 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Thu, 30 Jan 2025 00:27:02 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=8F=92=E4=BB=B6=E5=A4=84=E4=BA=8E?= =?UTF-8?q?=E7=A6=81=E7=94=A8=E7=8A=B6=E6=80=81=E6=97=B6=E5=85=B6=E6=89=80?= =?UTF-8?q?=E5=B1=9E=E7=9A=84=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E4=B8=8D=E5=8F=AF=E8=A2=AB=E5=90=AF=E7=94=A8=20#254?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/star/config.py | 4 ++++ astrbot/core/star/context.py | 7 ++++++- astrbot/core/star/star_manager.py | 5 +++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/astrbot/core/star/config.py b/astrbot/core/star/config.py index 914b2498f..83bb9f4cb 100644 --- a/astrbot/core/star/config.py +++ b/astrbot/core/star/config.py @@ -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 import os import json diff --git a/astrbot/core/star/context.py b/astrbot/core/star/context.py index 9dfb7bf5d..6b50f951c 100644 --- a/astrbot/core/star/context.py +++ b/astrbot/core/star/context.py @@ -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.provider.manager import ProviderManager 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 .filter.command import CommandFilter from .filter.regex import RegexFilter @@ -75,6 +75,11 @@ class Context: ''' func_tool = self.provider_manager.llm_tools.get_func(name) 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 inactivated_llm_tools: list = sp.get("inactivated_llm_tools", []) diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 6ad4c3976..4f6bbb398 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -327,13 +327,14 @@ class PluginManager: if plugin.module_path not in inactivated_plugins: 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 for func_tool in llm_tools.func_list: if func_tool.handler_module_path == plugin.module_path: 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_llm_tools", inactivated_llm_tools)