1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-06 03:53:50 +08:00

fix: unidirectional friend cache missing.

This commit is contained in:
Mrs4s 2021-09-16 18:08:45 +08:00
parent 59209068bf
commit 1290a3dd10
No known key found for this signature in database
GPG Key ID: 3186E98FA19CE3A7
2 changed files with 16 additions and 5 deletions

View File

@ -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)

View File

@ -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)