()
| 42 | } |
| 43 | |
| 44 | func 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 |
nothing calls this directly
no test coverage detected