mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-13 02:30:26 +00:00
⚡️ 🎨 🔥 优化代码结构
This commit is contained in:
@@ -1,45 +0,0 @@
|
||||
package vtbquotation
|
||||
|
||||
import (
|
||||
"github.com/fumiama/cron"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/FloatTech/zbputils/process"
|
||||
|
||||
"github.com/FloatTech/zbputils/control/order"
|
||||
|
||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation/model"
|
||||
)
|
||||
|
||||
func init() {
|
||||
go func() {
|
||||
defer order.DoneOnExit()()
|
||||
process.SleepAbout1sTo2s()
|
||||
log.Println("[vtb/cron] 开启vtb数据库日常更新")
|
||||
vtbDaily()
|
||||
}()
|
||||
}
|
||||
|
||||
func vtbDaily() {
|
||||
c := cron.New()
|
||||
_, err := c.AddFunc("0 4 * * *", func() { vtbData() })
|
||||
if err != nil {
|
||||
log.Errorln("定时任务有错误:", err)
|
||||
} else {
|
||||
log.Println("开启vtb数据库定时任务")
|
||||
c.Start()
|
||||
}
|
||||
}
|
||||
|
||||
func vtbData() {
|
||||
db := model.Initialize(dbfile)
|
||||
if db != nil {
|
||||
for _, v := range db.GetVtbList() {
|
||||
db.StoreVtb(v)
|
||||
}
|
||||
err := db.Close()
|
||||
if err != nil {
|
||||
log.Errorln("[vtb/cron]", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package vtbquotation
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/FloatTech/zbputils/file"
|
||||
"github.com/FloatTech/zbputils/process"
|
||||
|
||||
"github.com/FloatTech/zbputils/control/order"
|
||||
)
|
||||
|
||||
// 加载数据库
|
||||
func init() {
|
||||
go func() {
|
||||
defer order.DoneOnExit()()
|
||||
process.SleepAbout1sTo2s()
|
||||
_ = os.MkdirAll(dbpath, 0755)
|
||||
_, _ = file.GetLazyData(dbfile, false, false)
|
||||
}()
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
|
||||
control "github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/file"
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
|
||||
"github.com/FloatTech/zbputils/control/order"
|
||||
@@ -22,17 +23,19 @@ import (
|
||||
"github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation/model"
|
||||
)
|
||||
|
||||
const (
|
||||
regStr = ".*/(.*)"
|
||||
dbpath = "data/VtbQuotation/"
|
||||
dbfile = dbpath + "vtb.db"
|
||||
)
|
||||
const regStr = ".*/(.*)"
|
||||
|
||||
func init() {
|
||||
engine := control.Register("vtbquotation", order.AcquirePrio(), &control.Options{
|
||||
DisableOnDefault: false,
|
||||
Help: "vtbkeyboard.moe\n- vtb语录\n- 随机vtb\n- 更新vtb\n",
|
||||
PublicDataFolder: "VtbQuotation",
|
||||
})
|
||||
dbfile := engine.DataFolder() + "vtb.db"
|
||||
go func() {
|
||||
defer order.DoneOnExit()()
|
||||
_, _ = file.GetLazyData(dbfile, false, false)
|
||||
}()
|
||||
engine.OnFullMatch("vtb语录").SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
var firstIndex int
|
||||
@@ -198,7 +201,16 @@ func init() {
|
||||
engine.OnFullMatch("更新vtb", zero.SuperUserPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
ctx.Send("少女祈祷中......")
|
||||
vtbData()
|
||||
db := model.Initialize(dbfile)
|
||||
if db != nil {
|
||||
for _, v := range db.GetVtbList() {
|
||||
db.StoreVtb(v)
|
||||
}
|
||||
err := db.Close()
|
||||
if err != nil {
|
||||
log.Errorln("[vtb/cron]", err)
|
||||
}
|
||||
}
|
||||
ctx.Send("vtb数据库已更新")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user