fix(kook): 私聊(临时会话)以对端用户为回复目标——修'不能是自己'40000
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

KOOK 临时私聊里用户→bot 事件的 target_id=bot 自己、author_id=对端用户;原 ChannelID=
target_id(bot id),导致回复发给自己→KOOK 40000 不能是自己。修:非群聊时 ChannelID=发送者
(对端)id,回复即发给对端、每 DM 独立会话。加 TestToUnified_PrivateDmUsesPeerAsChannelID。
build/vet/test 全绿, 已重建部署.
This commit is contained in:
Aska committed 2026-09-07 20:09:32 +08:00
1 parent 64efb569c3
commit c4fe5a0cfd
2 files changed
+35 -1

No files matched your search

+24
View File
@@ -7,6 +7,30 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/channel/adapter"
)
func TestToUnified_PrivateDmUsesPeerAsChannelID(t *testing.T) {
t.Parallel()
a := New(Config{BotToken: "x"})
a.setBotIdentity(botIdentity{ID: "bot-1", Username: "Cyrene", Nickname: "Cyrene"})
// KOOK temp/临时私聊: the user→bot DM event's target_id is the BOT (bot-1),
// author_id is the peer user. ChannelID must be the peer so the reply targets the
// user, not the bot ("不能是自己" otherwise).
data := json.RawMessage(`{
"channel_type":"PERSON","type":1,"target_id":"bot-1","author_id":"u-1",
"content":"在吗","msg_id":"m-dm","msg_timestamp":1700000000000,"nonce":"",
"extra":{"type":1,"author":{"id":"u-1","username":"alice","nickname":"Alice"}}
}`)
msg, ok := a.toUnifiedMessage(data, nil)
if !ok {
t.Fatal("expected a deliverable private message")
}
if msg.ChannelID != "u-1" {
t.Errorf("private ChannelID = %q, want peer u-1", msg.ChannelID)
}
if msg.SenderID != "u-1" {
t.Errorf("SenderID = %q, want u-1", msg.SenderID)
}
}
func TestToUnified_DropsSelfEcho(t *testing.T) {
t.Parallel()
a := New(Config{BotToken: "x"})