Skip to content

Commit ed7cef7

Browse files
authored
添加随机女装 (#514)
1 parent 3349ec7 commit ed7cef7

File tree

4 files changed

+168
-1
lines changed

4 files changed

+168
-1
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,20 @@ print("run[CQ:image,file="+j["img"]+"]")
633633

634634
- [x] 教你一篇小作文[作文]
635635

636+
</details>
637+
<details>
638+
<summary>女装</summary>
639+
640+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/dress"`
641+
642+
- [x] 女装
643+
644+
- [x] 男装
645+
646+
- [x] 随机女装
647+
648+
- [x] 随机男装
649+
636650
</details>
637651
<details>
638652
<summary>漂流瓶</summary>

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import (
7878
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cpstory" // cp短打
7979
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/danbooru" // DeepDanbooru二次元图标签识别
8080
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/diana" // 嘉心糖发病
81+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/dress" // 女装
8182
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/drift_bottle" // 漂流瓶
8283
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/emojimix" // 合成emoji
8384
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/epidemic" // 城市疫情查询
@@ -136,7 +137,7 @@ import (
136137
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenxinAI" // 百度文心AI画图
137138
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/word_count" // 聊天热词
138139
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
139-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ygo" // 游戏王相关插件
140+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ygo" // 游戏王相关插件
140141
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame
141142

142143
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/wtf" // 鬼东西

plugin/dress/api.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dress
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/FloatTech/floatbox/web"
7+
"github.com/tidwall/gjson"
8+
)
9+
10+
const (
11+
dressURL = "http://www.yoooooooooo.com/gitdress"
12+
male = "dress"
13+
female = "girldress"
14+
dressListURL = dressURL + "/%v/album/list.json"
15+
dressDetailURL = dressURL + "/%v/album/%v/info.json"
16+
dressImageURL = dressURL + "/%v/album/%v/%v-m.webp"
17+
)
18+
19+
func dressList(sex string) (dressList []string, err error) {
20+
data, err := web.GetData(fmt.Sprintf(dressListURL, sex))
21+
if err != nil {
22+
return
23+
}
24+
arr := gjson.ParseBytes(data).Get("@this").Array()
25+
dressList = make([]string, len(arr))
26+
for i, v := range arr {
27+
dressList[i] = v.String()
28+
}
29+
return
30+
}
31+
32+
func detail(sex, name string) (count int, err error) {
33+
data, err := web.GetData(fmt.Sprintf(dressDetailURL, sex, name))
34+
if err != nil {
35+
return
36+
}
37+
count = int(gjson.ParseBytes(data).Get("@this.#").Int())
38+
return
39+
}

plugin/dress/dress.go

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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

Comments
 (0)