diff --git a/plugin/nativesetu/data.go b/plugin/nativesetu/data.go index 6d3aa05a..b1cbe72e 100644 --- a/plugin/nativesetu/data.go +++ b/plugin/nativesetu/data.go @@ -33,10 +33,8 @@ type nsetu struct { func (n *nsetu) List() (l []string) { if file.IsExist(n.db.DBPath) { - err := n.db.Open(time.Hour * 24) - if err == nil { - l, err = n.db.ListTables() - } + var err error + l, err = n.db.ListTables() if err != nil { logrus.Errorln("[nsetu]", err) } @@ -49,6 +47,10 @@ func (n *nsetu) scanall(path string) error { root := os.DirFS(path) _ = n.db.Close() _ = os.Remove(n.db.DBPath) + err := n.db.Open(time.Hour * 24) + if err != nil { + return err + } return fs.WalkDir(root, ".", func(path string, d fs.DirEntry, err error) error { if err != nil { return err diff --git a/plugin/nativesetu/main.go b/plugin/nativesetu/main.go index 802ea2e7..cec363d8 100644 --- a/plugin/nativesetu/main.go +++ b/plugin/nativesetu/main.go @@ -4,6 +4,7 @@ package nativesetu import ( "fmt" "os" + "time" "github.com/sirupsen/logrus" zero "github.com/wdvxdr1123/ZeroBot" @@ -42,6 +43,10 @@ func init() { logrus.Infoln("[nsetu] set setu dir to", setupath) } } + err := ns.db.Open(time.Hour * 24) + if err != nil { + panic(err) + } engine.OnRegex(`^本地(.*)$`, fcext.ValueInList(func(ctx *zero.Ctx) string { return ctx.State["regex_matched"].([]string)[1] }, ns)).SetBlock(true). Handle(func(ctx *zero.Ctx) {