mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 12:03:50 +08:00
fix: unidirectional friend cache missing.
This commit is contained in:
parent
59209068bf
commit
1290a3dd10
18
coolq/bot.go
18
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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user