🐛 增加百人一首 修复Lazy不关闭

This commit is contained in:
源文雨
2022-03-28 17:11:44 +08:00
parent 636f14c450
commit 68980a69b5
9 changed files with 204 additions and 65 deletions

View File

@@ -8,6 +8,7 @@ import (
"math/rand"
"sort"
"strings"
"sync"
"time"
"github.com/FloatTech/zbputils/control"
@@ -53,7 +54,10 @@ type dictionary map[int]struct {
cet4 []string
}
var words = make(dictionary)
var (
words = make(dictionary)
wordsmu sync.Mutex
)
func init() {
en := control.Register("wordle", order.AcquirePrio(), &control.Options{
@@ -72,26 +76,34 @@ func init() {
)
}),
))
go func() {
for i := 5; i <= 7; i++ {
for i := 5; i <= 7; i++ {
go func(i int) {
dc, err := file.GetLazyData(fmt.Sprintf("%scet-4_%d.txt", en.DataFolder(), i), true, true)
if err != nil {
panic(err)
}
c := strings.Split(string(dc), "\n")
sort.Strings(c)
wordsmu.Lock()
tmp := words[i]
tmp.cet4 = c
words[i] = tmp
wordsmu.Unlock()
}(i)
go func(i int) {
dd, err := file.GetLazyData(fmt.Sprintf("%sdict_%d.txt", en.DataFolder(), i), true, true)
if err != nil {
panic(err)
}
d := strings.Split(string(dd), "\n")
sort.Strings(d)
words[i] = struct {
dict []string
cet4 []string
}{d, c}
}
}()
wordsmu.Lock()
tmp := words[i]
tmp.dict = d
words[i] = tmp
wordsmu.Unlock()
}(i)
}
en.OnRegex(`(个人|团队)(五阶|六阶|七阶)?猜单词`, zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
class := classdict[ctx.State["regex_matched"].([]string)[2]]