()
| 15 | ) |
| 16 | |
| 17 | func init() { |
| 18 | engine.OnRegex(`^买(.*猫)$`, zero.OnlyGroup, func(ctx *zero.Ctx) bool { |
| 19 | if now := time.Now().Hour(); now >= 6 && now <= 20 { |
| 20 | return true |
| 21 | } |
| 22 | ctx.SendChain(message.Text("猫店已经关门了,早上六点后再来吧")) |
| 23 | return false |
| 24 | }, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { |
| 25 | id := ctx.Event.MessageID |
| 26 | gidStr := "group" + strconv.FormatInt(ctx.Event.GroupID, 10) |
| 27 | uidStr := strconv.FormatInt(ctx.Event.UserID, 10) |
| 28 | userInfo, err := catdata.find(gidStr, uidStr) |
| 29 | if err != nil { |
| 30 | ctx.SendChain(message.Text("[ERROR]:", err)) |
| 31 | return |
| 32 | } |
| 33 | /*******************************************************/ |
| 34 | if userInfo != (catInfo{}) && userInfo.Name != "" { |
| 35 | id = ctx.SendChain(message.Reply(id), message.Text("你居然背着你家喵喵出来找小三!")) |
| 36 | if rand.Intn(100) < 20 { |
| 37 | process.SleepAbout1sTo2s() |
| 38 | if rand.Intn(50) == 30 { |
| 39 | if catdata.del(gidStr, uidStr) == nil { |
| 40 | ctx.SendChain(message.Reply(id), message.Text("喔,天啊!你家喵喵带着所有猫粮离家出走了!\n你失去了所有!")) |
| 41 | } |
| 42 | } else if catdata.delcat(gidStr, uidStr) == nil { |
| 43 | ctx.SendChain(message.Reply(id), message.Text("喔,天啊!你家喵喵离家出走了!\n你失去了喵喵!")) |
| 44 | } |
| 45 | } |
| 46 | return |
| 47 | } |
| 48 | /*******************************************************/ |
| 49 | lastTime := time.Unix(userInfo.LastTime, 0).Day() |
| 50 | if lastTime != time.Now().Day() { |
| 51 | userInfo.Work = 0 |
| 52 | userInfo.LastTime = 0 |
| 53 | } |
| 54 | /*******************************************************/ |
| 55 | userInfo.User = ctx.Event.UserID |
| 56 | typeOfcat := ctx.State["regex_matched"].([]string)[1] |
| 57 | if userInfo.LastTime != 0 && typeOfcat == "猫" { |
| 58 | ctx.SendChain(message.Reply(id), message.Text("抱歉,一天只能去猫店一次")) |
| 59 | return |
| 60 | } else if userInfo.Work > 1 { |
| 61 | ctx.SendChain(message.Reply(id), message.Text("抱歉,一天只能选购两次")) |
| 62 | return |
| 63 | } |
| 64 | /*******************************************************/ |
| 65 | if typeOfcat == "猫" { |
| 66 | userInfo.LastTime = time.Now().Unix() |
| 67 | } else { |
| 68 | userInfo.Work++ |
| 69 | } |
| 70 | if err = catdata.insert(gidStr, &userInfo); err != nil { |
| 71 | ctx.SendChain(message.Text("[ERROR]:", err)) |
| 72 | return |
| 73 | } |
| 74 | /*******************************************************/ |
nothing calls this directly
no test coverage detected