mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-23 09:40:04 +08:00
feat:解塔罗牌 (#217)
This commit is contained in:
parent
5081aab497
commit
6b56d6649e
@ -807,6 +807,7 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
|
|
||||||
- [x] 抽塔罗牌
|
- [x] 抽塔罗牌
|
||||||
- [x] 抽n张塔罗牌
|
- [x] 抽n张塔罗牌
|
||||||
|
- [x] 解塔罗牌[牌名]
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
@ -15,27 +16,29 @@ import (
|
|||||||
|
|
||||||
const bed = "https://gitcode.net/shudorcl/zbp-tarot/-/raw/master/"
|
const bed = "https://gitcode.net/shudorcl/zbp-tarot/-/raw/master/"
|
||||||
|
|
||||||
type card struct {
|
type cardInfo struct {
|
||||||
Name string `json:"name"`
|
|
||||||
Info struct {
|
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
ReverseDescription string `json:"reverseDescription"`
|
ReverseDescription string `json:"reverseDescription"`
|
||||||
ImgURL string `json:"imgUrl"`
|
ImgURL string `json:"imgUrl"`
|
||||||
} `json:"info"`
|
|
||||||
}
|
}
|
||||||
type cardset = map[string]card
|
type card struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
cardInfo `json:"info"`
|
||||||
|
}
|
||||||
|
type cardSet = map[string]card
|
||||||
|
|
||||||
var cardMap = make(cardset, 256)
|
var cardMap = make(cardSet, 30)
|
||||||
var reasons = [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
|
var infoMap = make(map[string]cardInfo, 30)
|
||||||
var position = [...]string{"正位", "逆位"}
|
|
||||||
|
// var cardName = make([]string, 22)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
engine := control.Register("tarot", &control.Options{
|
engine := control.Register("tarot", &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "塔罗牌\n" +
|
Help: "塔罗牌\n" +
|
||||||
"- 抽塔罗牌\n" +
|
"- 抽塔罗牌\n" +
|
||||||
"- 抽n张塔罗牌",
|
"- 抽n张塔罗牌\n" +
|
||||||
// TODO 抽X张塔罗牌 解塔罗牌[牌名]
|
"- 解塔罗牌[牌名]",
|
||||||
PublicDataFolder: "Tarot",
|
PublicDataFolder: "Tarot",
|
||||||
}).ApplySingle(ctxext.DefaultSingle)
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
|
|
||||||
@ -57,6 +60,9 @@ func init() {
|
|||||||
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
match := ctx.State["regex_matched"].([]string)[1]
|
match := ctx.State["regex_matched"].([]string)[1]
|
||||||
n := 1
|
n := 1
|
||||||
|
reasons := [...]string{"您抽到的是~\n", "锵锵锵,塔罗牌的预言是~\n", "诶,让我看看您抽到了~\n"}
|
||||||
|
position := [...]string{"正位", "逆位"}
|
||||||
|
reverse := [...]string{"", "Reverse"}
|
||||||
if match != "" {
|
if match != "" {
|
||||||
var err error
|
var err error
|
||||||
n, err = strconv.Atoi(match[:len(match)-3])
|
n, err = strconv.Atoi(match[:len(match)-3])
|
||||||
@ -78,34 +84,82 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n == 1 {
|
if n == 1 {
|
||||||
if id := ctx.Send(randTarot()); id.ID() == 0 {
|
i := rand.Intn(22)
|
||||||
|
p := rand.Intn(2)
|
||||||
|
card := cardMap[(strconv.Itoa(i))]
|
||||||
|
name := card.Name
|
||||||
|
if id := ctx.SendChain(
|
||||||
|
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
||||||
|
message.Image(fmt.Sprintf(bed+"MajorArcana%s/%d.png", reverse[p], i))); id.ID() == 0 {
|
||||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
msg := make([]message.MessageSegment, n)
|
msg := make([]message.MessageSegment, n)
|
||||||
|
randomIntMap := make(map[int]int, 30)
|
||||||
for i := range msg {
|
for i := range msg {
|
||||||
msg[i] = ctxext.FakeSenderForwardNode(ctx, randTarot()...)
|
j := rand.Intn(22)
|
||||||
|
_, ok := randomIntMap[j]
|
||||||
|
for ok {
|
||||||
|
j = rand.Intn(22)
|
||||||
|
_, ok = randomIntMap[j]
|
||||||
|
}
|
||||||
|
randomIntMap[j] = 0
|
||||||
|
p := rand.Intn(2)
|
||||||
|
card := cardMap[(strconv.Itoa(j))]
|
||||||
|
name := card.Name
|
||||||
|
tarotMsg := []message.MessageSegment{
|
||||||
|
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
||||||
|
message.Image(fmt.Sprintf(bed+"MajorArcana%s/%d.png", reverse[p], j))}
|
||||||
|
msg[i] = ctxext.FakeSenderForwardNode(ctx, tarotMsg...)
|
||||||
}
|
}
|
||||||
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
func randTarot() []message.MessageSegment {
|
engine.OnRegex(`^解塔罗牌\s?(.*)`, ctxext.DoOnceOnSuccess(
|
||||||
i := rand.Intn(22)
|
func(ctx *zero.Ctx) bool {
|
||||||
p := rand.Intn(2)
|
if len(cardMap) > 0 {
|
||||||
card := cardMap[(strconv.Itoa(i))]
|
for _, card := range cardMap {
|
||||||
name := card.Name
|
infoMapKey := strings.Split(card.Name, "(")[0]
|
||||||
var info string
|
infoMap[infoMapKey] = card.cardInfo
|
||||||
if p == 0 {
|
// 可以拿来显示大阿尔卡纳列表
|
||||||
info = card.Info.Description
|
// cardName = append(cardName, infoMapKey)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
tempMap := make(cardSet, 30)
|
||||||
|
data, err := engine.GetLazyData("tarots.json", true)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(data, &tempMap)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, card := range tempMap {
|
||||||
|
infoMapKey := strings.Split(card.Name, "(")[0]
|
||||||
|
infoMap[infoMapKey] = card.cardInfo
|
||||||
|
// 可以拿来显示大阿尔卡纳列表
|
||||||
|
// cardName = append(cardName, infoMapKey)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
|
match := ctx.State["regex_matched"].([]string)[1]
|
||||||
|
info, ok := infoMap[match]
|
||||||
|
if ok {
|
||||||
|
ctx.SendChain(
|
||||||
|
message.Image(bed+info.ImgURL),
|
||||||
|
message.Text("\n", match, "的含义是~"),
|
||||||
|
message.Text("\n正位:", info.Description),
|
||||||
|
message.Text("\n逆位:", info.ReverseDescription))
|
||||||
} else {
|
} else {
|
||||||
info = card.Info.ReverseDescription
|
ctx.SendChain(message.Text("没有找到", match, "噢~"))
|
||||||
}
|
|
||||||
return []message.MessageSegment{
|
|
||||||
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
|
||||||
message.Image(fmt.Sprintf(bed+"MajorArcana/%d.png", i)),
|
|
||||||
message.Text("\n其意义为: ", info),
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user