diff --git a/coolq/cqcode.go b/coolq/cqcode.go index 2426922..50fbd54 100644 --- a/coolq/cqcode.go +++ b/coolq/cqcode.go @@ -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" } diff --git a/global/fs.go b/global/fs.go index 8aad7fb..43d8c3c 100644 --- a/global/fs.go +++ b/global/fs.go @@ -21,13 +21,17 @@ import ( ) var ( - IMAGE_PATH = path.Join("data", "images") - VOICE_PATH = path.Join("data", "voices") - VIDEO_PATH = path.Join("data", "videos") - CACHE_PATH = path.Join("data", "cache") + 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"