Skip to content

Commit

Permalink
imgfinder add more info
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Jun 10, 2022
1 parent b9fd590 commit 9f748a8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/FloatTech/AnimeAPI v1.4.1-0.20220610045824-90f281c6eece
github.com/FloatTech/sqlite v0.2.1
github.com/FloatTech/zbpctrl v1.4.1-0.20220604065149-1ca23316481c
github.com/FloatTech/zbputils v1.4.1-0.20220604095022-69b69d618e08
github.com/FloatTech/zbputils v1.4.1-0.20220610052426-fd549a8c7867
github.com/antchfx/htmlquery v1.2.4
github.com/corona10/goimagehash v1.0.3
github.com/fogleman/gg v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/FloatTech/sqlite v0.2.1 h1:9t6Me48XJJCIoPy4nLRvcdhcVKfT0c2lilp7SEKROG
github.com/FloatTech/sqlite v0.2.1/go.mod h1:6NfHRzqOo9RWeMJEoAQVuo51Omd5LFNxCNQhMF02/9U=
github.com/FloatTech/zbpctrl v1.4.1-0.20220604065149-1ca23316481c h1:1LhskkE5oP1Y2Vi9f4/s5Lns5M5vIzvGAAwJ4z23h+o=
github.com/FloatTech/zbpctrl v1.4.1-0.20220604065149-1ca23316481c/go.mod h1:x57TwTlC6zGhs+HHzWATD0sabyoDpSt8b7OzV3Mvrdc=
github.com/FloatTech/zbputils v1.4.1-0.20220604095022-69b69d618e08 h1:5L+ucTyGTgEop0lUIZtGcih4Ro/quen2BxhjSHhv+us=
github.com/FloatTech/zbputils v1.4.1-0.20220604095022-69b69d618e08/go.mod h1:xlw8tTnwv+pglm2WZTDr/9Gl767ALYBguwsqibDqYpI=
github.com/FloatTech/zbputils v1.4.1-0.20220610052426-fd549a8c7867 h1:bGCxabeJfHZDG2jw63fguzt/y8cyWZpDjjyxQ8rNJNQ=
github.com/FloatTech/zbputils v1.4.1-0.20220610052426-fd549a8c7867/go.mod h1:xlw8tTnwv+pglm2WZTDr/9Gl767ALYBguwsqibDqYpI=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c h1:cNPOdTNiVwxLpROLjXCgbIPvdkE+BwvxDvgmdYmWx6Q=
github.com/RomiChan/syncx v0.0.0-20220404072119-d7ea0ae15a4c/go.mod h1:KqZzu7slNKROh3TSYEH/IUMG6f4M+1qubZ5e52QypsE=
Expand Down
42 changes: 37 additions & 5 deletions plugin/image_finder/keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/rand"
"net/http"
"net/url"
"reflect"
"strings"

"github.com/lucas-clemente/quic-go/http3"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/FloatTech/AnimeAPI/pixiv"

ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/binary"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/img/pool"
Expand Down Expand Up @@ -51,9 +53,8 @@ type resultjson struct {
} `json:"statistic"`
Image string `json:"image"`
} `json:"illusts"`
Scores []float64 `json:"scores"`
Highlight []string `json:"highlight"`
HasNext bool `json:"has_next"`
Scores []float64 `json:"scores"`
HasNext bool `json:"has_next"`
} `json:"data"`
}

Expand All @@ -71,7 +72,8 @@ func init() {
return
}
rannum := rand.Intn(len(soutujson.Data.Illusts))
illust, err := pixiv.Works(soutujson.Data.Illusts[rannum].ID)
il := soutujson.Data.Illusts[rannum]
illust, err := pixiv.Works(il.ID)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
Expand All @@ -83,7 +85,19 @@ func init() {
err = pool.SendImageFromPool(n, f, func() error {
// 下载图片
return illust.DownloadToCache(0)
}, ctxext.SendFakeForwardToGroup(ctx), ctxext.GetFirstMessageInForward(ctx))
}, ctxext.SendFakeForwardToGroup(ctx,
message.Text(
il.Width, "x", il.Height, "\n",
"标题: ", il.Title, "\n",
"副标题: ", il.AltTitle, "\n",
"ID: ", il.ID,
"简介: ", il.Description, "\n",
"画师: ", illust.UserName, "\n",
"画师ID: ", illust.UserId, "\n",
"分级:", il.Sanity, "\n",
printtags(reflect.ValueOf(&il.Tags)),
),
), ctxext.GetFirstMessageInForward(ctx))
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
Expand All @@ -109,3 +123,21 @@ func soutuapi(keyword string) (r resultjson, err error) {
}
return
}

func printtags(r reflect.Value) string {
tags := r.Elem()
s := binary.BytesToString(binary.NewWriterF(func(w *binary.Writer) {
for i := 0; i < tags.Len(); i++ {
tag := tags.Index(i)
_ = w.WriteByte('#')
w.WriteString(tag.Field(0).String())
w.WriteString(" (")
w.WriteString(tag.Field(1).String())
w.WriteString(")\n")
}
}))
if len(s) > 0 {
s = s[:len(s)-1]
}
return s
}

0 comments on commit 9f748a8

Please sign in to comment.