Skip to content

Commit

Permalink
定时任务增加过期cookie推送,微信支持配置管理员
Browse files Browse the repository at this point in the history
  • Loading branch information
johlanse committed Aug 18, 2022
1 parent cdc38af commit b5f2520
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 83 deletions.
4 changes: 4 additions & 0 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Config struct {
LoginTempID string `json:"login_temp_id" yaml:"login_temp_id"`
NormalTempID string `json:"normal_temp_id" yaml:"normal_temp_id"`
PushLoginWarn bool `json:"push_login_warn" yaml:"push_login_warn"`
SuperOpenID string `json:"super_open_id" yaml:"super_open_id"`
} `json:"wechat" yaml:"wechat"`
// 专项答题可接受的最小值
SpecialMinScore int `json:"special_min_score" yaml:"special_min_score"`
Expand All @@ -79,6 +80,9 @@ type Config struct {
AppKey string `json:"app_key" yaml:"app_key"`
} `json:"ji_guang_push" yaml:"ji_guang_push"`

SuperUser string `json:"super_user" yaml:"super_user"`
SuperPassword string `json:"super_password" yaml:"super_password"`

version string
}

Expand Down
2 changes: 2 additions & 0 deletions conf/config_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ wechat:
normal_temp_id: ""
# xxqg会每隔两小时左右检查所有用户的ck有效性,若开启该选项,会在检查失败时推送提醒消息
push_login_warn: false
# 微信管理员的openid,可点击关于按钮获得,配置后请重启程序
super_open_id: ""

# 登录重试配置
retry:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
)

require (
github.com/Luoxin/go-pushdeer-sdk v0.0.0-20220308071956-e50d1ec38c98 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f h1:2dk3eOnYllh+wUOuDhOoC2vUVoJF/5z478ryJ+wzEII=
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
github.com/Luoxin/go-pushdeer-sdk v0.0.0-20220308071956-e50d1ec38c98 h1:88VEoycHG8Fecaf8h/Tq5FSP5Jjl1+yodHiPAJawDe0=
github.com/Luoxin/go-pushdeer-sdk v0.0.0-20220308071956-e50d1ec38c98/go.mod h1:ZO6lLdHMY7Hj7VDqvy+k+s5AQdkxK0KV08GU9CUuqR0=
github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
Expand All @@ -22,6 +24,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-playground/validator/v10 v10.5.0 h1:X9rflw/KmpACwT8zdrm1upefpvdy6ur8d1kWyq6sg3E=
github.com/go-playground/validator/v10 v10.5.0/go.mod h1:xm76BBt941f7yWdGnI2DVPFFg1UK3YY04qifoXU3lOk=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.4.0-beta.0 h1:mbEDV1g6RBzKd4sFjOWuyZdxItw4CWu5Kq4KaBAJbHM=
Expand Down Expand Up @@ -109,6 +112,7 @@ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qq
github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E=
github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
Expand Down Expand Up @@ -150,6 +154,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220111093109-d55c255bac03 h1:0FB83qp0AzVJm+0wcIlauAjJ+tNdh7jLuacRYCIVv7s=
golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
Expand All @@ -158,6 +163,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
5 changes: 5 additions & 0 deletions lib/core.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lib

import (
"encoding/base64"
"errors"
"fmt"
"image"
Expand Down Expand Up @@ -149,6 +150,10 @@ func (c *Core) GenerateCode(pushID string) (string, string, error) {
} else {
log.Infoln("二维码已生成到目录下的qrcode.png")
}
if conf.GetConfig().QrCOde {
data, _ := os.ReadFile("qrcode.png")
c.Push(pushID, "image", base64.StdEncoding.EncodeToString(data))
}

qrCodeString := qrcodeTerminal.New2(qrcodeTerminal.ConsoleColors.BrightBlack, qrcodeTerminal.ConsoleColors.BrightWhite, qrcodeTerminal.QRCodeRecoveryLevels.Low).Get(codeURL)
qrCodeString.Print()
Expand Down
25 changes: 14 additions & 11 deletions lib/respond.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ func (c *Core) RespondDaily(user *model.User, model string) {
// 填空题
switch {
case strings.Contains(categoryText, "填空题"):
if len(tips) < 1 {
tips = append(tips, "不知道")
}

// 填充填空题
err := FillBlank(page, tips)
if err != nil {
Expand Down Expand Up @@ -576,10 +574,9 @@ func getTips(data string) []string {
func FillBlank(page playwright.Page, tips []string) error {
video := false
var answer []string
for _, tip := range tips {
if tip == "请观看视频" {
video = true
}
if len(tips) < 1 {
log.Warningln("检测到未获取到提示信息")
video = true
}
if video {
answer = append(answer, "不知道")
Expand All @@ -591,7 +588,7 @@ func FillBlank(page playwright.Page, tips []string) error {
log.Errorln("获取输入框错误" + err.Error())
return err
}
log.Debugln("获取到", len(inouts), "个填空")
log.Infoln("获取到", len(inouts), "个填空")
if len(inouts) == 1 && len(tips) > 1 {
temp := ""
for _, tip := range tips {
Expand All @@ -600,16 +597,22 @@ func FillBlank(page playwright.Page, tips []string) error {
answer = strings.Split(temp, ",")
log.Infoln("答案已合并处理")
}
var ans string
for i := 0; i < len(inouts); i++ {
err := inouts[i].Fill(answer[i])
if video {
ans = "不知道"
} else {
ans = answer[i]
}
err := inouts[i].Fill(ans)
if err != nil {
log.Errorln("填充答案失败" + err.Error())
continue
}
r := rand2.Intn(5)
r := rand2.Intn(4) + 1
time.Sleep(time.Duration(r) * time.Second)
}
r := rand2.Intn(2)
r := rand2.Intn(1) + 1
time.Sleep(time.Duration(r) * time.Second)
checkNextBotton(page)
return nil
Expand Down
2 changes: 1 addition & 1 deletion lib/study.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (c *Core) LearnVideo(user *model.User) {
c.Push(user.PushId, "text", "正在观看视频:"+links[n].Title)
log.Infoln("视频发布时间:" + links[n].PublishTime)
log.Infoln("视频学习链接:" + links[n].Url)
learnTime := 60 + rand.Intn(10) + 5
learnTime := 60 + rand.Intn(10)
for i := 0; i < learnTime; i++ {
if c.IsQuit() {
return
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func main() {
}
getPush := push.GetPush(config)
getPush("", "flush", "学习强国助手已上线")
model.SetPush(getPush)
if !config.TG.Enable && config.Cron == "" && !config.Wechat.Enable {
log.Infoln("已采用普通学习模式")
do("normal")
Expand All @@ -194,6 +195,10 @@ func do(m string) {

getPush := push.GetPush(config)
getPush("", "flush", "学习强国助手已上线")
failUser, _ := model.QueryFailUser()
for _, user := range failUser {
getPush(user.PushId, "flush", user.Nick+"的cookie已过期")
}
core := &lib.Core{ShowBrowser: config.ShowBrowser, Push: getPush}
defer core.Quit()
core.Init()
Expand Down
3 changes: 3 additions & 0 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func init() {
login_time integer not null,
push_id TEXT
);
`)
_, _ = db.Exec(`alter table user
add status integer default 1;
`)
}

Expand Down
Loading

0 comments on commit b5f2520

Please sign in to comment.