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

Function init

plugin/mcfish/store.go:46–661  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44}
45
46func init() {
47 engine.OnFullMatchGroup([]string{"钓鱼看板", "钓鱼商店"}, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
48 infos, err := dbdata.getStoreInfo()
49 if err != nil {
50 ctx.SendChain(message.Text("[ERROR at store.go.2]:", err))
51 return
52 }
53 var picImage image.Image
54 if len(infos) == 0 {
55 picImage, err = drawStroeEmptyImage()
56 } else {
57 picImage, err = drawStroeInfoImage(infos)
58 }
59 if err != nil {
60 ctx.SendChain(message.Text("[ERROR at store.go.3]:", err))
61 return
62 }
63 pic, err := factory.ToBytes(picImage)
64 if err != nil {
65 ctx.SendChain(message.Text("[ERROR at store.go.4]:", err))
66 return
67 }
68 ctx.SendChain(message.ImageBytes(pic))
69 })
70 engine.OnRegex(`^出售(`+strings.Join(thingList, "|")+`)\s*(\d*)$`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
71 uid := ctx.Event.UserID
72 thingName := ctx.State["regex_matched"].([]string)[1]
73 number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
74 if number == 0 || strings.Contains(thingName, "竿") {
75 number = 1
76 }
77
78 // 检测物品交易次数
79 if strings.Contains(thingName, "竿") {
80 number, err := dbdata.checkCanSalesFor(uid, thingName, number)
81 if err != nil {
82 ctx.SendChain(message.Text("[ERROR,查询购买资质失败]:", err))
83 return
84 }
85 if number <= 0 {
86 ctx.SendChain(message.Text("一天只能交易10把鱼竿,明天再来售卖吧"))
87 return
88 }
89 }
90
91 articles, err := dbdata.getUserThingInfo(uid, thingName)
92 if err != nil {
93 ctx.SendChain(message.Text("[ERROR at store.go.5]:", err))
94 return
95 }
96 if len(articles) == 0 {
97 ctx.SendChain(message.Text("你的背包不存在该物品"))
98 return
99 }
100 index := 0
101 thing := article{}
102 if len(articles) > 1 {
103 msg := make(message.Message, 0, 3+len(articles))

Callers

nothing calls this directly

Calls 15

drawStroeEmptyImageFunction · 0.85
drawStroeInfoImageFunction · 0.85
getStoreInfoMethod · 0.80
checkCanSalesForMethod · 0.80
getUserThingInfoMethod · 0.80
updateUserThingInfoMethod · 0.80
getNumberForMethod · 0.80
getStoreThingInfoMethod · 0.80
updateStoreInfoMethod · 0.80
updateCurseForMethod · 0.80
updateCanSalesForMethod · 0.80
getUserTypeInfoMethod · 0.80

Tested by

no test coverage detected