mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-07 04:23:49 +08:00
support old coolq data path. #499
This commit is contained in:
parent
474de6ad3d
commit
aa77810491
@ -573,6 +573,9 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (m interf
|
||||
case "record":
|
||||
f := d["file"]
|
||||
data, err := global.FindFile(f, d["cache"], global.VOICE_PATH)
|
||||
if err == global.ErrSyntax {
|
||||
data, err = global.FindFile(f, d["cache"], global.VOICE_PATH_OLD)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -817,6 +820,9 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
||||
return message.NewImage(b), nil
|
||||
}
|
||||
rawPath := path.Join(global.IMAGE_PATH, f)
|
||||
if !global.PathExists(rawPath) && global.PathExists(path.Join(global.IMAGE_PATH_OLD, f)) {
|
||||
rawPath = path.Join(global.IMAGE_PATH_OLD, f)
|
||||
}
|
||||
if !global.PathExists(rawPath) && global.PathExists(rawPath+".cqimg") {
|
||||
rawPath += ".cqimg"
|
||||
}
|
||||
|
@ -22,12 +22,16 @@ import (
|
||||
|
||||
var (
|
||||
IMAGE_PATH = path.Join("data", "images")
|
||||
IMAGE_PATH_OLD = path.Join("data", "image")
|
||||
VOICE_PATH = path.Join("data", "voices")
|
||||
VOICE_PATH_OLD = path.Join("data", "record")
|
||||
VIDEO_PATH = path.Join("data", "videos")
|
||||
CACHE_PATH = path.Join("data", "cache")
|
||||
|
||||
HEADER_AMR = []byte("#!AMR")
|
||||
HEADER_SILK = []byte("\x02#!SILK_V3")
|
||||
|
||||
ErrSyntax = errors.New("syntax error")
|
||||
)
|
||||
|
||||
func PathExists(path string) bool {
|
||||
@ -58,7 +62,7 @@ func IsAMRorSILK(b []byte) bool {
|
||||
}
|
||||
|
||||
func FindFile(f, cache, PATH string) (data []byte, err error) {
|
||||
data, err = nil, errors.New("syntax error")
|
||||
data, err = nil, ErrSyntax
|
||||
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
||||
if cache == "" {
|
||||
cache = "1"
|
||||
|
Loading…
x
Reference in New Issue
Block a user