From 50eee15a67f9ea34e42062cf075fcb05f17a5602 Mon Sep 17 00:00:00 2001 From: Arnie97 Date: Thu, 13 Aug 2020 20:53:42 +0800 Subject: [PATCH] remove os.ModePerm --- coolq/bot.go | 2 +- coolq/event.go | 7 +++---- global/fs.go | 2 +- main.go | 10 +++++----- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/coolq/bot.go b/coolq/bot.go index e7649b3..926a3cf 100644 --- a/coolq/bot.go +++ b/coolq/bot.go @@ -191,7 +191,7 @@ func (bot *CQBot) dispatchEventMessage(m MSG) { fn(m) end := time.Now() if end.Sub(start) > time.Second*5 { - log.Debugf("警告: 事件处理耗时超过 5 秒 (%v秒), 请检查应用是否有堵塞.", end.Sub(start)/time.Second) + log.Debugf("警告: 事件处理耗时超过 5 秒 (%v), 请检查应用是否有堵塞.", end.Sub(start)) } }() } diff --git a/coolq/event.go b/coolq/event.go index f1aa697..142e096 100644 --- a/coolq/event.go +++ b/coolq/event.go @@ -8,7 +8,6 @@ import ( "github.com/Mrs4s/go-cqhttp/global" log "github.com/sirupsen/logrus" "io/ioutil" - "os" "path" "strconv" "strings" @@ -374,7 +373,7 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) { w.WriteUInt32(uint32(i.Size)) w.WriteString(i.Filename) w.WriteString(i.Url) - }), os.ModePerm) + }), 0644) } i.Filename = filename case *message.VoiceElement: @@ -386,7 +385,7 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) { log.Warnf("语音文件 %v 下载失败: %v", i.Name, err) continue } - _ = ioutil.WriteFile(path.Join(global.VOICE_PATH, i.Name), b, os.ModePerm) + _ = ioutil.WriteFile(path.Join(global.VOICE_PATH, i.Name), b, 0644) } case *message.ShortVideoElement: filename := hex.EncodeToString(i.Md5) + ".video" @@ -396,7 +395,7 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) { w.WriteUInt32(uint32(i.Size)) w.WriteString(i.Name) w.Write(i.Uuid) - }), os.ModePerm) + }), 0644) } i.Name = filename i.Url = bot.Client.GetShortVideoUrl(i.Uuid, i.Md5) diff --git a/global/fs.go b/global/fs.go index 952ee57..ec19a6f 100644 --- a/global/fs.go +++ b/global/fs.go @@ -27,7 +27,7 @@ func ReadAllText(path string) string { } func WriteAllText(path, text string) { - _ = ioutil.WriteFile(path, []byte(text), 0777) + _ = ioutil.WriteFile(path, []byte(text), 0644) } func Check(err error) { diff --git a/main.go b/main.go index 6eee6cf..70170fe 100644 --- a/main.go +++ b/main.go @@ -37,17 +37,17 @@ func init() { log.SetOutput(io.MultiWriter(os.Stderr, w)) } if !global.PathExists(global.IMAGE_PATH) { - if err := os.MkdirAll(global.IMAGE_PATH, os.ModePerm); err != nil { + if err := os.MkdirAll(global.IMAGE_PATH, 0755); err != nil { log.Fatalf("创建图片缓存文件夹失败: %v", err) } } if !global.PathExists(global.VOICE_PATH) { - if err := os.MkdirAll(global.VOICE_PATH, os.ModePerm); err != nil { + if err := os.MkdirAll(global.VOICE_PATH, 0755); err != nil { log.Fatalf("创建语音缓存文件夹失败: %v", err) } } if !global.PathExists(global.VIDEO_PATH) { - if err := os.MkdirAll(global.VIDEO_PATH, os.ModePerm); err != nil { + if err := os.MkdirAll(global.VIDEO_PATH, 0755); err != nil { log.Fatalf("创建视频缓存文件夹失败: %v", err) } } @@ -135,7 +135,7 @@ func main() { if !global.PathExists("device.json") { log.Warn("虚拟设备信息不存在, 将自动生成随机设备.") client.GenRandomDevice() - _ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), os.ModePerm) + _ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0644) log.Info("已生成设备信息并保存到 device.json 文件.") } else { log.Info("将使用 device.json 内的设备信息运行Bot.") @@ -171,7 +171,7 @@ func main() { if !rsp.Success { switch rsp.Error { case client.NeedCaptcha: - _ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, os.ModePerm) + _ = ioutil.WriteFile("captcha.jpg", rsp.CaptchaImage, 0644) img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage)) fmt.Println(asciiart.New("image", img).Art) log.Warn("请输入验证码 (captcha.jpg): (Enter 提交)")