Skip to content

Commit 199712e

Browse files
♻️ 重构 Discord 出站序列化 (#87)
* ♻️ Introduce outbound serialization helpers * ♻️ Move Discord transport encoding to boundaries * 🔧 Refresh uv lock metadata * 🚨 auto fix by pre-commit hooks * 🐛 Stabilize transport JSON text encoding * ♻️ Tighten prepared transport request typing * ⚡️ Optimize v2 transport JSON data encoding --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7877e50 commit 199712e

10 files changed

Lines changed: 778 additions & 249 deletions

nonebot/adapters/discord/adapter.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import contextlib
44
from functools import lru_cache
55
import inspect
6-
import json
76
import sys
87
from types import UnionType
98
from typing import Any, cast
@@ -36,7 +35,8 @@
3635
Reconnect,
3736
Resume,
3837
)
39-
from .utils import decompress_data, log, model_dump
38+
from .serialization import encode_model_json_text
39+
from .utils import decompress_data, log
4040

4141
RECONNECT_INTERVAL = 3.0
4242

@@ -297,7 +297,7 @@ async def _heartbeat(ws: WebSocket, bot: Bot) -> None:
297297
{"data": bot.sequence if bot.has_sequence else None},
298298
)
299299
with contextlib.suppress(Exception):
300-
await ws.send(json.dumps(model_dump(payload, by_alias=True)))
300+
await ws.send(encode_model_json_text(payload, by_alias=True))
301301

302302
async def _heartbeat_task(
303303
self, ws: WebSocket, bot: Bot, heartbeat_interval: int
@@ -342,13 +342,8 @@ async def _authenticate(
342342

343343
try:
344344
await ws.send(
345-
json.dumps(
346-
model_dump(
347-
payload,
348-
by_alias=True,
349-
exclude_none=True,
350-
omit_unset_values=True,
351-
)
345+
encode_model_json_text(
346+
payload, by_alias=True, exclude_none=True, omit_unset_values=True
352347
)
353348
)
354349
except Exception as e:

nonebot/adapters/discord/api/client.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is auto-generated by scripts/generate_client_pyi.py.
22
# Do not edit this file directly.
3-
# Generated at: 2026-02-26T19:42:13Z
3+
# Generated at: 2026-03-16T08:58:21Z
44
# Source file: nonebot/adapters/discord/api/handle.py
5-
# Source SHA256: b377b5d9309e2fe7268299cffc7777caec3d0f9a0cc7f25b6b1ebbb2ae846e0c
5+
# Source SHA256: 8d5b74fe9c3de234287ba1e845638d1b814dbe1ef47d9b64f2875db0d29826f4
66
# Script SHA256: bca3059c41f047e5cfb7f59a630cbcd9f80c226dc2138e28b19cd6b811cd03dc
77

88
from datetime import datetime

0 commit comments

Comments
 (0)