Skip to content

Commit

Permalink
feat: expand forward message
Browse files Browse the repository at this point in the history
if received a nested forward, the content would be an array rather than a `[CQ:forward]`
  • Loading branch information
wdvxdr1123 committed Dec 17, 2021
1 parent cb16c08 commit 2f1077e
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions coolq/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1515,20 +1515,31 @@ func (bot *CQBot) CQGetForwardMessage(resID string) global.MSG {
if m == nil {
return Failed(100, "MSG_NOT_FOUND", "消息不存在")
}
r := make([]global.MSG, 0, len(m.Nodes))
for _, n := range m.Nodes {
bot.checkMedia(n.Message, 0)
r = append(r, global.MSG{
"sender": global.MSG{
"user_id": n.SenderId,
"nickname": n.SenderName,
},
"time": n.Time,
"content": ToFormattedMessage(n.Message, MessageSource{SourceType: MessageSourceGroup}, false),
})

var transformNodes func(nodes []*message.ForwardNode) []global.MSG
transformNodes = func(nodes []*message.ForwardNode) []global.MSG {
r := make([]global.MSG, len(nodes))
for i, n := range nodes {
bot.checkMedia(n.Message, 0)
content := ToFormattedMessage(n.Message, MessageSource{SourceType: MessageSourceGroup}, false)
if len(n.Message) == 1 {
if forward, ok := n.Message[0].(*message.ForwardMessage); ok {
content = transformNodes(forward.Nodes)
}
}
r[i] = global.MSG{
"sender": global.MSG{
"user_id": n.SenderId,
"nickname": n.SenderName,
},
"time": n.Time,
"content": content,
}
}
return r
}
return OK(global.MSG{
"messages": r,
"messages": transformNodes(m.Nodes),
})
}

Expand Down

0 comments on commit 2f1077e

Please sign in to comment.