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

Function init

plugin/mcfish/fish.go:17–376  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func init() {
18 engine.OnRegex(`^进行(([1-5]\d|[1-9])次)?钓鱼$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
19 uid := ctx.Event.UserID
20 numberOfPole, err := dbdata.getNumberFor(uid, "竿")
21 if err != nil {
22 ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err))
23 return
24 }
25 if numberOfPole > 30 {
26 ctx.SendChain(message.Text("你有", numberOfPole, "支鱼竿,大于30支的玩家不允许钓鱼"))
27 return
28 }
29 fishNumber := 1
30 info := ctx.State["regex_matched"].([]string)[2]
31 if info != "" {
32 number, err := strconv.Atoi(info)
33 if err != nil || number > FishLimit {
34 ctx.SendChain(message.Text("请输入正确的次数"))
35 return
36 }
37 fishNumber = number
38 }
39 equipInfo, err := dbdata.getUserEquip(uid)
40 if err != nil {
41 ctx.SendChain(message.Text("[ERROR at fish.go.2]:", err))
42 return
43 }
44 if equipInfo == (equip{}) {
45 ok, err := dbdata.checkEquipFor(uid)
46 if err != nil {
47 ctx.SendChain(message.Text("[ERROR at fish.go.2.1]:", err))
48 return
49 }
50 if !ok {
51 ctx.SendChain(message.At(uid), message.Text("请装备鱼竿后钓鱼", err))
52 return
53 }
54 ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你尚未装备鱼竿,是否花费100购买鱼竿?\n回答\"是\"或\"否\""))
55 // 等待用户下一步选择
56 recv, cancel := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
57 defer cancel()
58 buy := false
59 for {
60 select {
61 case <-time.After(time.Second * 120):
62 ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("等待超时,取消购买")))
63 return
64 case e := <-recv:
65 nextcmd := e.Event.Message.String()
66 if nextcmd == "否" {
67 ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("已取消购买")))
68 return
69 }
70 money := wallet.GetWalletOf(uid)
71 if money < 100 {
72 ctx.SendChain(message.Text("你钱包当前只有", money, wallet.GetWalletName(), ",无法完成支付"))
73 return
74 }

Callers

nothing calls this directly

Calls 11

getNumberForMethod · 0.80
getUserEquipMethod · 0.80
checkEquipForMethod · 0.80
updateUserEquipMethod · 0.80
setEquipForMethod · 0.80
updateFishInfoMethod · 0.80
pickFishForMethod · 0.80
getUserThingInfoMethod · 0.80
updateUserThingInfoMethod · 0.80
updateCurseForMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected