diff --git a/go.mod b/go.mod index e45574a18c..adc326b18e 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/FloatTech/sqlite v1.6.3 github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 github.com/FloatTech/zbpctrl v1.6.2-0.20240904160347-1317e11a15bb - github.com/FloatTech/zbputils v1.7.2-0.20240911161040-1d89a7b10ff8 + github.com/FloatTech/zbputils v1.7.2-0.20241013175349-67b3df244b08 github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 github.com/antchfx/htmlquery v1.3.3 diff --git a/go.sum b/go.sum index c1d648a653..1a0d88d01f 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= github.com/FloatTech/zbpctrl v1.6.2-0.20240904160347-1317e11a15bb h1:sGqwCiMDyUD/znWEVVRVxbd6Kg1KLgGnnIuq5bCUWaQ= github.com/FloatTech/zbpctrl v1.6.2-0.20240904160347-1317e11a15bb/go.mod h1:I+MetM++1sJhNPg3zww1aw04BicYsNohvHC4Jh52XSo= -github.com/FloatTech/zbputils v1.7.2-0.20240911161040-1d89a7b10ff8 h1:XlOrX7WJqIQVBziB+ZXXzp/OG0YQICO5IC6T9s4iohE= -github.com/FloatTech/zbputils v1.7.2-0.20240911161040-1d89a7b10ff8/go.mod h1:2ZS6vZHn/imRIOhlDytd/FPVdBIY5KYdTPTIwBJU9Js= +github.com/FloatTech/zbputils v1.7.2-0.20241013175349-67b3df244b08 h1:fwVPkvJ5dR0/GisRomaDHEJ5whQBu6dSLQJpAP1gbwA= +github.com/FloatTech/zbputils v1.7.2-0.20241013175349-67b3df244b08/go.mod h1:J/uDSgIGr8exK1B49XebRKAKphgg/Gpfh1bpjb6t6GY= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU= github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w= diff --git a/plugin/fortune/fortune.go b/plugin/fortune/fortune.go index 705f852d70..17bae08f07 100644 --- a/plugin/fortune/fortune.go +++ b/plugin/fortune/fortune.go @@ -146,7 +146,7 @@ func init() { digest := md5.Sum(helper.StringToBytes(zipfile + strconv.Itoa(index) + title + text)) cachefile := cache + hex.EncodeToString(digest[:]) - err = pool.SendImageFromPool(cachefile, cachefile, func() error { + err = pool.SendImageFromPool(cachefile, func(cachefile string) error { f, err := os.Create(cachefile) if err != nil { return err @@ -154,7 +154,7 @@ func init() { _, err = draw(background, fontdata, title, text, f) _ = f.Close() return err - }, ctxext.Send(ctx), ctxext.GetMessage(ctx)) + }, ctxext.Send(ctx)) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return diff --git a/plugin/lolicon/lolicon.go b/plugin/lolicon/lolicon.go index 25f5eb3465..040f9d9659 100644 --- a/plugin/lolicon/lolicon.go +++ b/plugin/lolicon/lolicon.go @@ -18,7 +18,6 @@ import ( ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" - imagepool "github.com/FloatTech/zbputils/img/pool" ) const ( @@ -68,18 +67,7 @@ func init() { ctx.SendChain(message.Text("ERROR: ", err)) continue } - name := imageurl[strings.LastIndex(imageurl, "/")+1 : len(imageurl)-4] - m, err := imagepool.GetImage(name) - if err != nil { - m.SetFile(imageurl) - _, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) - process.SleepAbout1sTo2s() - } - if err == nil { - queue <- m.String() - } else { - queue <- imageurl - } + queue <- imageurl } }() select { diff --git a/plugin/saucenao/searcher.go b/plugin/saucenao/searcher.go index 9afb04bad4..4c129bcc67 100644 --- a/plugin/saucenao/searcher.go +++ b/plugin/saucenao/searcher.go @@ -22,7 +22,6 @@ import ( ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" - "github.com/FloatTech/zbputils/img/pool" ) const ( @@ -73,20 +72,10 @@ func init() { // 插件主体 for i := range illust.ImageUrls { f := file.BOTPATH + "/" + illust.Path(i) n := name + "_p" + strconv.Itoa(i) - var m *pool.Image if file.IsNotExist(f) { - m, err = pool.GetImage(n) - if err == nil { - imgs = append(imgs, message.Image(m.String())) - continue - } logrus.Debugln("[saucenao]开始下载", n) logrus.Debugln("[saucenao]urls:", illust.ImageUrls) err1 := illust.DownloadToCache(i) - if err1 == nil { - m.SetFile(f) - _, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) - } if err1 != nil { logrus.Debugln("[saucenao]下载err:", err1) } diff --git a/plugin/setutime/setu_geter.go b/plugin/setutime/setu_geter.go index 1e8eeeeb65..fbd261b869 100644 --- a/plugin/setutime/setu_geter.go +++ b/plugin/setutime/setu_geter.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "strconv" - "strings" "sync" "time" @@ -158,28 +157,16 @@ func (p *imgpool) push(ctx *zero.Ctx, imgtype string, illust *pixiv.Illust) { if len(illust.ImageUrls) == 0 { return } - u := illust.ImageUrls[0] - n := u[strings.LastIndex(u, "/")+1 : len(u)-4] - m, err := imagepool.GetImage(n) var msg message.MessageSegment f := fileutil.BOTPATH + "/" + illust.Path(0) - if err != nil { - if fileutil.IsNotExist(f) { - // 下载图片 - if err := illust.DownloadToCache(0); err != nil { - ctx.SendChain(message.Text("ERROR: ", err)) - return - } - } - m.SetFile(f) - _, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) - msg = message.Image("file:///" + f) - } else { - msg = message.Image(m.String()) - if ctxext.SendToSelf(ctx)(msg) == 0 { - msg = msg.Add("cache", "0") + if fileutil.IsNotExist(f) { + // 下载图片 + if err := illust.DownloadToCache(0); err != nil { + ctx.SendChain(message.Text("ERROR: ", err)) + return } } + msg = message.Image("file:///" + f) p.poolmu.Lock() p.pool[imgtype] = append(p.pool[imgtype], &msg) p.poolmu.Unlock() @@ -229,9 +216,9 @@ func (p *imgpool) add(ctx *zero.Ctx, imgtype string, id int64) error { if len(illust.ImageUrls) == 0 { return errors.New("nil image url") } - err = imagepool.SendImageFromPool(strconv.FormatInt(illust.Pid, 10)+"_p0", illust.Path(0), func() error { + err = imagepool.SendImageFromPool(illust.Path(0), func(string) error { return illust.DownloadToCache(0) - }, ctxext.Send(ctx), ctxext.GetMessage(ctx)) + }, ctxext.Send(ctx)) if err != nil { return err } diff --git a/plugin/tarot/tarot.go b/plugin/tarot/tarot.go index 442313b817..45cc944364 100644 --- a/plugin/tarot/tarot.go +++ b/plugin/tarot/tarot.go @@ -148,18 +148,18 @@ func init() { imgname = name } imgpath := cache + "/" + imgname + ".png" - err := pool.SendImageFromPool("pool"+imgname, imgpath, func() error { + 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(imgpath) + f, err := os.Create(pth) if err != nil { return err } defer f.Close() return os.WriteFile(f.Name(), data, 0755) - }, ctxext.Send(ctx), ctxext.GetMessage(ctx)) + }, ctxext.Send(ctx)) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -190,9 +190,9 @@ func init() { var imgmsg message.MessageSegment var err error if p == 1 { - imgmsg, err = poolimg(ctx, imgurl, reverse[p][:len(reverse[p])-1]+name, cache) + imgmsg, err = poolimg(imgurl, reverse[p][:len(reverse[p])-1]+name, cache) } else { - imgmsg, err = poolimg(ctx, imgurl, name, cache) + imgmsg, err = poolimg(imgurl, name, cache) } if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) @@ -213,7 +213,7 @@ func init() { if ok { imgurl := bed + info.ImgURL var tarotmsg message.Message - imgmsg, err := poolimg(ctx, imgurl, match, cache) + imgmsg, err := poolimg(imgurl, match, cache) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -284,9 +284,9 @@ func init() { var imgmsg message.MessageSegment var err error if p == 1 { - imgmsg, err = poolimg(ctx, imgurl, reverse[p][:len(reverse[p])-1]+name, cache) + imgmsg, err = poolimg(imgurl, reverse[p][:len(reverse[p])-1]+name, cache) } else { - imgmsg, err = poolimg(ctx, imgurl, name, cache) + imgmsg, err = poolimg(imgurl, name, cache) } if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) @@ -319,17 +319,9 @@ func init() { }) } -func poolimg(ctx *zero.Ctx, imgurl, imgname, cache string) (msg message.MessageSegment, err error) { +func poolimg(imgurl, imgname, cache string) (msg message.MessageSegment, err error) { imgfile := cache + "/" + imgname + ".png" aimgfile := file.BOTPATH + "/" + imgfile - m, err := pool.GetImage("pool" + imgname) - if err == nil { - msg = message.Image(m.String()) - if ctxext.SendToSelf(ctx)(msg) == 0 { - msg = msg.Add("cache", "0") - } - return - } if file.IsNotExist(aimgfile) { var data []byte data, err = web.RequestDataWith(web.NewTLS12Client(), imgurl, "GET", "gitcode.net", web.RandUA(), nil) @@ -347,8 +339,6 @@ func poolimg(ctx *zero.Ctx, imgurl, imgname, cache string) (msg message.MessageS return } } - m.SetFile(aimgfile) - _, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) msg = message.Image("file:///" + aimgfile) return }