1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

Merge branch 'master' into dev

This commit is contained in:
Mrs4s 2021-04-10 20:41:09 +08:00
commit 37e2fdaea7
3 changed files with 19 additions and 26 deletions

3
go.mod
View File

@ -4,7 +4,7 @@ go 1.16
require ( require (
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
github.com/Mrs4s/MiraiGo v0.0.0-20210406093140-5ec6c651b797 github.com/Mrs4s/MiraiGo v0.0.0-20210410123741-46a09462b006
github.com/dustin/go-humanize v1.0.0 github.com/dustin/go-humanize v1.0.0
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
@ -25,6 +25,7 @@ require (
github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60 github.com/wdvxdr1123/go-silk v0.0.0-20210316130616-d47b553def60
github.com/willf/bitset v1.1.11 // indirect github.com/willf/bitset v1.1.11 // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
golang.org/x/term v0.0.0-20210317153231-de623e64d2a6 golang.org/x/term v0.0.0-20210317153231-de623e64d2a6
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c

6
go.sum
View File

@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
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 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/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20210406093140-5ec6c651b797 h1:u6jJ6bbYghAEM1DVe0SQKoIVva6od7fsdFRRC15DKMw= github.com/Mrs4s/MiraiGo v0.0.0-20210410123741-46a09462b006 h1:WgHUpyyPxtdg01atpzl/qtg0f8vPvdvA8IEe9xM54vI=
github.com/Mrs4s/MiraiGo v0.0.0-20210406093140-5ec6c651b797/go.mod h1:NjiWhlvGxwv1ftOWIoiFa/OzklnAYI4YqNexFOKSZKw= github.com/Mrs4s/MiraiGo v0.0.0-20210410123741-46a09462b006/go.mod h1:NjiWhlvGxwv1ftOWIoiFa/OzklnAYI4YqNexFOKSZKw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -134,6 +134,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb h1:fqpd0EBDzlHRCjiphRR5Zo/RSWWQlWv34418dnEixWk=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=

36
main.go
View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"bufio"
"crypto/aes" "crypto/aes"
"crypto/md5" "crypto/md5"
"crypto/sha1" "crypto/sha1"
@ -301,6 +300,10 @@ func main() {
// c := server.Console // c := server.Console
isQRCodeLogin := (conf.Account.Uin == 0 || len(conf.Account.Password) == 0) && !conf.Account.Encrypt isQRCodeLogin := (conf.Account.Uin == 0 || len(conf.Account.Password) == 0) && !conf.Account.Encrypt
isTokenLogin := false isTokenLogin := false
saveToken := func() {
global.AccountToken = cli.GenToken()
_ = ioutil.WriteFile("session.token", global.AccountToken, 0677)
}
if global.PathExists("session.token") { if global.PathExists("session.token") {
token, err := ioutil.ReadFile("session.token") token, err := ioutil.ReadFile("session.token")
if err == nil { if err == nil {
@ -322,6 +325,7 @@ func main() {
if err = cli.TokenLogin(token); err != nil { if err = cli.TokenLogin(token); err != nil {
_ = os.Remove("session.token") _ = os.Remove("session.token")
log.Warnf("恢复会话失败: %v , 尝试使用正常流程登录.", err) log.Warnf("恢复会话失败: %v , 尝试使用正常流程登录.", err)
time.Sleep(time.Second)
} else { } else {
isTokenLogin = true isTokenLogin = true
} }
@ -338,11 +342,6 @@ func main() {
} }
} }
} }
saveToken := func() {
global.AccountToken = cli.GenToken()
_ = ioutil.WriteFile("session.token", global.AccountToken, 0677)
}
saveToken()
var times uint = 1 // 重试次数 var times uint = 1 // 重试次数
var reLoginLock sync.Mutex var reLoginLock sync.Mutex
cli.OnDisconnected(func(q *client.QQClient, e *client.ClientDisconnectedEvent) { cli.OnDisconnected(func(q *client.QQClient, e *client.ClientDisconnectedEvent) {
@ -357,6 +356,9 @@ func main() {
} }
if conf.Account.ReLogin.Interval > 0 { if conf.Account.ReLogin.Interval > 0 {
log.Warnf("将在 %v 秒后尝试重连. 重连次数:%v/%v", conf.Account.ReLogin.Interval, times, conf.Account.ReLogin.MaxTimes) log.Warnf("将在 %v 秒后尝试重连. 重连次数:%v/%v", conf.Account.ReLogin.Interval, times, conf.Account.ReLogin.MaxTimes)
time.Sleep(time.Second * time.Duration(conf.Account.ReLogin.Interval))
} else {
time.Sleep(time.Second)
} }
log.Warnf("尝试重连...") log.Warnf("尝试重连...")
if cli.Online { if cli.Online {
@ -373,6 +375,7 @@ func main() {
log.Fatalf("登录时发生致命错误: %v", err) log.Fatalf("登录时发生致命错误: %v", err)
} }
}) })
saveToken()
cli.AllowSlider = true cli.AllowSlider = true
log.Infof("登录成功 欢迎使用: %v", cli.Nickname) log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
log.Info("开始加载好友列表...") log.Info("开始加载好友列表...")
@ -471,15 +474,11 @@ func checkUpdate() {
return return
} }
var res string var res string
if err := gout.GET("https://api.github.com/repos/Mrs4s/go-cqhttp/releases").BindBody(&res).Do(); err != nil { if err := gout.GET("https://api.github.com/repos/Mrs4s/go-cqhttp/releases/latest").BindBody(&res).Do(); err != nil {
log.Warnf("检查更新失败: %v", err) log.Warnf("检查更新失败: %v", err)
return return
} }
detail := gjson.Parse(res) info := gjson.Parse(res)
if len(detail.Array()) < 1 {
return
}
info := detail.Array()[0]
if global.VersionNameCompare(coolq.Version, info.Get("tag_name").Str) { if global.VersionNameCompare(coolq.Version, info.Get("tag_name").Str) {
log.Infof("当前有更新的 go-cqhttp 可供更新, 请前往 https://github.com/Mrs4s/go-cqhttp/releases 下载.") log.Infof("当前有更新的 go-cqhttp 可供更新, 请前往 https://github.com/Mrs4s/go-cqhttp/releases 下载.")
log.Infof("当前版本: %v 最新版本: %v", coolq.Version, info.Get("tag_name").Str) log.Infof("当前版本: %v 最新版本: %v", coolq.Version, info.Get("tag_name").Str)
@ -489,22 +488,13 @@ func checkUpdate() {
} }
func selfUpdate(imageURL string) { func selfUpdate(imageURL string) {
console := bufio.NewReader(os.Stdin)
readLine := func() (str string) {
str, _ = console.ReadString('\n')
return
}
log.Infof("正在检查更新.") log.Infof("正在检查更新.")
var res string var res string
if err := gout.GET("https://api.github.com/repos/Mrs4s/go-cqhttp/releases").BindBody(&res).Do(); err != nil { if err := gout.GET("https://api.github.com/repos/Mrs4s/go-cqhttp/releases/latest").BindBody(&res).Do(); err != nil {
log.Warnf("检查更新失败: %v", err) log.Warnf("检查更新失败: %v", err)
return return
} }
detail := gjson.Parse(res) info := gjson.Parse(res)
if len(detail.Array()) < 1 {
return
}
info := detail.Array()[0]
version := info.Get("tag_name").Str version := info.Get("tag_name").Str
if coolq.Version != version { if coolq.Version != version {
log.Info("当前最新版本为 ", version) log.Info("当前最新版本为 ", version)