From 259b29f6e3566413fa2f8a0c30c26b872402d5df Mon Sep 17 00:00:00 2001 From: fumiama Date: Mon, 7 Feb 2022 20:39:49 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E2=9C=A8=20=E2=9A=A1=EF=B8=8F?= =?UTF-8?q?=20=F0=9F=94=A5=20ascii2d=E8=BF=94=E5=9B=9E=E5=A4=9A=E7=BB=93?= =?UTF-8?q?=E6=9E=9C&=E4=BF=AE=E5=A4=8D=E5=90=88=E5=B9=B6=E8=BD=AC?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 6 ++-- go.sum | 12 ++++---- plugin_coser/coser.go | 5 +-- plugin_danbooru/main.go | 2 +- plugin_hs/run.go | 5 ++- plugin_saucenao/searcher.go | 61 +++++++++++++++++++++++++------------ 6 files changed, 56 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index c3c1aed4..fa1ff891 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/FloatTech/ZeroBot-Plugin go 1.17 require ( - github.com/FloatTech/AnimeAPI v1.2.5-beta7 - github.com/FloatTech/zbputils v1.2.5-beta6 + github.com/FloatTech/AnimeAPI v1.2.5-beta10 + github.com/FloatTech/zbputils v1.2.5-beta7 github.com/antchfx/htmlquery v1.2.4 github.com/corona10/goimagehash v1.0.3 github.com/fogleman/gg v1.3.0 @@ -19,7 +19,7 @@ require ( github.com/shirou/gopsutil/v3 v3.21.12 github.com/sirupsen/logrus v1.8.1 github.com/tidwall/gjson v1.13.0 - github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220127075442-eb7b296fc97e + github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220207114459-068919ac2b02 golang.org/x/image v0.0.0-20211028202545-6944b10bf410 ) diff --git a/go.sum b/go.sum index 0046bc75..96545ae8 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ -github.com/FloatTech/AnimeAPI v1.2.5-beta7 h1:cVELpbFGGJxpAc4IlR3cDiv5mDtwL+T2wAKDcTfrJh4= -github.com/FloatTech/AnimeAPI v1.2.5-beta7/go.mod h1:vKbLI2uuJJLZceI6cqNgr/4PWLNHMEhCop83DrdVwpU= +github.com/FloatTech/AnimeAPI v1.2.5-beta10 h1:C4gvZ4VbVjNUA8WBgNnq0ra0YG1uNyL8VmHGFdpZ1Tc= +github.com/FloatTech/AnimeAPI v1.2.5-beta10/go.mod h1:QXGkLikmx2G4nVL24RwLdfcA8Hd54SdfCqVqu/Znd5A= github.com/FloatTech/bot-manager v1.0.0/go.mod h1:8YYRJ16oroGHQGD2En0oVnmcKJkxR9O/jd5BPSfWfOQ= -github.com/FloatTech/zbputils v1.2.5-beta6 h1:WLJLAvqloLuPqTZdbChnXlufMSQMKYFZ2xVHAW8CmEM= -github.com/FloatTech/zbputils v1.2.5-beta6/go.mod h1:1VE4gxnrr+uRz/TDPgx3GT8GmVayoF5e0wolBQU3t+k= +github.com/FloatTech/zbputils v1.2.5-beta7 h1:5mgJaYa8fTx/PQp+oL13pJGQ6GEjkUDg1r1T2ECAiac= +github.com/FloatTech/zbputils v1.2.5-beta7/go.mod h1:3XY4b7OJuQD2zUOaBc1EzDdpXvx3YM4FvpUKZNwgreA= github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb h1:Rkj28fqIwGx/EgBzRYtpmJRfH6wqVn7cNdc7aJ0QE4M= github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= @@ -166,8 +166,8 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw= github.com/wdvxdr1123/ZeroBot v1.3.2/go.mod h1:i2DIqQjtjE+3gvVi9r9sc+QpNaUuyTXx/HNXXayIpwI= github.com/wdvxdr1123/ZeroBot v1.4.1/go.mod h1:7t9m4vDZPwWAmzKlhP6IvUoisOIiqNdm/3AJgiY3+ew= -github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220127075442-eb7b296fc97e h1:0LG8ZvBHtRyPY68G9keReiOtPqsNFoRLBoYO27BUfMA= -github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220127075442-eb7b296fc97e/go.mod h1:NwXIp7PgjV+kUALMXJ4v4/3QcsRSOodtjhLekuPXFog= +github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220207114459-068919ac2b02 h1:Tm5gEjJpm0M2sY6RegimsrRekqNBD26qZjYwTx5Gt6s= +github.com/wdvxdr1123/ZeroBot v1.4.2-0.20220207114459-068919ac2b02/go.mod h1:NwXIp7PgjV+kUALMXJ4v4/3QcsRSOodtjhLekuPXFog= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= diff --git a/plugin_coser/coser.go b/plugin_coser/coser.go index 239c9717..c5c88f14 100644 --- a/plugin_coser/coser.go +++ b/plugin_coser/coser.go @@ -48,12 +48,13 @@ func init() { text, )) gjson.Get(helper.BytesToString(data), "data.data").ForEach(func(_, value gjson.Result) bool { - imgcq := `[CQ:image,file=` + value.String() + `]` m = append(m, message.CustomNode( ctx.Event.Sender.NickName, ctx.Event.UserID, - imgcq), + []message.MessageSegment{ + message.Image(value.String()), + }), ) return true }) diff --git a/plugin_danbooru/main.go b/plugin_danbooru/main.go index 3adf0ebb..1d2c8cf2 100644 --- a/plugin_danbooru/main.go +++ b/plugin_danbooru/main.go @@ -41,7 +41,7 @@ func init() { // 插件主体 if err != nil { name = "未知图片" } else { - name = r.Title + name = r[0].Title } t, err := danbooru.TagURL(name, url) if err != nil { diff --git a/plugin_hs/run.go b/plugin_hs/run.go index 2706bf60..312c9d99 100644 --- a/plugin_hs/run.go +++ b/plugin_hs/run.go @@ -71,7 +71,6 @@ func init() { for i := 0; i < t && i < 5; i++ { cid := gjson.Get(g, `list.`+strconv.Itoa(i)+`.CardID`).String() cachefile := cachedir + cid - imgcq := `[CQ:image,file=` + "file:///" + cachefile + `]` if file.IsNotExist(cachefile) { data, err := web.ReqWith( `https://res.fbigame.com/hs/v13/`+cid+`.png?auth_key=`+ @@ -81,7 +80,7 @@ func init() { err = os.WriteFile(cachefile, data, 0644) } if err != nil { - imgcq = err.Error() + continue } } sk = append( @@ -89,7 +88,7 @@ func init() { message.CustomNode( zero.BotConfig.NickName[0], ctx.Event.SelfID, - imgcq, // 图片 + []message.MessageSegment{message.Image("file:///" + cachefile)}, // 图片 ), ) } diff --git a/plugin_saucenao/searcher.go b/plugin_saucenao/searcher.go index 9915c1bc..eb705e08 100644 --- a/plugin_saucenao/searcher.go +++ b/plugin_saucenao/searcher.go @@ -97,7 +97,7 @@ func init() { // 插件主体 } }) // 以图搜图 - engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, ctxext.CmdMatch, ctxext.MustGiven).SetBlock(true). + engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, zero.OnlyGroup, ctxext.CmdMatch, ctxext.MustGiven).SetBlock(true). Handle(func(ctx *zero.Ctx) { // 开始搜索图片 ctx.SendChain(message.Text("少女祈祷中......")) @@ -109,34 +109,55 @@ func init() { // 插件主体 // 返回SauceNAO的结果 ctx.SendChain( message.Text("我有把握是这个!"), - message.Image(result.Thumbnail), + message.Image(result[0].Thumbnail), message.Text( "\n", - "相似度:", result.Similarity, "\n", - "标题:", result.Title, "\n", - "插画ID:", result.PixivID, "\n", - "画师:", result.MemberName, "\n", - "画师ID:", result.MemberID, "\n", - "直链:", "https://pixivel.moe/detail?id=", result.PixivID, + "相似度:", result[0].Similarity, "\n", + "标题:", result[0].Title, "\n", + "插画ID:", result[0].PixivID, "\n", + "画师:", result[0].MemberName, "\n", + "画师ID:", result[0].MemberID, "\n", + "直链:", "https://pixivel.moe/detail?id=", result[0].PixivID, ), ) continue } if result, err := ascii2d.Ascii2d(pic); err != nil { ctx.SendChain(message.Text("ERROR: ", err)) - } else { - // 返回Ascii2d的结果 - ctx.SendChain( - message.Text( - "大概是这个?", "\n", - "标题:", result.Title, "\n", - "插画ID:", result.Pid, "\n", - "画师:", result.UserName, "\n", - "画师ID:", result.UserId, "\n", - "直链:", "https://pixivel.moe/detail?id=", result.Pid, - ), - ) continue + } else { + var msg message.Message = []message.MessageSegment{ + message.CustomNode( + ctx.Event.Sender.Name(), + ctx.Event.UserID, + "ascii2d搜图结果", + )} + for i := 0; i < len(result) && i < 5; i++ { + msg = append( + msg, + message.CustomNode( + ctx.Event.Sender.Name(), + ctx.Event.UserID, + []message.MessageSegment{ + message.Image(result[i].Thumb), + message.Text(fmt.Sprintf( + "标题:%s\n图源:%s\n画师:%s\n画师链接:%s\n图片链接:%s", + result[i].Name, + result[i].Type, + result[i].AuthNm, + result[i].Author, + result[i].Link, + )), + }, + ), + ) + } + if id := ctx.SendGroupForwardMessage( + ctx.Event.GroupID, + msg, + ).Get("message_id").Int(); id == 0 { + ctx.SendChain(message.Text("ERROR: 可能被风控了")) + } } } })