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

fix http api send raw msg error.

This commit is contained in:
Mrs4s 2020-08-02 15:21:19 +08:00
parent 81d2ad3e79
commit 06fccbd9ef
3 changed files with 57 additions and 38 deletions

View File

@ -96,9 +96,27 @@ func (bot *CQBot) CQGetGroupMemberInfo(groupId, userId int64, noCache bool) MSG
}
// https://cqhttp.cc/docs/4.15/#/API?id=send_group_msg-%E5%8F%91%E9%80%81%E7%BE%A4%E6%B6%88%E6%81%AF
func (bot *CQBot) CQSendGroupMessage(groupId int64, m gjson.Result) MSG {
if m.Type == gjson.String {
str := m.Str
func (bot *CQBot) CQSendGroupMessage(groupId int64, i interface{}) MSG {
var str string
if m, ok := i.(gjson.Result); ok {
if m.Type == gjson.JSON {
elem := bot.ConvertObjectMessage(m, true)
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
if mid == -1 {
return Failed(100)
}
return OK(MSG{"message_id": mid})
}
str = func() string {
if m.Str != "" {
return m.Str
}
return m.Raw
}()
}
if s, ok := i.(string); ok {
str = s
}
if str == "" {
return Failed(100)
}
@ -109,16 +127,6 @@ func (bot *CQBot) CQSendGroupMessage(groupId int64, m gjson.Result) MSG {
}
return OK(MSG{"message_id": mid})
}
if m.Type == gjson.JSON {
elem := bot.ConvertObjectMessage(m, true)
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
if mid == -1 {
return Failed(100)
}
return OK(MSG{"message_id": mid})
}
return Failed(100)
}
func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
if m.Type != gjson.JSON {
@ -191,16 +199,9 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
}
// https://cqhttp.cc/docs/4.15/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF
func (bot *CQBot) CQSendPrivateMessage(userId int64, m gjson.Result) MSG {
if m.Type == gjson.String {
str := m.Str
elem := bot.ConvertStringMessage(str, false)
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
if mid == -1 {
return Failed(100)
}
return OK(MSG{"message_id": mid})
}
func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}) MSG {
var str string
if m, ok := i.(gjson.Result); ok {
if m.Type == gjson.JSON {
elem := bot.ConvertObjectMessage(m, true)
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
@ -209,8 +210,26 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, m gjson.Result) MSG {
}
return OK(MSG{"message_id": mid})
}
str = func() string {
if m.Str != "" {
return m.Str
}
return m.Raw
}()
}
if s, ok := i.(string); ok {
str = s
}
if str == "" {
return Failed(100)
}
elem := bot.ConvertStringMessage(str, false)
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
if mid == -1 {
return Failed(100)
}
return OK(MSG{"message_id": mid})
}
// https://cqhttp.cc/docs/4.15/#/API?id=set_group_card-%E8%AE%BE%E7%BD%AE%E7%BE%A4%E5%90%8D%E7%89%87%EF%BC%88%E7%BE%A4%E5%A4%87%E6%B3%A8%EF%BC%89
func (bot *CQBot) CQSetGroupCard(groupId, userId int64, card string) MSG {

View File

@ -93,7 +93,7 @@ func (bot *CQBot) SendGroupMessage(groupId int64, m *message.SendingMessage) int
if i, ok := elem.(*message.ImageElement); ok {
gm, err := bot.Client.UploadGroupImage(groupId, i.Data)
if err != nil {
log.Warnf("警告: 群 %v 消息图片上传失败.", groupId)
log.Warnf("警告: 群 %v 消息图片上传失败: %v", groupId, err)
continue
}
newElem = append(newElem, gm)

View File

@ -239,7 +239,7 @@ func (s *httpServer) SendPrivateMessage(c *gin.Context) {
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Parse(msg)))
return
}
c.JSON(200, s.bot.CQSendPrivateMessage(uid, gjson.Result{Type: gjson.String, Str: msg}))
c.JSON(200, s.bot.CQSendPrivateMessage(uid, msg))
}
func (s *httpServer) SendGroupMessage(c *gin.Context) {
@ -249,7 +249,7 @@ func (s *httpServer) SendGroupMessage(c *gin.Context) {
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Parse(msg)))
return
}
c.JSON(200, s.bot.CQSendGroupMessage(gid, gjson.Result{Type: gjson.String, Str: msg}))
c.JSON(200, s.bot.CQSendGroupMessage(gid, msg))
}
func (s *httpServer) SendGroupForwardMessage(c *gin.Context) {