@@ -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+ }
3038type cardSet = map [string ]card
3139
3240var cardMap = make (cardSet , 30 )
3341var 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
3747func 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