feat(plugin): 新增极简插件开发模式

新增 SimplePlugin 基类,提供面向新手的极简插件开发方式
添加相关示例代码和文档说明
This commit is contained in:
2026-03-08 19:02:09 +08:00
parent dec1a43f28
commit 958c1df1fc
5 changed files with 430 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
from core.plugin import Plugin, command, on_message
from models.events.message import MessageEvent
from core.permission import Permission
# 插件元信息
__plugin_meta__ = {
"name": "类风格插件示例",
"description": "演示如何使用类风格编写插件",
"usage": "/hello - 打招呼\n/echo <msg> - 复读消息",
}
class MyPlugin(Plugin):
def __init__(self):
super().__init__()
# 可以在这里初始化一些状态
self.count = 0
@command("hello")
async def hello(self, event: MessageEvent, args: list[str]):
self.count += 1
await self.reply(event, f"Hello from class-based plugin! (Called {self.count} times)")
@command("echo", permission=Permission.USER)
async def echo(self, event: MessageEvent, args: list[str]):
if args:
await self.reply(event, " ".join(args))
else:
await self.reply(event, "请输入要复读的内容。")
@on_message()
async def handle_message(self, event: MessageEvent):
# 这是一个通用的消息处理器,会处理所有消息
# 注意:这可能会与命令冲突,通常需要过滤
if "特定关键词" in event.raw_message:
await self.reply(event, "检测到特定关键词!")
# 实例化插件以注册
plugin = MyPlugin()