修复pixiv下载

This commit is contained in:
fumiama 2022-02-27 14:17:29 +08:00
parent d9e195ccd0
commit 0e15ac78b2
4 changed files with 19 additions and 33 deletions

4
go.mod
View File

@ -3,9 +3,9 @@ module github.com/FloatTech/ZeroBot-Plugin
go 1.17 go 1.17
require ( require (
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220224052148-f7a1379d4a00 github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220227060429-ae266747b1df
github.com/FloatTech/sqlite v0.2.0 github.com/FloatTech/sqlite v0.2.0
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220226150734-48567d2365af github.com/FloatTech/zbputils v1.3.0-beta8.0.20220227042832-376a84a3ea87
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

9
go.sum
View File

@ -1,11 +1,10 @@
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220224052148-f7a1379d4a00 h1:idUMQfvkooUapF1B2WDrm84QQqz7t+/bVnSTIrs4Khg= github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220227060429-ae266747b1df h1:pz6mcz4pC8hEbyygM/QX/mX7pgvQOIpYF8H940/4Z8Q=
github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220224052148-f7a1379d4a00/go.mod h1:WGkFlN/5QbdptbQuvGrS7KQl5nAdQbvZLFsbrM7rWCU= github.com/FloatTech/AnimeAPI v1.3.0-beta8.0.20220227060429-ae266747b1df/go.mod h1:uMe7TzdyGnyRn6AzMmkvDXp+GfTTWV/vBlv6mhhP8kg=
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/sqlite v0.2.0 h1:x3uls/hExXH1+bbaNLkvilce6ATtWlDx4IqoxBW/bv8= github.com/FloatTech/sqlite v0.2.0 h1:x3uls/hExXH1+bbaNLkvilce6ATtWlDx4IqoxBW/bv8=
github.com/FloatTech/sqlite v0.2.0/go.mod h1:xIDWIvpOFl8AXmZm0FC8t3PZjiR6ZutytCpBv2EWCns= github.com/FloatTech/sqlite v0.2.0/go.mod h1:xIDWIvpOFl8AXmZm0FC8t3PZjiR6ZutytCpBv2EWCns=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220224051618-597cdb58b3fe/go.mod h1:Jn5LmnwqYivr64qQJBdhDwm2gRut8Hhq5gPBydV0Gvg= github.com/FloatTech/zbputils v1.3.0-beta8.0.20220227042832-376a84a3ea87 h1:nyUTZLGUAJP/kLXx48j2qdxQBPVqaZgypjjIqpIRqwk=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220226150734-48567d2365af h1:nwXPR9+RuTbjk0zh+4Sg37wWaqfQb8kGvSfPA1wsF+0= github.com/FloatTech/zbputils v1.3.0-beta8.0.20220227042832-376a84a3ea87/go.mod h1:Jn5LmnwqYivr64qQJBdhDwm2gRut8Hhq5gPBydV0Gvg=
github.com/FloatTech/zbputils v1.3.0-beta8.0.20220226150734-48567d2365af/go.mod h1:Jn5LmnwqYivr64qQJBdhDwm2gRut8Hhq5gPBydV0Gvg=
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0= github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc h1:AAx50/fb/xS4lvsdQg+bFbGvqSDhyV1MF+p2PLCamZ0=
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0= github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc/go.mod h1:OMmITAib6POA37xCichWM0aRnoVpSMZO1rB/G01wrr0=

View File

@ -58,6 +58,9 @@ func init() { // 插件主体
m.SetFile(f) m.SetFile(f)
_, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) _, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx))
} }
if err1 != nil {
logrus.Debugln("[sausenao]下载err:", err1)
}
} }
imgs = append(imgs, message.Image("file:///"+f)) imgs = append(imgs, message.Image("file:///"+f))
} }

View File

@ -2,7 +2,6 @@
package setutime package setutime
import ( import (
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
@ -158,11 +157,13 @@ func (p *imgpool) push(ctx *zero.Ctx, imgtype string, illust *pixiv.Illust) {
var msg message.MessageSegment var msg message.MessageSegment
f := fileutil.BOTPATH + "/" + illust.Path(0) f := fileutil.BOTPATH + "/" + illust.Path(0)
if err != nil { if err != nil {
if fileutil.IsNotExist(f) {
// 下载图片 // 下载图片
if err := illust.DownloadToCache(0); err != nil { if err := illust.DownloadToCache(0); err != nil {
ctx.SendChain(message.Text("ERROR: ", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
}
if err != imagepool.ErrImgFileAsync { if err != imagepool.ErrImgFileAsync {
m.SetFile(f) m.SetFile(f)
_, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx)) _, _ = m.Push(ctxext.SendToSelf(ctx), ctxext.GetMessage(ctx))
@ -190,21 +191,6 @@ func (p *imgpool) pop(imgtype string) (msg *message.MessageSegment) {
return return
} }
func (p *imgpool) cachefile(i *pixiv.Illust) string {
filename := fmt.Sprint(i.Pid) + "_p0"
filepath := fileutil.BOTPATH + `/` + p.path + filename
if fileutil.IsExist(filepath + ".jpg") {
return `file:///` + filepath + ".jpg"
}
if fileutil.IsExist(filepath + ".png") {
return `file:///` + filepath + ".png"
}
if fileutil.IsExist(filepath + ".gif") {
return `file:///` + filepath + ".gif"
}
return ""
}
// fill 补充池子 // fill 补充池子
func (p *imgpool) fill(ctx *zero.Ctx, imgtype string) { func (p *imgpool) fill(ctx *zero.Ctx, imgtype string) {
times := math.Min(p.max-p.size(imgtype), 2) times := math.Min(p.max-p.size(imgtype), 2)
@ -235,14 +221,12 @@ func (p *imgpool) add(ctx *zero.Ctx, imgtype string, id int64) error {
if err != nil { if err != nil {
return err return err
} }
// 下载插画 err = imagepool.SendImageFromPool(strconv.FormatInt(illust.Pid, 10)+"_p0", illust.Path(0), func() error {
if err := illust.DownloadToCache(0); err != nil { return illust.DownloadToCache(0)
}, ctxext.Send(ctx), ctxext.GetMessage(ctx))
if err != nil {
return err return err
} }
// 发送到发送者
if id := ctx.SendChain(message.Image(p.cachefile(illust))); id.ID() == 0 {
return errors.New("可能被风控,发送失败")
}
// 添加插画到对应的数据库table // 添加插画到对应的数据库table
if err := p.db.Insert(imgtype, illust); err != nil { if err := p.db.Insert(imgtype, illust); err != nil {
return err return err