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

feat: remove session.token on error.

This commit is contained in:
Mrs4s 2021-04-07 19:10:44 +08:00
parent bdc0a15465
commit 3c5779ebd3
2 changed files with 7 additions and 3 deletions

View File

@ -64,8 +64,11 @@ func WriteAllText(path, text string) error {
}
// Check 检测err是否为nil
func Check(err error) {
func Check(err error, deleteSession bool) {
if err != nil {
if deleteSession && PathExists("session.token") {
_ = os.Remove("session.token")
}
log.Fatalf("遇到错误: %v", err)
}
}

View File

@ -294,6 +294,7 @@ func main() {
token, err := ioutil.ReadFile("session.token")
if err == nil {
if err = cli.TokenLogin(token); err != nil {
_ = os.Remove("session.token")
log.Warnf("恢复会话失败: %v , 尝试使用正常流程登录.", err)
} else {
isTokenLogin = true
@ -349,10 +350,10 @@ func main() {
cli.AllowSlider = true
log.Infof("登录成功 欢迎使用: %v", cli.Nickname)
log.Info("开始加载好友列表...")
global.Check(cli.ReloadFriendList())
global.Check(cli.ReloadFriendList(), true)
log.Infof("共加载 %v 个好友.", len(cli.FriendList))
log.Infof("开始加载群列表...")
global.Check(cli.ReloadGroupList())
global.Check(cli.ReloadGroupList(), true)
log.Infof("共加载 %v 个群.", len(cli.GroupList))
bot := coolq.NewQQBot(cli, conf)
_ = bot.Client