Skip to content

Commit a8d93de

Browse files
feat:塔罗牌阵 (#268)
* 优化在两个命令中使用空格分隔的体验 - fortune的设置底图功能 - b14的加密功能 * 优化四个插件中使用空格分隔的体验 - 加密 - 哔哩哔哩推送 - 藏头诗 - 运势 * 优化并修正了上一个commit - 加上了因为复制粘贴疏忽又没有注意测试遗漏的`?` - 调整藏头诗和加密的正则触发,使其不必多此一举 - 删去了未被发现的测试代码 * - 删去了遗漏的Trim * 优化了更多插件中使用空格的体验 - 优化了music bilibili image_finder 中使用空格的体验 - 补上了plugin_bilibili中未实现的vup开头触发 - 为plugin_bilibili_parse输出的消息加上一个换行符,优化排版 * - 调整funny - 补回readme中bilibili_push的注释说明 * - 简化funny说明 * - 用暴力的办法使抽多张塔罗牌不重复 - 逆位的图片现在可以倒过来了 * - 解塔罗牌 * - 修改readme * 大幅减少全局变量,简化抽塔罗牌输出 * - 更新了塔罗牌阵 * - 顺lint心意 - 添加判断避免重复装填 * 调整塔罗牌阵消息 - 用图片说明牌阵信息避免被封 * 调整DoOnceOnSuccess,减少冗余 * 🎨 改进代码样式 * 调整发送牌阵信息 * 🎨 改进代码样式 * 改回base64 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 2da5de3 commit a8d93de

2 files changed

Lines changed: 91 additions & 50 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ print("run[CQ:image,file="+j["img"]+"]")
862862
- [x] 抽塔罗牌
863863
- [x] 抽n张塔罗牌
864864
- [x] 解塔罗牌[牌名]
865+
- [x] 塔罗牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]"
865866

866867
</details>
867868
<details>

plugin/tarot/tarot.go

Lines changed: 90 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"strings"
1010

1111
ctrl "github.com/FloatTech/zbpctrl"
12+
"github.com/FloatTech/zbputils/binary"
1213
"github.com/FloatTech/zbputils/control"
1314
"github.com/FloatTech/zbputils/ctxext"
15+
"github.com/FloatTech/zbputils/img/text"
1416
"github.com/sirupsen/logrus"
1517
zero "github.com/wdvxdr1123/ZeroBot"
1618
"github.com/wdvxdr1123/ZeroBot/message"
@@ -27,39 +29,64 @@ type card struct {
2729
Name string `json:"name"`
2830
cardInfo `json:"info"`
2931
}
32+
33+
type formation struct {
34+
CardsNum int `json:"cards_num"`
35+
IsCut bool `json:"is_cut"`
36+
Represent [][]string `json:"represent"`
37+
}
3038
type cardSet = map[string]card
3139

3240
var cardMap = make(cardSet, 30)
3341
var infoMap = make(map[string]cardInfo, 30)
42+
var formationMap = make(map[string]formation, 10)
3443

35-
// var cardName = make([]string, 22)
44+
// var cardName = make([]string, 30)
45+
// var formationName = make([]string, 10)
3646

3747
func init() {
3848
engine := control.Register("tarot", &ctrl.Options[*zero.Ctx]{
3949
DisableOnDefault: false,
4050
Help: "塔罗牌\n" +
4151
"- 抽塔罗牌\n" +
4252
"- 抽n张塔罗牌\n" +
43-
"- 解塔罗牌[牌名]",
53+
"- 解塔罗牌[牌名]\n" +
54+
"- 塔罗牌阵[圣三角|时间之流|四要素|五牌阵|吉普赛十字|马蹄|六芒星]",
4455
PublicDataFolder: "Tarot",
4556
}).ApplySingle(ctxext.DefaultSingle)
4657

47-
engine.OnRegex(`^抽(\d{1,2}张)?塔罗牌$`, ctxext.DoOnceOnSuccess(
48-
func(ctx *zero.Ctx) bool {
49-
data, err := engine.GetLazyData("tarots.json", true)
50-
if err != nil {
51-
ctx.SendChain(message.Text("ERROR:", err))
52-
return false
53-
}
54-
err = json.Unmarshal(data, &cardMap)
55-
if err != nil {
56-
ctx.SendChain(message.Text("ERROR:", err))
57-
return false
58-
}
59-
logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap))
60-
return true
61-
},
62-
)).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
58+
getTarot := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
59+
data, err := engine.GetLazyData("tarots.json", true)
60+
if err != nil {
61+
ctx.SendChain(message.Text("ERROR:", err))
62+
return false
63+
}
64+
err = json.Unmarshal(data, &cardMap)
65+
if err != nil {
66+
ctx.SendChain(message.Text("ERROR:", err))
67+
return false
68+
}
69+
for _, card := range cardMap {
70+
infoMapKey := strings.Split(card.Name, "(")[0]
71+
infoMap[infoMapKey] = card.cardInfo
72+
// 可以拿来显示大阿尔卡纳列表
73+
// cardName = append(cardName, infoMapKey)
74+
}
75+
logrus.Infof("[tarot]读取%d张大阿尔卡纳塔罗牌", len(cardMap))
76+
formation, err := engine.GetLazyData("formation.json", true)
77+
if err != nil {
78+
ctx.SendChain(message.Text("ERROR:", err))
79+
return false
80+
}
81+
err = json.Unmarshal(formation, &formationMap)
82+
if err != nil {
83+
ctx.SendChain(message.Text("ERROR:", err))
84+
return false
85+
}
86+
logrus.Infof("[tarot]读取%d组塔罗牌阵", len(formationMap))
87+
return true
88+
})
89+
engine.OnRegex(`^抽(\d{1,2}张)?塔罗牌$`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
6390
match := ctx.State["regex_matched"].([]string)[1]
6491
n := 1
6592
reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
@@ -118,38 +145,7 @@ func init() {
118145
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
119146
})
120147

