1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 11:33:48 +08:00
This commit is contained in:
wdvxdr 2020-09-22 11:39:14 +08:00
parent d2d408a8e9
commit cd09a68e0d

View File

@ -338,42 +338,10 @@ func (bot *CQBot) ToElement(t string, d map[string]string, group bool) (message.
return nil, errors.New("private voice unsupported now") return nil, errors.New("private voice unsupported now")
} }
f := d["file"] f := d["file"]
var data []byte data, err := global.FindFile(f, d["cache"], global.VOICE_PATH)
if strings.HasPrefix(f, "http") || strings.HasPrefix(f, "https") {
b, err := global.GetBytes(f)
if err != nil { if err != nil {
return nil, err return nil, err
} }
data = b
}
if strings.HasPrefix(f, "base64") {
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
if err != nil {
return nil, err
}
data = b
}
if strings.HasPrefix(f, "file") {
fu, err := url.Parse(f)
if err != nil {
return nil, err
}
if strings.HasPrefix(fu.Path, "/") && runtime.GOOS == `windows` {
fu.Path = fu.Path[1:]
}
b, err := ioutil.ReadFile(fu.Path)
if err != nil {
return nil, err
}
data = b
}
if global.PathExists(path.Join(global.VOICE_PATH, f)) {
b, err := ioutil.ReadFile(path.Join(global.VOICE_PATH, f))
if err != nil {
return nil, err
}
data = b
}
if !global.IsAMRorSILK(data) { if !global.IsAMRorSILK(data) {
return nil, errors.New("unsupported voice file format (please use AMR file for now)") return nil, errors.New("unsupported voice file format (please use AMR file for now)")
} }