feat: Enhance plugin configuration management and SDK integration
- Add support for configuration reload scopes in the plugin runtime. - Implement validation for SDK plugins to ensure required lifecycle methods are overridden. - Update the configuration update handling to include scope information. - Introduce tests for expression auto-check task and NapCat adapter SDK integration. - Refactor configuration management to support callbacks with variable arguments. - Improve plugin loading and error handling for configuration updates. - Ensure that plugins can manage their own configuration updates effectively.
This commit is contained in:
@@ -3,12 +3,18 @@
|
||||
通过 /chat 命令设置和查看聊天频率。
|
||||
"""
|
||||
|
||||
from maibot_sdk import MaiBotPlugin, Command
|
||||
from maibot_sdk import Command, MaiBotPlugin
|
||||
|
||||
|
||||
class BetterFrequencyPlugin(MaiBotPlugin):
|
||||
"""聊天频率控制插件"""
|
||||
|
||||
async def on_load(self) -> None:
|
||||
"""处理插件加载。"""
|
||||
|
||||
async def on_unload(self) -> None:
|
||||
"""处理插件卸载。"""
|
||||
|
||||
@Command(
|
||||
"set_talk_frequency",
|
||||
description="设置当前聊天的talk_frequency值:/chat talk_frequency <数字> 或 /chat t <数字>",
|
||||
@@ -80,6 +86,25 @@ class BetterFrequencyPlugin(MaiBotPlugin):
|
||||
await self.ctx.send.text(status_msg, stream_id)
|
||||
return True, None, False
|
||||
|
||||
async def on_config_update(self, scope: str, config_data: dict[str, object], version: str) -> None:
|
||||
"""处理配置热重载事件。
|
||||
|
||||
Args:
|
||||
scope: 配置变更范围。
|
||||
config_data: 最新配置数据。
|
||||
version: 配置版本号。
|
||||
"""
|
||||
|
||||
del scope
|
||||
del config_data
|
||||
del version
|
||||
|
||||
|
||||
def create_plugin() -> BetterFrequencyPlugin:
|
||||
"""创建聊天频率插件实例。
|
||||
|
||||
Returns:
|
||||
BetterFrequencyPlugin: 新的聊天频率插件实例。
|
||||
"""
|
||||
|
||||
def create_plugin():
|
||||
return BetterFrequencyPlugin()
|
||||
|
||||
Reference in New Issue
Block a user