✏️ 修复一下碧油鸡 (#136)

This commit is contained in:
Kanri 2022-02-24 18:06:23 +08:00 committed by GitHub
parent ba2d011d48
commit 7ec7ab8682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View File

@ -28,7 +28,14 @@ func init() {
Help: "摸鱼人日历\n" + Help: "摸鱼人日历\n" +
"- /启用 moyucalendar\n" + "- /启用 moyucalendar\n" +
"- /禁用 moyucalendar", "- /禁用 moyucalendar",
}) }).OnFullMatch("摸鱼人日历").SetBlock(true).
Handle(func(ctx *zero.Ctx) {
image, err := crew()
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
}
ctx.SendChain(message.Image(image))
})
// 定时任务每天8点执行一次 // 定时任务每天8点执行一次
_, err := process.CronTab.AddFunc("* 8 * * *", func() { _, err := process.CronTab.AddFunc("* 8 * * *", func() {

View File

@ -41,6 +41,7 @@ var colors = [...]color.RGBA{
} }
var words []string var words []string
var questions []string
func init() { func init() {
en := control.Register("wordle", order.AcquirePrio(), &control.Options{ en := control.Register("wordle", order.AcquirePrio(), &control.Options{
@ -60,11 +61,20 @@ func init() {
}), }),
)) ))
go func() { go func() {
data, err := file.GetLazyData(en.DataFolder()+"words.bin", true, true) questionsdata, err := file.GetLazyData(en.DataFolder()+"questions.bin", true, true)
if err != nil { if err != nil {
panic(err) panic(err)
} }
wordpacks := loadwords(data) questionspacks := loadwords(questionsdata)
questions = make([]string, len(questionspacks))
for i := range questionspacks {
questions[i] = questionspacks[i].String()
}
wordsdata, err := file.GetLazyData(en.DataFolder()+"words.bin", true, true)
if err != nil {
panic(err)
}
wordpacks := loadwords(wordsdata)
words = make([]string, len(wordpacks)) words = make([]string, len(wordpacks))
for i := range wordpacks { for i := range wordpacks {
words[i] = wordpacks[i].String() words[i] = wordpacks[i].String()
@ -73,7 +83,7 @@ func init() {
}() }()
en.OnRegex(`(个人|团队)猜单词`, zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser). en.OnRegex(`(个人|团队)猜单词`, zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
target := words[rand.Intn(len(words))] target := questions[rand.Intn(len(questions))]
game := newWordleGame(target) game := newWordleGame(target)
_, img, cl, _ := game("") _, img, cl, _ := game("")
typ := ctx.State["regex_matched"].([]string)[1] typ := ctx.State["regex_matched"].([]string)[1]
@ -90,8 +100,6 @@ func init() {
} else { } else {
next = zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^[A-Z]{5}$|^[a-z]{5}$`), zero.OnlyGroup, zero.CheckGroup(ctx.Event.GroupID)) next = zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^[A-Z]{5}$|^[a-z]{5}$`), zero.OnlyGroup, zero.CheckGroup(ctx.Event.GroupID))
} }
recv, cancel := next.Repeat()
defer cancel()
var win bool var win bool
var err error var err error
for { for {
@ -103,7 +111,7 @@ func init() {
), ),
) )
return return
case e := <-recv: case e := <-next.Next():
win, img, cl, err = game(e.Message.String()) win, img, cl, err = game(e.Message.String())
switch { switch {
case win: case win: