Skip to content

Commit

Permalink
fix: resource for sunday
Browse files Browse the repository at this point in the history
  • Loading branch information
RicheyJang committed Mar 13, 2022
1 parent d4f061b commit 187c5cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions plugins/genshin/genshin_resource/genshin.pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 { // 直到成功
Expand Down
4 changes: 3 additions & 1 deletion plugins/genshin/genshin_resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ var snapshotFunctions = []func(filename string) error{
getTodayEventByMhyObc, // 1 通过米游社的观测枢获取今日活动进展图
}

const resourcePicBGColor = "#f6f2ee"

// 获取今日素材图片文件(会强制替换已有文件)
func getTodayResource() (filename string, err error) {
filename, err = getTodayResourceFilename()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 187c5cf

Please sign in to comment.