From 187c5cf0e823e70128697d52b6fdf21d423f7f97 Mon Sep 17 00:00:00 2001 From: RicheyJang <773602577@qq.com> Date: Sun, 13 Mar 2022 16:23:41 +0800 Subject: [PATCH] fix: resource for sunday --- plugins/genshin/genshin_resource/genshin.pub.go | 13 +++++++++++++ plugins/genshin/genshin_resource/resource.go | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/genshin/genshin_resource/genshin.pub.go b/plugins/genshin/genshin_resource/genshin.pub.go index 8a7c7ce..dfaf9a2 100644 --- a/plugins/genshin/genshin_resource/genshin.pub.go +++ b/plugins/genshin/genshin_resource/genshin.pub.go @@ -5,11 +5,24 @@ import ( "io/ioutil" "time" + "github.com/RicheyJang/PaimengBot/utils/images" + "github.com/chromedp/chromedp" log "github.com/sirupsen/logrus" ) func getTodayResourceByGenshinPub(file string) (err error) { + // 周日特判 + if time.Now().Weekday() == time.Sunday { + str := "今日素材:周日,什么都能打!" + img := images.NewImageCtxWithBGColor(1000, 100, resourcePicBGColor) + err = img.PasteStringDefault(str, 32, 1.3, 30, 40, 500) + if err != nil { + return err + } + return img.SavePNG(file) + } + // 正常工作日 for i := 0; i < 3; i++ { // 最多尝试3次 err = tryGetGenshinPubResourceShot(file) if err == nil { // 直到成功 diff --git a/plugins/genshin/genshin_resource/resource.go b/plugins/genshin/genshin_resource/resource.go index e0aee8e..e63c876 100644 --- a/plugins/genshin/genshin_resource/resource.go +++ b/plugins/genshin/genshin_resource/resource.go @@ -93,6 +93,8 @@ var snapshotFunctions = []func(filename string) error{ getTodayEventByMhyObc, // 1 通过米游社的观测枢获取今日活动进展图 } +const resourcePicBGColor = "#f6f2ee" + // 获取今日素材图片文件(会强制替换已有文件) func getTodayResource() (filename string, err error) { filename, err = getTodayResourceFilename() @@ -128,7 +130,7 @@ func getTodayResource() (filename string, err error) { if len(srcFilenames) == 0 { return "", fmt.Errorf("no snapshot success") } else { // 有至少一个截图成功了 - err = images.MergeImageFile("#f6f2ee", filename, srcFilenames...) + err = images.MergeImageFile(resourcePicBGColor, filename, srcFilenames...) if err != nil { log.Errorf("MergeImageFile err: %v", err) return filename, err