|
| 1 | +// Package dress 女装 |
| 2 | +package dress |
| 3 | + |
| 4 | +import ( |
| 5 | + "fmt" |
| 6 | + "math/rand" |
| 7 | + "strconv" |
| 8 | + "strings" |
| 9 | + "time" |
| 10 | + |
| 11 | + "github.com/FloatTech/floatbox/binary" |
| 12 | + ctrl "github.com/FloatTech/zbpctrl" |
| 13 | + "github.com/FloatTech/zbputils/control" |
| 14 | + "github.com/FloatTech/zbputils/ctxext" |
| 15 | + "github.com/FloatTech/zbputils/img/text" |
| 16 | + zero "github.com/wdvxdr1123/ZeroBot" |
| 17 | + "github.com/wdvxdr1123/ZeroBot/message" |
| 18 | +) |
| 19 | + |
| 20 | +func init() { // 插件主体 |
| 21 | + engine := control.Register("dress", &ctrl.Options[*zero.Ctx]{ |
| 22 | + DisableOnDefault: false, |
| 23 | + Brief: "女装", |
| 24 | + Help: "女装\n" + |
| 25 | + "- 女装\n" + |
| 26 | + "- 男装\n" + |
| 27 | + "- 随机女装\n" + |
| 28 | + "- 随机男装", |
| 29 | + PrivateDataFolder: "dress", |
| 30 | + }) |
| 31 | + engine.OnFullMatchGroup([]string{"女装", "男装"}).SetBlock(true). |
| 32 | + Handle(func(ctx *zero.Ctx) { |
| 33 | + matched := ctx.State["matched"].(string) |
| 34 | + sex := male |
| 35 | + if matched == "男装" { |
| 36 | + sex = female |
| 37 | + } |
| 38 | + next := zero.NewFutureEvent("message", 999, false, ctx.CheckSession()) |
| 39 | + recv, cancel := next.Repeat() |
| 40 | + defer cancel() |
| 41 | + nameList, err := dressList(sex) |
| 42 | + if err != nil { |
| 43 | + ctx.SendChain(message.Text("ERROR: ", err)) |
| 44 | + return |
| 45 | + } |
| 46 | + tex := "请输入" + matched + "序号\n" |
| 47 | + for i, v := range nameList { |
| 48 | + tex += fmt.Sprintf("%d. %s\n", i, v) |
| 49 | + } |
| 50 | + base64Str, err := text.RenderToBase64(tex, text.FontFile, 400, 20) |
| 51 | + if err != nil { |
| 52 | + ctx.SendChain(message.Text("ERROR: ", err)) |
| 53 | + return |
| 54 | + } |
| 55 | + ctx.SendChain(message.Image("base64://" + binary.BytesToString(base64Str))) |
| 56 | + for { |
| 57 | + select { |
| 58 | + case <-time.After(time.Second * 120): |
| 59 | + ctx.SendChain(message.Text(matched, "指令过期")) |
| 60 | + return |
| 61 | + case c := <-recv: |
| 62 | + msg := c.Event.Message.ExtractPlainText() |
| 63 | + num, err := strconv.Atoi(msg) |
| 64 | + if err != nil { |
| 65 | + ctx.SendChain(message.Text("请输入数字!")) |
| 66 | + continue |
| 67 | + } |
| 68 | + if num < 0 || num >= len(nameList) { |
| 69 | + ctx.SendChain(message.Text("序号非法!")) |
| 70 | + continue |
| 71 | + } |
| 72 | + name := nameList[num] |
| 73 | + sendImage(ctx, sex, matched, name) |
| 74 | + return |
| 75 | + } |
| 76 | + } |
| 77 | + }) |
| 78 | + engine.OnFullMatchGroup([]string{"随机女装", "随机男装"}).SetBlock(true). |
| 79 | + Handle(func(ctx *zero.Ctx) { |
| 80 | + matched := strings.TrimPrefix(ctx.State["matched"].(string), "随机") |
| 81 | + sex := male |
| 82 | + if matched == "男装" { |
| 83 | + sex = female |
| 84 | + } |
| 85 | + nameList, err := dressList(sex) |
| 86 | + if err != nil { |
| 87 | + ctx.SendChain(message.Text("ERROR: ", err)) |
| 88 | + return |
| 89 | + } |
| 90 | + name := nameList[rand.Intn(len(nameList))] |
| 91 | + sendImage(ctx, sex, matched, name) |
| 92 | + }) |
| 93 | +} |
| 94 | + |
| 95 | +func sendImage(ctx *zero.Ctx, sex, matched, name string) { |
| 96 | + ctx.SendChain(message.Text("请欣赏", matched, ": ", name)) |
| 97 | + count, err := detail(sex, name) |
| 98 | + if err != nil { |
| 99 | + ctx.SendChain(message.Text("ERROR: ", err)) |
| 100 | + return |
| 101 | + } |
| 102 | + imageList := make([]string, count) |
| 103 | + for i := range imageList { |
| 104 | + imageList[i] = fmt.Sprintf(dressImageURL, sex, name, i+1) |
| 105 | + } |
| 106 | + m := message.Message{} |
| 107 | + for _, v := range imageList { |
| 108 | + m = append(m, ctxext.FakeSenderForwardNode(ctx, message.Image(v))) |
| 109 | + } |
| 110 | + if id := ctx.Send(m).ID(); id == 0 { |
| 111 | + ctx.SendChain(message.Text("ERROR: 可能被风控或下载图片用时过长,请耐心等待")) |
| 112 | + } |
| 113 | +} |
0 commit comments