From c4fe5a0cfda9b3d77a0e71fd6650e571ba0430e4 Mon Sep 17 00:00:00 2001 From: Aska Date: Mon, 7 Sep 2026 20:09:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(kook):=20=E7=A7=81=E8=81=8A(=E4=B8=B4?= =?UTF-8?q?=E6=97=B6=E4=BC=9A=E8=AF=9D)=E4=BB=A5=E5=AF=B9=E7=AB=AF?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=BA=E5=9B=9E=E5=A4=8D=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E2=80=94=E2=80=94=E4=BF=AE'=E4=B8=8D=E8=83=BD=E6=98=AF?= =?UTF-8?q?=E8=87=AA=E5=B7=B1'40000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KOOK 临时私聊里用户→bot 事件的 target_id=bot 自己、author_id=对端用户;原 ChannelID= target_id(bot id),导致回复发给自己→KOOK 40000 不能是自己。修:非群聊时 ChannelID=发送者 (对端)id,回复即发给对端、每 DM 独立会话。加 TestToUnified_PrivateDmUsesPeerAsChannelID。 build/vet/test 全绿, 已重建部署. --- plugins/channels/kook/message.go | 12 +++++++++++- plugins/channels/kook/message_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/plugins/channels/kook/message.go b/plugins/channels/kook/message.go index 2a148b5..902a0da 100644 --- a/plugins/channels/kook/message.go +++ b/plugins/channels/kook/message.go @@ -91,10 +91,20 @@ func (a *Adapter) toUnifiedMessage(data json.RawMessage, frame []byte) (adapter. ct, media := messageKind(ev.Type, content) group := channelIsGroup(ev.ChannelType) + // KOOK temp/临时私聊: for a user→bot DM the event's target_id is the BOT's own id + // (the recipient), while author_id is the peer user. Using target_id as the reply + // target would make the bot reply to itself ("不能是自己", KOOK 40000). So for a + // private (non-group) message we key the conversation by the peer sender, which is + // also the correct reply target and keeps each DM a distinct session. + channelID := ev.TargetID + if group != adapter.ChannelGroup { + channelID = senderID + } + msg := adapter.UnifiedMessage{ Platform: platformName, ChannelType: group, - ChannelID: ev.TargetID, + ChannelID: channelID, SenderID: senderID, SenderName: senderName, Content: content, diff --git a/plugins/channels/kook/message_test.go b/plugins/channels/kook/message_test.go index 4f84881..7bf1b36 100644 --- a/plugins/channels/kook/message_test.go +++ b/plugins/channels/kook/message_test.go @@ -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"})