Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize: 更换经常出问题的iw233接口为MoeHu #412

Merged
merged 8 commits into from
Sep 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions plugin/score/sign_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ import (
"github.com/Coloured-glaze/gg"
"github.com/golang/freetype"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/wcharczuk/go-chart/v2"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"

"github.com/FloatTech/floatbox/binary"
"github.com/FloatTech/floatbox/file"
"github.com/FloatTech/floatbox/img/writer"
"github.com/FloatTech/floatbox/web"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
Expand All @@ -27,22 +24,22 @@ import (
)

const (
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"
backgroundURL = "https://img.moehu.org/pic.php?id=pc"
signinMax = 1
// SCOREMAX 分数上限定为120
SCOREMAX = 120
)

var levelArray = [...]int{0, 1, 2, 5, 10, 20, 35, 55, 75, 100, 120}

func init() {
engine := control.Register("score", &ctrl.Options[*zero.Ctx]{
var (
levelArray = [...]int{0, 1, 2, 5, 10, 20, 35, 55, 75, 100, 120}
engine = control.Register("score", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Help: "签到得分\n- 签到\n- 获得签到背景[@xxx] | 获得签到背景\n- 查看分数排名",
PrivateDataFolder: "score",
})
)

func init() {
cachePath := engine.DataFolder() + "cache/"
go func() {
_ = os.RemoveAll(cachePath)
Expand Down Expand Up @@ -274,14 +271,5 @@ func initPic(picFile string) error {
if file.IsExist(picFile) {
return nil
}
data, err := web.RequestDataWith(web.NewDefaultClient(), backgroundURL, "GET", referer, ua)
if err != nil {
return err
}
picURL := gjson.Get(binary.BytesToString(data), "pic.0").Str
data, err = web.RequestDataWith(web.NewDefaultClient(), picURL, "GET", "", ua)
if err != nil {
return err
}
return os.WriteFile(picFile, data, 0644)
return file.DownloadTo(backgroundURL, picFile, true)
}