ZeroBot-Plugin/plugin_cpstory/data.go
github-actions[bot] 3f69308603 🎨 改进代码样式
2021-12-26 14:00:48 +00:00

38 lines
706 B
Go

package cpstory
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
"github.com/FloatTech/ZeroBot-Plugin/utils/process"
"github.com/FloatTech/ZeroBot-Plugin/utils/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)
}()
}