From 977f818559bc1890add8ada11ed29032db3bf1e2 Mon Sep 17 00:00:00 2001 From: Redmomn <109732988+Redmomn@users.noreply.github.com> Date: Sat, 5 Oct 2024 15:17:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coolq/api.go | 67 ++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index 24af1dc53..f3a54b223 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -1222,39 +1222,40 @@ func (bot *CQBot) CQDownloadFile(url string, headers gjson.Result, threadCount i // https://git.io/Jtz1F // @route(get_forward_msg) // @rename(res_id->"[message_id\x2Cid].0") -//func (bot *CQBot) CQGetForwardMessage(resID string) global.MSG { -// m := bot.Client.GetForwardMessage(resID) -// if m == nil { -// return Failed(100, "MSG_NOT_FOUND", "消息不存在") -// } -// -// 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, message.Source{SourceType: message.SourceGroup}) -// 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, -// "group_id": n.GroupId, -// } -// } -// return r -// } -// return OK(global.MSG{ -// "messages": transformNodes(m.Nodes), -// }) -//} +func (bot *CQBot) CQGetForwardMessage(resID string) global.MSG { + m, err := bot.Client.FetchForwardMsg(resID) + if err != nil { + return Failed(100, "MSG_NOT_FOUND", "消息不存在") + } + + 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 { + source := message.Source{SourceType: message.SourceGroup} + bot.checkMedia(n.Message, source) + content := ToFormattedMessage(n.Message, source) + 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, + "group_id": n.GroupId, + } + } + return r + } + return OK(global.MSG{ + "messages": transformNodes(m.Nodes), + }) +} // CQGetMessage 获取消息 //