mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
✨ 抽n张塔罗牌
This commit is contained in:
parent
b8a6e07095
commit
a166d06096
@ -33,12 +33,13 @@ 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张塔罗牌",
|
||||||
// TODO 抽X张塔罗牌 解塔罗牌[牌名]
|
// TODO 抽X张塔罗牌 解塔罗牌[牌名]
|
||||||
PublicDataFolder: "Tarot",
|
PublicDataFolder: "Tarot",
|
||||||
}).ApplySingle(ctxext.DefaultSingle)
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
|
|
||||||
engine.OnFullMatch("抽塔罗牌", ctxext.DoOnceOnSuccess(
|
engine.OnRegex(`^抽(\d{1,3}张)?塔罗牌$`, ctxext.DoOnceOnSuccess(
|
||||||
func(ctx *zero.Ctx) bool {
|
func(ctx *zero.Ctx) bool {
|
||||||
data, err := engine.GetLazyData("tarots.json", true)
|
data, err := engine.GetLazyData("tarots.json", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -47,14 +48,53 @@ func init() {
|
|||||||
}
|
}
|
||||||
err = json.Unmarshal(data, &cardMap)
|
err = json.Unmarshal(data, &cardMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap))
|
logrus.Infof("[tarot]读取%d张塔罗牌", len(cardMap))
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
i := ctxext.RandSenderPerDayN(ctx, 22)
|
match := ctx.State["regex_matched"].([]string)[1]
|
||||||
p := ctxext.RandSenderPerDayN(ctx, 2)
|
n := 1
|
||||||
|
if match != "" {
|
||||||
|
var err error
|
||||||
|
n, err = strconv.Atoi(match[:len(match)-3])
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n <= 0 {
|
||||||
|
ctx.SendChain(message.Text("ERROR:张数必须为正"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n > 1 && !zero.OnlyGroup(ctx) {
|
||||||
|
ctx.SendChain(message.Text("ERROR:抽取多张仅支持群聊"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n > 20 {
|
||||||
|
ctx.SendChain(message.Text("ERROR:抽取张数过多"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if n == 1 {
|
||||||
|
if id := ctx.Send(randTarot()); id.ID() == 0 {
|
||||||
|
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
msg := make([]message.MessageSegment, n)
|
||||||
|
for i := range msg {
|
||||||
|
msg[i] = ctxext.FakeSenderForwardNode(ctx, randTarot()...)
|
||||||
|
}
|
||||||
|
ctx.SendGroupForwardMessage(ctx.Event.GroupID, msg)
|
||||||
|
return
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func randTarot() []message.MessageSegment {
|
||||||
|
i := rand.Intn(22)
|
||||||
|
p := rand.Intn(2)
|
||||||
card := cardMap[(strconv.Itoa(i))]
|
card := cardMap[(strconv.Itoa(i))]
|
||||||
name := card.Name
|
name := card.Name
|
||||||
var info string
|
var info string
|
||||||
@ -63,13 +103,9 @@ func init() {
|
|||||||
} else {
|
} else {
|
||||||
info = card.Info.ReverseDescription
|
info = card.Info.ReverseDescription
|
||||||
}
|
}
|
||||||
if id := ctx.SendChain(
|
return []message.MessageSegment{
|
||||||
message.At(ctx.Event.UserID),
|
|
||||||
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
message.Text(reasons[rand.Intn(len(reasons))], position[p], " 的 ", name, "\n"),
|
||||||
message.Image(fmt.Sprintf(bed+"MajorArcana/%d.png", i)),
|
message.Image(fmt.Sprintf(bed+"MajorArcana/%d.png", i)),
|
||||||
message.Text("\n其意义为: ", info),
|
message.Text("\n其意义为: ", info),
|
||||||
); id.ID() == 0 {
|
|
||||||
ctx.SendChain(message.Text("ERROR:可能被风控了"))
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user