From 1290a3dd10e966228dcfcff9b3c763d8906e726d Mon Sep 17 00:00:00 2001 From: Mrs4s Date: Thu, 16 Sep 2021 18:08:45 +0800 Subject: [PATCH] fix: unidirectional friend cache missing. --- coolq/bot.go | 18 ++++++++++++++++-- coolq/event.go | 3 --- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index 5c7f926..8cd656e 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -39,7 +39,6 @@ type CQBot struct { db *leveldb.DB friendReqCache sync.Map tempSessionCache sync.Map - oneWayMsgCache sync.Map } // MSG 消息Map @@ -335,6 +334,21 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen } m.Elements = newElem bot.checkMedia(newElem) + + // 单向好友是否存在 + unidirectionalFriendExists := func() bool { + list, err := bot.Client.GetUnidirectionalFriendList() + if err != nil { + return false + } + for _, f := range list { + if f.Uin == target { + return true + } + } + return false + } + var id int32 = -1 if bot.Client.FindFriend(target) != nil { // 双向好友 msg := bot.Client.SendPrivateMessage(target, m) @@ -366,7 +380,7 @@ func (bot *CQBot) SendPrivateMessage(target int64, groupID int64, m *message.Sen id = bot.InsertTempMessage(target, msg) } } - } else if _, ok := bot.oneWayMsgCache.Load(target); ok { // 单向好友 + } else if unidirectionalFriendExists() { // 单向好友 msg := bot.Client.SendPrivateMessage(target, m) if msg != nil { id = bot.InsertPrivateMessage(msg) diff --git a/coolq/event.go b/coolq/event.go index 8b88c10..dd8fdaf 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -36,9 +36,6 @@ func ToFormattedMessage(e []message.IMessageElement, groupID int64, isRaw ...boo func (bot *CQBot) privateMessageEvent(c *client.QQClient, m *message.PrivateMessage) { bot.checkMedia(m.Elements) cqm := ToStringMessage(m.Elements, 0, true) - if !m.Sender.IsFriend { - bot.oneWayMsgCache.Store(m.Sender.Uin, "") - } id := m.Id if bot.db != nil { id = bot.InsertPrivateMessage(m)