MaiBot 插件开发 SDK
Project description
MaiBot Plugin SDK
MaiBot 插件开发的唯一依赖。提供插件基类、组件装饰器、能力代理和类型定义。
完整文档:插件开发指南 — 覆盖全部 13 种能力代理、5 种组件装饰器、消息模型、生命周期、调试与发布。
安装
pip install maibot-plugin-sdk
快速开始
from maibot_sdk import MaiBotPlugin, Action, Command
class MyPlugin(MaiBotPlugin):
@Action("greet", description="打招呼")
async def handle_greet(self, **kwargs):
await self.ctx.send.text("你好!", kwargs["stream_id"])
return True, "已回复"
@Command("hello", pattern=r"^/hello")
async def handle_hello(self, **kwargs):
await self.ctx.send.text("Hello!", kwargs["stream_id"])
return True, "Hello!", 2
def create_plugin():
return MyPlugin()
将上述代码保存为 plugin.py,放入 MaiBot 的 plugins/ 目录即可自动加载。
能力一览
通过 self.ctx 访问所有能力,调用自动转发为 RPC 请求:
| 属性 | 说明 |
|---|---|
ctx.send |
发送文本、图片、表情、转发、混合消息 |
ctx.db |
数据库增删改查计数 |
ctx.llm |
LLM 文本生成与工具调用 |
ctx.config |
插件配置读取 |
ctx.emoji |
表情包管理 |
ctx.message |
历史消息查询 |
ctx.frequency |
发言频率控制 |
ctx.component |
插件与组件管理 |
ctx.chat |
聊天流查询 |
ctx.person |
用户信息查询 |
ctx.knowledge |
LPMM 知识库搜索 |
ctx.tool |
LLM 工具定义查询 |
ctx.logger |
插件日志(标准 logging.Logger) |
插件目录结构
my_plugin/
plugin.py # 插件入口,包含 create_plugin()
config.toml # 可选配置
环境要求
- Python >= 3.10
- pydantic >= 2.0
- msgpack >= 1.0
开发
git clone https://github.com/Mai-with-u/maibot-plugin-sdk.git
cd maibot-plugin-sdk
pip install -e ".[dev]"
ruff check maibot_sdk/ # lint
mypy maibot_sdk/ # 类型检查
pytest -v # 测试
许可证
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file maibot_plugin_sdk-1.2.3.tar.gz.
File metadata
- Download URL: maibot_plugin_sdk-1.2.3.tar.gz
- Upload date:
- Size: 48.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53c397461091ab886a715b5b370f0685e419910189241cab8f68a6b5c8702266
|
|
| MD5 |
b02bc605d883d568fa4f17cfd551fff8
|
|
| BLAKE2b-256 |
aa20cdfa16b60ca8bf0ea87bb7d4bb000fe4704461c16aeefa2102f28eee98d6
|
Provenance
The following attestation bundles were made for maibot_plugin_sdk-1.2.3.tar.gz:
Publisher:
publish.yml on Mai-with-u/maibot-plugin-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
maibot_plugin_sdk-1.2.3.tar.gz -
Subject digest:
53c397461091ab886a715b5b370f0685e419910189241cab8f68a6b5c8702266 - Sigstore transparency entry: 1094169385
- Sigstore integration time:
-
Permalink:
Mai-with-u/maibot-plugin-sdk@9c46cc1fb372e63a2b1e55b1d48c7002a1f37204 -
Branch / Tag:
refs/tags/v1.2.3 - Owner: https://github.com/Mai-with-u
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9c46cc1fb372e63a2b1e55b1d48c7002a1f37204 -
Trigger Event:
release
-
Statement type:
File details
Details for the file maibot_plugin_sdk-1.2.3-py3-none-any.whl.
File metadata
- Download URL: maibot_plugin_sdk-1.2.3-py3-none-any.whl
- Upload date:
- Size: 73.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7982ab0920739e68234e3eae8366bc36fc9ee1b5161de01ed8192cc2b92c6df
|
|
| MD5 |
6b681fb2eb864f9611c324e049101b8f
|
|
| BLAKE2b-256 |
741e36e74e368c751c0becdb91165963d8a6f6ba4edf4d33f8c3b00927ae5554
|
Provenance
The following attestation bundles were made for maibot_plugin_sdk-1.2.3-py3-none-any.whl:
Publisher:
publish.yml on Mai-with-u/maibot-plugin-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
maibot_plugin_sdk-1.2.3-py3-none-any.whl -
Subject digest:
b7982ab0920739e68234e3eae8366bc36fc9ee1b5161de01ed8192cc2b92c6df - Sigstore transparency entry: 1094169453
- Sigstore integration time:
-
Permalink:
Mai-with-u/maibot-plugin-sdk@9c46cc1fb372e63a2b1e55b1d48c7002a1f37204 -
Branch / Tag:
refs/tags/v1.2.3 - Owner: https://github.com/Mai-with-u
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9c46cc1fb372e63a2b1e55b1d48c7002a1f37204 -
Trigger Event:
release
-
Statement type: