From 047cc82dbb3187b226b335876d54a4c6eda85e3c Mon Sep 17 00:00:00 2001 From: johlanse Date: Tue, 24 May 2022 21:36:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E6=9C=AA=E6=8E=A8=E9=80=81=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=BE=93=E5=85=A5=E8=B6=85=E6=97=B6=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=94=A8=E6=88=B71=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core.go | 2 +- lib/respond.go | 6 +-- main.go | 117 +++++++++++++++++++++-------------------------- push/pushPlus.go | 11 ++++- 4 files changed, 66 insertions(+), 70 deletions(-) diff --git a/lib/core.go b/lib/core.go index 170b349..fb95302 100644 --- a/lib/core.go +++ b/lib/core.go @@ -171,7 +171,7 @@ func (c *Core) L(retryTimes int) (*model.User, error) { qrCodeString := qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.QRCodeRecoveryLevels.Low).Get(codeURL) qrCodeString.Print() - c.Push("text", config.Scheme+url.QueryEscape(codeURL)) + c.Push("flush", "登录链接:\r\n"+config.Scheme+url.QueryEscape(codeURL)) checkQrCode := func() (bool, string) { res := new(checkQrCodeResp) _, err := client.R().SetResult(res).SetFormData(map[string]string{ diff --git a/lib/respond.go b/lib/respond.go index 1d4b89f..b0260a8 100644 --- a/lib/respond.go +++ b/lib/respond.go @@ -17,10 +17,10 @@ const ( DailyBUTTON = `#app > div > div.layout-body > div > div.my-points-section > div.my-points-content > div:nth-child(5) > div.my-points-card-footer > div.buttonbox > div` - WEEKEND = `#app > div > div.layout-body > -div > div.my-points-section > div.my-points-content > div:nth-child(6) > div.my-points-card-footer > div.buttonbox > div` + WEEKEND = `#app > div > div.layout-body > div > div.my-points-section > div.my-points-content > +div:nth-child(7) > div.my-points-card-footer > div.buttonbox > div` SPECIALBUTTON = `#app > div > div.layout-body > -div > div.my-points-section > div.my-points-content > div:nth-child(7) > div.my-points-card-footer > div.buttonbox > div` +div > div.my-points-section > div.my-points-content > div:nth-child(6) > div.my-points-card-footer > div.buttonbox > div` ) func (c *Core) RespondDaily(user *model.User, model string) { diff --git a/main.go b/main.go index 9d87e59..3fe96a1 100644 --- a/main.go +++ b/main.go @@ -153,11 +153,35 @@ func do(m string) { log.Infoln("检测到模式", config.Model) getPush := push.GetPush(config) - core := lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush} + core := &lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush} defer core.Quit() core.Init() var user *model.User users, _ := model.Query() + for i := 0; i < 25; i++ { + core.Push("text", "登录") + } + study := func(core2 *lib.Core, u *model.User) { + go core2.LearnArticle(u) + go core2.LearnVideo(u) + lib.WaitStudy(u, "") + if config.Model == 2 { + core2.RespondDaily(u, "daily") + } else if config.Model == 3 { + core2.RespondDaily(u, "daily") + core2.RespondDaily(u, "weekly") + core2.RespondDaily(u, "special") + } + score, err := lib.GetUserScore(u.ToCookies()) + if err != nil { + log.Errorln("获取成绩失败") + log.Debugln(err.Error()) + return + } + message := u.Nick + " 学习完成:今日得分:" + strconv.Itoa(score.TodayScore) + core2.Push("markdown", message) + core2.Push("flush", "") + } // 用户小于1时自动登录 if len(users) < 1 { @@ -172,24 +196,15 @@ func do(m string) { // 如果为定时模式则直接循环所以用户依次运行 if m == "cron" { for _, u := range users { - go core.LearnArticle(u) - go core.LearnVideo(u) - lib.WaitStudy(u, "") - if config.Model == 2 { - core.RespondDaily(u, "daily") - } else if config.Model == 3 { - core.RespondDaily(u, "daily") - core.RespondDaily(u, "weekly") - core.RespondDaily(u, "special") - } - score, err := lib.GetUserScore(u.ToCookies()) + study(core, u) + } + if len(users) < 1 { + user, err := core.L(config.Retry.Times) if err != nil { - log.Errorln("获取成绩失败") - log.Debugln(err.Error()) + core.Push("msg", "登录超时") return } - message := u.Nick + " 学习完成:今日得分:" + strconv.Itoa(score.TodayScore) - core.Push("markdown", message) + study(core, user) } return } @@ -198,8 +213,27 @@ func do(m string) { log.Infoln("序号:", i+1, " ===> ", user.Nick) } log.Infoln("请输入对应序号选择对应账户,输入0添加用户:") + + inputChan := make(chan int, 1) + go func(c chan int) { + var i int + _, _ = fmt.Scanln(&i) + c <- i + }(inputChan) + var i int - _, _ = fmt.Scanln(&i) + select { + case i = <-inputChan: + log.Infoln("已获取到输入") + case <-time.After(time.Minute): + log.Errorln("获取输入超时,默认选择第一个用户") + if len(users) < 1 { + return + } else { + i = 1 + } + } + if i == 0 { u, err := core.L(config.Retry.Times) if err != nil { @@ -213,51 +247,6 @@ func do(m string) { } } - // switch { - // case len(users) < 1: - // log.Infoln("未检测到有效用户信息,将采用登录模式") - // u, err := core.L(config.Retry.Times) - // if err != nil { - // log.Errorln(err.Error()) - // return - // } - // user = u - //case len(users) == 1: - // log.Infoln("检测到1位有效用户信息,采用默认用户") - // user = users[0] - // log.Infoln("已选择用户: ", users[0].Nick) - //default: - // if m == "cron" { - // - // } - // for i, user := range users { - // log.Infoln("序号:", i+1, " ===> ", user.Nick) - // } - // log.Infoln("请输入对应序号选择对应账户") - // var i int - // _, _ = fmt.Scanln(&i) - // user = users[i-1] - // log.Infoln("已选择用户: ", users[i-1].Nick) - //} - - go core.LearnArticle(user) - go core.LearnVideo(user) - lib.WaitStudy(user, "") - if config.Model == 2 { - core.RespondDaily(user, "daily") - } else if config.Model == 3 { - core.RespondDaily(user, "daily") - core.RespondDaily(user, "weekly") - core.RespondDaily(user, "special") - } - - score, err := lib.GetUserScore(user.ToCookies()) - if err != nil { - log.Errorln("获取成绩失败") - log.Debugln(err.Error()) - return - } - message := "学习完成:今日得分:" + strconv.Itoa(score.TodayScore) - core.Push("markdown", message) - core.Push("flush", "学习完成") + study(core, user) + core.Push("flush", "") } diff --git a/push/pushPlus.go b/push/pushPlus.go index 76ac90b..df04b1f 100644 --- a/push/pushPlus.go +++ b/push/pushPlus.go @@ -35,10 +35,17 @@ func (p *PushPlus) Init() func(kind, message string) { message = fmt.Sprintf("![](%v)", "data:image/png;base64,"+message) send(message) case kind == "flush": - send(strings.Join(datas, "\n")) + if message == "" { + send(strings.Join(datas, "
")) + datas = []string{} + return + } + datas = append(datas, message) + send(strings.Join(datas, "
")) + datas = []string{} default: if len(datas) > 10 { - send(strings.Join(datas, "\n")) + send(strings.Join(datas, "
")) datas = []string{} } else { datas = append(datas, message)