diff --git a/ban.go b/ban.go index 4ad42cc..2ad7a5e 100644 --- a/ban.go +++ b/ban.go @@ -4,14 +4,11 @@ import ( "crypto/md5" "encoding/binary" "fmt" - "strconv" log "github.com/sirupsen/logrus" "github.com/wdvxdr1123/ZeroBot/utils/helper" ) -var banCache = make(map[uint64]bool) - // Ban 禁止某人在某群使用本插件 func (m *Control[CTX]) Ban(uid, gid int64) { var err error @@ -21,7 +18,7 @@ func (m *Control[CTX]) Ban(uid, gid int64) { id := binary.LittleEndian.Uint64(digest[:8]) m.Manager.Lock() err = m.Manager.D.Insert(m.Service+"ban", &BanStatus{ID: int64(id), UserID: uid, GroupID: gid}) - banCache[id] = true + m.Manager.banCache[id] = true m.Manager.Unlock() if err == nil { log.Debugf("[control] plugin %s is banned in grp %d for usr %d.", m.Service, gid, uid) @@ -33,7 +30,7 @@ func (m *Control[CTX]) Ban(uid, gid int64) { id := binary.LittleEndian.Uint64(digest[:8]) m.Manager.Lock() err = m.Manager.D.Insert(m.Service+"ban", &BanStatus{ID: int64(id), UserID: uid, GroupID: 0}) - banCache[id] = true + m.Manager.banCache[id] = true m.Manager.Unlock() if err == nil { log.Debugf("[control] plugin %s is banned in all grp for usr %d.", m.Service, uid) @@ -47,8 +44,8 @@ func (m *Control[CTX]) Permit(uid, gid int64) { digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("[%s]%d_%d", m.Service, uid, gid))) id := binary.LittleEndian.Uint64(digest[:8]) m.Manager.Lock() - _ = m.Manager.D.Del(m.Service+"ban", "WHERE id = "+strconv.FormatInt(int64(id), 10)) - banCache[id] = false + _ = m.Manager.D.Del(m.Service+"ban", "WHERE id = ?", id) + m.Manager.banCache[id] = false m.Manager.Unlock() log.Debugf("[control] plugin %s is permitted in grp %d for usr %d.", m.Service, gid, uid) return @@ -57,8 +54,8 @@ func (m *Control[CTX]) Permit(uid, gid int64) { digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("[%s]%d_all", m.Service, uid))) id := binary.LittleEndian.Uint64(digest[:8]) m.Manager.Lock() - _ = m.Manager.D.Del(m.Service+"ban", "WHERE id = "+strconv.FormatInt(int64(id), 10)) - banCache[id] = false + _ = m.Manager.D.Del(m.Service+"ban", "WHERE id = ?", id) + m.Manager.banCache[id] = false m.Manager.Unlock() log.Debugf("[control] plugin %s is permitted in all grp for usr %d.", m.Service, uid) } @@ -72,41 +69,41 @@ func (m *Control[CTX]) IsBannedIn(uid, gid int64) bool { digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("[%s]%d_%d", m.Service, uid, gid))) id := binary.LittleEndian.Uint64(digest[:8]) m.Manager.RLock() - if yes, ok := banCache[id]; ok { + if yes, ok := m.Manager.banCache[id]; ok { m.Manager.RUnlock() return yes } - err = m.Manager.D.Find(m.Service+"ban", &b, "WHERE id = "+strconv.FormatInt(int64(id), 10)) + err = m.Manager.D.Find(m.Service+"ban", &b, "WHERE id = ?", id) m.Manager.RUnlock() if err == nil && gid == b.GroupID && uid == b.UserID { log.Debugf("[control] plugin %s is banned in grp %d for usr %d.", m.Service, b.GroupID, b.UserID) m.Manager.Lock() - banCache[id] = true + m.Manager.banCache[id] = true m.Manager.Unlock() return true } m.Manager.Lock() - banCache[id] = false + m.Manager.banCache[id] = false m.Manager.Unlock() } digest = md5.Sum(helper.StringToBytes(fmt.Sprintf("[%s]%d_all", m.Service, uid))) id := binary.LittleEndian.Uint64(digest[:8]) m.Manager.RLock() - if yes, ok := banCache[id]; ok { + if yes, ok := m.Manager.banCache[id]; ok { m.Manager.RUnlock() return yes } - err = m.Manager.D.Find(m.Service+"ban", &b, "WHERE id = "+strconv.FormatInt(int64(id), 10)) + err = m.Manager.D.Find(m.Service+"ban", &b, "WHERE id = ?", id) m.Manager.RUnlock() if err == nil && b.GroupID == 0 && uid == b.UserID { log.Debugf("[control] plugin %s is banned in all grp for usr %d.", m.Service, b.UserID) m.Manager.Lock() - banCache[id] = true + m.Manager.banCache[id] = true m.Manager.Unlock() return true } m.Manager.Lock() - banCache[id] = false + m.Manager.banCache[id] = false m.Manager.Unlock() return false } diff --git a/block.go b/block.go index 47a6959..bd473b2 100644 --- a/block.go +++ b/block.go @@ -1,20 +1,14 @@ package control -import ( - "strconv" -) - func (manager *Manager[CTX]) initBlock() error { return manager.D.Create("__block", &BlockStatus{}) } -var blockCache = make(map[int64]bool) - // DoBlock 封禁 func (manager *Manager[CTX]) DoBlock(uid int64) error { manager.Lock() defer manager.Unlock() - blockCache[uid] = true + manager.blockCache[uid] = true return manager.D.Insert("__block", &BlockStatus{UserID: uid}) } @@ -22,21 +16,21 @@ func (manager *Manager[CTX]) DoBlock(uid int64) error { func (manager *Manager[CTX]) DoUnblock(uid int64) error { manager.Lock() defer manager.Unlock() - blockCache[uid] = false - return manager.D.Del("__block", "where uid = "+strconv.FormatInt(uid, 10)) + manager.blockCache[uid] = false + return manager.D.Del("__block", "where uid = ?", uid) } // IsBlocked 是否封禁 func (manager *Manager[CTX]) IsBlocked(uid int64) bool { manager.RLock() - isbl, ok := blockCache[uid] + isbl, ok := manager.blockCache[uid] manager.RUnlock() if ok { return isbl } manager.Lock() defer manager.Unlock() - isbl = manager.D.CanFind("__block", "where uid = "+strconv.FormatInt(uid, 10)) - blockCache[uid] = isbl + isbl = manager.D.CanFind("__block", "where uid = ?", uid) + manager.blockCache[uid] = isbl return isbl } diff --git a/control.go b/control.go index 49d156a..d47f30d 100644 --- a/control.go +++ b/control.go @@ -2,7 +2,6 @@ package control import ( "math/bits" - "strconv" log "github.com/sirupsen/logrus" ) @@ -54,7 +53,7 @@ func (manager *Manager[CTX]) NewControl(service string, o *Options[CTX]) *Contro func (m *Control[CTX]) Enable(groupID int64) { var c GroupConfig m.Manager.RLock() - err := m.Manager.D.Find(m.Service, &c, "WHERE gid="+strconv.FormatInt(groupID, 10)) + err := m.Manager.D.Find(m.Service, &c, "WHERE gid = ?", groupID) m.Manager.RUnlock() if err != nil { c.GroupID = groupID @@ -74,7 +73,7 @@ func (m *Control[CTX]) Enable(groupID int64) { func (m *Control[CTX]) Disable(groupID int64) { var c GroupConfig m.Manager.RLock() - err := m.Manager.D.Find(m.Service, &c, "WHERE gid="+strconv.FormatInt(groupID, 10)) + err := m.Manager.D.Find(m.Service, &c, "WHERE gid = ?", groupID) m.Manager.RUnlock() if err != nil { c.GroupID = groupID @@ -99,7 +98,7 @@ func (m *Control[CTX]) Reset(groupID int64) { } else { m.Cache[groupID] = 0 } - err := m.Manager.D.Del(m.Service, "WHERE gid="+strconv.FormatInt(groupID, 10)) + err := m.Manager.D.Del(m.Service, "WHERE gid = ?", groupID) m.Manager.Unlock() if err != nil { log.Errorf("[control] %v", err) @@ -145,7 +144,7 @@ func (m *Control[CTX]) IsEnabledIn(gid int64) bool { m.Manager.RUnlock() if !ok { m.Manager.RLock() - err = m.Manager.D.Find(m.Service, &c, "WHERE gid="+strconv.FormatInt(gid, 10)) + err = m.Manager.D.Find(m.Service, &c, "WHERE gid = ?", gid) m.Manager.RUnlock() if err == nil && gid == c.GroupID { m.Manager.Lock() diff --git a/data.go b/data.go index 7beac42..d3c7185 100644 --- a/data.go +++ b/data.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "math/bits" - "strconv" log "github.com/sirupsen/logrus" "github.com/wdvxdr1123/ZeroBot/utils/helper" @@ -22,7 +21,7 @@ func (m *Control[CTX]) GetData(gid int64) int64 { var c GroupConfig var err error m.Manager.RLock() - err = m.Manager.D.Find(m.Service, &c, "WHERE gid="+strconv.FormatInt(gid, 10)) + err = m.Manager.D.Find(m.Service, &c, "WHERE gid = ?", gid) m.Manager.RUnlock() if err == nil && gid == c.GroupID { log.Debugf("[control] plugin %s of grp %d : 0x%x", m.Service, c.GroupID, c.Disable>>1) @@ -35,7 +34,7 @@ func (m *Control[CTX]) GetData(gid int64) int64 { func (m *Control[CTX]) SetData(groupID int64, data int64) error { var c GroupConfig m.Manager.RLock() - err := m.Manager.D.Find(m.Service, &c, "WHERE gid="+strconv.FormatInt(groupID, 10)) + err := m.Manager.D.Find(m.Service, &c, "WHERE gid = ?", groupID) m.Manager.RUnlock() if err != nil { c.GroupID = groupID @@ -81,7 +80,7 @@ func (manager *Manager[CTX]) getExtra(gid int64, obj any) error { } var rsp ResponseGroup manager.RLock() - err := manager.D.Find("__resp", &rsp, "where gid = "+strconv.FormatInt(gid, 10)) + err := manager.D.Find("__resp", &rsp, "where gid = ?", gid) manager.RUnlock() if err != nil || rsp.Extra == "-" { manager.Lock() diff --git a/go.mod b/go.mod index a975f0b..80feee8 100644 --- a/go.mod +++ b/go.mod @@ -3,23 +3,25 @@ module github.com/FloatTech/zbpctrl go 1.20 require ( - github.com/FloatTech/sqlite v1.6.3 + github.com/FloatTech/sqlite v1.7.0 github.com/sirupsen/logrus v1.9.3 - github.com/wdvxdr1123/ZeroBot v1.7.5-0.20240501144516-eb574bbdad32 + github.com/wdvxdr1123/ZeroBot v1.8.0 ) require ( - github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b // indirect - github.com/google/uuid v1.3.0 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect - golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect - modernc.org/libc v1.21.5 // indirect - modernc.org/mathutil v1.5.0 // indirect - modernc.org/memory v1.4.0 // indirect - modernc.org/sqlite v1.20.0 // indirect + github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 // indirect + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/ncruces/go-strftime v0.1.9 // indirect + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + golang.org/x/sys v0.26.0 // indirect + modernc.org/libc v1.61.0 // indirect + modernc.org/mathutil v1.6.0 // indirect + modernc.org/memory v1.8.0 // indirect + modernc.org/sqlite v1.33.1 // indirect ) -replace modernc.org/sqlite => github.com/fumiama/sqlite3 v1.20.0-with-win386 +replace modernc.org/sqlite => github.com/fumiama/sqlite3 v1.29.10-simp -replace github.com/remyoudompheng/bigfft => github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b +replace modernc.org/libc => github.com/fumiama/libc v0.0.0-20240530081950-6f6d8586b5c5 diff --git a/go.sum b/go.sum index 2312c3f..9448882 100644 --- a/go.sum +++ b/go.sum @@ -1,36 +1,51 @@ -github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4M= -github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY= -github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJGLDNIdRX3BI546D3O7k7vrVueZw= -github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= +github.com/FloatTech/sqlite v1.7.0 h1:FGSn4pCR12kESozn7IvNx3U39dwR/AcFM9oPyGACsl0= +github.com/FloatTech/sqlite v1.7.0/go.mod h1:/4tzfCGhrZnnjC1U8vcfwGQeF6eR649fhOsS3+Le0+s= +github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ/VCf80LiQo9C7jHgrunZDwiRcY= +github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b h1:Zt3pFQditAdWTHCOVkiloc9ZauBoWrb37guFV4iIRvE= -github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= -github.com/fumiama/sqlite3 v1.20.0-with-win386 h1:ZR1AXGBEtkfq9GAXehOVcwn+aaCG8itrkgEsz4ggx5k= -github.com/fumiama/sqlite3 v1.20.0-with-win386/go.mod h1:Os58MHwYCcYZCy2PGChBrQtBAw5/LS1ZZOkfc+C/I7s= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/fumiama/libc v0.0.0-20240530081950-6f6d8586b5c5 h1:jDxsIupsT84A6WHcs6kWbst+KqrRQ8/o0VyoFMnbBOA= +github.com/fumiama/libc v0.0.0-20240530081950-6f6d8586b5c5/go.mod h1:15P6ublJ9FJR8YQCGy8DeQ2Uwur7iW9Hserr/T3OFZE= +github.com/fumiama/sqlite3 v1.29.10-simp h1:c5y3uKyU0q9t0/SyfynzYyuslQ5zP+5CD8e0yYY554A= +github.com/fumiama/sqlite3 v1.29.10-simp/go.mod h1:ItX2a1OVGgNsFh6Dv60JQvGfJfTPHPVpV6DF59akYOA= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= +github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/wdvxdr1123/ZeroBot v1.7.5-0.20240501144516-eb574bbdad32 h1:GuVwh4uGtDegpKNgSkcqpbISLAn5nCpqoGxXmiEv4iI= -github.com/wdvxdr1123/ZeroBot v1.7.5-0.20240501144516-eb574bbdad32/go.mod h1:J6uHaXS/Am2VsLxF9TcU6il19PbOeC4SvgxHJ1E2jaE= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/wdvxdr1123/ZeroBot v1.8.0 h1:v7m+0kGtL6XQlUH9O/LzmOntDJs2clzVj93YsAWWMbk= +github.com/wdvxdr1123/ZeroBot v1.8.0/go.mod h1:C86nQ0gIdAri4K2vg8IIQIslt08zzrKMcqYt8zhkx1M= +golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -modernc.org/libc v1.21.5 h1:xBkU9fnHV+hvZuPSRszN0AXDG4M7nwPLwTWwkYcvLCI= -modernc.org/libc v1.21.5/go.mod h1:przBsL5RDOZajTVslkugzLBj1evTue36jEomFQOoYuI= -modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= -modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= -modernc.org/memory v1.4.0 h1:crykUfNSnMAXaOJnnxcSzbUGMqkLWjklJKkBK2nwZwk= -modernc.org/memory v1.4.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= +modernc.org/cc/v4 v4.21.2 h1:dycHFB/jDc3IyacKipCNSDrjIC0Lm1hyoWOZTRR20Lk= +modernc.org/ccgo/v4 v4.17.8 h1:yyWBf2ipA0Y9GGz/MmCmi3EFpKgeS7ICrAFes+suEbs= +modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE= +modernc.org/gc/v2 v2.4.1 h1:9cNzOqPyMJBvrUipmynX0ZohMhcxPtMccYgGOJdOiBw= +modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= +modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= +modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= +modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU= +modernc.org/opt v0.1.3 h1:3XOZf2yznlhC+ibLltsDGzABUGVx8J6pnFMS3E4dcq4= +modernc.org/sortutil v1.2.0 h1:jQiD3PfS2REGJNzNCMMaLSp/wdMNieTbKX920Cqdgqc= +modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= +modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= diff --git a/manager.go b/manager.go index d079211..036c6c6 100644 --- a/manager.go +++ b/manager.go @@ -13,8 +13,10 @@ import ( // Manager 管理 type Manager[CTX any] struct { sync.RWMutex - M map[string]*Control[CTX] - D sql.Sqlite + M map[string]*Control[CTX] + D sql.Sqlite + banCache map[uint64]bool + blockCache map[int64]bool } // NewManager 打开管理数据库 @@ -38,8 +40,10 @@ func NewManager[CTX any](dbpath string) (m Manager[CTX]) { } } m = Manager[CTX]{ - M: map[string]*Control[CTX]{}, - D: sql.Sqlite{DBPath: dbpath}, + M: map[string]*Control[CTX]{}, + D: sql.New(dbpath), + banCache: make(map[uint64]bool, 8), + blockCache: make(map[int64]bool, 8), } err := m.D.Open(time.Hour) if err != nil { diff --git a/response.go b/response.go index c7294bc..83be7e9 100644 --- a/response.go +++ b/response.go @@ -31,7 +31,7 @@ func (manager *Manager[CTX]) Silence(gid int64) error { } manager.Lock() respCache[gid] = "-" - err := manager.D.Del("__resp", "where gid = "+strconv.FormatInt(gid, 10)) + err := manager.D.Del("__resp", "where gid = ?", gid) manager.Unlock() return err } @@ -61,7 +61,7 @@ func (manager *Manager[CTX]) CanResponse(gid int64) bool { return true } manager.RLock() - err = manager.D.Find("__resp", &rsp, "where gid = "+strconv.FormatInt(gid, 10)) + err = manager.D.Find("__resp", &rsp, "where gid = ?", gid) manager.RUnlock() if err != nil { manager.Lock()