mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 01:40:15 +08:00
feat(events): Expand MessageEvent with reply capabilities and detailed docstrings fix(loader): Ensure plugin path is correctly managed in sys.path feat(star): Improve Star class documentation and lifecycle method descriptions feat(testing): Add plugin metadata handling in MockContext and enhance PluginHarness feat(hello): Refactor HelloPlugin to utilize new reply methods and structured capabilities test(decorators): Add tests for input/output model support in provide_capability test(events): Implement tests for reply_image and reply_chain methods in MessageEvent test(http): Validate API registration with capability handler references and error handling test(tests): Enhance tests for plugin harness and directory handling in dev commands
1.1 KiB
1.1 KiB
Hello Plugin
这是给 AstrBot SDK 插件作者准备的最小示例。
目录结构
hello_plugin/
├── plugin.yaml
├── requirements.txt
├── main.py
└── tests
└── test_plugin.py
能学到什么
- 如何定义一个
Star插件 - 如何注册命令 handler
- 如何使用
MessageEvent.reply() - 如何用
PluginHarness.from_plugin_dir()走真实 dispatch 链 - 如何从
Context里读取当前插件元数据 - 如何用
MockContext/MockMessageEvent写插件测试
运行
在仓库根目录执行:
cd examples/hello_plugin
astrbot-sdk validate
astrbot-sdk dev --local --event-text hello
astrbot-sdk dev --local --watch --event-text hello
测试
python -m pytest examples/hello_plugin/tests/test_plugin.py -v
代码说明
hello: 最小命令,收到hello时回复Hello, World!about: 读取ctx.metadata.get_current_plugin(),演示 capability 客户端的基础用法tests/test_plugin.py: 展示 direct handler testtests/test_dispatch.py: 展示PluginHarness.from_plugin_dir()dispatch test