ZeroBot-Plugin/plugin_chouxianghua/data.go
2021-12-25 13:01:05 +08:00

38 lines
717 B
Go

package chouxianghua
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/ChouXiangHua/"
dbfile = dbpath + "cxh.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("pinyin", &pinyin{})
if err != nil {
panic(err)
}
n, err := db.Count("pinyin")
if err != nil {
panic(err)
}
log.Printf("[chouxianghua]读取%d条拼音", n)
}()
}