diff --git a/plugin_diana/data/text.go b/plugin_diana/data/text.go index 14d8e68a..838c7714 100644 --- a/plugin_diana/data/text.go +++ b/plugin_diana/data/text.go @@ -65,7 +65,7 @@ func LoadText() error { log.Printf("[Diana]从镜像下载小作文%d字节...", resp.ContentLength) data, err := io.ReadAll(resp.Body) if err == nil && len(data) > 0 { - f.Write(data) + _, _ = f.Write(data) return compo.Unmarshal(data) } return err diff --git a/plugin_hs/run.go b/plugin_hs/run.go index eedc3735..cbbc7064 100644 --- a/plugin_hs/run.go +++ b/plugin_hs/run.go @@ -1,3 +1,4 @@ +// Package hs 炉石 package hs import ( @@ -5,6 +6,7 @@ import ( "os" "strconv" "strings" + "time" "github.com/imroc/req" "github.com/tidwall/gjson" @@ -12,12 +14,19 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" ) +const cachedir = "data/hs/" + var header = req.Header{ "user-agent": `Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36`, "referer": `https://hs.fbigame.com`, } func init() { + os.RemoveAll(cachedir) + err := os.MkdirAll(cachedir, 0755) + if err != nil { + panic(err) + } zero.OnRegex(`^搜卡(.+)$`). SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) { List := ctx.State["regex_matched"].([]string)[1] @@ -26,32 +35,38 @@ func init() { gjson.Get(g, `list.0.CardID`).String()+ `.png?auth_key=`+ gjson.Get(g, `list.0.auth_key`).String(), header) - im.ToFile("data/image/1.png") - file, _ := os.Open("data/image/1.png") - sg, _ := req.Post("https://pic.sogou.com/pic/upload_pic.jsp", req.FileUpload{ - File: file, - FieldName: "image", // FieldName 是表单字段名 - FileName: "avatar.png", // Filename 是要上传的文件的名称,我们使用它来猜测mimetype,并将其上传到服务器上 - }) - var tx string - t := int(gjson.Get(g, `list.#`).Int()) - if t == 0 { - ctx.SendChain(message.Text("查询为空!")) - return + cachefile := cachedir + strconv.Itoa(int(time.Now().Unix())) + err := im.ToFile(cachefile) + if err == nil { + file, err := os.Open(cachefile) + if err == nil { + defer file.Close() + sg, _ := req.Post("https://pic.sogou.com/pic/upload_pic.jsp", req.FileUpload{ + File: file, + FieldName: "image", // FieldName 是表单字段名 + FileName: "avatar.png", // Filename 是要上传的文件的名称,我们使用它来猜测mimetype,并将其上传到服务器上 + }) + var tx string + t := int(gjson.Get(g, `list.#`).Int()) + if t == 0 { + ctx.Send("查询为空!") + return + } + for i := 0; i < t && i < 10; i++ { + tx += strconv.Itoa(i+1) + ". 法力:" + + gjson.Get(g, `list.`+strconv.Itoa(i)+`.COST`).String() + + " " + + gjson.Get(g, `list.`+strconv.Itoa(i)+`.CARDNAME`).String() + + "\n" + } + ctx.SendChain( + message.Image(sg.String()), + message.Text(tx), + ) + } } - for i := 0; i < t && i < 10; i++ { - tx += strconv.Itoa(i+1) + ". 法力:" + - gjson.Get(g, `list.`+strconv.Itoa(i)+`.COST`).String() + - " " + - gjson.Get(g, `list.`+strconv.Itoa(i)+`.CARDNAME`).String() + - "\n" - } - ctx.SendChain( - message.Image(sg.String()), - message.Text(tx), - ) }) - //卡组 + // 卡组 zero.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`). SetBlock(true).SetPriority(20).Handle(func(ctx *zero.Ctx) { fmt.Print("成功") diff --git a/plugin_setutime/setu_geter.go b/plugin_setutime/setu_geter.go index 198de29f..0df53efe 100644 --- a/plugin_setutime/setu_geter.go +++ b/plugin_setutime/setu_geter.go @@ -4,7 +4,6 @@ package setutime import ( "fmt" "io" - "log" "net/http" "os" "strconv" @@ -12,11 +11,11 @@ import ( "sync" "time" + "github.com/FloatTech/AnimeAPI/pixiv" + "github.com/sirupsen/logrus" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/extension/rate" "github.com/wdvxdr1123/ZeroBot/message" - - "github.com/FloatTech/AnimeAPI/pixiv" ) // Pools 图片缓冲池 @@ -58,10 +57,13 @@ func newPools() *imgpool { if err == nil { defer resp.Body.Close() if resp.ContentLength > 0 { - log.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength) + logrus.Printf("[Setu]从镜像下载数据库%d字节...", resp.ContentLength) data, err := io.ReadAll(resp.Body) if err == nil && len(data) > 0 { - f.Write(data) + _, err = f.Write(data) + if err != nil { + logrus.Errorf("[Setu]写入数据库失败: %v", err) + } } } }