Skip to main content

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                 # 测试

许可证

LGPL-3.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maibot_plugin_sdk-1.2.3.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maibot_plugin_sdk-1.2.3-py3-none-any.whl (73.1 kB view details)

Uploaded Python 3

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

Hashes for maibot_plugin_sdk-1.2.3.tar.gz
Algorithm Hash digest
SHA256 53c397461091ab886a715b5b370f0685e419910189241cab8f68a6b5c8702266
MD5 b02bc605d883d568fa4f17cfd551fff8
BLAKE2b-256 aa20cdfa16b60ca8bf0ea87bb7d4bb000fe4704461c16aeefa2102f28eee98d6

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file maibot_plugin_sdk-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for maibot_plugin_sdk-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b7982ab0920739e68234e3eae8366bc36fc9ee1b5161de01ed8192cc2b92c6df
MD5 6b681fb2eb864f9611c324e049101b8f
BLAKE2b-256 741e36e74e368c751c0becdb91165963d8a6f6ba4edf4d33f8c3b00927ae5554

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page