Skip to content

Commit

Permalink
🐛 fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kanrichan committed Jan 31, 2021
1 parent 6348f8c commit cdf5582
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions onebot/sendMsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ func (target msgTarget) cq2xqRecord(message gjson.Result) string {
if message.Get("data.cache").Exists() {
cache = message.Get("data.cache").Bool()
}
rec := picDownloader{
rec := recDownloader{
file: file,
url: url,
suffix: ".mp3",
savePath: RecordPath,
iscache: cache,
}
return fmt.Sprintf("[pic=%s]", rec.path())
return fmt.Sprintf("[Voi=%s]", rec.path())
}

func (target msgTarget) cq2xqVideo(message gjson.Result) string {
Expand Down
19 changes: 15 additions & 4 deletions onebot/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,48 @@ func TEST(s string, v ...interface{}) {
}
}

// PathExecute 返回当前运行目录
func PathExecute() string {
dir, err := os.Getwd()
if err != nil {
ERROR("判断当前运行路径失败")
panic(err)
}
return dir + "/"
}

// CreatePath 生成路径或文件所对应的目录
func CreatePath(path string) {
length := len(path)
switch {
case path[length-1:] != "/":
case path[length:] != "/":
path = path[:strings.LastIndex(path, "/")]
case path[length-1:] != "\\":
case path[length:] != "\\":
path = path[:strings.LastIndex(path, "\\")]
default:
//
}
if !PathExists(path) {
err := os.MkdirAll(path, 0644)
if err != nil {
ERROR("生成应用目录失败")
panic(err)
}
}
}

// PathExists 判断路径或文件是否存在
func PathExists(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
}

// FileSize 获取文件大小
func FileSize(file string) int64 {
if fi, err := os.Stat(file); err == nil {
return fi.Size()
}
return 0
}

func ReadAllText(path string) string {
b, err := ioutil.ReadFile(path)
if err != nil {
Expand Down

0 comments on commit cdf5582

Please sign in to comment.