121-
engine.OnRegex(`^解塔罗牌\s?(.*)`, ctxext.DoOnceOnSuccess(
122-
func(ctx *zero.Ctx) bool {
123-
if len(cardMap) > 0 {
124-
for _, card := range cardMap {
125-
infoMapKey := strings.Split(card.Name, "(")[0]
126-
infoMap[infoMapKey] = card.cardInfo
127-
// 可以拿来显示大阿尔卡纳列表
128-
// cardName = append(cardName, infoMapKey)
129-
}
130-
return true
131-
}
132-
tempMap := make(cardSet, 30)
133-
data, err := engine.GetLazyData("tarots.json", true)
134-
if err != nil {
135-
ctx.SendChain(message.Text("ERROR:", err))
136-
return false
137-
}
138-
err = json.Unmarshal(data, &tempMap)
139-
if err != nil {
140-
ctx.SendChain(message.Text("ERROR:", err))
141-
return false
142-
}
143-
144-
for _, card := range tempMap {
145-
infoMapKey := strings.Split(card.Name, "(")[0]
146-
infoMap[infoMapKey] = card.cardInfo
147-
// 可以拿来显示大阿尔卡纳列表
148-
// cardName = append(cardName, infoMapKey)
149-
}
150-
return true
151-
},
152-
)).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
148+
engine.OnRegex(`^解塔罗牌\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
153149
match := ctx.State["regex_matched"].([]string)[1]
154150
info, ok := infoMap[match]
155151
if ok {
@@ -162,4 +158,48 @@ func init() {
162158
ctx.SendChain(message.Text("没有找到", match, "噢~"))
163159
}
164160
})
161+
engine.OnRegex(`^塔罗牌阵\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
162+
match := ctx.State["regex_matched"].([]string)[1]
163+
info, ok := formationMap[match]
164+
position := [...]string{"正位", "逆位"}
165+
reverse := [...]string{"", "Reverse"}
166+
if ok {
167+
var build strings.Builder
168+
build.WriteString(ctx.CardOrNickName(ctx.Event.UserID))
169+
build.WriteString("\n")
170+
msg := make([]message.MessageSegment, info.CardsNum)
171+
randomIntMap := make(map[int]int, 30)
172+
for i := range msg {
173+
j := rand.Intn(22)
174+
_, ok := randomIntMap[j]
175+
for ok {
176+
j = rand.Intn(22)
177+
_, ok = randomIntMap[j]
178+
}
179+
randomIntMap[j] = 0
180+
p := rand.Intn(2)
181+
card := cardMap[(strconv.Itoa(j))]
182+
name := card.Name
183+
tarotMsg := []message.MessageSegment{message.Image(fmt.Sprintf(bed+"MajorArcana%s/%d.png", reverse[p], j))}
184+
build.WriteString(info.Represent[0][i])
185+
build.WriteString(": ")
186+
build.WriteString(position[p])
187+
build.WriteString(" 的 ")
188+
build.WriteString(name)
189+
build.WriteString("\n")
190+
msg[i] = ctxext.FakeSenderForwardNode(ctx, tarotMsg...)
191+
}
192+
txt := build.String()
193+
formation, err := text.RenderToBase64(txt, text.FontFile, 400, 20)
194+
if err != nil {
195+
ctx.SendChain(message.Text("ERROR:", err))
196+
return
197+
}
198+
// TODO 视gocq变化将牌阵信息加入转发列表中
199+
ctx.SendChain(message.Image("base64://" + binary.BytesToString(formation)))
200+
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
201+
} else {
202+
ctx.SendChain(message.Text("没有找到", match, "噢~"))
203+
}
204+
})
165205
}

0 commit comments

Comments
 (0)