feat(qq): Bot 所有者消息升到 L2;普通消息保持 L1

jianf:所有者的话不该被普通人的消息打断/挤到队尾。

- 新增 interruptLevel(owner):owner → PriorityL2(一般提醒),其余 → PriorityL1(后台)。
  一批里只要有一条来自 owner,整批按 L2 投递。
- 为什么不是 L3:L3 是时钟/终端那类"实时",QQ 是异步消息,抬到 L3 会打断真正实时的工作。
- 新增测试 TestOwnerMessagesGetHigherInterruptLevel 钉住 owner=L2 / 普通人=L1。
This commit is contained in:
JianFeeeee
2026-09-14 16:31:27 +08:00
parent a01fe21ab1
commit fe1c4cdb09
2 changed files with 50 additions and 9 deletions

View File

@ -242,7 +242,7 @@ func TestDowngradedAuthStillAllowsQQOutput(t *testing.T) {
// collectInterrupts 用注入钩子收集中断文本(避免测试依赖真实 SDK
func collectInterrupts(p *Plugin) *[]string {
got := []string{}
p.injectHook = func(s string) { got = append(got, s) }
p.injectHook = func(s, _ string) { got = append(got, s) }
return &got
}
@ -312,3 +312,25 @@ func TestSingleMessageKeepsOriginalText(t *testing.T) {
t.Fatalf("单条消息应沿用原文(含所有者前缀),实际 %#v", *got)
}
}
// Bot 所有者/管理员的消息给 L2普通人的给 L1 —— 否则所有者的话会被路人
// 的 L1 闲聊抢占/挤到队尾。
func TestOwnerMessagesGetHigherInterruptLevel(t *testing.T) {
p := newPermissionTestPlugin(t)
got := []string{}
p.injectHook = func(text, level string) { got = append(got, text+"|"+level) }
p.batchWindow = 20 * time.Millisecond
p.batchMax = time.Second
p.enqueueInterrupt("private", 1, 0, 1, "owner", "owner-msg", true, false)
p.enqueueInterrupt("private", 2, 0, 2, "someone", "other-msg", false, false)
time.Sleep(120 * time.Millisecond)
joined := strings.Join(got, ",")
if !strings.Contains(joined, "owner-msg|L2") {
t.Fatalf("所有者消息应为 L2实际 %q", joined)
}
if !strings.Contains(joined, "other-msg|L1") {
t.Fatalf("普通人消息应为 L1实际 %q", joined)
}
}