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

fix(coolq): upload resources when send forward message.

Fixes: #987
This commit is contained in:
wdvxdr 2021-08-04 23:57:41 +08:00
parent 38865584ec
commit b44f9545a8
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
3 changed files with 18 additions and 18 deletions

View File

@ -414,6 +414,21 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
return true
})
var resolveElement = func(elems []message.IMessageElement) []message.IMessageElement {
for i, elem := range elems {
switch elem.(type) {
case *LocalImageElement, *LocalVideoElement:
gm, err := bot.uploadMedia(elem, groupID, true)
if err != nil {
log.Warnf("警告: 群 %d %s上传失败: %v", groupID, elem.Type().String(), err)
continue
}
elems[i] = gm
}
}
return elems
}
var convert func(e gjson.Result) *message.ForwardNode
convert = func(e gjson.Result) *message.ForwardNode {
if e.Get("type").Str != "node" {
@ -435,7 +450,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
}
return msgTime
}(),
Message: bot.ConvertStringMessage(m["message"].(string), true),
Message: resolveElement(bot.ConvertStringMessage(m["message"].(string), true)),
}
}
log.Warnf("警告: 引用消息 %v 错误或数据库未开启.", e.Get("data.id").Str)
@ -476,24 +491,11 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
}
content := bot.ConvertObjectMessage(e.Get("data.content"), true)
if uin != 0 && name != "" && len(content) > 0 {
var newElem []message.IMessageElement
for _, elem := range content {
switch elem.(type) {
case *LocalImageElement, *LocalVideoElement:
gm, err := bot.uploadMedia(elem, groupID, true)
if err != nil {
log.Warnf("警告: 群 %d %s上传失败: %v", groupID, elem.Type().String(), err)
continue
}
elem = gm
}
newElem = append(newElem, elem)
}
return &message.ForwardNode{
SenderId: uin,
SenderName: name,
Time: int32(msgTime),
Message: newElem,
Message: resolveElement(content),
}
}
log.Warnf("警告: 非法 Forward node 将跳过. uin: %v name: %v content count: %v", uin, name, len(content))

3
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/Microsoft/go-winio v0.5.0
github.com/Mrs4s/MiraiGo v0.0.0-20210803073620-cb396f0f5649
github.com/dustin/go-humanize v1.0.0
github.com/gabriel-vasile/mimetype v1.3.1 // indirect
github.com/gabriel-vasile/mimetype v1.3.1
github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.2.1
github.com/jonboulle/clockwork v0.2.2 // indirect
@ -28,7 +28,6 @@ require (
github.com/willf/bitset v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b
golang.org/x/text v0.3.6 // indirect
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

1
go.sum
View File

@ -148,7 +148,6 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 h1:Ugb8sMTWuWRC3+sz5WeN/4kejDx9BvIwnPUiJBjJE+8=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=