Skip to content

Commit b5fc36c

Browse files
authored
Implement fallback for image loading in wifegame
Added a fallback mechanism for loading images in the guessing game, attempting local file retrieval if remote download fails.
1 parent b05358d commit b5fc36c

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

plugin/wife/wifegame.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/wdvxdr1123/ZeroBot/message"
1616

1717
"github.com/FloatTech/imgfactory"
18+
"github.com/sirupsen/logrus"
1819
)
1920

2021
var (
@@ -31,24 +32,32 @@ func init() {
3132
class := 3
3233

3334
card := cards[rand.Intn(len(cards))]
35+
36+
// --- 修改部分:增加图片加载的回退机制 ---
3437
pic, err := engine.GetLazyData("wives/"+card, true)
3538
if err != nil {
36-
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
37-
return
39+
logrus.Warnf("[wife] 猜老婆图片同步失败: %v,尝试读取本地文件...", err)
40+
pic, err = engine.GetLazyData("wives/"+card, false)
41+
if err != nil {
42+
ctx.SendChain(message.Text("[猜老婆] 远程下载及本地读取图片均失败:\n", err))
43+
return
44+
}
3845
}
46+
// ------------------------------------
47+
3948
work, name := card2name(card)
4049
name = strings.ToLower(name)
4150
img, _, err := image.Decode(bytes.NewReader(pic))
4251
if err != nil {
43-
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
52+
ctx.SendChain(message.Text("[猜老婆] 图片解码失败:\n", err))
4453
return
4554
}
4655
dst := imgfactory.Size(img, img.Bounds().Dx(), img.Bounds().Dy())
4756
q, err := mosaic(dst, class)
4857
if err != nil {
4958
ctx.SendChain(
5059
message.Reply(ctx.Event.MessageID),
51-
message.Text("[猜老婆]图片生成失败:\n", err),
60+
message.Text("[猜老婆] 磨砂图片生成失败:\n", err),
5261
)
5362
return
5463
}
@@ -80,8 +89,6 @@ func init() {
8089
)
8190
return
8291
case c := <-recv:
83-
// tick.Reset(105 * time.Second)
84-
// after.Reset(120 * time.Second)
8592
msg := strings.ReplaceAll(c.Event.Message.String(), "酱", "")
8693
if msg == "" {
8794
continue

0 commit comments

Comments
 (0)