1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

clean send msg arg.

This commit is contained in:
wdvxdr 2021-07-26 18:10:36 +08:00
parent 89eaf91371
commit e5a8a406a4
No known key found for this signature in database
GPG Key ID: 703F8C071DE7A1B6
2 changed files with 24 additions and 42 deletions

View File

@ -351,8 +351,7 @@ func (bot *CQBot) CQGetWordSlices(content string) MSG {
// CQSendGroupMessage 发送群消息 // CQSendGroupMessage 发送群消息
// //
// https://git.io/Jtz1c // https://git.io/Jtz1c
func (bot *CQBot) CQSendGroupMessage(groupID int64, i interface{}, autoEscape bool) MSG { func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape bool) MSG {
var str string
group := bot.Client.FindGroup(groupID) group := bot.Client.FindGroup(groupID)
if group == nil { if group == nil {
return Failed(100, "GROUP_NOT_FOUND", "群聊不存在") return Failed(100, "GROUP_NOT_FOUND", "群聊不存在")
@ -363,33 +362,26 @@ func (bot *CQBot) CQSendGroupMessage(groupID int64, i interface{}, autoEscape bo
mem := group.FindMember(at.Target) mem := group.FindMember(at.Target)
if mem != nil { if mem != nil {
at.Display = "@" + mem.DisplayName() at.Display = "@" + mem.DisplayName()
} else {
at.Display = "@" + strconv.FormatInt(at.Target, 10)
} }
at.Display = "@" + strconv.FormatInt(at.Target, 10)
} }
} }
} }
if m, ok := i.(gjson.Result); ok {
if m.Type == gjson.JSON { if m.Type == gjson.JSON {
elem := bot.ConvertObjectMessage(m, true) elem := bot.ConvertObjectMessage(m, true)
fixAt(elem) fixAt(elem)
mid := bot.SendGroupMessage(groupID, &message.SendingMessage{Elements: elem}) mid := bot.SendGroupMessage(groupID, &message.SendingMessage{Elements: elem})
if mid == -1 { if mid == -1 {
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出") return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
}
log.Infof("发送群 %v(%v) 的消息: %v (%v)", group.Name, groupID, limitedString(ToStringMessage(elem, groupID)), mid)
return OK(MSG{"message_id": mid})
} }
str = func() string { log.Infof("发送群 %v(%v) 的消息: %v (%v)", group.Name, groupID, limitedString(ToStringMessage(elem, groupID)), mid)
if m.Str != "" { return OK(MSG{"message_id": mid})
return m.Str
}
return m.Raw
}()
} else if s, ok := i.(string); ok {
str = s
} }
str := m.String()
if str == "" { if str == "" {
log.Warnf("群消息发送失败: 信息为空. MSG: %v", i) log.Warn("群消息发送失败: 信息为空.")
return Failed(100, "EMPTY_MSG_ERROR", "消息为空") return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
} }
var elem []message.IMessageElement var elem []message.IMessageElement
@ -532,27 +524,17 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) MSG {
// CQSendPrivateMessage 发送私聊消息 // CQSendPrivateMessage 发送私聊消息
// //
// https://git.io/Jtz1l // https://git.io/Jtz1l
func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, i interface{}, autoEscape bool) MSG { func (bot *CQBot) CQSendPrivateMessage(userID int64, groupID int64, m gjson.Result, autoEscape bool) MSG {
var str string if m.Type == gjson.JSON {
if m, ok := i.(gjson.Result); ok { elem := bot.ConvertObjectMessage(m, false)
if m.Type == gjson.JSON { mid := bot.SendPrivateMessage(userID, groupID, &message.SendingMessage{Elements: elem})
elem := bot.ConvertObjectMessage(m, false) if mid == -1 {
mid := bot.SendPrivateMessage(userID, groupID, &message.SendingMessage{Elements: elem}) return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
if mid == -1 {
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
}
log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userID, userID, limitedString(m.String()), mid)
return OK(MSG{"message_id": mid})
} }
str = func() string { log.Infof("发送好友 %v(%v) 的消息: %v (%v)", userID, userID, limitedString(m.String()), mid)
if m.Str != "" { return OK(MSG{"message_id": mid})
return m.Str
}
return m.Raw
}()
} else if s, ok := i.(string); ok {
str = s
} }
str := m.String()
if str == "" { if str == "" {
return Failed(100, "EMPTY_MSG_ERROR", "消息为空") return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
} }

View File

@ -116,7 +116,7 @@ func RunLambdaClient(bot *coolq.CQBot, conf *config.LambdaServer) {
req := cli.next() req := cli.next()
if req == nil { if req == nil {
writer := lambdaResponseWriter{statusCode: 200} writer := lambdaResponseWriter{statusCode: 200}
writer.Write(nil) _, _ = writer.Write(nil)
continue continue
} }
func() { func() {