⬆️ update sqlite

This commit is contained in:
源文雨
2022-06-10 15:47:47 +08:00
parent 9f748a8119
commit fbeb048c44
15 changed files with 122 additions and 47 deletions

View File

@@ -2,6 +2,8 @@
package bookreview
import (
"time"
log "github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
@@ -24,7 +26,12 @@ func init() {
db.DBPath = engine.DataFolder() + "bookreview.db"
// os.RemoveAll(dbpath)
_, _ = engine.GetLazyData("bookreview.db", true)
err := db.Create("bookreview", &book{})
err := db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("bookreview", &book{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false

View File

@@ -2,6 +2,8 @@
package chouxianghua
import (
"time"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
@@ -23,7 +25,12 @@ func init() {
db.DBPath = en.DataFolder() + "cxh.db"
// os.RemoveAll(dbpath)
_, _ = en.GetLazyData("cxh.db", true)
err := db.Create("pinyin", &pinyin{})
err := db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("pinyin", &pinyin{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false

View File

@@ -3,6 +3,7 @@ package cpstory
import (
"strings"
"time"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
@@ -25,7 +26,12 @@ func init() {
db.DBPath = engine.DataFolder() + "cp.db"
// os.RemoveAll(dbpath)
_, _ = engine.GetLazyData("cp.db", true)
err := db.Create("cp_story", &cpstory{})
err := db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("cp_story", &cpstory{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false

View File

@@ -2,6 +2,8 @@
package curse
import (
"time"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
@@ -31,6 +33,11 @@ func init() {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("curse", &curse{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))

View File

@@ -4,6 +4,7 @@ package data
import (
"crypto/md5"
"encoding/binary"
"time"
sql "github.com/FloatTech/sqlite"
binutils "github.com/FloatTech/zbputils/binary"
@@ -25,6 +26,10 @@ func LoadText(dbfile string) error {
if err != nil {
return err
}
err = db.Open(time.Hour * 24)
if err != nil {
return err
}
err = db.Create("text", &text{})
if err != nil {
return err

View File

@@ -5,6 +5,7 @@ import (
"strconv"
"strings"
"sync"
"time"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
@@ -20,7 +21,7 @@ func init() {
PrivateDataFolder: "driftbottle",
})
sea.DBPath = en.DataFolder() + "sea.db"
err := sea.Open()
err := sea.Open(time.Hour * 24)
if err != nil {
panic(err)
}

View File

@@ -3,6 +3,7 @@ package funny
import (
"strings"
"time"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
@@ -36,6 +37,11 @@ func init() {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("jokes", &joke{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))

View File

@@ -6,6 +6,7 @@ import (
"hash/crc64"
"regexp"
"strconv"
"time"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/binary"
@@ -31,7 +32,12 @@ func init() {
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
db.DBPath = engine.DataFolder() + "pics.db"
_, _ = engine.GetLazyData("pics.db", false)
err := db.Create("picture", &picture{})
err := db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("picture", &picture{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false

View File

@@ -68,8 +68,12 @@ func init() { // 插件主体
go func() {
db.DBPath = engine.DataFolder() + "config.db"
err := db.Open(time.Hour * 24)
if err != nil {
panic(err)
}
clock = timer.NewClock(db)
err := db.Create("welcome", &welcome{})
err = db.Create("welcome", &welcome{})
if err != nil {
panic(err)
}

View File

@@ -7,6 +7,7 @@ import (
"os"
"strings"
"sync"
"time"
"github.com/corona10/goimagehash"
"github.com/sirupsen/logrus"
@@ -32,7 +33,7 @@ type nsetu struct {
func (n *nsetu) List() (l []string) {
if file.IsExist(n.db.DBPath) {
err := n.db.Open()
err := n.db.Open(time.Hour * 24)
if err == nil {
l, err = n.db.ListTables()
}
@@ -77,7 +78,8 @@ func (n *nsetu) scanclass(root fs.FS, path, clsn string) error {
return err
}
n.mu.Lock()
_ = n.db.Truncate(clsn)
_ = n.db.Drop(clsn)
_ = n.db.Create(clsn, &setuclass{})
n.mu.Unlock()
for _, d := range ds {
nm := d.Name()

View File

@@ -3,6 +3,7 @@ package omikuji
import (
"fmt"
"time"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
@@ -42,6 +43,11 @@ func init() { // 插件主体
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("kuji", &kuji{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))

View File

@@ -64,7 +64,7 @@ func init() { // 插件主体
// 如果数据库不存在则下载
pool.db.DBPath = engine.DataFolder() + "SetuTime.db"
_, _ = engine.GetLazyData("SetuTime.db", false)
err := pool.db.Open()
err := pool.db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false

View File

@@ -2,6 +2,8 @@
package tiangou
import (
"time"
sql "github.com/FloatTech/sqlite"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
@@ -34,6 +36,11 @@ func init() {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Open(time.Hour * 24)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
err = db.Create("tiangou", &tiangou{})
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))