mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 03:53:50 +08:00
fix #557 & remove some goto
This commit is contained in:
parent
b075280d2b
commit
de4de5052d
@ -354,7 +354,7 @@ func (bot *CQBot) CQSendPrivateMessage(userId int64, i interface{}, autoEscape b
|
|||||||
var str string
|
var str string
|
||||||
if m, ok := i.(gjson.Result); ok {
|
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, false)
|
||||||
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
mid := bot.SendPrivateMessage(userId, &message.SendingMessage{Elements: elem})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考输出")
|
||||||
|
@ -895,9 +895,7 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
|||||||
}
|
}
|
||||||
hasCacheFile:
|
hasCacheFile:
|
||||||
if video {
|
if video {
|
||||||
return &LocalVideoElement{
|
return &LocalVideoElement{File: cacheFile}, nil
|
||||||
File: cacheFile,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
return &LocalImageElement{File: cacheFile}, nil
|
return &LocalImageElement{File: cacheFile}, nil
|
||||||
}
|
}
|
||||||
@ -917,21 +915,36 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if video {
|
if video {
|
||||||
goto videos
|
if info.Size() == 0 || info.Size() >= maxVideoSize {
|
||||||
|
return nil, errors.New("invalid video size")
|
||||||
|
}
|
||||||
|
return &LocalVideoElement{File: fu.Path}, nil
|
||||||
}
|
}
|
||||||
if info.Size() == 0 || info.Size() >= maxImageSize {
|
if info.Size() == 0 || info.Size() >= maxImageSize {
|
||||||
return nil, errors.New("invalid image size")
|
return nil, errors.New("invalid image size")
|
||||||
}
|
}
|
||||||
return &LocalImageElement{File: fu.Path}, nil
|
return &LocalImageElement{File: fu.Path}, nil
|
||||||
videos:
|
|
||||||
if info.Size() == 0 || info.Size() >= maxVideoSize {
|
|
||||||
return nil, errors.New("invalid video size")
|
|
||||||
}
|
|
||||||
return &LocalVideoElement{File: fu.Path}, nil
|
|
||||||
}
|
}
|
||||||
rawPath := path.Join(global.IMAGE_PATH, f)
|
rawPath := path.Join(global.IMAGE_PATH, f)
|
||||||
if video {
|
if video {
|
||||||
goto video
|
rawPath = path.Join(global.VIDEO_PATH, f)
|
||||||
|
if !global.PathExists(rawPath) {
|
||||||
|
return nil, errors.New("invalid video")
|
||||||
|
}
|
||||||
|
if path.Ext(rawPath) == ".video" {
|
||||||
|
b, _ := ioutil.ReadFile(rawPath)
|
||||||
|
r := binary.NewReader(b)
|
||||||
|
return &LocalVideoElement{ShortVideoElement: message.ShortVideoElement{ // todo 检查缓存是否有效
|
||||||
|
Md5: r.ReadBytes(16),
|
||||||
|
ThumbMd5: r.ReadBytes(16),
|
||||||
|
Size: r.ReadInt32(),
|
||||||
|
ThumbSize: r.ReadInt32(),
|
||||||
|
Name: r.ReadString(),
|
||||||
|
Uuid: r.ReadAvailable(),
|
||||||
|
}}, nil
|
||||||
|
} else {
|
||||||
|
return &LocalVideoElement{File: rawPath}, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(f, "base64") {
|
if strings.HasPrefix(f, "base64") {
|
||||||
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
||||||
@ -1012,25 +1025,6 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
|||||||
return rsp, nil
|
return rsp, nil
|
||||||
}
|
}
|
||||||
return nil, errors.New("invalid image")
|
return nil, errors.New("invalid image")
|
||||||
video:
|
|
||||||
rawPath = path.Join(global.VIDEO_PATH, f)
|
|
||||||
if !global.PathExists(rawPath) {
|
|
||||||
return nil, errors.New("invalid video")
|
|
||||||
}
|
|
||||||
if path.Ext(rawPath) == ".video" {
|
|
||||||
b, _ := ioutil.ReadFile(rawPath)
|
|
||||||
r := binary.NewReader(b)
|
|
||||||
return &LocalVideoElement{ShortVideoElement: message.ShortVideoElement{ // todo 检查缓存是否有效
|
|
||||||
Md5: r.ReadBytes(16),
|
|
||||||
ThumbMd5: r.ReadBytes(16),
|
|
||||||
Size: r.ReadInt32(),
|
|
||||||
ThumbSize: r.ReadInt32(),
|
|
||||||
Name: r.ReadString(),
|
|
||||||
Uuid: r.ReadAvailable(),
|
|
||||||
}}, nil
|
|
||||||
} else {
|
|
||||||
return &LocalVideoElement{File: rawPath}, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//makeShowPic 一种xml 方式发送的群消息图片
|
//makeShowPic 一种xml 方式发送的群消息图片
|
||||||
|
Loading…
x
Reference in New Issue
Block a user