diff --git a/coolq/bot.go b/coolq/bot.go index d27ff7b..6d34bda 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -23,12 +23,13 @@ import ( type CQBot struct { Client *client.QQClient - events []func(MSG) - db *nutsdb.DB - friendReqCache sync.Map - invitedReqCache sync.Map - joinReqCache sync.Map - tempMsgCache sync.Map + events []func(MSG) + db *nutsdb.DB + friendReqCache sync.Map + invitedReqCache sync.Map + joinReqCache sync.Map + tempMsgCache sync.Map + oneWayMsgCache sync.Map } type MSG map[string]interface{} @@ -166,12 +167,15 @@ func (bot *CQBot) SendPrivateMessage(target int64, m *message.SendingMessage) in if msg != nil { id = msg.Id } - } else { - if code, ok := bot.tempMsgCache.Load(target); ok { - msg := bot.Client.SendTempMessage(code.(int64), target, m) - if msg != nil { - id = msg.Id - } + } else if code, ok := bot.tempMsgCache.Load(target); ok { + msg := bot.Client.SendTempMessage(code.(int64), target, m) + if msg != nil { + id = msg.Id + } + } else if _, ok := bot.oneWayMsgCache.Load(target); ok { + msg := bot.Client.SendPrivateMessage(target, m) + if msg != nil { + id = msg.Id } } if id == -1 { diff --git a/coolq/event.go b/coolq/event.go index 142e096..e91a0ed 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -32,6 +32,9 @@ func ToFormattedMessage(e []message.IMessageElement, code int64, raw ...bool) (r 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, "") + } log.Infof("收到好友 %v(%v) 的消息: %v", m.Sender.DisplayName(), m.Sender.Uin, cqm) fm := MSG{ "post_type": "message", diff --git a/go.mod b/go.mod index c227ae1..017cc9d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp go 1.14 require ( - github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839 + github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07 github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect github.com/gin-gonic/gin v1.6.3 github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum index 49aaf0a..7d781a6 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839 h1:TDhaPfWcubIMKDz1HU+N07SwIUjj7oVUQ7EXZBbDUxs= github.com/Mrs4s/MiraiGo v0.0.0-20200825052841-d3b0f5f9e839/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= +github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07 h1:AO8HeAS3GbUIfLQHlM7sPfYYN/KsKUpTTB+gVZNvo30= +github.com/Mrs4s/MiraiGo v0.0.0-20200827162217-d7e61afdfe07/go.mod h1:0je03wji/tSw4bUH4QCF2Z4/EjyNWjSJTyy5tliX6EM= github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0= github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=