Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forward msg套娃 #518

Merged
merged 2 commits into from
Dec 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions coolq/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
if m.Type != gjson.JSON {
return Failed(100)
}
var nodes []*message.ForwardNode
var sendNodes []*message.ForwardNode
ts := time.Now().Add(-time.Minute * 5)
hasCustom := func() bool {
for _, item := range m.Array() {
Expand All @@ -242,13 +242,14 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
}
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" {
return
return nil
}
ts.Add(time.Second)
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))
if m != nil {
sender := m["sender"].(message.Sender)
Expand All @@ -270,6 +271,30 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
}
uin, _ := strconv.ParseInt(e.Get("data.uin").Str, 10, 64)
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)
if uin != 0 && name != "" && len(content) > 0 {
var newElem []message.IMessageElement
Expand All @@ -294,16 +319,17 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
return
}
log.Warnf("警告: 非法 Forward node 将跳过")
return
}
if m.IsArray() {
for _, item := range m.Array() {
convert(item)
sendNodes = append(sendNodes, convert(item)...)
}
} else {
convert(m)
sendNodes = convert(m)
}
if len(nodes) > 0 {
gm := bot.Client.SendGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: nodes})
if len(sendNodes) > 0 {
gm := bot.Client.SendGroupForwardMessage(groupId, &message.ForwardMessage{Nodes: sendNodes})
return OK(MSG{
"message_id": ToGlobalId(groupId, gm.Id),
})
Expand Down
6 changes: 3 additions & 3 deletions global/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
type MSG map[string]interface{}

func (m MSG) Get(s string) MSG {
if v,ok := m[s];ok {
if msg,ok := v.(MSG);ok {
if v, ok := m[s]; ok {
if msg, ok := v.(MSG); ok {
return msg
}
return MSG{"__str__": v} // 用这个名字应该没问题吧
Expand All @@ -23,7 +23,7 @@ func (m MSG) Get(s string) MSG {
}

func (m MSG) String() string {
if str,ok:=m["__str__"];ok {
if str, ok := m["__str__"]; ok {
return fmt.Sprint(str)
}
str, _ := json.MarshalToString(m)
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ module github.com/Mrs4s/go-cqhttp
go 1.15

require (
github.com/Mrs4s/MiraiGo v0.0.0-20201220045933-93ff7797ed6b
github.com/Mrs4s/MiraiGo v0.0.0-20201225142205-d3ded1965ca7
github.com/dustin/go-humanize v1.0.0
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c
github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect
github.com/gin-contrib/pprof v1.3.0
github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2
github.com/guonaihong/gout v0.1.3
github.com/hjson/hjson-go v3.1.0+incompatible
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.10
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/kr/binarydist v0.1.0 // indirect
Expand All @@ -21,6 +24,7 @@ require (
github.com/sirupsen/logrus v1.7.0
github.com/syndtr/goleveldb v1.0.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/tebeka/strftime v0.1.5 // indirect
github.com/tidwall/gjson v1.6.4
github.com/wdvxdr1123/go-silk v0.0.0-20201210140933-bcdbcb2f1093
github.com/yinghau76/go-ascii-art v0.0.0-20190517192627-e7f465a30189
Expand Down
Loading