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:
DrSmoothl
2026-03-23 20:06:12 +08:00
parent 9dea6b0e6f
commit d13767ee21
16 changed files with 907 additions and 71 deletions

View File

@@ -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()

View File

@@ -3,17 +3,23 @@
通过 /emoji 命令管理表情包的添加、列表和删除。
"""
from maibot_sdk import Command, MaiBotPlugin
import base64
import datetime
import hashlib
import re
from maibot_sdk import MaiBotPlugin, Command
class EmojiManagePlugin(MaiBotPlugin):
"""表情包管理插件"""
async def on_load(self) -> None:
"""处理插件加载。"""
async def on_unload(self) -> None:
"""处理插件卸载。"""
# ===== 工具方法 =====
@staticmethod
@@ -208,6 +214,25 @@ class EmojiManagePlugin(MaiBotPlugin):
await self.ctx.send.forward(messages, stream_id)
return True, "已发送随机表情包", True
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() -> EmojiManagePlugin:
"""创建表情包管理插件实例。
Returns:
EmojiManagePlugin: 新的表情包管理插件实例。
"""
def create_plugin():
return EmojiManagePlugin()

View File

@@ -3,16 +3,22 @@
你的第一个 MaiCore 插件,包含问候功能、时间查询等基础示例。
"""
from maibot_sdk import Action, Command, EventHandler, MaiBotPlugin, Tool
from maibot_sdk.types import ActivationType, EventType, ToolParameterInfo, ToolParamType
import datetime
import random
from maibot_sdk import MaiBotPlugin, Action, Command, Tool, EventHandler
from maibot_sdk.types import ActivationType, EventType, ToolParameterInfo, ToolParamType
class HelloWorldPlugin(MaiBotPlugin):
"""Hello World 示例插件"""
async def on_load(self) -> None:
"""处理插件加载。"""
async def on_unload(self) -> None:
"""处理插件卸载。"""
# ===== Tool 组件 =====
@Tool(
@@ -146,6 +152,25 @@ class HelloWorldPlugin(MaiBotPlugin):
return True, True, None, None, None
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() -> HelloWorldPlugin:
"""创建 Hello World 示例插件实例。
Returns:
HelloWorldPlugin: 新的示例插件实例。
"""
def create_plugin():
return HelloWorldPlugin()