pylibob
另一个 LibOneBot Python 库,旨在帮助开发者实现 OneBot 12 标准。
这是什么?
这是一个 Python 的 LibOneBot,旨在帮助开发者快速实现 OneBot 12 标准。
LibOneBot 对 OneBot Connect 和动作、事件、消息段进行了包装,便于开发者使用。
下文涉及的 OneBot 概念请参考 OneBot 术语表
安装
pip install pylibob
快速上手
from __future__ import annotations
# from typing_extensions import Annotated # python<3.9
from typing import Annotated # python>=3.9
from pylibob import (
HTTP,
Bot,
Event,
HTTPWebhook,
OneBotImpl,
WebSocket,
WebSocketReverse,
)
impl = OneBotImpl(
"test", # 实现名称
"1.0.0", # 实现版本
[
HTTP(
host="0.0.0.0", # HTTP 服务器监听 IP
port=8080, # HTTP 服务器监听端口
event_enabled=True, # 是否启用 get_latest_events 元动作
event_buffer_size=20, # 事件缓冲区大小
access_token="access_token", # 访问令牌
),
HTTPWebhook(
url="http://127.0.0.1:8080/onebot/v12/http/", # Webhook 上报地址
),
# WebSocket 均存在 enable_heartbeat 和 heartbeat_interval
WebSocket(
enable_heartbeat=True, # 启用心跳
heartbeat_interval=5000, # 心跳间隔
),
WebSocketReverse(url="ws://127.0.0.1:8081/onebot/v12/ws/"),
],
Bot(platform="qq", user_id="1", online=True), # 任意个数 Bot 实例
)
@impl.action("hello")
async def _(
# 采用类型注解的方式声明参数及类型
a: str,
# 扩展参数使用 Annotated,第一个 metadata 会被视为参数名
b: Annotated[int, "extra.param"],
# 注解为 Bot 的参数不计入动作需要的参数,会内部处理传入 Bot 实例
c: Bot,
# 允许默认值
d: int = 5,
):
# 此动作 `hello` 需要必须参数:
# a (string)
# extra.param (int)
# 可选参数:
# d (int) (default = 5)
# 向应用推送事件
await impl.emit(Event(...))
return a, b, c, d # 返回的内容会传入到响应的 data
# 机器人准备好后(一般指机器人登录完成)
# 实现良好状态默认为 False,准备好需手动调整为 True
# impl.is_good = True
# 还要调用此方法去更新状态
# await impl.update_status()
impl.run() # 运行
许可证
MIT
Metadata
Release files for pylibob 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pylibob-0.1.1.tar.gz | 22.4 kB | Without provenance | Details for pylibob-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pylibob-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pylibob-0.1.1-py3-none-any.whl |
Total release size: 50.9 kB
Release files / pylibob-0.1.1.tar.gz
| Download URL | pylibob-0.1.1.tar.gz |
|---|---|
| Size | 22.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5695ed256f3a89356adc9dc6fc4cab63f8506bb9151008a1a302f196fae04fd9
|
|
BLAKE2b-256 checksum How to use checksums |
9e7326219d80fd44e17d5b3823a6bf10f2bba2879d6d5baf131d3f172bc96951
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.9.3 CPython/3.10.12
|
Release files / pylibob-0.1.1-py3-none-any.whl
| Download URL | pylibob-0.1.1-py3-none-any.whl |
|---|---|
| Size | 28.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2113c3087fa4074af105b834bc9e639bd3c931b9dbe4086c9739c9c823fde2b
|
|
BLAKE2b-256 checksum How to use checksums |
26809970922debdce5beef6481657864c2762d58c03ae7bcc4ad42ec16c85c7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.9.3 CPython/3.10.12
|
Security for pylibob 0.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.