优化 ctx ERROR

This commit is contained in:
源文雨 2023-03-25 20:23:56 +08:00
parent 1aa11879dc
commit 0c8dfb3f9c
3 changed files with 11 additions and 11 deletions

View File

@ -29,7 +29,7 @@ func init() {
} }
picURL := gjson.Get(binary.BytesToString(data), "imageUrl").String() picURL := gjson.Get(binary.BytesToString(data), "imageUrl").String()
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
ctx.SendChain(message.Image(picURL)) ctx.SendChain(message.Image(picURL))

View File

@ -55,7 +55,7 @@ func init() {
en.OnFullMatchGroup([]string{"抽签列表", "刷新抽签列表"}).SetBlock(true).Handle(func(ctx *zero.Ctx) { en.OnFullMatchGroup([]string{"抽签列表", "刷新抽签列表"}).SetBlock(true).Handle(func(ctx *zero.Ctx) {
lotsList, err := getList() // 刷新列表 lotsList, err := getList() // 刷新列表
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
messageText := &strings.Builder{} messageText := &strings.Builder{}
@ -67,7 +67,7 @@ func init() {
} }
textPic, err := text.RenderToBase64(messageText.String(), text.BoldFontFile, 400, 50) textPic, err := text.RenderToBase64(messageText.String(), text.BoldFontFile, 400, 50)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
ctx.SendChain(message.Image("base64://" + helper.BytesToString(textPic))) ctx.SendChain(message.Image("base64://" + helper.BytesToString(textPic)))
@ -82,7 +82,7 @@ func init() {
if fileInfo.lotsType == "folder" { if fileInfo.lotsType == "folder" {
picPath, err := randFile(lotsType, 3) picPath, err := randFile(lotsType, 3)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("file:///"+picPath)) ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Image("file:///"+picPath))
@ -90,13 +90,13 @@ func init() {
} }
lotsImg, err := randGif(lotsType + "." + fileInfo.lotsType) lotsImg, err := randGif(lotsType + "." + fileInfo.lotsType)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
// 生成图片 // 生成图片
data, err := imgfactory.ToBytes(lotsImg) data, err := imgfactory.ToBytes(lotsImg)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.ImageBytes(data)) ctx.SendChain(message.Reply(ctx.Event.MessageID), message.ImageBytes(data))
@ -129,13 +129,13 @@ func init() {
} }
im, err := gif.DecodeAll(bytes.NewReader(gifdata)) im, err := gif.DecodeAll(bytes.NewReader(gifdata))
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
fileName := datapath + "/" + lotsName + ".gif" fileName := datapath + "/" + lotsName + ".gif"
err = file.DownloadTo(picURL, fileName) err = file.DownloadTo(picURL, fileName)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
lotsList[lotsName] = info{ lotsList[lotsName] = info{
@ -158,7 +158,7 @@ func init() {
} }
err := os.Remove(datapath + lotsName + "." + fileInfo.lotsType) err := os.Remove(datapath + lotsName + "." + fileInfo.lotsType)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return return
} }
delete(lotsList, lotsName) delete(lotsList, lotsName)

View File

@ -25,12 +25,12 @@ func init() {
func(ctx *zero.Ctx) bool { func(ctx *zero.Ctx) bool {
data, err := engine.GetLazyData("wife.json", true) data, err := engine.GetLazyData("wife.json", true)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return false return false
} }
err = json.Unmarshal(data, &cards) err = json.Unmarshal(data, &cards)
if err != nil { if err != nil {
ctx.SendChain(message.Text("ERROR:", err)) ctx.SendChain(message.Text("ERROR: ", err))
return false return false
} }
logrus.Infof("[wife]加载%d个老婆", len(cards)) logrus.Infof("[wife]加载%d个老婆", len(cards))