mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 11:33:48 +08:00
commit
a77977b12e
15
coolq/api.go
15
coolq/api.go
@ -198,11 +198,24 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
|||||||
name := e.Get("data.name").Str
|
name := e.Get("data.name").Str
|
||||||
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
|
||||||
|
for _, elem := range content {
|
||||||
|
if img, ok := elem.(*message.ImageElement); ok {
|
||||||
|
gm, err := bot.Client.UploadGroupImage(groupId, img.Data)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("警告:群 %v 图片上传失败: %v", groupId, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newElem = append(newElem, gm)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
newElem = append(newElem, elem)
|
||||||
|
}
|
||||||
nodes = append(nodes, &message.ForwardNode{
|
nodes = append(nodes, &message.ForwardNode{
|
||||||
SenderId: uin,
|
SenderId: uin,
|
||||||
SenderName: name,
|
SenderName: name,
|
||||||
Time: int32(ts.Unix()),
|
Time: int32(ts.Unix()),
|
||||||
Message: content,
|
Message: newElem,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -71,10 +71,13 @@ func NewQQBot(cli *client.QQClient, conf *global.JsonConfig) *CQBot {
|
|||||||
bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent)
|
bot.Client.OnUserWantJoinGroup(bot.groupJoinReqEvent)
|
||||||
go func() {
|
go func() {
|
||||||
i := conf.HeartbeatInterval
|
i := conf.HeartbeatInterval
|
||||||
if i < 1 {
|
if i < 0 {
|
||||||
log.Warn("警告: 心跳功能已关闭,若非预期,请检查配置文件。")
|
log.Warn("警告: 心跳功能已关闭,若非预期,请检查配置文件。")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if i == 0 {
|
||||||
|
i = 5
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
time.Sleep(time.Second * i)
|
time.Sleep(time.Second * i)
|
||||||
bot.dispatchEventMessage(MSG{
|
bot.dispatchEventMessage(MSG{
|
||||||
|
@ -32,6 +32,17 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
|||||||
if len(raw) != 0 {
|
if len(raw) != 0 {
|
||||||
ur = raw[0]
|
ur = raw[0]
|
||||||
}
|
}
|
||||||
|
m := &message.SendingMessage{Elements: e}
|
||||||
|
reply := m.FirstOrNil(func(e message.IMessageElement) bool {
|
||||||
|
_, ok := e.(*message.ReplyElement)
|
||||||
|
return ok
|
||||||
|
})
|
||||||
|
if reply != nil {
|
||||||
|
r = append(r, MSG{
|
||||||
|
"type": "reply",
|
||||||
|
"data": map[string]string{"id": fmt.Sprint(ToGlobalId(code, reply.(*message.ReplyElement).ReplySeq))},
|
||||||
|
})
|
||||||
|
}
|
||||||
for _, elem := range e {
|
for _, elem := range e {
|
||||||
m := MSG{}
|
m := MSG{}
|
||||||
switch o := elem.(type) {
|
switch o := elem.(type) {
|
||||||
@ -40,6 +51,11 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"data": map[string]string{"text": o.Content},
|
"data": map[string]string{"text": o.Content},
|
||||||
}
|
}
|
||||||
|
case *message.LightAppElement:
|
||||||
|
m = MSG{
|
||||||
|
"type": "text",
|
||||||
|
"data": map[string]string{"text": o.Content},
|
||||||
|
}
|
||||||
case *message.AtElement:
|
case *message.AtElement:
|
||||||
if o.Target == 0 {
|
if o.Target == 0 {
|
||||||
m = MSG{
|
m = MSG{
|
||||||
@ -52,11 +68,6 @@ func ToArrayMessage(e []message.IMessageElement, code int64, raw ...bool) (r []M
|
|||||||
"data": map[string]string{"qq": fmt.Sprint(o.Target)},
|
"data": map[string]string{"qq": fmt.Sprint(o.Target)},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case *message.ReplyElement:
|
|
||||||
m = MSG{
|
|
||||||
"type": "reply",
|
|
||||||
"data": map[string]string{"id": fmt.Sprint(ToGlobalId(code, o.ReplySeq))},
|
|
||||||
}
|
|
||||||
case *message.ForwardElement:
|
case *message.ForwardElement:
|
||||||
m = MSG{
|
m = MSG{
|
||||||
"type": "forward",
|
"type": "forward",
|
||||||
@ -155,6 +166,8 @@ func ToStringMessage(e []message.IMessageElement, code int64, raw ...bool) (r st
|
|||||||
} else {
|
} else {
|
||||||
r += fmt.Sprintf(`[CQ:image,file=%s,url=%s]`, o.Filename, CQCodeEscapeValue(o.Url))
|
r += fmt.Sprintf(`[CQ:image,file=%s,url=%s]`, o.Filename, CQCodeEscapeValue(o.Url))
|
||||||
}
|
}
|
||||||
|
case *message.LightAppElement:
|
||||||
|
r += CQCodeEscapeText(o.Content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user