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":
|
case "record":
|
||||||
f := d["file"]
|
f := d["file"]
|
||||||
data, err := global.FindFile(f, d["cache"], global.VOICE_PATH)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -817,6 +820,9 @@ func (bot *CQBot) makeImageElem(d map[string]string, group bool) (message.IMessa
|
|||||||
return message.NewImage(b), nil
|
return message.NewImage(b), nil
|
||||||
}
|
}
|
||||||
rawPath := path.Join(global.IMAGE_PATH, f)
|
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") {
|
if !global.PathExists(rawPath) && global.PathExists(rawPath+".cqimg") {
|
||||||
rawPath += ".cqimg"
|
rawPath += ".cqimg"
|
||||||
}
|
}
|
||||||
|
14
global/fs.go
14
global/fs.go
@ -21,13 +21,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
IMAGE_PATH = path.Join("data", "images")
|
IMAGE_PATH = path.Join("data", "images")
|
||||||
VOICE_PATH = path.Join("data", "voices")
|
IMAGE_PATH_OLD = path.Join("data", "image")
|
||||||
VIDEO_PATH = path.Join("data", "videos")
|
VOICE_PATH = path.Join("data", "voices")
|
||||||
CACHE_PATH = path.Join("data", "cache")
|
VOICE_PATH_OLD = path.Join("data", "record")
|
||||||
|
VIDEO_PATH = path.Join("data", "videos")
|
||||||
|
CACHE_PATH = path.Join("data", "cache")
|
||||||
|
|
||||||
HEADER_AMR = []byte("#!AMR")
|
HEADER_AMR = []byte("#!AMR")
|
||||||
HEADER_SILK = []byte("\x02#!SILK_V3")
|
HEADER_SILK = []byte("\x02#!SILK_V3")
|
||||||
|
|
||||||
|
ErrSyntax = errors.New("syntax error")
|
||||||
)
|
)
|
||||||
|
|
||||||
func PathExists(path string) bool {
|
func PathExists(path string) bool {
|
||||||
@ -58,7 +62,7 @@ func IsAMRorSILK(b []byte) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FindFile(f, cache, PATH string) (data []byte, err error) {
|
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 strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
|
||||||
if cache == "" {
|
if cache == "" {
|
||||||
cache = "1"
|
cache = "1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user