From 14d81411b136440d158bcc2c031ede5c4199ccc8 Mon Sep 17 00:00:00 2001 From: MoeMagicMango Date: Sat, 17 Sep 2022 13:43:38 +0800 Subject: [PATCH] =?UTF-8?q?Optimize:=20=E6=9B=B4=E6=8D=A2=E7=BB=8F?= =?UTF-8?q?=E5=B8=B8=E5=87=BA=E9=97=AE=E9=A2=98=E7=9A=84iw233=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=B8=BAMoeHu=20(#412)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/score/sign_in.go | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/plugin/score/sign_in.go b/plugin/score/sign_in.go index df9b3184..b03eefe5 100644 --- a/plugin/score/sign_in.go +++ b/plugin/score/sign_in.go @@ -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" @@ -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) @@ -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) }