🐛 🔥 ascii2d返回多结果&修复合并转发

This commit is contained in:
fumiama 2022-02-07 20:39:49 +08:00
parent 477868c601
commit 259b29f6e3
6 changed files with 56 additions and 35 deletions

6
go.mod
View File

@ -3,8 +3,8 @@ module github.com/FloatTech/ZeroBot-Plugin
go 1.17 go 1.17
require ( require (
github.com/FloatTech/AnimeAPI v1.2.5-beta7 github.com/FloatTech/AnimeAPI v1.2.5-beta10
github.com/FloatTech/zbputils v1.2.5-beta6 github.com/FloatTech/zbputils v1.2.5-beta7
github.com/antchfx/htmlquery v1.2.4 github.com/antchfx/htmlquery v1.2.4
github.com/corona10/goimagehash v1.0.3 github.com/corona10/goimagehash v1.0.3
github.com/fogleman/gg v1.3.0 github.com/fogleman/gg v1.3.0
@ -19,7 +19,7 @@ require (
github.com/shirou/gopsutil/v3 v3.21.12 github.com/shirou/gopsutil/v3 v3.21.12
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.8.1
github.com/tidwall/gjson v1.13.0 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 golang.org/x/image v0.0.0-20211028202545-6944b10bf410
) )

12
go.sum
View File

@ -1,8 +1,8 @@
github.com/FloatTech/AnimeAPI v1.2.5-beta7 h1:cVELpbFGGJxpAc4IlR3cDiv5mDtwL+T2wAKDcTfrJh4= github.com/FloatTech/AnimeAPI v1.2.5-beta10 h1:C4gvZ4VbVjNUA8WBgNnq0ra0YG1uNyL8VmHGFdpZ1Tc=
github.com/FloatTech/AnimeAPI v1.2.5-beta7/go.mod h1:vKbLI2uuJJLZceI6cqNgr/4PWLNHMEhCop83DrdVwpU= 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/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-beta7 h1:5mgJaYa8fTx/PQp+oL13pJGQ6GEjkUDg1r1T2ECAiac=
github.com/FloatTech/zbputils v1.2.5-beta6/go.mod h1:1VE4gxnrr+uRz/TDPgx3GT8GmVayoF5e0wolBQU3t+k= 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 h1:Rkj28fqIwGx/EgBzRYtpmJRfH6wqVn7cNdc7aJ0QE4M=
github.com/Mrs4s/MiraiGo v0.0.0-20211120033824-43b23f4e6fcb/go.mod h1:imVKbfKqqeit+C/eaWGb4MKQ3z3gN6pRpBU5RMtp5so= 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= 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/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.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.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.20220207114459-068919ac2b02 h1:Tm5gEjJpm0M2sY6RegimsrRekqNBD26qZjYwTx5Gt6s=
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/go.mod h1:NwXIp7PgjV+kUALMXJ4v4/3QcsRSOodtjhLekuPXFog=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 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/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=

View File

@ -48,12 +48,13 @@ func init() {
text, text,
)) ))
gjson.Get(helper.BytesToString(data), "data.data").ForEach(func(_, value gjson.Result) bool { gjson.Get(helper.BytesToString(data), "data.data").ForEach(func(_, value gjson.Result) bool {
imgcq := `[CQ:image,file=` + value.String() + `]`
m = append(m, m = append(m,
message.CustomNode( message.CustomNode(
ctx.Event.Sender.NickName, ctx.Event.Sender.NickName,
ctx.Event.UserID, ctx.Event.UserID,
imgcq), []message.MessageSegment{
message.Image(value.String()),
}),
) )
return true return true
}) })

View File

@ -41,7 +41,7 @@ func init() { // 插件主体
if err != nil { if err != nil {
name = "未知图片" name = "未知图片"
} else { } else {
name = r.Title name = r[0].Title
} }
t, err := danbooru.TagURL(name, url) t, err := danbooru.TagURL(name, url)
if err != nil { if err != nil {

View File

@ -71,7 +71,6 @@ func init() {
for i := 0; i < t && i < 5; i++ { for i := 0; i < t && i < 5; i++ {
cid := gjson.Get(g, `list.`+strconv.Itoa(i)+`.CardID`).String() cid := gjson.Get(g, `list.`+strconv.Itoa(i)+`.CardID`).String()
cachefile := cachedir + cid cachefile := cachedir + cid
imgcq := `[CQ:image,file=` + "file:///" + cachefile + `]`
if file.IsNotExist(cachefile) { if file.IsNotExist(cachefile) {
data, err := web.ReqWith( data, err := web.ReqWith(
`https://res.fbigame.com/hs/v13/`+cid+`.png?auth_key=`+ `https://res.fbigame.com/hs/v13/`+cid+`.png?auth_key=`+
@ -81,7 +80,7 @@ func init() {
err = os.WriteFile(cachefile, data, 0644) err = os.WriteFile(cachefile, data, 0644)
} }
if err != nil { if err != nil {
imgcq = err.Error() continue
} }
} }
sk = append( sk = append(
@ -89,7 +88,7 @@ func init() {
message.CustomNode( message.CustomNode(
zero.BotConfig.NickName[0], zero.BotConfig.NickName[0],
ctx.Event.SelfID, ctx.Event.SelfID,
imgcq, // 图片 []message.MessageSegment{message.Image("file:///" + cachefile)}, // 图片
), ),
) )
} }

View File

@ -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) { Handle(func(ctx *zero.Ctx) {
// 开始搜索图片 // 开始搜索图片
ctx.SendChain(message.Text("少女祈祷中......")) ctx.SendChain(message.Text("少女祈祷中......"))
@ -109,34 +109,55 @@ func init() { // 插件主体
// 返回SauceNAO的结果 // 返回SauceNAO的结果
ctx.SendChain( ctx.SendChain(
message.Text("我有把握是这个!"), message.Text("我有把握是这个!"),
message.Image(result.Thumbnail), message.Image(result[0].Thumbnail),
message.Text( message.Text(
"\n", "\n",
"相似度:", result.Similarity, "\n", "相似度:", result[0].Similarity, "\n",
"标题:", result.Title, "\n", "标题:", result[0].Title, "\n",
"插画ID", result.PixivID, "\n", "插画ID", result[0].PixivID, "\n",
"画师:", result.MemberName, "\n", "画师:", result[0].MemberName, "\n",
"画师ID", result.MemberID, "\n", "画师ID", result[0].MemberID, "\n",
"直链:", "https://pixivel.moe/detail?id=", result.PixivID, "直链:", "https://pixivel.moe/detail?id=", result[0].PixivID,
), ),
) )
continue continue
} }
if result, err := ascii2d.Ascii2d(pic); err != nil { if result, err := ascii2d.Ascii2d(pic); err != nil {
ctx.SendChain(message.Text("ERROR: ", err)) 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 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: 可能被风控了"))
}
} }
} }
}) })