|
| 1 | +package poker |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "math/rand" |
| 6 | + |
| 7 | + fcext "github.com/FloatTech/floatbox/ctxext" |
| 8 | + ctrl "github.com/FloatTech/zbpctrl" |
| 9 | + "github.com/FloatTech/zbputils/control" |
| 10 | + "github.com/FloatTech/zbputils/ctxext" |
| 11 | + zero "github.com/wdvxdr1123/ZeroBot" |
| 12 | + "github.com/wdvxdr1123/ZeroBot/message" |
| 13 | +) |
| 14 | + |
| 15 | +// 图片来源 https://www.bilibili.com/opus/834601953403076633 |
| 16 | + |
| 17 | +var cardImgPathList []string |
| 18 | + |
| 19 | +func init() { |
| 20 | + engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{ |
| 21 | + DisableOnDefault: false, |
| 22 | + Brief: "抽扑克牌", |
| 23 | + Help: "- 抽扑克\n- poker", |
| 24 | + PublicDataFolder: "Poker", |
| 25 | + }).ApplySingle(ctxext.DefaultSingle) |
| 26 | + |
| 27 | + getImg := fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool { |
| 28 | + data, err := engine.GetLazyData("imgdata.json", true) |
| 29 | + if err != nil { |
| 30 | + ctx.SendChain(message.Text("ERROR:", err)) |
| 31 | + return false |
| 32 | + } |
| 33 | + err = json.Unmarshal(data, &cardImgPathList) |
| 34 | + if err != nil { |
| 35 | + ctx.SendChain(message.Text("ERROR:", err)) |
| 36 | + return false |
| 37 | + } |
| 38 | + return true |
| 39 | + }) |
| 40 | + |
| 41 | + engine.OnFullMatchGroup([]string{"抽扑克", "poker"}, getImg).SetBlock(true). |
| 42 | + Handle(func(ctx *zero.Ctx) { |
| 43 | + randomIndex := rand.Intn(len(cardImgPathList)) |
| 44 | + randomImgPath := cardImgPathList[randomIndex] |
| 45 | + imgData, err := engine.GetLazyData(randomImgPath, true) |
| 46 | + if err != nil { |
| 47 | + ctx.Send("[poker]读取扑克图片失败") |
| 48 | + return |
| 49 | + } |
| 50 | + ctx.Send(message.ImageBytes(imgData)) |
| 51 | + }) |
| 52 | +} |
0 commit comments