MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / newHandouGame

Function newHandouGame

plugin/handou/game.go:246–514  ·  view source on GitHub ↗
(target idiomJSON)

Source from the content-addressed store, hash-verified

244}
245
246func newHandouGame(target idiomJSON) func(string) (bool, []byte, error) {
247 var (
248 class = len(target.Chars)
249 words = target.Word
250 chars = target.Chars
251 pinyin = target.Pinyin
252
253 tickTruePinyin = make([]string, class)
254 tickExistChars = make([]string, class)
255 tickExistPinyin = make([]string, 0, class)
256
257 record = make([]string, 0, 7)
258 )
259 // 初始化 tick, 第一个是已知的拼音
260 for i := range class {
261 if i == 0 {
262 tickTruePinyin[i] = pinyin[0]
263 } else {
264 tickTruePinyin[i] = ""
265 }
266 tickExistChars[i] = "?"
267 }
268
269 return func(s string) (win bool, data []byte, err error) {
270 answer := []rune(s)
271 var answerData idiomJSON
272
273 if s != "" {
274 if words == s {
275 win = true
276 }
277
278 if len(answer) != len(chars) {
279 err = errLengthNotEnough
280 return
281 }
282 if slices.Contains(record, s) {
283 err = errHadGuessed
284 return
285 }
286
287 answerInfo, ok := idiomInfoMap[s]
288 if !ok {
289 newIdiom, err1 := geiAPIdata(s)
290 if err1 != nil {
291 logrus.Debugln("通过API获取成语信息时发生错误: ", err1)
292 err = errUnknownWord
293 return
294 }
295 logrus.Debugln("通过API获取成语信息: ", newIdiom.Word)
296 if newIdiom.Word != "" {
297 idiomInfoMap[newIdiom.Word] = *newIdiom
298 go func() { _ = saveIdiomJSON() }()
299 }
300 if newIdiom.Word != s {
301 err = errUnknownWord
302 return
303 }

Callers 1

initFunction · 0.85

Calls 3

geiAPIdataFunction · 0.85
saveIdiomJSONFunction · 0.85
drawHanBlockFunction · 0.85

Tested by

no test coverage detected