diff --git a/README.md b/README.md
index b682a51443..9c8f4c95fb 100644
--- a/README.md
+++ b/README.md
@@ -793,14 +793,6 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 百人一首之n
-
-
- 关键字搜图
-
- `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/image_finder"`
-
- - [x] 来张 [xxx]
-
注入指令
diff --git a/go.mod b/go.mod
index 99f15b0615..7337704290 100644
--- a/go.mod
+++ b/go.mod
@@ -25,6 +25,7 @@ require (
github.com/fumiama/go-registry v0.2.6
github.com/fumiama/gotracemoe v0.0.3
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
+ github.com/fumiama/terasu v0.0.0-20240502091919-c887e26289a8
github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/jinzhu/gorm v1.9.16
@@ -57,7 +58,6 @@ require (
github.com/fumiama/go-simple-protobuf v0.1.0 // indirect
github.com/fumiama/gofastTEA v0.0.10 // indirect
github.com/fumiama/imgsz v0.0.2 // indirect
- github.com/fumiama/terasu v0.0.0-20240502091919-c887e26289a8 // indirect
github.com/gabriel-vasile/mimetype v1.0.4 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
diff --git a/main.go b/main.go
index 8ceb3b48e7..5e95c10365 100644
--- a/main.go
+++ b/main.go
@@ -95,7 +95,6 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hitokoto" // 一言
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hs" // 炉石
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hyaku" // 百人一首
- _ "github.com/FloatTech/ZeroBot-Plugin/plugin/imgfinder" // 关键字搜图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/inject" // 注入指令
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan" // 煎蛋网无聊图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jptingroom" // 日语听力学习材料
diff --git a/plugin/emojimix/mix.go b/plugin/emojimix/mix.go
index eef35e72ee..4cd532f17c 100644
--- a/plugin/emojimix/mix.go
+++ b/plugin/emojimix/mix.go
@@ -9,6 +9,7 @@ import (
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
+ "github.com/fumiama/terasu/http2"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
@@ -30,7 +31,7 @@ func init() {
u2 := fmt.Sprintf(bed, emojis[r2], r2, r2, r1)
logrus.Debugln("[emojimix] u1:", u1)
logrus.Debugln("[emojimix] u2:", u2)
- resp1, err := http.Head(u1)
+ resp1, err := http2.Head(u1)
if err == nil {
resp1.Body.Close()
if resp1.StatusCode == http.StatusOK {
@@ -38,7 +39,7 @@ func init() {
return
}
}
- resp2, err := http.Head(u2)
+ resp2, err := http2.Head(u2)
if err == nil {
resp2.Body.Close()
if resp2.StatusCode == http.StatusOK {
diff --git a/plugin/imgfinder/keyword.go b/plugin/imgfinder/keyword.go
deleted file mode 100644
index ce8b25a3f7..0000000000
--- a/plugin/imgfinder/keyword.go
+++ /dev/null
@@ -1,150 +0,0 @@
-// Package imagefinder 关键字搜图
-package imagefinder
-
-import (
- "encoding/json"
- "errors"
- "math/rand"
- "net/http"
- "net/url"
- "reflect"
- "regexp"
- "strings"
-
- "github.com/quic-go/quic-go/http3"
-
- zero "github.com/wdvxdr1123/ZeroBot"
- "github.com/wdvxdr1123/ZeroBot/message"
-
- "github.com/FloatTech/AnimeAPI/pixiv"
-
- "github.com/FloatTech/floatbox/binary"
- "github.com/FloatTech/floatbox/web"
- ctrl "github.com/FloatTech/zbpctrl"
- "github.com/FloatTech/zbputils/control"
- "github.com/FloatTech/zbputils/ctxext"
- "github.com/FloatTech/zbputils/img/pool"
-)
-
-type resultjson struct {
- Error bool `json:"error"`
- Message string `json:"message"`
- Data struct {
- Illusts []struct {
- ID int64 `json:"id"`
- Title string `json:"title"`
- AltTitle string `json:"altTitle"`
- Description string `json:"description"`
- Type int64 `json:"type"`
- CreateDate string `json:"createDate"`
- UploadDate string `json:"uploadDate"`
- Sanity int64 `json:"sanity"`
- Width int64 `json:"width"`
- Height int64 `json:"height"`
- PageCount int64 `json:"pageCount"`
- Tags []struct {
- Name string `json:"name"`
- Translation string `json:"translation"`
- } `json:"tags"`
- Statistic struct {
- Bookmarks int64 `json:"bookmarks"`
- Likes int64 `json:"likes"`
- Comments int64 `json:"comments"`
- Views int64 `json:"views"`
- } `json:"statistic"`
- Image string `json:"image"`
- } `json:"illusts"`
- Scores []float64 `json:"scores"`
- HasNext bool `json:"has_next"`
- } `json:"data"`
-}
-
-var hrefre = regexp.MustCompile(``)
-
-func init() {
- control.AutoRegister(&ctrl.Options[*zero.Ctx]{
- DisableOnDefault: false,
- Brief: "关键字搜图",
- Help: "- 来张 [xxx]",
- }).OnRegex(`^来张\s?(.*)$`, zero.AdminPermission).SetBlock(true).
- Handle(func(ctx *zero.Ctx) {
- keyword := ctx.State["regex_matched"].([]string)[1]
- soutujson, err := soutuapi(keyword)
- if err != nil {
- ctx.SendChain(message.Text("ERROR: ", err))
- return
- }
- rannum := rand.Intn(len(soutujson.Data.Illusts))
- il := soutujson.Data.Illusts[rannum]
- illust, err := pixiv.Works(il.ID)
- if err != nil {
- ctx.SendChain(message.Text("ERROR: ", err))
- return
- }
- if len(illust.ImageUrls) == 0 {
- ctx.SendChain(message.Text("ERROR: nil image url"))
- return
- }
- u := illust.ImageUrls[0]
- n := u[strings.LastIndex(u, "/")+1 : len(u)-4]
- f := illust.Path(0)
-
- err = pool.SendImageFromPool(n, f, func() error {
- // 下载图片
- return illust.DownloadToCache(0)
- }, ctxext.SendFakeForwardToGroup(ctx,
- message.Text(
- il.Width, "x", il.Height, "\n",
- "标题: ", il.Title, "\n",
- "副标题: ", il.AltTitle, "\n",
- "ID: ", il.ID, "\n",
- "画师: ", illust.UserName, " (", illust.UserID, ")", "\n",
- "分级:", il.Sanity, "\n",
- hrefre.ReplaceAllString(strings.ReplaceAll(strings.ReplaceAll(il.Description, "
", "\n"), "", ""), ""),
- printtags(reflect.ValueOf(&il.Tags)),
- ),
- ), ctxext.GetFirstMessageInForward(ctx))
- if err != nil {
- ctx.SendChain(message.Text("ERROR: ", err))
- return
- }
- })
-}
-
-// soutuapi 请求api
-func soutuapi(keyword string) (r resultjson, err error) {
- var data []byte
- data, err = web.RequestDataWith(&http.Client{Transport: &http3.RoundTripper{}},
- "https://api.pixivel.moe/v2/pixiv/illust/search/"+url.QueryEscape(keyword)+"?page=0",
- "GET",
- "https://pixivel.moe/",
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36",
- nil,
- )
- if err != nil {
- return
- }
- err = json.Unmarshal(data, &r)
- if err == nil && r.Error {
- err = errors.New(r.Message)
- }
- 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++ {
- _ = w.WriteByte('\n')
- tag := tags.Index(i)
- _ = w.WriteByte('#')
- w.WriteString(tag.Field(0).String())
- if !tag.Field(1).IsZero() {
- w.WriteString(" (")
- w.WriteString(tag.Field(1).String())
- w.WriteString(")")
- }
- }
- }))
- return s
-}