From 3c01c3f0babf28f496e9866a51dedfb2d4b27762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Thu, 12 May 2022 14:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20danbooru?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/saucenao/searcher.go | 72 +++++++++++++++---------------------- 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/plugin/saucenao/searcher.go b/plugin/saucenao/searcher.go index e26ecee3..9be55809 100644 --- a/plugin/saucenao/searcher.go +++ b/plugin/saucenao/searcher.go @@ -3,7 +3,9 @@ package saucenao import ( "fmt" + "net/http" "os" + "reflect" "strconv" "github.com/sirupsen/logrus" @@ -113,70 +115,54 @@ func init() { // 插件主体 if err == nil && resp.Count() > 0 { result := resp.First() // 返回SauceNAO的结果 - picid := 0 - picidstr := "" source := "" switch { case result.IsPixiv(): - picid = result.Data.PixivID source = "Pixiv" case result.IsAniDB(): - picid = result.Data.AniDBAID source = "AniDB" case result.IsBcy(): - picid = result.Data.BcyID source = "Bcy" case result.IsDanbooru(): - picid = result.Data.DanbooruID source = "Danbooru" case result.IsDeviantArt(): - picid = result.Data.DeviantArtID source = "DeviantArt" case result.IsIMDb(): - picidstr = result.Data.IMDbID source = "IMDb" case result.IsPawoo(): - picid = result.Data.PawooID source = "Pawoo" case result.IsSankaku(): - picid = result.Data.SankakuID source = "Sankaku" case result.IsSeiga(): - picid = result.Data.SeigaID source = "Seiga" } - if picid != 0 { - ctx.SendChain( - message.Text("我有把握是这个!"), - message.Image(result.Header.Thumbnail), - message.Text( - "\n", - "图源: ", source, "\n", - "相似度: ", result.Header.Similarity, "\n", - "标题: ", result.Data.Title, "\n", - "插画ID: ", picid, "\n", - "画师: ", result.Data.MemberName, "\n", - "画师ID: ", result.Data.MemberID, "\n", - "直链: ", "https://pixivel.moe/detail?id=", result.Data.PixivID, - ), - ) - continue - } - if picidstr != "" { - ctx.SendChain( - message.Text("我有把握是这个!"), - message.Image(result.Header.Thumbnail), - message.Text( - "\n", - "图源: ", source, "\n", - "相似度: ", result.Header.Similarity, "\n", - "标题: ", result.Data.Title, "\n", - "插画ID: ", picidstr, "\n", - "画师: ", result.Data.MemberName, "\n", - "画师ID: ", result.Data.MemberID, "\n", - "直链: ", "https://pixivel.moe/detail?id=", result.Data.PixivID, - ), - ) + if source != "" { + rr := reflect.ValueOf(&result).Elem() + b := binary.NewWriterF(func(w *binary.Writer) { + r := rr.Type() + for i := 0; i < r.NumField(); i++ { + if !rr.Field(i).IsZero() { + w.WriteString("\n") + w.WriteString(r.Field(i).Name) + w.WriteString(": ") + w.WriteString(fmt.Sprint(rr.Field(i).Interface())) + } + } + }) + resp, err := http.Head(result.Header.Thumbnail) + if err == nil && resp.StatusCode == http.StatusOK { + ctx.SendChain( + message.Text("我有把握是这个!"), + message.Image(result.Header.Thumbnail), + message.Text("\n图源: ", source, binary.BytesToString(b)), + ) + } else { + ctx.SendChain( + message.Text("我有把握是这个!"), + message.Image(pic), + message.Text("\n图源: ", source, binary.BytesToString(b)), + ) + } continue } }