diff --git a/conf/config_default.yml b/conf/config_default.yml index ffb7b4a..df6560f 100644 --- a/conf/config_default.yml +++ b/conf/config_default.yml @@ -2,7 +2,7 @@ # 1:只刷文章何视频 # 2:只刷文章和视频和每日答题 # 3:刷文章和视频和每日答题每周答题和专项答题 -model: 2 +model: 3 # 日志等级 # panic diff --git a/lib/core.go b/lib/core.go index 6e62f2d..7a11bee 100644 --- a/lib/core.go +++ b/lib/core.go @@ -63,11 +63,7 @@ type checkQrCodeResp struct { Data string `json:"data"` } -// Init -/** - * @Description: - * @receiver c - */ +// 初始化 func (c *Core) Init() { if runtime.GOOS == "windows" { c.initWindows() @@ -76,6 +72,7 @@ func (c *Core) Init() { } } +// 获取Token func GetToken(code, sign, pushId string) (bool, error) { client := utils.GetClient() response, err := client.R().SetQueryParams(map[string]string{ @@ -113,13 +110,7 @@ func GetToken(code, sign, pushId string) (bool, error) { return true, err } -// GenerateCode -/* @Description: 生成二维码 - * @receiver c - * @return string 二维码连接 - * @return string 二维码回调查询的code - * @return error - */ +// 生成二维码 func (c *Core) GenerateCode(pushID string) (string, string, error) { client := utils.GetClient() g := new(gennerateResp) @@ -136,6 +127,7 @@ func (c *Core) GenerateCode(pushID string) (string, string, error) { return codeURL, g.Result, err } +// 检查二维码状态 func (c *Core) CheckQrCode(code, pushID string) (*model.User, bool, error) { client := utils.GetClient() checkQrCode := func() (bool, string) { @@ -191,13 +183,7 @@ func (c *Core) CheckQrCode(code, pushID string) (*model.User, bool, error) { } } -// L -/** - * @Description: - * @receiver c - * @return *model.User - * @return error - */ +// 轮询 func (c *Core) L(retryTimes int, pushID string) (*model.User, error) { _, codeData, err := c.GenerateCode(pushID) if err != nil { @@ -218,6 +204,7 @@ func (c *Core) L(retryTimes int, pushID string) (*model.User, error) { return c.L(retryTimes-1, pushID) } +// 初始化Windows系统 func (c *Core) initWindows() { _, err := os.Stat("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe") if err != nil { @@ -297,6 +284,7 @@ func (c *Core) initWindows() { c.browser = browser } +// 初始化非Windows系统 func (c *Core) initNotWindows() { dir, err := os.Getwd() if err != nil { @@ -369,6 +357,7 @@ func (c *Core) initNotWindows() { c.browser = browser } +// 关闭浏览器 func (c *Core) Quit() { err := c.browser.Close() if err != nil { @@ -381,6 +370,7 @@ func (c *Core) Quit() { } } +// 检查浏览器是否关闭 func (c *Core) IsQuit() bool { return !c.browser.IsConnected() } diff --git a/lib/lib.go b/lib/lib.go index 746cc0f..c05961c 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -23,14 +23,11 @@ func Study(core2 *Core, u *model.User) { core2.LearnArticle(u) - core2.RadioStation(u) - core2.RadioStation(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") } endTime := time.Now() @@ -41,7 +38,6 @@ func Study(core2 *Core, u *model.User) { return } - score, _ = GetUserScore(u.ToCookies()) message := fmt.Sprintf("%v 学习完成,用时%.1f分钟\n%v", u.Nick, endTime.Sub(startTime).Minutes(), FormatScoreShort(score)) core2.Push(u.PushId, "flush", message) } diff --git a/lib/respond.go b/lib/respond.go index f89b2d0..30b20b3 100644 --- a/lib/respond.go +++ b/lib/respond.go @@ -30,12 +30,7 @@ const ( SPECIALBUTTON = `#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` ) -// RespondDaily -/* @Description: - * @receiver c - * @param user - * @param model - */ +// 每日答题 func (c *Core) RespondDaily(user *model.User, model string) { var title string @@ -157,19 +152,6 @@ func (c *Core) RespondDaily(user *model.User, model string) { } case "special": { - // 检测是否已经完成 - if score.Content["special"].CurrentScore >= score.Content["special"].MaxScore { - log.Infoln("检测到特殊答题已经完成,即将退出答题") - - return - } - // err = page.Click(SPECIALBUTTON) - // if err != nil { - // log.Errorln("跳转到积分页面错误") - // - // return - //} - //获取专项答题ID id, err = getSpecialID(user.ToCookies()) if err != nil { @@ -452,7 +434,7 @@ func (c *Core) RespondDaily(user *model.User, model string) { } } -func getAnswerPage(page playwright.Page, model string) bool { +func GetAnswerPage(page playwright.Page, model string) bool { selectPages, err := page.QuerySelectorAll(`#app .ant-pagination .ant-pagination-item`) if err != nil { log.Errorln("获取到页码失败") @@ -562,6 +544,7 @@ func radioCheck(page playwright.Page, answer []string) error { return nil } +// 获取选项 func getOptions(page playwright.Page) ([]string, error) { handles, err := page.QuerySelectorAll(`.q-answer.choosable`) if err != nil { @@ -579,6 +562,7 @@ func getOptions(page playwright.Page) ([]string, error) { return options, err } +// 获取问题提示 func getTips(data string) []string { data = strings.ReplaceAll(data, " ", "") data = strings.ReplaceAll(data, "\n", "") @@ -594,6 +578,7 @@ func getTips(data string) []string { return tips } +// 填空题 func FillBlank(page playwright.Page, tips []string) error { video := false var answer []string @@ -648,12 +633,13 @@ func FillBlank(page playwright.Page, tips []string) error { r := rand2.Intn(4) + 1 time.Sleep(time.Duration(r) * time.Second) } - r := rand2.Intn(1) + 1 + r := rand2.Intn(2) time.Sleep(time.Duration(r) * time.Second) checkNextBotton(page) return nil } +// 检查下一题按钮 func checkNextBotton(page playwright.Page) { btns, err := page.QuerySelectorAll(`#app .action-row > button`) if err != nil { @@ -704,6 +690,7 @@ func RemoveRepByLoop(slc []string) []string { return result } +// 获取专项答题ID func getSpecialID(cookies []*http.Cookie) (int, error) { c := req.C() c.SetCommonCookies(cookies...) @@ -754,6 +741,7 @@ func getSpecialID(cookies []*http.Cookie) (int, error) { return 0, errors.New("未找到专项答题") } +// 获取每周答题ID func getweekID(cookies []*http.Cookie) (int, error) { c := req.C() c.SetCommonCookies(cookies...) @@ -819,7 +807,8 @@ func GetSpecialContent(cookies []*http.Cookie, id int) *SpecialContent { return content } -func getweekIDs(cookies []*http.Cookie) []int { +// 获取每周答题ID列表 +func GetweekIDs(cookies []*http.Cookie) []int { c := req.C() c.SetCommonCookies(cookies...) repo, err := c.R().SetQueryParams(map[string]string{"pageSize": "500", "pageNo": "1"}).Get(queryWeekList) @@ -852,7 +841,9 @@ func getweekIDs(cookies []*http.Cookie) []int { } return ids } -func getSpecialIDs(cookies []*http.Cookie) []int { + +// 获取专项答题ID列表 +func GetSpecialIDs(cookies []*http.Cookie) []int { c := req.C() c.SetCommonCookies(cookies...) diff --git a/lib/score.go b/lib/score.go index d947bba..5008d7a 100644 --- a/lib/score.go +++ b/lib/score.go @@ -22,6 +22,7 @@ type Data struct { MaxScore int `json:"max_score"` } +// 获取用户总分 func GetUserScore(cookies []*http.Cookie) (Score, error) { var score Score var resp []byte @@ -41,7 +42,7 @@ func GetUserScore(cookies []*http.Cookie) (Score, error) { response, err = client.R().SetCookies(cookies...).SetHeaders(header).Get(userTodaytotalscoreUrl) if err != nil { - log.Errorln("获取用户总分错误" + err.Error()) + log.Errorln("获取用户今日得分错误" + err.Error()) return Score{}, err } resp = response.Bytes() @@ -49,7 +50,7 @@ func GetUserScore(cookies []*http.Cookie) (Score, error) { response, err = client.R().SetCookies(cookies...).SetHeaders(header).Get(userRatescoreUrl) if err != nil { - log.Errorln("获取用户总分错误" + err.Error()) + log.Errorln("获取用户详情得分错误" + err.Error()) return Score{}, err } resp = response.Bytes() @@ -77,6 +78,7 @@ func GetUserScore(cookies []*http.Cookie) (Score, error) { return score, err } +// 输出总分 func PrintScore(score Score) string { result := "" result += fmt.Sprintf("当前学习总积分:%d\n今日得分:%d\n", score.TotalScore, score.TodayScore) @@ -92,6 +94,7 @@ func PrintScore(score Score) string { return result } +// 格式化总分 func FormatScore(score Score) string { result := "" result += fmt.Sprintf("当前学习总积分:%d\n今日得分:%d\n", score.TotalScore, score.TodayScore) @@ -104,6 +107,7 @@ func FormatScore(score Score) string { return result } +// 格式化短格式总分 func FormatScoreShort(score Score) string { result := "" result += fmt.Sprintf("当前学习总积分:%d\n今日得分:%d\n", score.TotalScore, score.TodayScore) diff --git a/lib/study.go b/lib/study.go index bad710d..f60d431 100644 --- a/lib/study.go +++ b/lib/study.go @@ -36,6 +36,7 @@ var ( "https://www.xuexi.cn/lgdata/3o3ufqgl8rsn.json", "https://www.xuexi.cn/lgdata/525pi8vcj24p.json", "https://www.xuexi.cn/lgdata/1742g60067k.json"} + yp_url_list = []string{ "https://www.xuexi.cn/lgdata/1ode6kjlu7m.json", "https://www.xuexi.cn/lgdata/1ggb81u8f7m.json", @@ -66,6 +67,7 @@ type Link struct { DataValid bool `json:"dataValid"` } +// 获取学习链接列表 func getLinks(model string) ([]Link, error) { UID := rand.Intn(20000000) + 10000000 learnUrl := "" @@ -98,12 +100,7 @@ func getLinks(model string) ([]Link, error) { return links, err } -// LearnArticle -/** - * @Description: 文章学习 - * @receiver c - * @param cookies - */ +// 文章学习 func (c *Core) LearnArticle(user *model.User) { defer func() { err := recover() @@ -215,12 +212,7 @@ func (c *Core) LearnArticle(user *model.User) { } } -// LearnVideo -/** - * @Description: 视频学习 - * @receiver c - * @param cookies - */ +// 视频学习 func (c *Core) LearnVideo(user *model.User) { defer func() { err := recover() @@ -326,9 +318,7 @@ func (c *Core) LearnVideo(user *model.User) { } } -/** - * @Description: 音频 - */ +// 音频学习 func (c *Core) RadioStation(user *model.User) { defer func() { err := recover() @@ -348,9 +338,6 @@ func (c *Core) RadioStation(user *model.User) { links, _ := getLinks("yp") if !(score.Content["video"].CurrentScore >= score.Content["video"].MaxScore && score.Content["video_time"].CurrentScore >= score.Content["video_time"].MaxScore) { log.Infoln("开始加载音频学习模块") - // core := Core{} - // core.Init() - context, err := c.browser.NewContext(playwright.BrowserNewContextOptions{ Viewport: &playwright.BrowserNewContextOptionsViewport{ Width: playwright.Int(1920), diff --git a/lib/url.go b/lib/url.go index 4fa689b..2449754 100644 --- a/lib/url.go +++ b/lib/url.go @@ -11,6 +11,7 @@ const ( queryWeekList = "https://pc-proxy-api.xuexi.cn/api/exam/service/practice/pc/weekly/more" ) +// 专项答题JSON结构 type SpecialList struct { PageNo int `json:"pageNo"` PageSize int `json:"pageSize"` diff --git a/lib/user.go b/lib/user.go index b106ac0..c12bd3d 100644 --- a/lib/user.go +++ b/lib/user.go @@ -10,14 +10,7 @@ import ( "github.com/sjkhsl/study_xxqg/utils" ) -// GetUserInfo -/** - * @Description: 获取用户信息 - * @param cookies - * @return string - * @return string - * @return error - */ +// 获取用户信息 func GetUserInfo(cookies []*http.Cookie) (string, string, error) { var resp []byte response, err := utils.GetClient().R().SetCookies(cookies...).SetHeader("Cache-Control", "no-cache").Get(userInfoUrl) @@ -33,12 +26,7 @@ func GetUserInfo(cookies []*http.Cookie) (string, string, error) { return uid, nick, err } -// CheckUserCookie -/** - * @Description: 获取用户成绩 - * @param user - * @return bool - */ +// 获取用户成绩 func CheckUserCookie(user *model.User) bool { _, err := GetUserScore(user.ToCookies()) if err != nil && err.Error() == "token check failed" { diff --git a/lib/utils.go b/lib/utils.go index e44ea08..c6bacbf 100644 --- a/lib/utils.go +++ b/lib/utils.go @@ -6,7 +6,7 @@ import ( "github.com/playwright-community/playwright-go" ) -func cookieToJar(cookies []Cookie) []*http.Cookie { +func CookieToJar(cookies []Cookie) []*http.Cookie { var ( cooks []*http.Cookie ) @@ -28,7 +28,7 @@ func cookieToJar(cookies []Cookie) []*http.Cookie { return cooks } -func cookieToParam(cookies []Cookie) []playwright.BrowserContextAddCookiesOptionsCookies { +func CookieToParam(cookies []Cookie) []playwright.BrowserContextAddCookiesOptionsCookies { var ( cooks []playwright.BrowserContextAddCookiesOptionsCookies ) diff --git a/push/qq.go b/push/qq.go index 4346fbe..ac18114 100644 --- a/push/qq.go +++ b/push/qq.go @@ -119,7 +119,7 @@ func qqStudy(event *Event, args []string) { if len(users) == 1 { user = users[0] } else { - if len(args) < 0 { + if len(args) <= 0 { event.Send("缺少序号参数,请输入 .study 序号") return } else { diff --git a/push/tg.go b/push/tg.go index 60ba29a..bd3befa 100644 --- a/push/tg.go +++ b/push/tg.go @@ -92,11 +92,11 @@ type Mather struct { handle func(bot *Telegram, from int64, args []string) } -func (m Mather) getCommand() string { +func (m Mather) GetCommand() string { return m.command } -func (m Mather) execute(bot *Telegram, from int64, args []string) { +func (m Mather) Execute(bot *Telegram, from int64, args []string) { m.handle(bot, from, args) } @@ -404,7 +404,7 @@ func studyAll(bot *Telegram, from int64, args []string) { core.LearnArticle(user) core.RadioStation(user) core.RespondDaily(user, "daily") - core.RespondDaily(user, "weekly") + // core.RespondDaily(user, "weekly") core.RespondDaily(user, "special") c <- 1 }() diff --git a/push/wx.go b/push/wx.go index 0bdc8fd..6d255d0 100644 --- a/push/wx.go +++ b/push/wx.go @@ -103,8 +103,6 @@ func initWechat() { log.Errorln("添加客服失败" + err.Error()) return } - } else { - } wx.HandleFunc("eventCLICK", func(wx *mp.WeiXin, w http.ResponseWriter, r *request.WeiXinRequest, timestamp, nonce string) { if lastNonce == nonce { diff --git a/web/controller.go b/web/controller.go index 8986630..f84a8c3 100644 --- a/web/controller.go +++ b/web/controller.go @@ -316,7 +316,7 @@ func study() gin.HandlerFunc { core.RespondDaily(user, "daily") } else if config.Model == 3 { core.RespondDaily(user, "daily") - core.RespondDaily(user, "weekly") + // core.RespondDaily(user, "weekly") core.RespondDaily(user, "special") } state.Delete(uid)