Skip to main content

tenko-api

Tenko 第三方插件使用的稳定宿主接口。

插件依赖它,而不是依赖 tenko 本体:tenko-api 没有任何运行时依赖, 只是转发到正在运行的 Tenko 宿主,因此不会影响插件自己的依赖解析。插件声明 tenko-api>=0.1,<0.2 这样的范围,安装时由 pip / uv 的解析器拒绝不兼容的宿主, 不需要另写兼容检查。

当前为预览版(0.x)。1.0 之前接口可能调整,请把上限写到次版本。

最小示例

插件是标准 Python 包,写法与 Entari 原生插件相同,宿主能力一律从 tenko_api 导入:

# pyproject.toml
[project]
name = "tenko-plugin-hello"
version = "0.1.0"
dependencies = ["tenko-api>=0.1,<0.2"]

[project.entry-points."tenko.plugins"]
hello = "tenko_plugin_hello"   # 入口名 = 插件 ID
# src/tenko_plugin_hello/__init__.py
from arclet.alconna import Alconna
from arclet.entari import Session, command, plugin

from tenko_api.features import declare
from tenko_api.messages import text_message
from tenko_api.perm import Permission, require

plugin.metadata("你好", author=["you"], version="0.1.0", description="打招呼")
declare(
    scope="group", default_enabled=True, rate_weight=1, level=Permission.ActiveGroup
)


@command.on(Alconna("你好"))
@require(Permission.User)
async def hello(session: Session):
    return text_message("你好!")

权限与功能开关

限制命令的默认写法是装饰器,不要在函数体里重复写检查(漏写就等于没有权限控制):

装饰器 作用
@require(Permission.X) 发送者的成员权限不低于 X(含 Master、BotAdmin 和数据库里的黑名单);不足时回复“权限不足(当前权限:… / 需要权限:…)”
@require_group(Permission.X) 当前群等级不低于 X,不足时静默忽略;私聊不受限
@group_only() / @private_only() 只允许群聊 / 私聊,否则回复“该指令只能在群聊/私聊中使用”
  • 装饰器放在 @command.on(...) 之下,放在之上也同样生效;同一种装饰器在一个函数上只能用一次。 它们在命令匹配之后执行,所以只有命中命令的消息才会收到拒绝回复。
  • 声明的要求登记在处理函数上,/帮助 <编号> 会显示每条命令的“权限”。
  • 只有权限取决于运行时数据时(例如按参数区分的权限)才在函数体里调用 require_perm。
  • declare(level=Permission.X) 声明整个插件要求的群等级,默认 ActiveGroup:群等级更低的群里, 该插件的所有命令都被宿主静默忽略。
  • 不走命令的监听器(例如响应 @bot 的消息监听)没有宿主的命令策略保护,用 @feature_required() 检查所属插件的功能开关和维护模式(只在群聊生效,默认静默, notify=True 时回复提示)。所属插件按被装饰函数的模块确定,规则与 data_dir() 相同。
from arclet.entari import MessageCreatedEvent, plugin

from tenko_api.features import feature_required


@plugin.listen(MessageCreatedEvent)
@feature_required()
async def on_message(event: MessageCreatedEvent): ...

接口一览

模块 内容
tenko_api.context MessageContext、context_from_session
tenko_api.perm Permission;装饰器 require、require_group、group_only、private_only;函数体内的 require_perm、get_user_perm、get_group_perm
tenko_api.actions 发消息、禁言、踢人、撤回、查询群成员等宿主动作,以及 ActionServiceError 系列异常
tenko_api.accounts 只读账号信息:在线账号、某群可响应的账号
tenko_api.features feature_enabled 只读查询;declare 声明范围、默认开关、限流权重和群等级;feature_required 装饰非命令监听器
tenko_api.render render_or_none(浏览器不可用时回退文本)
tenko_api.messages text_message、report_error
tenko_api.storage 插件独立数据目录 data_dir()、带版本号并自动备份迁移的 JSON Store

完整的开发、测试和发布流程见仓库中的示例插件 examples/tenko-plugin-example。

版本承诺

版本号独立于 Tenko 本体,遵循语义化版本(1.0 起生效):

变更 版本号
新增能力 次版本号 +1
删除或改变语义 主版本号 +1

被废弃的接口至少保留一个次版本,并抛出 DeprecationWarning。

运行环境

需要在 Tenko 宿主进程中使用:开发和测试时把 tenko 作为开发依赖安装即可。 Python >=3.11,<3.14。

Metadata

Release files for tenko-api 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tenko-api 0.1.0
File Size Uploaded Provenance
tenko_api-0.1.0.tar.gz 8.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tenko-api 0.1.0
File Interpreter ABI Platform
tenko_api-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / tenko_api-0.1.0.tar.gz

Download URL tenko_api-0.1.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8f90ef5933a982eba0e614951ae3a14dda25e2bb6f0a105a63f8bbf7c91e0d80
BLAKE2b-256 checksum
How to use checksums
77e9623f752704b478d4c4dea9435822cbef25c4e28294a2177caa6e15400ce9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / tenko_api-0.1.0-py3-none-any.whl

Download URL tenko_api-0.1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5546aa33cf61e098074f6a5d0e10173acdbb2bc783b0f2299e5b4ed90ef18550
BLAKE2b-256 checksum
How to use checksums
be9151c161b670c5e6c36f2d64b51491613d2371ebd59afc0d9b14c0c46dd5bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for tenko-api 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tenko_api-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page