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

Function init

plugin/partygame/roulette.go:44–199  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42}
43
44func init() { // 插件主体
45 engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
46 DisableOnDefault: false,
47 Brief: "轮盘赌",
48 Help: "- 创建轮盘赌\n- 加入轮盘赌\n- 开始轮盘赌\n- 开火\n- 终止轮盘赌",
49 PrivateDataFolder: "roulette",
50 })
51 dataPath := engine.DataFolder() + "rate.json"
52 _ = os.Remove(dataPath)
53 checkFile(dataPath)
54
55 checkSession := func(ctx *zero.Ctx) bool {
56 ss := getSession(ctx.Event.GroupID, dataPath)
57 switch ctx.Event.RawMessage {
58 case "创建轮盘赌":
59 if ss.GroupID == 0 {
60 return true
61 }
62 if ss.IsValid {
63 if ss.isExpire() {
64 ss.close()
65 return true
66 }
67 ctx.SendChain(message.Text("轮盘赌游戏已经开始了"))
68 return false
69 }
70 default:
71 if ss.GroupID != ctx.Event.GroupID {
72 return false
73 }
74 if ss.IsValid {
75 if ss.isExpire() {
76 ctx.SendChain(message.Text("轮盘赌游戏已过期, 请重新开始"))
77 ss.close()
78 return false
79 }
80 ctx.SendChain(message.Text("轮盘赌游戏已经开始了"))
81 return false
82 }
83 }
84 return true
85 }
86 // 创建轮盘赌
87 engine.OnFullMatch(`创建轮盘赌`, zero.OnlyGroup, checkSession).SetBlock(true).
88 Handle(func(ctx *zero.Ctx) {
89 gid := ctx.Event.GroupID
90 uid := ctx.Event.UserID
91
92 // 创建会话
93 addSession(gid, uid, dataPath)
94 ctx.SendChain(message.Text("游戏开始, 目前有1位玩家, 最多还能再加入2名玩家, 发送\"加入轮盘赌\"加入游戏"))
95 })
96
97 // 加入轮盘赌
98 engine.OnFullMatch("加入轮盘赌", zero.OnlyGroup, checkSession).SetBlock(true).
99 Handle(func(ctx *zero.Ctx) {
100 gid := ctx.Event.GroupID
101 uid := ctx.Event.UserID

Callers

nothing calls this directly

Calls 13

checkFileFunction · 0.85
getSessionFunction · 0.85
addSessionFunction · 0.85
getTruthOrDareFunction · 0.85
isExpireMethod · 0.80
closeMethod · 0.80
checkJoinMethod · 0.80
countUserMethod · 0.80
addUserMethod · 0.80
rotateUserMethod · 0.80
checkTurnMethod · 0.80
cartridgesLeftMethod · 0.80

Tested by

no test coverage detected