From aa1f82d46ff5375471fc7863dd714e3383ed11fa Mon Sep 17 00:00:00 2001 From: fumiama Date: Mon, 24 Jan 2022 14:01:30 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=A2=9E=E5=8A=A0=20pixiv=20?= =?UTF-8?q?=E5=A4=9A=E7=BA=BF=E7=A8=8B=E4=B8=8B=E8=BD=BD=E4=B8=8E=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=BC=93=E5=AD=98?= 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 | 3 +-- plugin_saucenao/searcher.go | 47 +++++++++++++++++++++-------------- plugin_setutime/setu_geter.go | 2 +- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index a29a9874..665f2db8 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/FloatTech/ZeroBot-Plugin go 1.17 require ( - github.com/FloatTech/AnimeAPI v1.2.4-beta19 + github.com/FloatTech/AnimeAPI v1.2.4-beta21 github.com/FloatTech/zbputils v1.2.4-beta7 github.com/antchfx/htmlquery v1.2.4 github.com/corona10/goimagehash v1.0.3 diff --git a/go.sum b/go.sum index bfa3ad91..510837b3 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/FloatTech/AnimeAPI v1.2.4-beta19 h1:Yz19ppAdx9cZZbrJBEPqon6RNHY1TuCQl7SALFIW1lQ= -github.com/FloatTech/AnimeAPI v1.2.4-beta19/go.mod h1:rhYvzqLH2YTKBOk7DfJsXsdZlnxhpBP3HvctwqlLykM= +github.com/FloatTech/AnimeAPI v1.2.4-beta21 h1:C0CoX6mrEAOEWl1sLUhGBTasvwnwMkEMEGcDI4fps1I= +github.com/FloatTech/AnimeAPI v1.2.4-beta21/go.mod h1:rhYvzqLH2YTKBOk7DfJsXsdZlnxhpBP3HvctwqlLykM= github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ= github.com/FloatTech/zbputils v1.2.4-beta7 h1:DofQTSVEBU1BQnLb4GahNZqsqVqoj4Lu5GDJa2rJW9o= github.com/FloatTech/zbputils v1.2.4-beta7/go.mod h1:mPVpKu2scTyBiitNmzCrxGc9aIKs9rwfb6iqz/+heck= diff --git a/plugin_lolicon/lolicon.go b/plugin_lolicon/lolicon.go index 2230f330..ff83a09b 100644 --- a/plugin_lolicon/lolicon.go +++ b/plugin_lolicon/lolicon.go @@ -54,8 +54,7 @@ func init() { } url := json.Get("data.0.urls.original").Str url = strings.ReplaceAll(url, "i.pixiv.cat", "i.pixiv.re") - id := json.Get("data.0.pid").String() - m, err := imgpool.NewImage(ctx, id, url) + m, err := imgpool.NewImage(ctx, url[:strings.LastIndex(url, "/")+1], url) if err == nil { queue <- m.String() } else { diff --git a/plugin_saucenao/searcher.go b/plugin_saucenao/searcher.go index 326109d0..df89b0d4 100644 --- a/plugin_saucenao/searcher.go +++ b/plugin_saucenao/searcher.go @@ -7,6 +7,7 @@ import ( "strconv" "github.com/FloatTech/AnimeAPI/ascii2d" + "github.com/FloatTech/AnimeAPI/imgpool" "github.com/FloatTech/AnimeAPI/pixiv" "github.com/FloatTech/AnimeAPI/saucenao" "github.com/sirupsen/logrus" @@ -49,22 +50,32 @@ func init() { // 插件主体 } if illust.Pid > 0 { name := strconv.FormatInt(illust.Pid, 10) - filepath := datapath + name - switch { - case file.IsExist(filepath + ".jpg"): - filepath = "file:///" + filepath + ".jpg" - case file.IsExist(filepath + ".png"): - filepath = "file:///" + filepath + ".png" - case file.IsExist(filepath + ".gif"): - filepath = "file:///" + filepath + ".gif" - default: - filepath = "" - } - if filepath == "" { - logrus.Debug("[sausenao]开始下载", name) - filepath, err = pixiv.Download(illust.ImageUrls, datapath, name) - if err == nil { - filepath = "file:///" + filepath + var imgs message.Message + for i, u := range illust.ImageUrls { + n := name + "_p" + strconv.Itoa(i) + filepath := datapath + n + f := "" + switch { + case file.IsExist(filepath + ".jpg"): + f = filepath + ".jpg" + case file.IsExist(filepath + ".png"): + f = filepath + ".png" + case file.IsExist(filepath + ".gif"): + f = filepath + ".gif" + default: + logrus.Debugln("[sausenao]开始下载", n) + filepath, err = pixiv.Download(u, datapath, n) + if err == nil { + f = filepath + } + } + if f != "" { + m, err := imgpool.NewImage(ctx, n, f) + if err == nil { + imgs = append(imgs, message.Image(m.String())) + } else { + imgs = append(imgs, message.Image("file:///"+f)) + } } } txt := message.Text( @@ -74,9 +85,9 @@ func init() { // 插件主体 "画师ID:", illust.UserId, "\n", "直链:", "https://pixivel.moe/detail?id=", illust.Pid, ) - if filepath != "" { + if imgs != nil { // 发送搜索结果 - ctx.SendChain(message.Image(filepath), message.Text("\n"), txt) + ctx.Send(append(imgs, message.Text("\n"), txt)) } else { // 图片下载失败,仅发送文字结果 ctx.SendChain(txt) diff --git a/plugin_setutime/setu_geter.go b/plugin_setutime/setu_geter.go index 0a178659..f762f8ef 100644 --- a/plugin_setutime/setu_geter.go +++ b/plugin_setutime/setu_geter.go @@ -245,7 +245,7 @@ func download(i *pixiv.Illust, filedir string) /*(string, */ error /*)*/ { return /*filepath + ".gif",*/ nil } // 下载最大分辨率为 1200 的图片 - link := i.ImageUrls + link := i.ImageUrls[0] link = strings.ReplaceAll(link, "img-original", "img-master") link = strings.ReplaceAll(link, "_p0", "_p0_master1200") link = strings.ReplaceAll(link, ".png", ".jpg")