🎨 优化鉴赏图片, 文本重用 (#451)

This commit is contained in:
himawari 2022-10-14 20:47:34 +08:00 committed by GitHub
parent 55aa869b1a
commit 894cf41d37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View File

@ -444,7 +444,7 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 查弹幕 [xxx] 2 (最后一个参数是页码) - [x] 查弹幕 [xxx] 2 (最后一个参数是页码)
- [x] 设置b站cookie SESSDATA=82da790d,1663822823,06ecf\*31 (最好把cookie设全) - [x] 设置b站cookie b_ut=7;buvid3=0;i-wanna-go-back=-1;innersign=0; (最好把cookie设全)
获取Cookie可以使用[这个工具](https://github.com/XiaoMiku01/login_bili_go) 获取Cookie可以使用[这个工具](https://github.com/XiaoMiku01/login_bili_go)

View File

@ -53,7 +53,7 @@ func init() {
"- >user info [xxx]\n" + "- >user info [xxx]\n" +
"- 查成分 [xxx]\n" + "- 查成分 [xxx]\n" +
"- 查弹幕 [xxx]\n" + "- 查弹幕 [xxx]\n" +
"- 设置b站cookie [xxx]\n" + "- 设置b站cookie b_ut=7;buvid3=0;i-wanna-go-back=-1;innersign=0;\n" +
"- 更新vup", "- 更新vup",
PublicDataFolder: "Bilibili", PublicDataFolder: "Bilibili",
}) })

View File

@ -4,11 +4,13 @@ package deepdanbooru
import ( import (
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"strings"
"github.com/FloatTech/floatbox/file" "github.com/FloatTech/floatbox/file"
"github.com/FloatTech/floatbox/img/writer" "github.com/FloatTech/floatbox/img/writer"
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"
zero "github.com/wdvxdr1123/ZeroBot" zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/message"
"github.com/wdvxdr1123/ZeroBot/utils/helper" "github.com/wdvxdr1123/ZeroBot/utils/helper"
@ -29,7 +31,7 @@ func init() { // 插件主体
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text("少女祈祷中...")) ctx.SendChain(message.Text("少女祈祷中..."))
for _, url := range ctx.State["image_url"].([]string) { for _, url := range ctx.State["image_url"].([]string) {
t, err := tagurl("", url) t, st, err := tagurl("", url)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR: ", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
@ -39,7 +41,11 @@ func init() { // 插件主体
if file.IsNotExist(f) { if file.IsNotExist(f) {
_ = writer.SavePNG2Path(f, t) _ = writer.SavePNG2Path(f, t)
} }
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + f)) m := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Image("file:///"+file.BOTPATH+"/"+f))}
m = append(m, ctxext.FakeSenderForwardNode(ctx, message.Text("tags: ", strings.Join(st.tseq, ","))))
if id := ctx.Send(m).ID(); id == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控或下载图片用时过长,请耐心等待"))
}
} }
}) })
} }

View File

@ -46,7 +46,7 @@ func (s *sorttags) Swap(i, j int) {
s.tseq[j], s.tseq[i] = s.tseq[i], s.tseq[j] s.tseq[j], s.tseq[i] = s.tseq[i], s.tseq[j]
} }
func tagurl(name, u string) (im image.Image, err error) { func tagurl(name, u string) (im image.Image, st *sorttags, err error) {
ch := make(chan []byte, 1) ch := make(chan []byte, 1)
go func() { go func() {
var data []byte var data []byte
@ -72,7 +72,7 @@ func tagurl(name, u string) (im image.Image, err error) {
} }
longestlen++ longestlen++
st := newsorttags(tags) st = newsorttags(tags)
sort.Sort(st) sort.Sort(st)
_, err = file.GetLazyData(text.BoldFontFile, true) _, err = file.GetLazyData(text.BoldFontFile, true)