mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 11:33:48 +08:00
group forward msg套娃
This commit is contained in:
parent
86e98c8287
commit
13a0a0cfd1
42
coolq/api.go
42
coolq/api.go
@ -232,7 +232,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
if m.Type != gjson.JSON {
|
if m.Type != gjson.JSON {
|
||||||
return Failed(100)
|
return Failed(100)
|
||||||
}
|
}
|
||||||
var nodes []*message.ForwardNode
|
var sendNodes []*message.ForwardNode
|
||||||
ts := time.Now().Add(-time.Minute * 5)
|
ts := time.Now().Add(-time.Minute * 5)
|
||||||
hasCustom := func() bool {
|
hasCustom := func() bool {
|
||||||
for _, item := range m.Array() {
|
for _, item := range m.Array() {
|
||||||
@ -242,13 +242,14 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}()
|
}()
|
||||||
convert := func(e gjson.Result) {
|
var convert func(e gjson.Result) []*message.ForwardNode
|
||||||
|
convert = func(e gjson.Result) (nodes []*message.ForwardNode) {
|
||||||
if e.Get("type").Str != "node" {
|
if e.Get("type").Str != "node" {
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
ts.Add(time.Second)
|
ts.Add(time.Second)
|
||||||
if e.Get("data.id").Exists() {
|
if e.Get("data.id").Exists() {
|
||||||
i, _ := strconv.Atoi(e.Get("data.id").Str)
|
i, _ := strconv.Atoi(e.Get("data.id").String())
|
||||||
m := bot.GetMessage(int32(i))
|
m := bot.GetMessage(int32(i))
|
||||||
if m != nil {
|
if m != nil {
|
||||||
sender := m["sender"].(message.Sender)
|
sender := m["sender"].(message.Sender)
|
||||||
@ -270,6 +271,30 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
}
|
}
|
||||||
uin, _ := strconv.ParseInt(e.Get("data.uin").Str, 10, 64)
|
uin, _ := strconv.ParseInt(e.Get("data.uin").Str, 10, 64)
|
||||||
name := e.Get("data.name").Str
|
name := e.Get("data.name").Str
|
||||||
|
c := e.Get("data.content")
|
||||||
|
if c.IsArray() {
|
||||||
|
flag := false
|
||||||
|
c.ForEach(func(_, value gjson.Result) bool {
|
||||||
|
if value.Get("type").String() == "node" {
|
||||||
|
flag = true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
if flag {
|
||||||
|
var taowa []*message.ForwardNode
|
||||||
|
for _, item := range c.Array() {
|
||||||
|
taowa = append(taowa, convert(item)...)
|
||||||
|
}
|
||||||
|
nodes = append(nodes, &message.ForwardNode{
|
||||||
|
SenderId: uin,
|
||||||
|
SenderName: name,
|
||||||
|
Time: int32(ts.Unix()),
|
||||||
|
Message: []message.IMessageElement{bot.Client.UploadGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: taowa})},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
content := bot.ConvertObjectMessage(e.Get("data.content"), true)
|
content := bot.ConvertObjectMessage(e.Get("data.content"), true)
|
||||||
if uin != 0 && name != "" && len(content) > 0 {
|
if uin != 0 && name != "" && len(content) > 0 {
|
||||||
var newElem []message.IMessageElement
|
var newElem []message.IMessageElement
|
||||||
@ -294,16 +319,17 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Warnf("警告: 非法 Forward node 将跳过")
|
log.Warnf("警告: 非法 Forward node 将跳过")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if m.IsArray() {
|
if m.IsArray() {
|
||||||
for _, item := range m.Array() {
|
for _, item := range m.Array() {
|
||||||
convert(item)
|
sendNodes = append(sendNodes, convert(item)...)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
convert(m)
|
sendNodes = convert(m)
|
||||||
}
|
}
|
||||||
if len(nodes) > 0 {
|
if len(sendNodes) > 0 {
|
||||||
gm := bot.Client.SendGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: nodes})
|
gm := bot.Client.SendGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: sendNodes})
|
||||||
return OK(MSG{
|
return OK(MSG{
|
||||||
"message_id": ToGlobalId(groupId, gm.Id),
|
"message_id": ToGlobalId(groupId, gm.Id),
|
||||||
})
|
})
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
type MSG map[string]interface{}
|
type MSG map[string]interface{}
|
||||||
|
|
||||||
func (m MSG) Get(s string) MSG {
|
func (m MSG) Get(s string) MSG {
|
||||||
if v,ok := m[s];ok {
|
if v, ok := m[s]; ok {
|
||||||
if msg,ok := v.(MSG);ok {
|
if msg, ok := v.(MSG); ok {
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
return MSG{"__str__": v} // 用这个名字应该没问题吧
|
return MSG{"__str__": v} // 用这个名字应该没问题吧
|
||||||
@ -23,7 +23,7 @@ func (m MSG) Get(s string) MSG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m MSG) String() string {
|
func (m MSG) String() string {
|
||||||
if str,ok:=m["__str__"];ok {
|
if str, ok := m["__str__"]; ok {
|
||||||
return fmt.Sprint(str)
|
return fmt.Sprint(str)
|
||||||
}
|
}
|
||||||
str, _ := json.MarshalToString(m)
|
str, _ := json.MarshalToString(m)
|
||||||
|
@ -334,7 +334,7 @@ func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
|
|||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
_ = c.WriteJSON(ret)
|
_ = c.WriteJSON(ret)
|
||||||
} else {
|
} else {
|
||||||
ret := coolq.Failed(1404,"API_NOT_FOUND","API不存在")
|
ret := coolq.Failed(1404, "API_NOT_FOUND", "API不存在")
|
||||||
if j.Get("echo").Exists() {
|
if j.Get("echo").Exists() {
|
||||||
ret["echo"] = j.Get("echo").Value()
|
ret["echo"] = j.Get("echo").Value()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user