ZeroBot-Plugin/plugin_cpstory/data.go
fumiama 0185d0c730 🚚 ⬆️ 📝 🔥 🎨 迁移 ctrl, utils
2022-01-11 11:40:33 +08:00

38 lines
670 B
Go

package cpstory
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/FloatTech/zbputils/file"
"github.com/FloatTech/zbputils/process"
"github.com/FloatTech/zbputils/sql"
)
const (
dbpath = "data/CpStory/"
dbfile = dbpath + "cp.db"
)
var db = &sql.Sqlite{DBPath: dbfile}
// 加载数据库
func init() {
go func() {
process.SleepAbout1sTo2s()
// os.RemoveAll(dbpath)
_ = os.MkdirAll(dbpath, 0755)
_, _ = file.GetLazyData(dbfile, false, true)
err := db.Create("cp_story", &cpstory{})
if err != nil {
panic(err)
}
n, err := db.Count("cp_story")
if err != nil {
panic(err)
}
log.Printf("[cpstory]读取%d条故事", n)
}()
}