From df148afe12ee7d77a1fe5c72207cb8f3a1888ad8 Mon Sep 17 00:00:00 2001 From: catboss <64726041+win-syswow64@users.noreply.github.com> Date: Sat, 4 Jan 2025 06:42:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?Update=20=E6=BB=A1=E8=B6=B3=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E9=9C=80=E8=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/tarot/tarot.go | 109 +++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index 176d13e056..08ab5565ce 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -12,19 +12,15 @@ import ( fcext "github.com/FloatTech/floatbox/ctxext" "github.com/FloatTech/floatbox/file" "github.com/FloatTech/floatbox/process" - "github.com/FloatTech/floatbox/web" ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" - "github.com/FloatTech/zbputils/img/pool" "github.com/FloatTech/zbputils/img/text" "github.com/sirupsen/logrus" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" ) -const bed = "https://gitcode.net/shudorcl/zbp-tarot/-/raw/master/" - type cardInfo struct { Description string `json:"description"` ReverseDescription string `json:"reverseDescription"` @@ -61,13 +57,42 @@ func init() { PublicDataFolder: "Tarot", }).ApplySingle(ctxext.DefaultSingle) - cache := engine.DataFolder() + "cache" - _ = os.RemoveAll(cache) - err := os.MkdirAll(cache, 0755) - if err != nil { - panic(err) + logrus.Infof("[tarot]uri: %s", engine.DataFolder()) + + MajorArcana := engine.DataFolder() + "MajorArcana" + if _, err := os.Stat(MajorArcana); os.IsNotExist(err) { + err := os.MkdirAll(MajorArcana, 0755) + if err != nil { + panic(err) + } } + MinorArcana := engine.DataFolder() + "MinorArcana" + if _, err := os.Stat(MinorArcana); os.IsNotExist(err) { + err := os.MkdirAll(MinorArcana, 0755) + if err != nil { + panic(err) + } + } + + Reverse_MajorArcana := engine.DataFolder() + "Reverse/MajorArcana" + if _, err := os.Stat(Reverse_MajorArcana); os.IsNotExist(err) { + err := os.MkdirAll(Reverse_MajorArcana, 0755) + if err != nil { + panic(err) + } + } + + Reverse_MinorArcana := engine.DataFolder() + "Reverse/MinorArcana" + if _, err := os.Stat(Reverse_MinorArcana); os.IsNotExist(err) { + err := os.MkdirAll(Reverse_MinorArcana, 0755) + if err != nil { + panic(err) + } + } + + + getTarot := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { data, err := engine.GetLazyData("tarots.json", true) if err != nil { @@ -140,30 +165,14 @@ func init() { if p == 1 { description = card.ReverseDescription } - imgurl := bed + reverse[p] + card.ImgURL - imgname := "" - if p == 1 { - imgname = reverse[p][:len(reverse[p])-1] + name - } else { - imgname = name - } - imgpath := cache + "/" + imgname + ".png" - err := pool.SendImageFromPool(imgpath, func(pth string) error { - data, err := web.RequestDataWith(web.NewTLS12Client(), imgurl, "GET", "gitcode.net", web.RandUA(), nil) - if err != nil { - return err - } - f, err := os.Create(pth) - if err != nil { - return err - } - defer f.Close() - return os.WriteFile(f.Name(), data, 0755) - }, ctxext.Send(ctx)) + imgurl := reverse[p] + card.ImgURL + _, err := engine.GetLazyData(imgurl, true) // 获取数据和错误 if err != nil { - ctx.SendChain(message.Text("ERROR: ", err)) - return + logrus.Infof("[tarot]下载数据错误: %s", err) + return } + imgpath := "/" + engine.DataFolder() + "/"+ imgurl + ctx.SendChain(message.Image("file:///" + file.BOTPATH + imgpath)) process.SleepAbout1sTo2s() ctx.SendChain(message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n其释义为: ", description)) return @@ -185,14 +194,14 @@ func init() { if p == 1 { description = card.ReverseDescription } - imgurl := bed + reverse[p] + card.ImgURL + imgurl := reverse[p] + card.ImgURL tarotmsg := message.Message{message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n")} var imgmsg message.Segment var err error if p == 1 { - imgmsg, err = poolimg(imgurl, reverse[p][:len(reverse[p])-1]+name, cache) + imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) } else { - imgmsg, err = poolimg(imgurl, name, cache) + imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) } if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) @@ -211,9 +220,9 @@ func init() { match := ctx.State["regex_matched"].([]string)[1] info, ok := infoMap[match] if ok { - imgurl := bed + info.ImgURL + imgurl := info.ImgURL var tarotmsg message.Message - imgmsg, err := poolimg(imgurl, match, cache) + imgmsg, err := poolimg(engine, imgurl, engine.DataFolder()) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -280,13 +289,13 @@ func init() { description = card.ReverseDescription } var tarotmsg message.Message - imgurl := bed + reverse[p] + card.ImgURL + imgurl := reverse[p] + card.ImgURL var imgmsg message.Segment var err error if p == 1 { - imgmsg, err = poolimg(imgurl, reverse[p][:len(reverse[p])-1]+name, cache) + imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) } else { - imgmsg, err = poolimg(imgurl, name, cache) + imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) } if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) @@ -319,26 +328,16 @@ func init() { }) } -func poolimg(imgurl, imgname, cache string) (msg message.Segment, err error) { - imgfile := cache + "/" + imgname + ".png" +func poolimg(engine *control.Engine, imgurl, cache string) (msg message.Segment, err error) { + imgfile := cache + "/" + imgurl aimgfile := file.BOTPATH + "/" + imgfile if file.IsNotExist(aimgfile) { - var data []byte - data, err = web.RequestDataWith(web.NewTLS12Client(), imgurl, "GET", "gitcode.net", web.RandUA(), nil) + _, err = engine.GetLazyData(imgurl, true) // 获取数据和错误 if err != nil { - return - } - var f *os.File - f, err = os.Create(imgfile) - if err != nil { - return - } - defer f.Close() - err = os.WriteFile(f.Name(), data, 0755) - if err != nil { - return + logrus.Infof("[tarot]下载数据错误: %s", err) + return } } msg = message.Image("file:///" + aimgfile) - return + return } From 72b4f2cbd55e93897025b286addb64e101f45d21 Mon Sep 17 00:00:00 2001 From: catboss <64726041+win-syswow64@users.noreply.github.com> Date: Sat, 4 Jan 2025 06:50:27 +0800 Subject: [PATCH 2/5] =?UTF-8?q?Update=20=E6=BB=A1=E8=B6=B3=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E9=9C=80=E8=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/tarot/tarot.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index 08ab5565ce..00022ffc3e 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -63,7 +63,7 @@ func init() { if _, err := os.Stat(MajorArcana); os.IsNotExist(err) { err := os.MkdirAll(MajorArcana, 0755) if err != nil { - panic(err) + return } } @@ -71,7 +71,7 @@ func init() { if _, err := os.Stat(MinorArcana); os.IsNotExist(err) { err := os.MkdirAll(MinorArcana, 0755) if err != nil { - panic(err) + return } } @@ -79,7 +79,7 @@ func init() { if _, err := os.Stat(Reverse_MajorArcana); os.IsNotExist(err) { err := os.MkdirAll(Reverse_MajorArcana, 0755) if err != nil { - panic(err) + return } } @@ -87,7 +87,7 @@ func init() { if _, err := os.Stat(Reverse_MinorArcana); os.IsNotExist(err) { err := os.MkdirAll(Reverse_MinorArcana, 0755) if err != nil { - panic(err) + return } } From 560ac8b5e1cdf7a93944044efe31ad3d9c085a21 Mon Sep 17 00:00:00 2001 From: catboss <64726041+win-syswow64@users.noreply.github.com> Date: Sat, 4 Jan 2025 06:58:26 +0800 Subject: [PATCH 3/5] =?UTF-8?q?Update=20=E6=BB=A1=E8=B6=B3=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E9=9C=80=E8=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/tarot/tarot.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index 00022ffc3e..7806f080c7 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -75,7 +75,7 @@ func init() { } } - Reverse_MajorArcana := engine.DataFolder() + "Reverse/MajorArcana" + ReverseMajorArcana := engine.DataFolder() + "Reverse/MajorArcana" if _, err := os.Stat(Reverse_MajorArcana); os.IsNotExist(err) { err := os.MkdirAll(Reverse_MajorArcana, 0755) if err != nil { @@ -83,7 +83,7 @@ func init() { } } - Reverse_MinorArcana := engine.DataFolder() + "Reverse/MinorArcana" + ReverseMinorArcana := engine.DataFolder() + "Reverse/MinorArcana" if _, err := os.Stat(Reverse_MinorArcana); os.IsNotExist(err) { err := os.MkdirAll(Reverse_MinorArcana, 0755) if err != nil { @@ -198,11 +198,7 @@ func init() { tarotmsg := message.Message{message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n")} var imgmsg message.Segment var err error - if p == 1 { - imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) - } else { - imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) - } + imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -292,11 +288,7 @@ func init() { imgurl := reverse[p] + card.ImgURL var imgmsg message.Segment var err error - if p == 1 { - imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) - } else { - imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) - } + imgmsg, err = poolimg(engine, imgurl, engine.DataFolder()) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return From d334c9f60d0de5e8840a07b81206a1372c7d2acc Mon Sep 17 00:00:00 2001 From: catboss <64726041+win-syswow64@users.noreply.github.com> Date: Sat, 4 Jan 2025 07:01:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?Update=20=E6=BB=A1=E8=B6=B3=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E9=9C=80=E8=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/tarot/tarot.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index 7806f080c7..6af759664c 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -76,16 +76,16 @@ func init() { } ReverseMajorArcana := engine.DataFolder() + "Reverse/MajorArcana" - if _, err := os.Stat(Reverse_MajorArcana); os.IsNotExist(err) { - err := os.MkdirAll(Reverse_MajorArcana, 0755) + if _, err := os.Stat(ReverseMajorArcana); os.IsNotExist(err) { + err := os.MkdirAll(ReverseMajorArcana, 0755) if err != nil { return } } ReverseMinorArcana := engine.DataFolder() + "Reverse/MinorArcana" - if _, err := os.Stat(Reverse_MinorArcana); os.IsNotExist(err) { - err := os.MkdirAll(Reverse_MinorArcana, 0755) + if _, err := os.Stat(ReverseMinorArcana); os.IsNotExist(err) { + err := os.MkdirAll(ReverseMinorArcana, 0755) if err != nil { return } From 38a1133a34ecd317f3a58e7e33a98346877f6952 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 3 Jan 2025 23:04:48 +0000 Subject: [PATCH 5/5] =?UTF-8?q?chore(lint):=20=E6=94=B9=E8=BF=9B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/tarot/tarot.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index 6af759664c..cdf67a1ff7 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -63,7 +63,7 @@ func init() { if _, err := os.Stat(MajorArcana); os.IsNotExist(err) { err := os.MkdirAll(MajorArcana, 0755) if err != nil { - return + return } } @@ -71,27 +71,25 @@ func init() { if _, err := os.Stat(MinorArcana); os.IsNotExist(err) { err := os.MkdirAll(MinorArcana, 0755) if err != nil { - return + return } } - + ReverseMajorArcana := engine.DataFolder() + "Reverse/MajorArcana" if _, err := os.Stat(ReverseMajorArcana); os.IsNotExist(err) { err := os.MkdirAll(ReverseMajorArcana, 0755) if err != nil { - return + return } } - + ReverseMinorArcana := engine.DataFolder() + "Reverse/MinorArcana" if _, err := os.Stat(ReverseMinorArcana); os.IsNotExist(err) { err := os.MkdirAll(ReverseMinorArcana, 0755) if err != nil { - return + return } } - - getTarot := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { data, err := engine.GetLazyData("tarots.json", true) @@ -166,12 +164,12 @@ func init() { description = card.ReverseDescription } imgurl := reverse[p] + card.ImgURL - _, err := engine.GetLazyData(imgurl, true) // 获取数据和错误 + _, err := engine.GetLazyData(imgurl, true) // 获取数据和错误 if err != nil { logrus.Infof("[tarot]下载数据错误: %s", err) - return + return } - imgpath := "/" + engine.DataFolder() + "/"+ imgurl + imgpath := "/" + engine.DataFolder() + "/" + imgurl ctx.SendChain(message.Image("file:///" + file.BOTPATH + imgpath)) process.SleepAbout1sTo2s() ctx.SendChain(message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n其释义为: ", description)) @@ -324,12 +322,12 @@ func poolimg(engine *control.Engine, imgurl, cache string) (msg message.Segment, imgfile := cache + "/" + imgurl aimgfile := file.BOTPATH + "/" + imgfile if file.IsNotExist(aimgfile) { - _, err = engine.GetLazyData(imgurl, true) // 获取数据和错误 + _, err = engine.GetLazyData(imgurl, true) // 获取数据和错误 if err != nil { logrus.Infof("[tarot]下载数据错误: %s", err) - return + return } } msg = message.Image("file:///" + aimgfile) - return + return }