fix tarot

This commit is contained in:
源文雨 2022-10-22 12:12:46 +08:00
parent a0df41b859
commit cbb4408668

View File

@ -11,6 +11,7 @@ import (
"github.com/FloatTech/floatbox/binary" "github.com/FloatTech/floatbox/binary"
fcext "github.com/FloatTech/floatbox/ctxext" fcext "github.com/FloatTech/floatbox/ctxext"
"github.com/FloatTech/floatbox/file" "github.com/FloatTech/floatbox/file"
"github.com/FloatTech/floatbox/process"
"github.com/FloatTech/floatbox/web" "github.com/FloatTech/floatbox/web"
ctrl "github.com/FloatTech/zbpctrl" ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/control"
@ -140,23 +141,32 @@ func init() {
description = card.ReverseDescription description = card.ReverseDescription
} }
imgurl := bed + reverse[p] + card.ImgURL imgurl := bed + reverse[p] + card.ImgURL
tarotmsg := message.Message{message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n")} imgname := ""
var imgmsg message.MessageSegment imgpath := cache + "/" + imgname + ".png"
var err error
if p == 1 { if p == 1 {
imgmsg, err = poolimg(ctx, imgurl, reverse[p][:len(reverse[p])-1]+card.Name, cache) imgname = reverse[p][:len(reverse[p])-1] + card.Name
} else { } else {
imgmsg, err = poolimg(ctx, imgurl, card.Name, cache) imgname = card.Name
} }
err := pool.SendImageFromPool(imgname, imgpath, func() error {
data, err := web.RequestDataWith(web.NewTLS12Client(), imgurl, "GET", "gitcode.net", web.RandUA())
if err != nil {
return err
}
var f *os.File
f, err = os.Create(imgpath)
if err != nil {
return err
}
defer f.Close()
return os.WriteFile(f.Name(), data, 0755)
}, ctxext.Send(ctx), ctxext.GetMessage(ctx))
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR: ", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
tarotmsg = append(tarotmsg, imgmsg) process.SleepAbout1sTo2s()
tarotmsg = append(tarotmsg, message.Text("\n其释义为: ", description)) ctx.SendChain(message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n其释义为: ", description))
if id := ctx.Send(tarotmsg).ID(); id == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
}
return return
} }
msg := make(message.Message, n) msg := make(message.Message, n)
@ -214,7 +224,8 @@ func init() {
if id := ctx.Send(tarotmsg).ID(); id == 0 { if id := ctx.Send(tarotmsg).ID(); id == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了")) ctx.SendChain(message.Text("ERROR: 可能被风控了"))
} }
} else { return
}
var build strings.Builder var build strings.Builder
build.WriteString("塔罗牌列表\n大阿尔卡纳:\n") build.WriteString("塔罗牌列表\n大阿尔卡纳:\n")
build.WriteString(strings.Join(majorArcanaName[:7], " ")) build.WriteString(strings.Join(majorArcanaName[:7], " "))
@ -230,7 +241,6 @@ func init() {
return return
} }
ctx.SendChain(message.Text("没有找到", match, "噢~"), message.Image("base64://"+binary.BytesToString(cardList))) ctx.SendChain(message.Text("没有找到", match, "噢~"), message.Image("base64://"+binary.BytesToString(cardList)))
}
}) })
engine.OnRegex(`^((塔罗|大阿(尔)?卡纳)|小阿(尔)?卡纳|混合)牌阵\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) { engine.OnRegex(`^((塔罗|大阿(尔)?卡纳)|小阿(尔)?卡纳|混合)牌阵\s?(.*)`, getTarot).SetBlock(true).Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) {
cardType := ctx.State["regex_matched"].([]string)[1] cardType := ctx.State["regex_matched"].([]string)[1]