修复了定时模式未推送登录链接的问题,新增输入超时默认选择用户1的功能
This commit is contained in:
parent
2aa0fa80b2
commit
047cc82dbb
|
@ -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 := qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.QRCodeRecoveryLevels.Low).Get(codeURL)
|
||||||
qrCodeString.Print()
|
qrCodeString.Print()
|
||||||
c.Push("text", config.Scheme+url.QueryEscape(codeURL))
|
c.Push("flush", "登录链接:\r\n"+config.Scheme+url.QueryEscape(codeURL))
|
||||||
checkQrCode := func() (bool, string) {
|
checkQrCode := func() (bool, string) {
|
||||||
res := new(checkQrCodeResp)
|
res := new(checkQrCodeResp)
|
||||||
_, err := client.R().SetResult(res).SetFormData(map[string]string{
|
_, err := client.R().SetResult(res).SetFormData(map[string]string{
|
||||||
|
|
|
@ -17,10 +17,10 @@ const (
|
||||||
|
|
||||||
DailyBUTTON = `#app > div > div.layout-body > div >
|
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`
|
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 >
|
WEEKEND = `#app > div > div.layout-body > div > div.my-points-section > div.my-points-content >
|
||||||
div > div.my-points-section > div.my-points-content > div:nth-child(6) > div.my-points-card-footer > div.buttonbox > div`
|
div:nth-child(7) > div.my-points-card-footer > div.buttonbox > div`
|
||||||
SPECIALBUTTON = `#app > div > div.layout-body >
|
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) {
|
func (c *Core) RespondDaily(user *model.User, model string) {
|
||||||
|
|
117
main.go
117
main.go
|
@ -153,11 +153,35 @@ func do(m string) {
|
||||||
log.Infoln("检测到模式", config.Model)
|
log.Infoln("检测到模式", config.Model)
|
||||||
|
|
||||||
getPush := push.GetPush(config)
|
getPush := push.GetPush(config)
|
||||||
core := lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush}
|
core := &lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush}
|
||||||
defer core.Quit()
|
defer core.Quit()
|
||||||
core.Init()
|
core.Init()
|
||||||
var user *model.User
|
var user *model.User
|
||||||
users, _ := model.Query()
|
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时自动登录
|
// 用户小于1时自动登录
|
||||||
if len(users) < 1 {
|
if len(users) < 1 {
|
||||||
|
@ -172,24 +196,15 @@ func do(m string) {
|
||||||
// 如果为定时模式则直接循环所以用户依次运行
|
// 如果为定时模式则直接循环所以用户依次运行
|
||||||
if m == "cron" {
|
if m == "cron" {
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
go core.LearnArticle(u)
|
study(core, u)
|
||||||
go core.LearnVideo(u)
|
}
|
||||||
lib.WaitStudy(u, "")
|
if len(users) < 1 {
|
||||||
if config.Model == 2 {
|
user, err := core.L(config.Retry.Times)
|
||||||
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())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("获取成绩失败")
|
core.Push("msg", "登录超时")
|
||||||
log.Debugln(err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
message := u.Nick + " 学习完成:今日得分:" + strconv.Itoa(score.TodayScore)
|
study(core, user)
|
||||||
core.Push("markdown", message)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -198,8 +213,27 @@ func do(m string) {
|
||||||
log.Infoln("序号:", i+1, " ===> ", user.Nick)
|
log.Infoln("序号:", i+1, " ===> ", user.Nick)
|
||||||
}
|
}
|
||||||
log.Infoln("请输入对应序号选择对应账户,输入0添加用户:")
|
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
|
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 {
|
if i == 0 {
|
||||||
u, err := core.L(config.Retry.Times)
|
u, err := core.L(config.Retry.Times)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -213,51 +247,6 @@ func do(m string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch {
|
study(core, user)
|
||||||
// case len(users) < 1:
|
core.Push("flush", "")
|
||||||
// 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", "学习完成")
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,17 @@ func (p *PushPlus) Init() func(kind, message string) {
|
||||||
message = fmt.Sprintf("", "data:image/png;base64,"+message)
|
message = fmt.Sprintf("", "data:image/png;base64,"+message)
|
||||||
send(message)
|
send(message)
|
||||||
case kind == "flush":
|
case kind == "flush":
|
||||||
send(strings.Join(datas, "\n"))
|
if message == "" {
|
||||||
|
send(strings.Join(datas, " <br/> "))
|
||||||
|
datas = []string{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
datas = append(datas, message)
|
||||||
|
send(strings.Join(datas, " <br/> "))
|
||||||
|
datas = []string{}
|
||||||
default:
|
default:
|
||||||
if len(datas) > 10 {
|
if len(datas) > 10 {
|
||||||
send(strings.Join(datas, "\n"))
|
send(strings.Join(datas, " <br/> "))
|
||||||
datas = []string{}
|
datas = []string{}
|
||||||
} else {
|
} else {
|
||||||
datas = append(datas, message)
|
datas = append(datas, message)
|
||||||
|
|
Loading…
Reference in New Issue