qqbot-sdk-python 0.4.1__cp310-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qqbot_sdk_python/__init__.py +9 -0
- qqbot_sdk_python/_native.pyd +0 -0
- qqbot_sdk_python/_native.pyi +57 -0
- qqbot_sdk_python/api.py +627 -0
- qqbot_sdk_python/py.typed +0 -0
- qqbot_sdk_python-0.4.1.dist-info/METADATA +87 -0
- qqbot_sdk_python-0.4.1.dist-info/RECORD +9 -0
- qqbot_sdk_python-0.4.1.dist-info/WHEEL +4 -0
- qqbot_sdk_python-0.4.1.dist-info/sboms/qqbot-sdk-python.cyclonedx.json +6985 -0
|
File without changes
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qqbot-sdk-python
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Async Python bindings for the QQ Bot SDK
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
7
|
+
|
|
8
|
+
# QQ Bot Python SDK
|
|
9
|
+
|
|
10
|
+
Python 3.10+ 原生绑定,通过 PyO3 复用 Rust SDK 的鉴权、限频和消息 API。JSON API 与 Node.js 共用 Rust 分发层。
|
|
11
|
+
|
|
12
|
+
## 从 PyPI 安装
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pip install qqbot-sdk-python
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
首次发布完成后即可安装,导入名为 `qqbot_sdk_python`。预编译 wheel 支持 CPython 3.10+,覆盖 Linux x86_64/ARM64、macOS Intel/Apple Silicon 和 Windows x64。
|
|
19
|
+
|
|
20
|
+
## 从源码安装
|
|
21
|
+
|
|
22
|
+
在仓库根目录运行,需要 Rust 工具链和 Python。
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
cd packages/python
|
|
26
|
+
python3 -m venv .venv
|
|
27
|
+
. .venv/bin/activate
|
|
28
|
+
python -m pip install 'maturin>=1.9.4,<2'
|
|
29
|
+
maturin develop --locked
|
|
30
|
+
python -m unittest discover -s tests -v
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
在同一目录运行 `maturin build --release --locked` 构建当前平台的 wheel。
|
|
34
|
+
|
|
35
|
+
## 使用
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
import asyncio
|
|
39
|
+
import os
|
|
40
|
+
|
|
41
|
+
from qqbot_sdk_python import Bot
|
|
42
|
+
|
|
43
|
+
async def main():
|
|
44
|
+
bot = Bot(os.environ["QQBOT_APP_ID"], os.environ["QQBOT_APP_SECRET"])
|
|
45
|
+
print(await bot.api.bot.me())
|
|
46
|
+
user = bot.user(os.environ["QQBOT_USER_OPENID"])
|
|
47
|
+
message = await user.send("你好")
|
|
48
|
+
print(message["id"])
|
|
49
|
+
|
|
50
|
+
asyncio.run(main())
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
被动回复时可传入 `await user.send("你好", msg_id=收到的消息ID)`。发送权限和额度取决于 QQ 开放平台的配置。
|
|
54
|
+
|
|
55
|
+
`bot.user(id)`、`bot.group(id)`、`bot.channel(id)` 和 `bot.direct(id)` 都提供 `send` 与 `recall`。发送时也可以传入使用 QQ 原生字段名的字典。权限检查与 Rust SDK 一致。
|
|
56
|
+
|
|
57
|
+
`bot.api` 与 Rust 和 Node.js 共用 11 个分组,包含 `bot`、`messages`、`users`、`groups`、`guilds`、`channels`、`materials`、`interactions`、`menu`、`panels` 和 `utility`。Python 使用和 Rust 相同的下划线方法名,参数顺序与 Node.js 一致。分页可选参数可省略,例如 `await bot.api.bot.guilds(limit=20)`。
|
|
58
|
+
|
|
59
|
+
二进制上传使用 `bot.api.materials.upload(...)`、`bot.api.messages.upload_media(...)` 和 `bot.api.messages.send_media(...)`,文件内容以 `bytes` 传入。两个消息富媒体方法也接受 URL 字符串。
|
|
60
|
+
|
|
61
|
+
分组和方法由共享核心生成。修改核心 API 后,在仓库根目录运行 `python3 packages/npm/scripts/generate-api.py` 更新 Rust 分发、TypeScript 声明和 Python 方法。
|
|
62
|
+
|
|
63
|
+
网关模式下使用 `await bot.run(callback)` 接收事件,调用 `bot.stop()` 结束。每个实例可启动一次。普通同步回调在 asyncio 循环中执行。Webhook 模式下,`bot.handle_webhook(timestamp, signature, raw_body)` 验证原始字节,返回 `response` 和可选的 `event`。HTTP 处理器应把 `response` 写回 QQ。
|
|
64
|
+
|
|
65
|
+
请求失败会抛出 `BotError`。平台业务错误是其子类 `ApiError`,提供 `status`、`code`、`message`、`trace_id` 和 `data`。无效参数会抛出 `ValueError`。
|
|
66
|
+
|
|
67
|
+
`Bot(..., api_base_url=...)` 可接入测试服务器。鉴权请求会把 App ID 和 App Secret 发送到该地址。
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## 发布到 PyPI
|
|
71
|
+
|
|
72
|
+
合并 Release Please 的统一版本 PR 后,[统一发布工作流](../../.github/workflows/release.yml) 会从发行标签构建五个平台的 wheel。每个 wheel 安装后运行 Python 测试,全部通过才发布。
|
|
73
|
+
|
|
74
|
+
首次发布前,在 PyPI 的 [Publishing 页面](https://pypi.org/manage/account/publishing/) 添加 pending Trusted Publisher。使用以下配置。
|
|
75
|
+
|
|
76
|
+
| 字段 | 值 |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| PyPI 项目名 | `qqbot-sdk-python` |
|
|
79
|
+
| GitHub owner | `Lovely-02` |
|
|
80
|
+
| Repository | `qqbot-sdk-rs` |
|
|
81
|
+
| Workflow name | `release.yml` |
|
|
82
|
+
| Environment name | `pypi` |
|
|
83
|
+
|
|
84
|
+
在 GitHub 仓库的 Settings → Environments 中创建 `pypi` 环境,并将允许部署的分支设为 `main`。工作流通过 GitHub OIDC 获取上传权限,无需配置 PyPI API Token。
|
|
85
|
+
|
|
86
|
+
重试时,在 Actions → 统一发布 → Run workflow 选择 `main`,填入已有的 `qqbot-sdk-rs-vX.Y.Z` 标签,选择 `target=python`。选择 `all` 会同时重试三个包仓库,选择 `both` 会重试 crates.io 和 GitHub Packages。
|
|
87
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
qqbot_sdk_python/__init__.py,sha256=5f8JAGLJKsb9Yok9YMq614aOmT9x17c4uQYo33IXz3I,292
|
|
2
|
+
qqbot_sdk_python/_native.pyd,sha256=KoOMjEW0AEwZjrJIhH5Mnh8rqM3GZPS7Xq8Yzn2ekKE,7588864
|
|
3
|
+
qqbot_sdk_python/_native.pyi,sha256=uad2gQV-rP_pciVMB2JxzuYic00h-xNlt1IZHAviBPg,1893
|
|
4
|
+
qqbot_sdk_python/api.py,sha256=udVFvkQkJwY1b1VWNeEEnV7OmZGDlscEqqL5HXqgLaQ,26107
|
|
5
|
+
qqbot_sdk_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
qqbot_sdk_python-0.4.1.dist-info/METADATA,sha256=KnIq4Ol8w_Yc-knTNvSBYPmddtYc_Z115q7HdrQaENU,4199
|
|
7
|
+
qqbot_sdk_python-0.4.1.dist-info/WHEEL,sha256=TzjyIyBUptJHnlQyOymQYLWjtXe7MGI0m3QvmcG7PpI,96
|
|
8
|
+
qqbot_sdk_python-0.4.1.dist-info/sboms/qqbot-sdk-python.cyclonedx.json,sha256=y-MBF3EPOlkBjLlN1sQ6T93lL_BJrA9_8f6z_5c_F3M,225572
|
|
9
|
+
qqbot_sdk_python-0.4.1.dist-info/RECORD,,
|