🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -29,29 +29,29 @@ class ConfigAPI:
|
||||
def get_config(self, key: str, default: Any = None) -> Any:
|
||||
"""
|
||||
从插件配置中获取值,支持嵌套键访问
|
||||
|
||||
|
||||
Args:
|
||||
key: 配置键名,支持嵌套访问如 "section.subsection.key"
|
||||
default: 如果配置不存在时返回的默认值
|
||||
|
||||
|
||||
Returns:
|
||||
Any: 配置值或默认值
|
||||
"""
|
||||
# 获取插件配置
|
||||
plugin_config = getattr(self, '_plugin_config', {})
|
||||
plugin_config = getattr(self, "_plugin_config", {})
|
||||
if not plugin_config:
|
||||
return default
|
||||
|
||||
|
||||
# 支持嵌套键访问
|
||||
keys = key.split('.')
|
||||
keys = key.split(".")
|
||||
current = plugin_config
|
||||
|
||||
|
||||
for k in keys:
|
||||
if isinstance(current, dict) and k in current:
|
||||
current = current[k]
|
||||
else:
|
||||
return default
|
||||
|
||||
|
||||
return current
|
||||
|
||||
async def get_user_id_by_person_name(self, person_name: str) -> tuple[str, str]:
|
||||
|
||||
@@ -157,8 +157,6 @@ class MessageAPI:
|
||||
message_type="text", content=text, platform=platform, target_id=user_id, is_group=False
|
||||
)
|
||||
|
||||
|
||||
|
||||
def get_chat_type(self) -> str:
|
||||
"""获取当前聊天类型
|
||||
|
||||
|
||||
@@ -33,7 +33,13 @@ class PluginAPI(MessageAPI, LLMAPI, DatabaseAPI, ConfigAPI, UtilsAPI, StreamAPI,
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self, chat_stream=None, expressor=None, replyer=None, observations=None, log_prefix: str = "[PluginAPI]", plugin_config: dict = None
|
||||
self,
|
||||
chat_stream=None,
|
||||
expressor=None,
|
||||
replyer=None,
|
||||
observations=None,
|
||||
log_prefix: str = "[PluginAPI]",
|
||||
plugin_config: dict = None,
|
||||
):
|
||||
"""
|
||||
初始化插件API
|
||||
@@ -109,7 +115,12 @@ class PluginAPI(MessageAPI, LLMAPI, DatabaseAPI, ConfigAPI, UtilsAPI, StreamAPI,
|
||||
|
||||
# 便捷的工厂函数
|
||||
def create_plugin_api(
|
||||
chat_stream=None, expressor=None, replyer=None, observations=None, log_prefix: str = "[Plugin]", plugin_config: dict = None
|
||||
chat_stream=None,
|
||||
expressor=None,
|
||||
replyer=None,
|
||||
observations=None,
|
||||
log_prefix: str = "[Plugin]",
|
||||
plugin_config: dict = None,
|
||||
) -> PluginAPI:
|
||||
"""
|
||||
创建插件API实例的便捷函数
|
||||
@@ -126,7 +137,12 @@ def create_plugin_api(
|
||||
PluginAPI: 配置好的插件API实例
|
||||
"""
|
||||
return PluginAPI(
|
||||
chat_stream=chat_stream, expressor=expressor, replyer=replyer, observations=observations, log_prefix=log_prefix, plugin_config=plugin_config
|
||||
chat_stream=chat_stream,
|
||||
expressor=expressor,
|
||||
replyer=replyer,
|
||||
observations=observations,
|
||||
log_prefix=log_prefix,
|
||||
plugin_config=plugin_config,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user