@@ -25,19 +25,28 @@ var (
2525 Brief : "从老婆库抽每日老婆" ,
2626 PublicDataFolder : "Wife" ,
2727 }).ApplySingle (ctxext .DefaultSingle )
28+
2829 getJSON = fcext .DoOnceOnSuccess (
2930 func (ctx * zero.Ctx ) bool {
31+ // 1. 优先尝试从镜像站更新同步
3032 data , err := engine .GetLazyData ("wife.json" , true )
3133 if err != nil {
32- ctx .SendChain (message .Text ("ERROR: " , err ))
33- return false
34+ // 2. 如果下载失败(如 MD5 不匹配),尝试直接读取本地已有文件
35+ logrus .Warnf ("[wife] 远程同步 wife.json 失败: %v,正在尝试读取本地缓存..." , err )
36+ data , err = engine .GetLazyData ("wife.json" , false )
37+ if err != nil {
38+ // 3. 本地也没有或读取失败才彻底报错
39+ ctx .SendChain (message .Text ("ERROR: 无法获取老婆库数据(同步及本地读取均失败): " , err ))
40+ return false
41+ }
3442 }
43+
3544 err = json .Unmarshal (data , & cards )
3645 if err != nil {
37- ctx .SendChain (message .Text ("ERROR: " , err ))
46+ ctx .SendChain (message .Text ("ERROR: 老婆库格式解析失败: " , err ))
3847 return false
3948 }
40- logrus .Infof ("[wife]加载%d个老婆 " , len (cards ))
49+ logrus .Infof ("[wife] 已成功加载 %d 个老婆 " , len (cards ))
4150 return true
4251 },
4352 )
@@ -56,6 +65,7 @@ func init() {
5665 engine .OnFullMatch ("抽老婆" , getJSON ).SetBlock (true ).
5766 Handle (func (ctx * zero.Ctx ) {
5867 card := cards [fcext .RandSenderPerDayN (ctx .Event .UserID , len (cards ))]
68+ // 图片获取同样可以考虑增加非强制下载逻辑,但通常图片 MD5 报错较少
5969 data , err := engine .GetLazyData ("wives/" + card , true )
6070 var msgText string
6171 work , name := card2name (card )
0 commit comments