mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
chore: del imgfinder due to 跑路
This commit is contained in:
parent
f54b9adf84
commit
6e54d214f0
@ -793,14 +793,6 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
|
|
||||||
- [x] 百人一首之n
|
- [x] 百人一首之n
|
||||||
|
|
||||||
</details>
|
|
||||||
<details>
|
|
||||||
<summary>关键字搜图</summary>
|
|
||||||
|
|
||||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/image_finder"`
|
|
||||||
|
|
||||||
- [x] 来张 [xxx]
|
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
<summary>注入指令</summary>
|
<summary>注入指令</summary>
|
||||||
|
|||||||
2
go.mod
2
go.mod
@ -25,6 +25,7 @@ require (
|
|||||||
github.com/fumiama/go-registry v0.2.6
|
github.com/fumiama/go-registry v0.2.6
|
||||||
github.com/fumiama/gotracemoe v0.0.3
|
github.com/fumiama/gotracemoe v0.0.3
|
||||||
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
|
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/fumiama/unibase2n v0.0.0-20221020155353-02876e777430
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||||
github.com/jinzhu/gorm v1.9.16
|
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/go-simple-protobuf v0.1.0 // indirect
|
||||||
github.com/fumiama/gofastTEA v0.0.10 // indirect
|
github.com/fumiama/gofastTEA v0.0.10 // indirect
|
||||||
github.com/fumiama/imgsz v0.0.2 // 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/gabriel-vasile/mimetype v1.0.4 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
|
||||||
|
|||||||
1
main.go
1
main.go
@ -95,7 +95,6 @@ import (
|
|||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hitokoto" // 一言
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hitokoto" // 一言
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hs" // 炉石
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hs" // 炉石
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hyaku" // 百人一首
|
_ "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/inject" // 注入指令
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan" // 煎蛋网无聊图
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan" // 煎蛋网无聊图
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jptingroom" // 日语听力学习材料
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jptingroom" // 日语听力学习材料
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
ctrl "github.com/FloatTech/zbpctrl"
|
ctrl "github.com/FloatTech/zbpctrl"
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/fumiama/terasu/http2"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
@ -30,7 +31,7 @@ func init() {
|
|||||||
u2 := fmt.Sprintf(bed, emojis[r2], r2, r2, r1)
|
u2 := fmt.Sprintf(bed, emojis[r2], r2, r2, r1)
|
||||||
logrus.Debugln("[emojimix] u1:", u1)
|
logrus.Debugln("[emojimix] u1:", u1)
|
||||||
logrus.Debugln("[emojimix] u2:", u2)
|
logrus.Debugln("[emojimix] u2:", u2)
|
||||||
resp1, err := http.Head(u1)
|
resp1, err := http2.Head(u1)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
resp1.Body.Close()
|
resp1.Body.Close()
|
||||||
if resp1.StatusCode == http.StatusOK {
|
if resp1.StatusCode == http.StatusOK {
|
||||||
@ -38,7 +39,7 @@ func init() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp2, err := http.Head(u2)
|
resp2, err := http2.Head(u2)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
resp2.Body.Close()
|
resp2.Body.Close()
|
||||||
if resp2.StatusCode == http.StatusOK {
|
if resp2.StatusCode == http.StatusOK {
|
||||||
|
|||||||
@ -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(`<a href=".*">`)
|
|
||||||
|
|
||||||
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, "<br />", "\n"), "</a>", ""), ""),
|
|
||||||
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
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user