From cf52997279bd5cb48d9321c1b2527a0422c0cfd6 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sat, 26 Feb 2022 23:20:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E6=B1=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 ++-- plugin/lolicon/lolicon.go | 22 +++++++++++----------- plugin/saucenao/searcher.go | 12 ++++-------- plugin/setutime/setu_geter.go | 16 +++++----------- 5 files changed, 23 insertions(+), 33 deletions(-) diff --git a/go.mod b/go.mod index 4dc9375e..12cddda1 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.17 require ( github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220224052148-f7a1379d4a00 github.com/FloatTech/sqlite v0.2.0 - github.com/FloatTech/zbputils v1.3.0-beta8.0.20220225052222-7539b0dd28e8 + github.com/FloatTech/zbputils v1.3.0-beta8.0.20220226150734-48567d2365af github.com/antchfx/htmlquery v1.2.4 github.com/corona10/goimagehash v1.0.3 github.com/fogleman/gg v1.3.0 diff --git a/go.sum b/go.sum index 1d9ce60c..39414d79 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,8 @@ github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9 github.com/FloatTech/sqlite v0.2.0 h1:x3uls/hExXH1+bbaNLkvilce6ATtWlDx4IqoxBW/bv8= github.com/FloatTech/sqlite v0.2.0/go.mod h1:xIDWIvpOFl8AXmZm0FC8t3PZjiR6ZutytCpBv2EWCns= github.com/FloatTech/zbputils v1.3.0-beta8.0.20220224051618-597cdb58b3fe/go.mod h1:Jn5LmnwqYivr64qQJBdhDwm2gRut8Hhq5gPBydV0Gvg= -github.com/FloatTech/zbputils v1.3.0-beta8.0.20220225052222-7539b0dd28e8 h1:/sfOwdrK5Q4OuDuEpu8dDkUemIqR+TsjD9kNv3OxF7M= -github.com/FloatTech/zbputils v1.3.0-beta8.0.20220225052222-7539b0dd28e8/go.mod h1:Jn5LmnwqYivr64qQJBdhDwm2gRut8Hhq5gPBydV0Gvg= +github.com/FloatTech/zbputils v1.3.0-beta8.0.20220226150734-48567d2365af h1:nwXPR9+RuTbjk0zh+4Sg37wWaqfQb8kGvSfPA1wsF+0= +github.com/FloatTech/zbputils v1.3.0-beta8.0.20220226150734-48567d2365af/go.mod h1:Jn5LmnwqYivr64qQJBdhDwm2gRut8Hhq5gPBydV0Gvg= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0= github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0= diff --git a/plugin/lolicon/lolicon.go b/plugin/lolicon/lolicon.go index 7fcabc7a..7fcd3a64 100644 --- a/plugin/lolicon/lolicon.go +++ b/plugin/lolicon/lolicon.go @@ -26,7 +26,7 @@ const ( ) var ( - queue = make(chan [2]string, capacity) + queue = make(chan string, capacity) ) func init() { @@ -58,28 +58,28 @@ func init() { url = strings.ReplaceAll(url, "i.pixiv.cat", "i.pixiv.re") name := url[strings.LastIndex(url, "/")+1 : len(url)-4] m, err := pool.GetImage(name) - if err != nil { + if err != nil && err != pool.ErrImgFileAsync { m.SetFile(url) _, err = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) process.SleepAbout1sTo2s() } if err == nil { - queue <- [2]string{name, m.String()} + queue <- m.String() } else { - queue <- [2]string{name, url} + queue <- url } } }() select { case <-time.After(time.Minute): ctx.SendChain(message.Text("ERROR: 等待填充,请稍后再试......")) - case o := <-queue: - name := o[0] - url := o[1] - err := pool.SendRemoteImageFromPool(name, url, ctxext.Send(ctx), ctxext.GetMessage(ctx)) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return + case img := <-queue: + id := ctx.SendChain(message.Image(img)) + if id.ID() == 0 { + id = ctx.SendChain(message.Image(img).Add("cache", "0")) + if id.ID() == 0 { + ctx.SendChain(message.Text("ERROR:图片发送失败,可能被风控了~")) + } } } }) diff --git a/plugin/saucenao/searcher.go b/plugin/saucenao/searcher.go index 6def900c..43d8d52a 100644 --- a/plugin/saucenao/searcher.go +++ b/plugin/saucenao/searcher.go @@ -49,16 +49,12 @@ func init() { // 插件主体 if file.IsNotExist(f) { m, err = pool.GetImage(n) if err == nil { - err = file.DownloadTo(m.String(), f, true) - if err != nil { - ctx.SendChain(message.Text("ERROR: ", err)) - return - } - break + imgs = append(imgs, message.Image(m.String())) + continue } logrus.Debugln("[sausenao]开始下载", n) - err = illust.DownloadToCache(i) - if err == nil { + err1 := illust.DownloadToCache(i) + if err != pool.ErrImgFileAsync && err1 == nil { m.SetFile(f) _, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) } diff --git a/plugin/setutime/setu_geter.go b/plugin/setutime/setu_geter.go index 9876bea3..9ace5186 100644 --- a/plugin/setutime/setu_geter.go +++ b/plugin/setutime/setu_geter.go @@ -159,25 +159,19 @@ func (p *imgpool) push(ctx *zero.Ctx, imgtype string, illust *pixiv.Illust) { f := fileutil.BOTPATH + "/" + illust.Path(0) if err != nil { // 下载图片 - if err = illust.DownloadToCache(0); err != nil { + 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)) + if err != imagepool.ErrImgFileAsync { + 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 ctxext.SendToSelf(ctx)(msg) == 0 { - err = fileutil.DownloadTo(m.String(), f, true) - if err != nil { - ctx.SendChain(message.Text("ERROR: ", err)) - return - } - msg = message.Image("file:///" + f) - } } } p.poolmu.Lock()