mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 11:33:48 +08:00
simplify
This commit is contained in:
parent
d2d408a8e9
commit
cd09a68e0d
@ -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)")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user