feat: intents 掩码直传——Bot(intents=) 参数与 INTENTS 环境变量,优先于 intents.toml

Intent 枚举(IntFlag)提升到顶层导出可直接 OR;掩码含未收录位仅告警不拦截。
This commit is contained in:
snowy-yang committed 2026-10-03 20:07:56 +08:00
1 parent bcd69099b6
commit 7e8794bf5f
9 files changed
+146 -5

No files matched your search

+14 -1
View File
@@ -17,7 +17,9 @@ class FakeToken:
return "tok"
def make_protocol(session: Session | None = None) -> tuple[WebsocketProtocol, Session]:
def make_protocol(
session: Session | None = None, intents: int | None = None
) -> tuple[WebsocketProtocol, Session]:
session = session or Session()
config = Config(
app_id="app",
@@ -29,6 +31,7 @@ def make_protocol(session: Session | None = None) -> tuple[WebsocketProtocol, Se
webhook_host="0.0.0.0",
webhook_port=8080,
webhook_path="/x",
intents=intents,
)
return WebsocketProtocol(config, session, FakeToken()), session # type: ignore[arg-type]
@@ -45,6 +48,16 @@ async def test_hello_without_session_identifies():
assert reply["d"]["shard"] == (0, 1)
@pytest.mark.asyncio
async def test_identify_carries_intents_mask():
mask = (1 << 25) | (1 << 26)
protocol, _ = make_protocol(intents=mask)
reply = await protocol.on_frame({"op": Opcode.HELLO, "d": {}})
assert reply is not None
assert reply["op"] == Opcode.IDENTIFY
assert reply["d"]["intents"] == mask
@pytest.mark.asyncio
async def test_hello_with_session_resumes():
protocol, session = make_protocol()