diff --git a/lib/core.go b/lib/core.go index 68fc89a..a7429ea 100644 --- a/lib/core.go +++ b/lib/core.go @@ -306,6 +306,22 @@ func Clip(in io.Reader, out io.Writer, wi, hi, x0, y0, x1, y1, quality int) (err return nil } +func WaitStudy(user *User) { + i := 0 + for i <= 180 { + score, err := GetUserScore(user.Cookies) + if err != nil { + return + } + if (score.Content["video"].CurrentScore >= score.Content["video"].MaxScore && score.Content["video_time"].CurrentScore >= score.Content["video_time"].MaxScore) && + score.Content["article"].CurrentScore >= score.Content["article"].MaxScore { + return + } + time.Sleep(10 * time.Second) + i++ + } +} + func GetPaymentStr(fi io.Reader) (paymentCodeUrl *gozxing.Result) { img, _, err := image.Decode(fi) if err != nil { diff --git a/lib/respond.go b/lib/respond.go index 76047f6..297ed20 100644 --- a/lib/respond.go +++ b/lib/respond.go @@ -250,6 +250,9 @@ func (c *Core) RespondDaily(cookies []Cookie, model string) { // 填空题 switch { case strings.Contains(categoryText, "填空题"): + if len(tips) < 1 { + tips = append(tips, "不知道") + } err := FillBlank(page, tips) if err != nil { log.Errorln("填空题答题失败" + err.Error()) diff --git a/lib/study.go b/lib/study.go index b126498..e6e68a8 100644 --- a/lib/study.go +++ b/lib/study.go @@ -159,12 +159,12 @@ func (c *Core) LearnArticle(cookies []Cookie) { time.Sleep(1 * time.Second) } fmt.Println() - + score, _ = GetUserScore(cookies) if score.Content["article"].CurrentScore >= score.Content["article"].MaxScore { log.Infoln("检测到本次阅读学习分数已满,退出学习") break } - score, _ = GetUserScore(cookies) + tryCount++ } else { log.Errorln("阅读学习出现异常,稍后可重新学习") @@ -262,11 +262,12 @@ func (c *Core) LearnVideo(cookies []Cookie) { time.Sleep(1 * time.Second) } fmt.Println() + score, _ = GetUserScore(cookies) if score.Content["video"].CurrentScore >= score.Content["video"].MaxScore && score.Content["video_time"].CurrentScore >= score.Content["video_time"].MaxScore { log.Infoln("检测到本次视频学习分数已满,退出学习") break } - score, _ = GetUserScore(cookies) + tryCount++ } else { log.Errorln("视频学习出现异常,稍后可重新学习") diff --git a/lib/tg.go b/lib/tg.go index 284919e..89b76b1 100644 --- a/lib/tg.go +++ b/lib/tg.go @@ -264,13 +264,14 @@ func study(bot *Telegram, args []string) { return } var cookies []Cookie - if len(users) == 1 { + switch { + case len(users) == 1: bot.SendMsg("仅存在一名用户信息,自动进行学习") cookies = users[0].Cookies - } else if len(users) == 0 { + case len(users) == 0: bot.SendMsg("未发现用户信息,请输入/login进行用户登录") return - } else { + default: if 0 <= len(args) { i, err := strconv.Atoi(args[0]) if err != nil { @@ -314,6 +315,7 @@ func study(bot *Telegram, args []string) { defer core.Quit() core.LearnArticle(cookies) core.LearnVideo(cookies) + WaitStudy(&User{Cookies: cookies}) core.RespondDaily(cookies, "daily") core.RespondDaily(cookies, "weekly") core.RespondDaily(cookies, "special") diff --git a/main.go b/main.go index 210721a..86be7f0 100644 --- a/main.go +++ b/main.go @@ -118,8 +118,9 @@ func do() { log.Infoln("已选择用户: ", users[i-1].Nick) } - //core.LearnArticle(cookies) - core.LearnVideo(cookies) + go core.LearnArticle(cookies) + go core.LearnVideo(cookies) + lib.WaitStudy(&lib.User{Cookies: cookies}) if config.Model == 2 { core.RespondDaily(cookies, "daily") } else if config.Model == 3 { @@ -127,6 +128,7 @@ func do() { core.RespondDaily(cookies, "weekly") core.RespondDaily(cookies, "special") } + score, err := lib.GetUserScore(cookies) if err != nil { log.Errorln("获取成绩失败")