MCPcopy Create free account
hub / github.com/FloatTech/ZeroBot-Plugin-Playground / init

Function init

plugin/cybercat/keepcat.go:17–289  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func init() {
18 engine.OnRegex(`^喂猫((\d+(.\d+)?)斤猫粮)?|猫猫状态$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
19 id := ctx.Event.MessageID
20 gidStr := "group" + strconv.FormatInt(ctx.Event.GroupID, 10)
21 uidStr := strconv.FormatInt(ctx.Event.UserID, 10)
22 userInfo, err := catdata.find(gidStr, uidStr)
23 if err != nil {
24 ctx.SendChain(message.Text("[ERROR]:", err))
25 return
26 }
27 if userInfo == (catInfo{}) || userInfo.Name == "" {
28 ctx.SendChain(message.Reply(id), message.Text("铲屎官你还没有属于你的主子喔,快去买一只吧!"))
29 return
30 }
31 /*************************判断指令类型**************************************/
32 cmd := false // false表示在喂猫
33 if ctx.State["regex_matched"].([]string)[0] == "猫猫状态" {
34 cmd = true
35 }
36 /**************************获取工作状态*************************************/
37 stauts := "休闲中"
38 money, workEnd := userInfo.settleOfWork(gidStr)
39 switch {
40 case !cmd && !workEnd:
41 ctx.SendChain(message.Reply(id), message.Text(userInfo.Name, "还在努力打工,没有回来呢"))
42 return
43 case cmd && !workEnd:
44 overwork := time.Unix(userInfo.Work/10, 0).Add(time.Hour * time.Duration(userInfo.Work%10))
45 stauts = overwork.Format("工作中\n(将在01月02日15:04下班)")
46 case cmd && money > 0:
47 stauts = "从工作回来休息中\n 为你赚了" + strconv.Itoa(money)
48 }
49 now := time.Now().Hour()
50 if !cmd && ((now < 6 || (now > 8 && now < 11) || (now > 14 && now < 17) || now > 21) && (userInfo.Satiety > 50 || rand.Intn(3) == 1)) {
51 if userInfo.Satiety > 50 {
52 ctx.SendChain(message.Text("猫猫拍了拍饱饱的肚子表示并不饿呢"))
53 return
54 }
55 ctx.SendChain(message.Text("猫猫只想和你一起吃传统早中晚饭咧"))
56 return
57 }
58 /****************************计算食物数量***********************************/
59 food := 0.0
60 if !cmd {
61 stauts = "刚刚的食物很美味"
62 // 如果没有指定猫粮就 (1 + 猫粮/5*x )斤猫粮
63 if ctx.State["regex_matched"].([]string)[2] != "" {
64 food, _ = strconv.ParseFloat(ctx.State["regex_matched"].([]string)[2], 64)
65 } else {
66 food = math.Max(1.0+math.Max(userInfo.Food-1, 0)/5*rand.Float64(), (100-userInfo.Satiety)*userInfo.Weight/200)
67 }
68 switch {
69 case userInfo.Food == 0 || userInfo.Food < food:
70 ctx.SendChain(message.Reply(id), message.Text("铲屎官你已经没有足够的猫粮了"))
71 return
72 // 如果猫粮太多就只吃一点,除非太饿了
73 case food > 5 && (rand.Intn(10) < 8 || userInfo.Satiety < 30):
74 food = 5

Callers

nothing calls this directly

Calls 9

findMethod · 0.80
settleOfWorkMethod · 0.80
FormatMethod · 0.80
settleOfWeightMethod · 0.80
settleOfSatietyMethod · 0.80
settleOfDataMethod · 0.80
delcatMethod · 0.80
avatarMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected