1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00
This commit is contained in:
Mrs4s 2020-08-14 08:28:55 +08:00
commit b545e05a9d
4 changed files with 10 additions and 11 deletions

View File

@ -191,7 +191,7 @@ func (bot *CQBot) dispatchEventMessage(m MSG) {
fn(m) fn(m)
end := time.Now() end := time.Now()
if end.Sub(start) > time.Second*5 { if end.Sub(start) > time.Second*5 {
log.Debugf("警告: 事件处理耗时超过 5 秒 (%v), 请检查应用是否有堵塞.", end.Sub(start)/time.Second) log.Debugf("警告: 事件处理耗时超过 5 秒 (%v), 请检查应用是否有堵塞.", end.Sub(start))
} }
}() }()
} }

View File

@ -8,7 +8,6 @@ import (
"github.com/Mrs4s/go-cqhttp/global" "github.com/Mrs4s/go-cqhttp/global"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"os"
"path" "path"
"strconv" "strconv"
"strings" "strings"
@ -374,7 +373,7 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
w.WriteUInt32(uint32(i.Size)) w.WriteUInt32(uint32(i.Size))
w.WriteString(i.Filename) w.WriteString(i.Filename)
w.WriteString(i.Url) w.WriteString(i.Url)
}), os.ModePerm) }), 0644)
} }
i.Filename = filename i.Filename = filename
case *message.VoiceElement: case *message.VoiceElement:
@ -386,7 +385,7 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
log.Warnf("语音文件 %v 下载失败: %v", i.Name, err) log.Warnf("语音文件 %v 下载失败: %v", i.Name, err)
continue 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: case *message.ShortVideoElement:
filename := hex.EncodeToString(i.Md5) + ".video" filename := hex.EncodeToString(i.Md5) + ".video"
@ -396,7 +395,7 @@ func (bot *CQBot) checkMedia(e []message.IMessageElement) {
w.WriteUInt32(uint32(i.Size)) w.WriteUInt32(uint32(i.Size))
w.WriteString(i.Name) w.WriteString(i.Name)
w.Write(i.Uuid) w.Write(i.Uuid)
}), os.ModePerm) }), 0644)
} }
i.Name = filename i.Name = filename
i.Url = bot.Client.GetShortVideoUrl(i.Uuid, i.Md5) i.Url = bot.Client.GetShortVideoUrl(i.Uuid, i.Md5)

View File

@ -27,7 +27,7 @@ func ReadAllText(path string) string {
} }
func WriteAllText(path, text string) { func WriteAllText(path, text string) {
_ = ioutil.WriteFile(path, []byte(text), 0777) _ = ioutil.WriteFile(path, []byte(text), 0644)
} }
func Check(err error) { func Check(err error) {

10
main.go
View File

@ -37,17 +37,17 @@ func init() {
log.SetOutput(io.MultiWriter(os.Stderr, w)) log.SetOutput(io.MultiWriter(os.Stderr, w))
} }
if !global.PathExists(global.IMAGE_PATH) { 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) log.Fatalf("创建图片缓存文件夹失败: %v", err)
} }
} }
if !global.PathExists(global.VOICE_PATH) { 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) log.Fatalf("创建语音缓存文件夹失败: %v", err)
} }
} }
if !global.PathExists(global.VIDEO_PATH) { 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) log.Fatalf("创建视频缓存文件夹失败: %v", err)
} }
} }
@ -135,7 +135,7 @@ func main() {
if !global.PathExists("device.json") { if !global.PathExists("device.json") {
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.") log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
client.GenRandomDevice() client.GenRandomDevice()
_ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), os.ModePerm) _ = ioutil.WriteFile("device.json", client.SystemDeviceInfo.ToJson(), 0644)
log.Info("已生成设备信息并保存到 device.json 文件.") log.Info("已生成设备信息并保存到 device.json 文件.")
} else { } else {
log.Info("将使用 device.json 内的设备信息运行Bot.") log.Info("将使用 device.json 内的设备信息运行Bot.")
@ -171,7 +171,7 @@ func main() {
if !rsp.Success { if !rsp.Success {
switch rsp.Error { switch rsp.Error {
case client.NeedCaptcha: 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)) img, _, _ := image.Decode(bytes.NewReader(rsp.CaptchaImage))
fmt.Println(asciiart.New("image", img).Art) fmt.Println(asciiart.New("image", img).Art)
log.Warn("请输入验证码 (captcha.jpg) (Enter 提交)") log.Warn("请输入验证码 (captcha.jpg) (Enter 提交)")