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

+21
View File
@@ -10,12 +10,15 @@ from qqbotsdk import (
Config,
EventEmitter,
EventQueue,
Intent,
Session,
WebhookConnecter,
WebsocketConnecter,
)
from qqbotsdk.payloads import GroupAtMessage
intent_mask = (1 << 25) | (1 << 26)
@pytest.fixture
def env(monkeypatch: pytest.MonkeyPatch) -> None:
@@ -29,6 +32,24 @@ def test_construction_loads_config(env: None) -> None:
assert bot.config.connecter == "websocket"
def test_intents_param_overrides_env(
env: None, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("INTENTS", str(1 << 0))
bot = Bot(intents=intent_mask)
assert bot.config.intents == intent_mask # Bot 参数 > INTENTS 环境变量
def test_intents_env_picked_up(env: None, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("INTENTS", str(intent_mask))
assert Bot().config.intents == intent_mask
def test_intents_accepts_intent_flag(env: None) -> None:
bot = Bot(intents=Intent.GROUP_AND_C2C_EVENT | Intent.INTERACTION)
assert bot.config.intents == (1 << 25) | (1 << 26)
def test_missing_credentials_raises(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("APPID", raising=False)
monkeypatch.delenv("APPSECRET", raising=False)