失效按钮乱点同样计数处罚;不再静默

This commit is contained in:
snowy-yang committed 2026-10-05 19:46:30 +08:00
1 parent 37e44a512d
commit 1db8f1cc0e
3 files changed
+49 -13

No files matched your search

+38 -5
View File
@@ -160,7 +160,9 @@ def test_foreign_clicker_muted_on_third_click(tmp_path, monkeypatch):
asyncio.run(scenario())
def test_stale_button_click_not_punished(tmp_path, monkeypatch):
def test_stale_button_clicks_counted_as_foreign(tmp_path, monkeypatch):
"""点已失效的残留按钮同样计入乱点处罚:3 次后禁言。"""
async def scenario():
monkeypatch.setenv("DATA_DIR", str(tmp_path))
bot = make_bot()
@@ -169,13 +171,44 @@ def test_stale_button_click_not_punished(tmp_path, monkeypatch):
fake = FakeApi()
bot.services[BotApi] = fake
# token 不属于任何在途题目(旧题残留按钮)
# token 不属于任何在途题目(验证通过后残留的按钮)
for seq in range(1, 4):
await bot._emitter.emit(interaction_payload("ghost", 1, "MEMBER_C", seq=seq))
await asyncio.sleep(0.03)
assert fake.raw_posts == [] # 三次都不触发禁言
assert all("不是给你的" in (m["markdown"] or "") for m in fake.group_messages)
assert all("<@MEMBER_C>" in (m["markdown"] or "") for m in fake.group_messages)
# 前两次带计数的警告(@点击者),第三次禁言
warns = [(m["markdown"] or "") for m in fake.group_messages[:2]]
assert all("不是给你的" in md and "<@MEMBER_C>" in md for md in warns)
assert "再乱点" in warns[0] and "再乱点 1 次" in warns[1]
mutes = [j for p, j in fake.raw_posts if p.endswith("/restrict_chat_setting")]
assert len(mutes) == 1
entry = mutes[0]["members"][0]
assert entry["op"] == "add"
assert entry["member_openid"] == "MEMBER_C"
asyncio.run(scenario())
def test_verified_member_clicking_stale_button_not_punished(tmp_path, monkeypatch):
"""刚通过验证的成员点自己残留的旧按钮:礼貌回复,不计处罚。"""
async def scenario():
import time as _time
monkeypatch.setenv("DATA_DIR", str(tmp_path))
monkeypatch.setenv("VERIFIED_TRUST_DAYS", "3") # 开启信任期,已通过成员才免计
bot = make_bot()
cfg = AuthConfig.load()
state = setup(bot, cfg)
fake = FakeApi()
bot.services[BotApi] = fake
key = pending_key("GROUP1", "MEMBER_C")
state.mark_verified(key) # trust 窗口内
await bot._emitter.emit(interaction_payload("ghost", 1, "MEMBER_C", seq=1))
await asyncio.sleep(0.05)
assert fake.raw_posts == [] # 不触发禁言
assert "已经通过验证" in (fake.group_messages[-1]["content"] or "")
asyncio.run(scenario())