更改 ban 时间为 10 分

This commit is contained in:
源文雨 2022-09-06 21:35:31 +08:00
parent 0e2d717aa6
commit 21bfa14b55
2 changed files with 7 additions and 7 deletions

View File

@ -17,11 +17,11 @@ import (
"github.com/wdvxdr1123/ZeroBot/message"
)
const banhour = 4
const bandur time.Duration = time.Minute * 10
var (
managers *ctrl.Manager[*zero.Ctx] // managers lazy load
cache = ttl.NewCacheOn(banhour*time.Hour, [4]func(int64, struct{}){nil, nil, onDel, nil})
cache = ttl.NewCacheOn(bandur, [4]func(int64, struct{}){nil, nil, onDel, nil})
db *antidb
)
@ -69,8 +69,8 @@ func init() {
if err := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]).Manager.DoBlock(uid); err == nil {
t := time.Now().Unix()
cache.Set(uid, struct{}{})
ctx.SetGroupBan(gid, uid, banhour*3600)
ctx.SendChain(message.Text("检测到违禁词, 已封禁/屏蔽", banhour, "小时"))
ctx.SetGroupBan(gid, uid, int64(bandur.Minutes()))
ctx.SendChain(message.Text("检测到违禁词, 已封禁/屏蔽", bandur))
db.Lock()
defer db.Unlock()
err := db.Create("__bantime__", nilbt)

View File

@ -31,13 +31,13 @@ var (
func newantidb(path string) (*antidb, error) {
db := &antidb{Sqlite: sqlite.Sqlite{DBPath: path}}
err := db.Open(time.Hour * banhour)
err := db.Open(bandur)
if err != nil {
return nil, err
}
_ = db.FindFor("__bantime__", nilbt, "", func() error {
t := time.Unix(nilbt.Time, 0)
ttl := time.Until(t.Add(time.Hour * banhour))
ttl := time.Until(t.Add(bandur))
if ttl < time.Minute {
_ = managers.DoUnblock(nilbt.ID)
return nil
@ -46,7 +46,7 @@ func newantidb(path string) (*antidb, error) {
cache.Touch(nilbt.ID, -time.Since(t))
return nil
})
_ = db.Del("__bantime__", "WHERE time<="+strconv.FormatInt(time.Now().Add(time.Minute-time.Hour*banhour).Unix(), 10))
_ = db.Del("__bantime__", "WHERE time<="+strconv.FormatInt(time.Now().Add(time.Minute-bandur).Unix(), 10))
return db, nil
}