fix nsetu

This commit is contained in:
源文雨 2022-11-25 15:23:16 +08:00
parent 27d04cbae2
commit daff47d912
2 changed files with 11 additions and 4 deletions

View File

@ -33,10 +33,8 @@ type nsetu struct {
func (n *nsetu) List() (l []string) { func (n *nsetu) List() (l []string) {
if file.IsExist(n.db.DBPath) { if file.IsExist(n.db.DBPath) {
err := n.db.Open(time.Hour * 24) var err error
if err == nil { l, err = n.db.ListTables()
l, err = n.db.ListTables()
}
if err != nil { if err != nil {
logrus.Errorln("[nsetu]", err) logrus.Errorln("[nsetu]", err)
} }
@ -49,6 +47,10 @@ func (n *nsetu) scanall(path string) error {
root := os.DirFS(path) root := os.DirFS(path)
_ = n.db.Close() _ = n.db.Close()
_ = os.Remove(n.db.DBPath) _ = 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 { return fs.WalkDir(root, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil { if err != nil {
return err return err

View File

@ -4,6 +4,7 @@ package nativesetu
import ( import (
"fmt" "fmt"
"os" "os"
"time"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot" zero "github.com/wdvxdr1123/ZeroBot"
@ -42,6 +43,10 @@ func init() {
logrus.Infoln("[nsetu] set setu dir to", setupath) 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). engine.OnRegex(`^本地(.*)$`, fcext.ValueInList(func(ctx *zero.Ctx) string { return ctx.State["regex_matched"].([]string)[1] }, ns)).SetBlock(true).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {