mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 03:53:50 +08:00
style: small code clean.
This commit is contained in:
parent
d266242887
commit
2f05775101
25
coolq/api.go
25
coolq/api.go
@ -418,14 +418,15 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
}
|
}
|
||||||
var sendNodes []*message.ForwardNode
|
var sendNodes []*message.ForwardNode
|
||||||
ts := time.Now().Add(-time.Minute * 5)
|
ts := time.Now().Add(-time.Minute * 5)
|
||||||
hasCustom := func() bool {
|
hasCustom := false
|
||||||
for _, item := range m.Array() {
|
m.ForEach(func(_, item gjson.Result) bool {
|
||||||
if item.Get("data.uin").Exists() || item.Get("data.user_id").Exists() {
|
if item.Get("data.uin").Exists() || item.Get("data.user_id").Exists() {
|
||||||
return true
|
hasCustom = true
|
||||||
}
|
return false
|
||||||
}
|
}
|
||||||
return false
|
return true
|
||||||
}()
|
})
|
||||||
|
|
||||||
var convert func(e gjson.Result) []*message.ForwardNode
|
var convert func(e gjson.Result) []*message.ForwardNode
|
||||||
convert = func(e gjson.Result) (nodes []*message.ForwardNode) {
|
convert = func(e gjson.Result) (nodes []*message.ForwardNode) {
|
||||||
if e.Get("type").Str != "node" {
|
if e.Get("type").Str != "node" {
|
||||||
@ -455,8 +456,8 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
uin := e.Get("data.[user_id,uin].0").Int()
|
uin := e.Get("data.[user_id,uin].0").Int()
|
||||||
msgTime, err := strconv.ParseInt(e.Get("data.time").Str, 10, 64)
|
msgTime := e.Get("data.time").Int()
|
||||||
if err != nil {
|
if msgTime == 0 {
|
||||||
msgTime = ts.Unix()
|
msgTime = ts.Unix()
|
||||||
}
|
}
|
||||||
name := e.Get("data.name").Str
|
name := e.Get("data.name").Str
|
||||||
@ -464,7 +465,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
if c.IsArray() {
|
if c.IsArray() {
|
||||||
flag := false
|
flag := false
|
||||||
c.ForEach(func(_, value gjson.Result) bool {
|
c.ForEach(func(_, value gjson.Result) bool {
|
||||||
if value.Get("type").String() == "node" {
|
if value.Get("type").Str == "node" {
|
||||||
flag = true
|
flag = true
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -520,6 +521,10 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if m.IsArray() {
|
if m.IsArray() {
|
||||||
|
m.ForEach(func(_, v gjson.Result) bool {
|
||||||
|
sendNodes = append(sendNodes, convert(v)...)
|
||||||
|
return true
|
||||||
|
})
|
||||||
for _, item := range m.Array() {
|
for _, item := range m.Array() {
|
||||||
sendNodes = append(sendNodes, convert(item)...)
|
sendNodes = append(sendNodes, convert(item)...)
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
|||||||
r = append(r, MSG{
|
r = append(r, MSG{
|
||||||
"type": "reply",
|
"type": "reply",
|
||||||
"data": map[string]string{
|
"data": map[string]string{
|
||||||
"id": fmt.Sprint(toGlobalID(rid, replyElem.ReplySeq)),
|
"id": strconv.FormatInt(int64(toGlobalID(rid, replyElem.ReplySeq)), 10),
|
||||||
"seq": strconv.FormatInt(int64(replyElem.ReplySeq), 10),
|
"seq": strconv.FormatInt(int64(replyElem.ReplySeq), 10),
|
||||||
"qq": strconv.FormatInt(replyElem.Sender, 10),
|
"qq": strconv.FormatInt(replyElem.Sender, 10),
|
||||||
"time": strconv.FormatInt(int64(replyElem.Time), 10),
|
"time": strconv.FormatInt(int64(replyElem.Time), 10),
|
||||||
@ -141,7 +141,7 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
|||||||
} else {
|
} else {
|
||||||
r = append(r, MSG{
|
r = append(r, MSG{
|
||||||
"type": "reply",
|
"type": "reply",
|
||||||
"data": map[string]string{"id": fmt.Sprint(toGlobalID(rid, replyElem.ReplySeq))},
|
"data": map[string]string{"id": strconv.FormatInt(int64(toGlobalID(rid, replyElem.ReplySeq)), 10)},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ func ToArrayMessage(e []message.IMessageElement, groupID int64) (r []MSG) {
|
|||||||
case *message.FaceElement:
|
case *message.FaceElement:
|
||||||
m = MSG{
|
m = MSG{
|
||||||
"type": "face",
|
"type": "face",
|
||||||
"data": map[string]string{"id": fmt.Sprint(o.Index)},
|
"data": map[string]string{"id": strconv.FormatInt(int64(o.Index), 10)},
|
||||||
}
|
}
|
||||||
case *message.VoiceElement:
|
case *message.VoiceElement:
|
||||||
m = MSG{
|
m = MSG{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user