1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-04 19:17:37 +08:00

尝试实现 #2421 (#2422)

This commit is contained in:
xiangxiangxiong9 2023-10-01 12:27:06 +08:00 committed by GitHub
parent 1c34643f4f
commit 07214e396e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -243,6 +243,16 @@ func toElements(e []message.IMessageElement, source message.Source) (r []msg.Ele
{K: "type", V: "sticker"}, {K: "type", V: "sticker"},
}, },
} }
case *message.GroupFileElement:
m = msg.Element{
Type: "file",
Data: pairs{
{K: "path", V: o.Path},
{K: "name", V: o.Name},
{K: "size", V: strconv.FormatInt(o.Size, 10)},
{K: "busid", V: strconv.FormatInt(int64(o.Busid), 10)},
},
}
case *msg.LocalImage: case *msg.LocalImage:
data := pairs{ data := pairs{
{K: "file", V: o.File}, {K: "file", V: o.File},
@ -378,6 +388,11 @@ func ToMessageContent(e []message.IMessageElement, source message.Source) (r []g
"type": "face", "type": "face",
"data": global.MSG{"id": o.ID, "type": "sticker"}, "data": global.MSG{"id": o.ID, "type": "sticker"},
} }
case *message.GroupFileElement:
m = global.MSG{
"type": "file",
"data": global.MSG{"path": o.Path, "name": o.Name, "size": strconv.FormatInt(o.Size, 10), "busid": strconv.FormatInt(int64(o.Busid), 10)},
}
default: default:
continue continue
} }
@ -849,6 +864,17 @@ func (bot *CQBot) ConvertElement(spec *onebot.Spec, elem msg.Element, sourceType
v.File = cacheFile v.File = cacheFile
} }
return v, nil return v, nil
case "file":
path := elem.Get("path")
name := elem.Get("name")
size, _ := strconv.ParseInt(elem.Get("size"), 10, 64)
busid, _ := strconv.ParseInt(elem.Get("busid"), 10, 64)
return &message.GroupFileElement{
Name: name,
Size: size,
Path: path,
Busid: int32(busid),
}, nil
default: default:
return nil, errors.New("unsupported message type: " + elem.Type) return nil, errors.New("unsupported message type: " + elem.Type)
} }

View File

@ -118,7 +118,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
"url": c.GetGroupFileUrl(m.GroupCode, file.Path, file.Busid), "url": c.GetGroupFileUrl(m.GroupCode, file.Path, file.Busid),
}, },
}) })
return // return
} }
} }
source := message.Source{ source := message.Source{