()
| 116 | ) |
| 117 | |
| 118 | func init() { |
| 119 | en.OnRegex(`^猜成语热门(汉字|成语)$`, zero.OnlyGroup, initialized).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { |
| 120 | if ctx.State["regex_matched"].([]string)[1] == "汉字" { |
| 121 | topChars := getTopCharacters(10) |
| 122 | ctx.SendChain(message.Text("热门汉字:\n", strings.Join(topChars, "\n"))) |
| 123 | } else { |
| 124 | topIdioms := getTopIdioms(10) |
| 125 | ctx.SendChain(message.Text("热门成语:\n", strings.Join(topIdioms, "\n"))) |
| 126 | } |
| 127 | }) |
| 128 | en.OnRegex(`^(个人|团队)猜成语$`, zero.OnlyGroup, initialized).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { |
| 129 | target := poolIdiom() |
| 130 | idiomData := idiomInfoMap[target] |
| 131 | game := newHandouGame(idiomData) |
| 132 | _, img, _ := game("") |
| 133 | anser := anserOutString(idiomData) |
| 134 | worldLength := len(idiomData.Chars) |
| 135 | ctx.Send( |
| 136 | message.ReplyWithMessage(ctx.Event.MessageID, |
| 137 | message.ImageBytes(img), |
| 138 | message.Text("你有", 7, "次机会猜出", worldLength, "字成语\n首字拼音为:", idiomData.Pinyin[0]), |
| 139 | ), |
| 140 | ) |
| 141 | var next *zero.FutureEvent |
| 142 | if ctx.State["regex_matched"].([]string)[1] == "个人" { |
| 143 | next = zero.NewFutureEvent("message", 999, false, zero.RegexRule(fmt.Sprintf(`^([\p{Han},,]){%d}$`, worldLength)), |
| 144 | zero.OnlyGroup, ctx.CheckSession()) |
| 145 | } else { |
| 146 | next = zero.NewFutureEvent("message", 999, false, zero.RegexRule(fmt.Sprintf(`^([\p{Han},,]){%d}$`, worldLength)), |
| 147 | zero.OnlyGroup, zero.CheckGroup(ctx.Event.GroupID)) |
| 148 | } |
| 149 | var err error |
| 150 | var win bool |
| 151 | recv, cancel := next.Repeat() |
| 152 | defer cancel() |
| 153 | tick := time.NewTimer(105 * time.Second) |
| 154 | after := time.NewTimer(120 * time.Second) |
| 155 | for { |
| 156 | select { |
| 157 | case <-tick.C: |
| 158 | ctx.SendChain(message.Text("猜成语,你还有15s作答时间")) |
| 159 | case <-after.C: |
| 160 | ctx.Send( |
| 161 | message.ReplyWithMessage(ctx.Event.MessageID, |
| 162 | message.Text("猜成语超时,游戏结束...\n答案是: ", anser), |
| 163 | ), |
| 164 | ) |
| 165 | return |
| 166 | case c := <-recv: |
| 167 | tick.Reset(105 * time.Second) |
| 168 | after.Reset(120 * time.Second) |
| 169 | err = updateHabits(c.Event.Message.String()) |
| 170 | if err != nil { |
| 171 | logrus.Warn("更新用户习惯库时发生错误: ", err) |
| 172 | } |
| 173 | win, img, err = game(c.Event.Message.String()) |
| 174 | switch { |
| 175 | case win: |
nothing calls this directly
no test coverage detected