Fix: 更换稳定的背景api + 修复因api问题签到结果无法出现但数据库已经记录的问题 (#236)

* 通过修改顺序解决签到背景API出问题

* Update sign_in.go

* 🎨 改进代码样式

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
MoeMagicMango 2022-05-21 22:53:20 +08:00 committed by GitHub
parent 88d136626d
commit 151a5d480f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,7 @@ import (
)
const (
backgroundURL = "https://iw233.cn/api.php?sort=pc&type=json"
backgroundURL = "https://mirlkoi.ifast3.vipnps.vip/api.php?sort=pc&type=json"
referer = "https://iw233.cn/main.html"
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
signinMax = 1
@ -56,11 +56,10 @@ func init() {
today := now.Format("20060102")
si := sdb.GetSignInByUID(uid)
siUpdateTimeStr := si.UpdatedAt.Format("20060102")
if siUpdateTimeStr != today {
_ = sdb.InsertOrUpdateSignInCountByUID(uid, 0)
}
drawedFile := cachePath + strconv.FormatInt(uid, 10) + today + "signin.png"
picFile := cachePath + strconv.FormatInt(uid, 10) + today + ".png"
if si.Count >= signinMax && siUpdateTimeStr == today {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("今天你已经签到过了!"))
if file.IsExist(drawedFile) {
@ -68,21 +67,21 @@ func init() {
}
return
}
picFile := cachePath + strconv.FormatInt(uid, 10) + today + ".png"
err := initPic(picFile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
_ = sdb.InsertOrUpdateSignInCountByUID(uid, si.Count+1)
back, err := gg.LoadImage(picFile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
if siUpdateTimeStr != today {
_ = sdb.InsertOrUpdateSignInCountByUID(uid, 0)
}
_ = sdb.InsertOrUpdateSignInCountByUID(uid, si.Count+1)
// 避免图片过大,最大 1280*720
back = img.Limit(back, 1280, 720)