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:
parent
81d2ad3e79
commit
06fccbd9ef
89
coolq/api.go
89
coolq/api.go
@ -96,28 +96,36 @@ 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
|
||||
if str == "" {
|
||||
return Failed(100)
|
||||
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})
|
||||
}
|
||||
elem := bot.ConvertStringMessage(str, 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 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})
|
||||
if s, ok := i.(string); ok {
|
||||
str = s
|
||||
}
|
||||
return Failed(100)
|
||||
if str == "" {
|
||||
return Failed(100)
|
||||
}
|
||||
elem := bot.ConvertStringMessage(str, true)
|
||||
mid := bot.SendGroupMessage(groupId, &message.SendingMessage{Elements: elem})
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
}
|
||||
return OK(MSG{"message_id": mid})
|
||||
}
|
||||
|
||||
func (bot *CQBot) CQSendGroupForwardMessage(groupId int64, m gjson.Result) MSG {
|
||||
@ -191,25 +199,36 @@ 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)
|
||||
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})
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
}
|
||||
return OK(MSG{"message_id": mid})
|
||||
}
|
||||
return OK(MSG{"message_id": mid})
|
||||
str = func() string {
|
||||
if m.Str != "" {
|
||||
return m.Str
|
||||
}
|
||||
return m.Raw
|
||||
}()
|
||||
}
|
||||
if m.Type == gjson.JSON {
|
||||
elem := bot.ConvertObjectMessage(m, true)
|
||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||
if mid == -1 {
|
||||
return Failed(100)
|
||||
}
|
||||
return OK(MSG{"message_id": mid})
|
||||
if s, ok := i.(string); ok {
|
||||
str = s
|
||||
}
|
||||
return Failed(100)
|
||||
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
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user