refactor(napcat): 将enable_plugin改为动态属性以支持配置文件控制
- 移除硬编码的enable_plugin布尔值 - 添加enable_plugin属性方法,支持通过配置文件动态控制插件启用状态 - 默认状态改为禁用,提高系统安全性 - 支持运行时通过_is_enabled属性缓存配置状态
This commit is contained in:
@@ -277,11 +277,19 @@ class StopNapcatAdapterHandler(BaseEventHandler):
|
|||||||
@register_plugin
|
@register_plugin
|
||||||
class NapcatAdapterPlugin(BasePlugin):
|
class NapcatAdapterPlugin(BasePlugin):
|
||||||
plugin_name = CONSTS.PLUGIN_NAME
|
plugin_name = CONSTS.PLUGIN_NAME
|
||||||
enable_plugin: bool = True
|
|
||||||
dependencies: List[str] = [] # 插件依赖列表
|
dependencies: List[str] = [] # 插件依赖列表
|
||||||
python_dependencies: List[str] = [] # Python包依赖列表
|
python_dependencies: List[str] = [] # Python包依赖列表
|
||||||
config_file_name: str = "config.toml" # 配置文件名
|
config_file_name: str = "config.toml" # 配置文件名
|
||||||
|
|
||||||
|
@property
|
||||||
|
def enable_plugin(self) -> bool:
|
||||||
|
"""通过配置文件动态控制插件启用状态"""
|
||||||
|
# 如果已经通过配置加载了状态,使用配置中的值
|
||||||
|
if hasattr(self, '_is_enabled'):
|
||||||
|
return self._is_enabled
|
||||||
|
# 否则使用默认值(禁用状态)
|
||||||
|
return False
|
||||||
|
|
||||||
# 配置节描述
|
# 配置节描述
|
||||||
config_section_descriptions = {"plugin": "插件基本信息"}
|
config_section_descriptions = {"plugin": "插件基本信息"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user