mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 12:03:50 +08:00
refactor(coolq): clean forward media upload.
This commit is contained in:
parent
404c39eb53
commit
e768ff0dc2
29
coolq/api.go
29
coolq/api.go
@ -360,13 +360,11 @@ func (bot *CQBot) CQSendGroupMessage(groupID int64, i interface{}, autoEscape bo
|
|||||||
fixAt := func(elem []message.IMessageElement) {
|
fixAt := func(elem []message.IMessageElement) {
|
||||||
for _, e := range elem {
|
for _, e := range elem {
|
||||||
if at, ok := e.(*message.AtElement); ok && at.Target != 0 && at.Display == "" {
|
if at, ok := e.(*message.AtElement); ok && at.Target != 0 && at.Display == "" {
|
||||||
at.Display = "@" + func() string {
|
|
||||||
mem := group.FindMember(at.Target)
|
mem := group.FindMember(at.Target)
|
||||||
if mem != nil {
|
if mem != nil {
|
||||||
return mem.DisplayName()
|
at.Display = "@" + mem.DisplayName()
|
||||||
}
|
}
|
||||||
return strconv.FormatInt(at.Target, 10)
|
at.Display = "@" + strconv.FormatInt(at.Target, 10)
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,23 +487,14 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
if uin != 0 && name != "" && len(content) > 0 {
|
if uin != 0 && name != "" && len(content) > 0 {
|
||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
for _, elem := range content {
|
for _, elem := range content {
|
||||||
if img, ok := elem.(*LocalImageElement); ok {
|
switch elem.(type) {
|
||||||
gm, err := bot.UploadLocalImageAsGroup(groupID, img)
|
case *LocalImageElement, *LocalVideoElement:
|
||||||
|
gm, err := bot.uploadMedia(elem, groupID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("警告:群 %v 图片上传失败: %v", groupID, err)
|
log.Warnf("警告: 群 %d %s上传失败: %v", groupID, elem.Type().String(), err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newElem = append(newElem, gm)
|
elem = gm
|
||||||
continue
|
|
||||||
}
|
|
||||||
if video, ok := elem.(*LocalVideoElement); ok {
|
|
||||||
gm, err := bot.UploadLocalVideo(groupID, video)
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("警告:群 %v 视频上传失败: %v", groupID, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
newElem = append(newElem, gm)
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
newElem = append(newElem, elem)
|
newElem = append(newElem, elem)
|
||||||
}
|
}
|
||||||
@ -521,10 +510,6 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m.IsArray() {
|
if m.IsArray() {
|
||||||
m.ForEach(func(_, v gjson.Result) bool {
|
|
||||||
sendNodes = append(sendNodes, convert(v)...)
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
for _, item := range m.Array() {
|
for _, item := range m.Array() {
|
||||||
sendNodes = append(sendNodes, convert(item)...)
|
sendNodes = append(sendNodes, convert(item)...)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user