Skip to content

Commit

Permalink
尝试实现 #2421 (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangxiangxiong9 authored Oct 1, 2023
1 parent 1c34643 commit 07214e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions coolq/cqcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ func toElements(e []message.IMessageElement, source message.Source) (r []msg.Ele
{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:
data := pairs{
{K: "file", V: o.File},
Expand Down Expand Up @@ -378,6 +388,11 @@ func ToMessageContent(e []message.IMessageElement, source message.Source) (r []g
"type": "face",
"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:
continue
}
Expand Down Expand Up @@ -849,6 +864,17 @@ func (bot *CQBot) ConvertElement(spec *onebot.Spec, elem msg.Element, sourceType
v.File = cacheFile
}
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:
return nil, errors.New("unsupported message type: " + elem.Type)
}
Expand Down
2 changes: 1 addition & 1 deletion coolq/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (bot *CQBot) groupMessageEvent(c *client.QQClient, m *message.GroupMessage)
"url": c.GetGroupFileUrl(m.GroupCode, file.Path, file.Busid),
},
})
return
// return
}
}
source := message.Source{
Expand Down

0 comments on commit 07214e3

Please sign in to comment.