From 4a13701e3763d77ea75d08ea14c983ac42555662 Mon Sep 17 00:00:00 2001 From: xlh001 <2402324010@qq.com> Date: Fri, 11 Aug 2023 14:20:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A7=86=E9=A2=91=E5=AD=A6?= =?UTF-8?q?=E4=B9=A0=E4=B8=BA=E9=9F=B3=E9=A2=91=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/shell.go | 2 +- go.mod | 14 +++--- go.sum | 20 ++++++++ lib/lib.go | 4 +- lib/study.go | 117 ++++++++++++++++++++++++++++++++++++++++++++++ push/tg.go | 39 +++++++--------- push/wx.go | 52 ++++++++------------- utils/util.go | 2 +- web/controller.go | 2 +- 9 files changed, 185 insertions(+), 67 deletions(-) diff --git a/cli/shell.go b/cli/shell.go index 52d491b..fd6676b 100644 --- a/cli/shell.go +++ b/cli/shell.go @@ -57,7 +57,7 @@ func study() *grumble.Command { l.Init() defer l.Quit() l.LearnArticle(user) - l.LearnVideo(user) + l.RadioStation(user) if config.Model == 2 { l.RespondDaily(user, "daily") } else if config.Model == 3 { diff --git a/go.mod b/go.mod index 118ae88..edb9476 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/Lyrics-you/sail-logrus-formatter v1.3.1 github.com/desertbit/grumble v1.1.3 github.com/dustin/go-humanize v1.0.0 - github.com/fsnotify/fsnotify v1.5.4 + github.com/fsnotify/fsnotify v1.6.0 github.com/getlantern/systray v1.2.1 github.com/gin-contrib/gzip v0.0.6 github.com/gin-gonic/gin v1.9.1 @@ -25,7 +25,7 @@ require ( github.com/playwright-community/playwright-go v0.2000.1 github.com/robfig/cron/v3 v3.0.0 github.com/sirupsen/logrus v1.9.0 - github.com/spf13/viper v1.12.0 + github.com/spf13/viper v1.16.0 github.com/tidwall/gjson v1.12.1 gopkg.in/yaml.v3 v3.0.1 modernc.org/sqlite v1.15.2 @@ -64,7 +64,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/lestrrat-go/strftime v1.0.5 // indirect - github.com/magiconair/properties v1.8.6 // indirect + github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -74,11 +74,11 @@ require ( github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect - github.com/spf13/afero v1.8.2 // indirect - github.com/spf13/cast v1.5.0 // indirect + github.com/spf13/afero v1.9.5 // indirect + github.com/spf13/cast v1.5.1 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/subosito/gotenv v1.3.0 // indirect + github.com/subosito/gotenv v1.4.2 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect @@ -92,7 +92,7 @@ require ( golang.org/x/text v0.9.0 // indirect golang.org/x/tools v0.6.0 // indirect google.golang.org/protobuf v1.30.0 // indirect - gopkg.in/ini.v1 v1.66.4 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect lukechampine.com/uint128 v1.1.1 // indirect diff --git a/go.sum b/go.sum index 5058ec8..98dc358 100644 --- a/go.sum +++ b/go.sum @@ -139,9 +139,12 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/getlantern/context v0.0.0-20190109183933-c447772a6520 h1:NRUJuo3v3WGC/g5YiyF790gut6oQr5f3FBI88Wv0dx4= @@ -403,6 +406,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -427,6 +431,8 @@ github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0U github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= @@ -547,6 +553,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= @@ -570,8 +577,12 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= github.com/spf13/afero v1.8.2 h1:xehSyVa0YnHWsJ49JFljMpg1HX19V6NDZ1fkm1Xznbo= github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo= +github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= +github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= @@ -580,6 +591,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.12.0 h1:CZ7eSOd3kZoaYDLbXnmzgQI5RlciuXBMA+18HwHRfZQ= github.com/spf13/viper v1.12.0/go.mod h1:b6COn30jlNxbm/V2IqWiNWkJ+vZNiMNksliPCiuKtSI= +github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= +github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= @@ -603,6 +616,8 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI= github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs= +github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= +github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tidwall/gjson v1.12.1 h1:ikuZsLdhr8Ws0IdROXUS1Gi4v9Z4pGqpX/CvJkxvfpo= @@ -671,6 +686,7 @@ golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -747,6 +763,7 @@ golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220111093109-d55c255bac03/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= @@ -832,6 +849,7 @@ golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -1029,6 +1047,8 @@ gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4= gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI= gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= diff --git a/lib/lib.go b/lib/lib.go index ab36bf5..746cc0f 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -23,9 +23,9 @@ func Study(core2 *Core, u *model.User) { core2.LearnArticle(u) - core2.LearnVideo(u) + core2.RadioStation(u) - core2.LearnVideo(u) + core2.RadioStation(u) if config.Model == 2 { core2.RespondDaily(u, "daily") } else if config.Model == 3 { diff --git a/lib/study.go b/lib/study.go index 0b300b3..bad710d 100644 --- a/lib/study.go +++ b/lib/study.go @@ -36,6 +36,13 @@ 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", + "https://www.xuexi.cn/lgdata/139993ri8nm.json", + "https://www.xuexi.cn/lgdata/u07dubuq7m.json", + "https://www.xuexi.cn/lgdata/spisr390nm.json", + "https://www.xuexi.cn/lgdata/1elt18mm57m.json"} ) type Link struct { @@ -66,6 +73,8 @@ func getLinks(model string) ([]Link, error) { learnUrl = article_url_list[rand.Intn(7)] } else if model == "video" { learnUrl = video_url_list[rand.Intn(7)] + } else if model == "yp" { + learnUrl = yp_url_list[rand.Intn(7)] } else { return nil, errors.New("model选择出现错误") } @@ -316,3 +325,111 @@ func (c *Core) LearnVideo(user *model.User) { log.Infoln("检测到视频学习已经完成") } } + +/** + * @Description: 音频 + */ +func (c *Core) RadioStation(user *model.User) { + defer func() { + err := recover() + if err != nil { + log.Errorln("电台学习模块异常结束") + log.Errorln(err) + } + }() + if c.IsQuit() { + return + } + score, err := GetUserScore(user.ToCookies()) + if err != nil { + log.Errorln(err.Error()) + return + } + 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), + Height: playwright.Int(1080), + }}) + _ = context.AddInitScript(playwright.BrowserContextAddInitScriptOptions{ + Script: playwright.String("Object.defineProperties(navigator, {webdriver:{get:()=>undefined}});")}) + if err != nil { + log.Errorln("创建实例对象错误" + err.Error()) + return + } + defer func(context playwright.BrowserContext) { + err := context.Close() + if err != nil { + log.Errorln("错误的关闭了实例对象" + err.Error()) + } + }(context) + + page, err := context.NewPage() + if err != nil { + return + } + defer func() { + page.Close() + }() + + err = context.AddCookies(user.ToBrowserCookies()...) + if err != nil { + log.Errorln("添加cookie失败" + err.Error()) + return + } + tryCount := 0 + for { + if tryCount < 20 { + PrintScore(score) + n := rand.Intn(len(links)) + _, err := page.Goto(links[n].Url, playwright.PageGotoOptions{ + Referer: playwright.String(links[rand.Intn(len(links))].Url), + Timeout: playwright.Float(10000), + WaitUntil: playwright.WaitUntilStateDomcontentloaded, + }) + if err != nil { + log.Errorln("页面跳转失败") + } + log.Infoln("正在收听:" + links[n].Title) + c.Push(user.PushId, "text", "正在收听:"+links[n].Title) + log.Infoln("音频发布时间:" + links[n].PublishTime) + log.Infoln("音频学习链接:" + links[n].Url) + learnTime := 60 + rand.Intn(10) + for i := 0; i < learnTime; i++ { + if c.IsQuit() { + return + } + fmt.Printf("\r[%v] [INFO]: 正在进行音频学习中,剩余%d个,当前剩余时间%d秒", time.Now().Format("2006-01-02 15:04:05"), score.Content["video"].MaxScore-score.Content["video"].CurrentScore, learnTime-i) + + if rand.Float32() > 0.5 { + go func() { + _, err := page.Evaluate(fmt.Sprintf(`let h = document.body.scrollHeight/120*%d;document.documentElement.scrollTop=h;`, i)) + if err != nil { + log.Errorln("视频滑动失败") + } + }() + } + time.Sleep(1 * time.Second) + } + fmt.Println() + score, _ = GetUserScore(user.ToCookies()) + if score.Content["video"].CurrentScore >= score.Content["video"].MaxScore && score.Content["video_time"].CurrentScore >= score.Content["video_time"].MaxScore { + log.Infoln("检测到本次音频学习分数已满,退出学习") + break + } + + tryCount++ + } else { + log.Errorln("音频学习出现异常,稍后可重新学习") + return + } + } + } else { + log.Infoln("检测到音频学习已经完成") + } +} diff --git a/push/tg.go b/push/tg.go index dabc8fa..60ba29a 100644 --- a/push/tg.go +++ b/push/tg.go @@ -75,7 +75,6 @@ func TgInit() { // Telegram // @Description: -// type Telegram struct { Token string ChatId int64 @@ -263,25 +262,21 @@ func getFailUser(bot *Telegram, from int64, args []string) { bot.SendMsg(from, "当前过期用户:\n"+msg) } -// -// checkVersion -// @Description: 检查版本信息 -// @param bot -// @param from -// @param args -// +// checkVersion +// @Description: 检查版本信息 +// @param bot +// @param from +// @param args func checkVersion(bot *Telegram, from int64, args []string) { about := utils.GetAbout() bot.SendMsg(from, about) } -// -// botRestart -// @Description: 重启程序 -// @param bot -// @param from -// @param args -// +// botRestart +// @Description: 重启程序 +// @param bot +// @param from +// @param args func botRestart(bot *Telegram, from int64, args []string) { if from != conf.GetConfig().TG.ChatID { bot.SendMsg(from, "请联系管理员解决!!") @@ -291,13 +286,11 @@ func botRestart(bot *Telegram, from int64, args []string) { utils.Restart() } -// -// botUpdate -// @Description: 更新程序 -// @param bot -// @param from -// @param args -// +// botUpdate +// @Description: 更新程序 +// @param bot +// @param from +// @param args func botUpdate(bot *Telegram, from int64, args []string) { if from != conf.GetConfig().TG.ChatID { bot.SendMsg(from, "请联系管理员解决!!") @@ -409,7 +402,7 @@ func studyAll(bot *Telegram, from int64, args []string) { core.Init() defer core.Quit() core.LearnArticle(user) - core.LearnVideo(user) + core.RadioStation(user) core.RespondDaily(user, "daily") core.RespondDaily(user, "weekly") core.RespondDaily(user, "special") diff --git a/push/wx.go b/push/wx.go index 0110aca..0bdc8fd 100644 --- a/push/wx.go +++ b/push/wx.go @@ -381,21 +381,17 @@ func handleGetOpenID(id string, msg string) { sendMsg(id, "你的open_id为"+id) } -// -// handleCheckUpdate -// @Description: 检查更新 -// @param id -// +// handleCheckUpdate +// @Description: 检查更新 +// @param id func handleCheckUpdate(id string, msg string) { about := utils.GetAbout() sendMsg(id, about) } -// -// handleUpdate -// @Description: 开始更新 -// @param id -// +// handleUpdate +// @Description: 开始更新 +// @param id func handleUpdate(id string, msg string) { if conf.GetConfig().Wechat.SuperOpenID != id { sendMsg(id, "请联系管理员处理!") @@ -406,11 +402,9 @@ func handleUpdate(id string, msg string) { utils.Restart() } -// -// handleRestart -// @Description: 重启程序 -// @param id -// +// handleRestart +// @Description: 重启程序 +// @param id func handleRestart(id string, msg string) { if conf.GetConfig().Wechat.SuperOpenID != id { sendMsg(id, "请联系管理员处理!") @@ -420,12 +414,10 @@ func handleRestart(id string, msg string) { utils.Restart() } -// -// sendMsg -// @Description: 发送消息 -// @param id -// @param message -// +// sendMsg +// @Description: 发送消息 +// @param id +// @param message func sendMsg(id, message string) { if wx == nil { @@ -527,11 +519,9 @@ func HandleWechat(rep http.ResponseWriter, req *http.Request) { wx.ServeHTTP(rep, req) } -// -// handleLogin -// @Description: 用户登录 -// @param id -// +// handleLogin +// @Description: 用户登录 +// @param id func handleLogin(id string, msg string) { core := &lib.Core{Push: func(id1 string, kind, message string) { if kind == "flush" && strings.Contains(message, "login.xuexi.cn") { @@ -555,11 +545,9 @@ func handleLogin(id string, msg string) { sendMsg(id, "登录成功") } -// -// handleStartStudy -// @Description: 开始学习 -// @param id -// +// handleStartStudy +// @Description: 开始学习 +// @param id func handleStartStudy(id string, msg string) { users, err := model.QueryByPushID(id) if err != nil { @@ -583,7 +571,7 @@ func handleStartStudy(id string, msg string) { } sendMsg(id, fmt.Sprintf("开始学习第%d个用户,用户名:%v", i+1, user.Nick)) core.LearnArticle(user) - core.LearnVideo(user) + core.RadioStation(user) if conf.GetConfig().Model == 2 { core.RespondDaily(user, "daily") } else if conf.GetConfig().Model == 3 { diff --git a/utils/util.go b/utils/util.go index 3dd21e4..c359307 100644 --- a/utils/util.go +++ b/utils/util.go @@ -48,7 +48,7 @@ func GetAbout() string { */ func CheckUserCookie(cookies []*http.Cookie) (bool, error) { client := GetClient() - response, err := client.R().SetCookies(cookies...).Get("https://pc-api.xuexi.cn/open/api/score/get") + response, err := client.R().SetCookies(cookies...).Get("https://pc-api.xuexi.cn/delegate/score/get") if err != nil { log.Errorln("获取用户总分错误" + err.Error()) return true, err diff --git a/web/controller.go b/web/controller.go index bc8a999..8986630 100644 --- a/web/controller.go +++ b/web/controller.go @@ -311,7 +311,7 @@ func study() gin.HandlerFunc { config := conf.GetConfig() go func() { core.LearnArticle(user) - core.LearnVideo(user) + core.RadioStation(user) if config.Model == 2 { core.RespondDaily(user, "daily") } else if config.Model == 3 {