使用真正lazy的资源下载方式

This commit is contained in:
源文雨
2022-04-16 00:02:41 +08:00
parent fef254031e
commit dfd184724b
22 changed files with 333 additions and 225 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/FloatTech/zbputils/binary"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/file"
"github.com/antchfx/htmlquery"
"github.com/sirupsen/logrus"
@@ -27,22 +28,25 @@ func init() {
PublicDataFolder: "Jandan",
})
go func() {
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
dbpath := engine.DataFolder()
db.DBPath = dbpath + "pics.db"
_, _ = file.GetLazyData(db.DBPath, false, false)
err := db.Create("picture", &picture{})
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
n, err := db.Count("picture")
if err != nil {
panic(err)
ctx.SendChain(message.Text("ERROR:", err))
return false
}
logrus.Printf("[jandan]读取%d张图片", n)
}()
return true
})
engine.OnRegex(`来份[屌|弔|吊]图`).SetBlock(true).
engine.OnRegex(`来份[屌|弔|吊]图`, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
u, err := getRandomPicture()
if err != nil {
@@ -52,7 +56,7 @@ func init() {
ctx.SendChain(message.Image(u))
})
engine.OnRegex(`更新[屌|弔|吊]图`, zero.SuperUserPermission).SetBlock(true).
engine.OnRegex(`更新[屌|弔|吊]图`, zero.SuperUserPermission, getdb).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.Send("少女更新中...")
webpageURL := api