Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:Tarot #1032

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,8 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] 今日老婆[@xxx]

- [x] 黄油角色[@xxx]

- [x] 娘化穿越到异世界[@xxx]

</details>
<details>
Expand Down
2 changes: 1 addition & 1 deletion data
Submodule data updated 157 files
4 changes: 3 additions & 1 deletion plugin/shindan/shindan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ func init() {
"- 异世界转生[@xxx]\n" +
"- 卖萌[@xxx]\n" +
"- 今日老婆[@xxx]\n" +
"- 黄油角色[@xxx]",
"- 黄油角色[@xxx]\n" +
"- 娘化穿越到异世界[@xxx]",
})
engine.OnPrefix("异世界转生", number(587874)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlepic)
engine.OnPrefix("今天是什么少女", number(162207)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlepic)
engine.OnPrefix("卖萌", number(360578)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handletxt)
engine.OnPrefix("今日老婆", number(1075116)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlecq)
engine.OnPrefix("黄油角色", number(1115465)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlepic)
engine.OnPrefix("娘化穿越到异世界", number(637918)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlepic)
}

func handletxt(ctx *zero.Ctx) {
Expand Down
81 changes: 16 additions & 65 deletions plugin/tarot/tarot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,15 @@

"github.com/FloatTech/floatbox/binary"
fcext "github.com/FloatTech/floatbox/ctxext"
"github.com/FloatTech/floatbox/file"
"github.com/FloatTech/floatbox/process"
"github.com/FloatTech/floatbox/web"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/img/pool"
"github.com/FloatTech/zbputils/img/text"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

const bed = "https://gitcode.net/shudorcl/zbp-tarot/-/raw/master/"

type cardInfo struct {
Description string `json:"description"`
ReverseDescription string `json:"reverseDescription"`
Expand Down Expand Up @@ -140,31 +134,14 @@
if p == 1 {
description = card.ReverseDescription
}
imgurl := bed + reverse[p] + card.ImgURL
imgname := ""
if p == 1 {
imgname = reverse[p][:len(reverse[p])-1] + name
} else {
imgname = name
}
imgpath := cache + "/" + imgname + ".png"
err := pool.SendImageFromPool(imgpath, func(pth string) error {
data, err := web.RequestDataWith(web.NewTLS12Client(), imgurl, "GET", "gitcode.net", web.RandUA(), nil)
if err != nil {
return err
}
f, err := os.Create(pth)
if err != nil {
return err
}
defer f.Close()
return os.WriteFile(f.Name(), data, 0755)
}, ctxext.Send(ctx))
imgurl := reverse[p] + card.ImgURL
logrus.Infof("尝试获取图片: " + imgurl)

Check failure on line 138 in plugin/tarot/tarot.go

View workflow job for this annotation

GitHub Actions / lint

printf: non-constant format string in call to github.com/sirupsen/logrus.Infof (govet)
data, err := engine.GetLazyData(imgurl, true)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
process.SleepAbout1sTo2s()
ctx.SendChain(message.ImageBytes(data))
ctx.SendChain(message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n其释义为: ", description))
return
}
Expand All @@ -185,15 +162,13 @@
if p == 1 {
description = card.ReverseDescription
}
imgurl := bed + reverse[p] + card.ImgURL
imgurl := reverse[p] + card.ImgURL
tarotmsg := message.Message{message.Text(reasons[rand.Intn(len(reasons))], position[p], "的『", name, "』\n")}
var imgmsg message.MessageSegment
var err error
if p == 1 {
imgmsg, err = poolimg(imgurl, reverse[p][:len(reverse[p])-1]+name, cache)
} else {
imgmsg, err = poolimg(imgurl, name, cache)
}
logrus.Infof("尝试获取图片: " + imgurl)

Check failure on line 169 in plugin/tarot/tarot.go

View workflow job for this annotation

GitHub Actions / lint

printf: non-constant format string in call to github.com/sirupsen/logrus.Infof (govet)
data, err := engine.GetLazyData(imgurl, true)
imgmsg = message.ImageBytes(data)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
Expand All @@ -211,9 +186,11 @@
match := ctx.State["regex_matched"].([]string)[1]
info, ok := infoMap[match]
if ok {
imgurl := bed + info.ImgURL
imgurl := info.ImgURL
var tarotmsg message.Message
imgmsg, err := poolimg(imgurl, match, cache)
logrus.Infof("尝试获取图片: " + imgurl)

Check failure on line 191 in plugin/tarot/tarot.go

View workflow job for this annotation

GitHub Actions / lint

printf: non-constant format string in call to github.com/sirupsen/logrus.Infof (govet)
data, err := engine.GetLazyData(imgurl, true)
imgmsg := message.ImageBytes(data)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
Expand Down Expand Up @@ -280,14 +257,12 @@
description = card.ReverseDescription
}
var tarotmsg message.Message
imgurl := bed + reverse[p] + card.ImgURL
imgurl := reverse[p] + card.ImgURL
var imgmsg message.MessageSegment
var err error
if p == 1 {
imgmsg, err = poolimg(imgurl, reverse[p][:len(reverse[p])-1]+name, cache)
} else {
imgmsg, err = poolimg(imgurl, name, cache)
}
logrus.Infof("尝试获取图片: " + imgurl)
data, err := engine.GetLazyData(imgurl, true)
imgmsg = message.ImageBytes(data)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
Expand Down Expand Up @@ -318,27 +293,3 @@
}
})
}

func poolimg(imgurl, imgname, cache string) (msg message.MessageSegment, err error) {
imgfile := cache + "/" + imgname + ".png"
aimgfile := file.BOTPATH + "/" + imgfile
if file.IsNotExist(aimgfile) {
var data []byte
data, err = web.RequestDataWith(web.NewTLS12Client(), imgurl, "GET", "gitcode.net", web.RandUA(), nil)
if err != nil {
return
}
var f *os.File
f, err = os.Create(imgfile)
if err != nil {
return
}
defer f.Close()
err = os.WriteFile(f.Name(), data, 0755)
if err != nil {
return
}
}
msg = message.Image("file:///" + aimgfile)
return
}
Loading