Skip to content

Commit 53c0eac

Browse files
committed
fix log
1 parent 8dc1d16 commit 53c0eac

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

pkg/util/util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ func ByteSliceToString(bs []byte) string {
9090

9191
func Check(err error) {
9292
if err != nil {
93-
log.Fatalf("遇到错误: %v", err)
93+
log.Errorf("遇到错误: %v", err)
94+
time.Sleep()
9495
}
9596
}
9697

service/bot/bot.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ func InitDevice(path string) {
3434
log.Infof("将使用 %s 内的设备信息运行", path)
3535
client.SystemDeviceInfo.IpAddress = []byte{192, 168, 31, 101}
3636
if err := client.SystemDeviceInfo.ReadJson([]byte(util.ReadAllText(path))); err != nil {
37-
log.Fatalf("加载设备信息失败: %v", err)
37+
log.Errorf("加载设备信息失败: %v", err)
38+
time.Sleep(5 * time.Second)
39+
os.Exit(0)
3840
}
3941
}
4042

@@ -66,7 +68,7 @@ func Login(cli *client.QQClient) (bool, error) {
6668
v, err := promise.Start(func() bool {
6769
ok, err := ProcessLoginRsp(cli, rsp)
6870
if err != nil {
69-
log.Fatalf("登陆遇到错误2:%v", err)
71+
log.Errorf("登陆遇到错误2:%v", err)
7072
time.Sleep(5 * time.Second)
7173
os.Exit(0)
7274
}
@@ -105,7 +107,8 @@ func SetRelogin(cli *client.QQClient, retryInterval int, retryCount int) {
105107
return
106108
}
107109
}
108-
log.Fatal("重连失败: 重连次数达到设置的上限值")
109-
log.Fatalf("Bot已离线:%v", e.Message)
110+
log.Errorf("重连失败: 重连次数达到设置的上限值")
111+
time.Sleep(5 * time.Second)
112+
os.Exit(0)
110113
})
111114
}

service/handler/bot.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/Mrs4s/MiraiGo/client"
1010
"github.com/ProtobufBot/Go-Mirai-Client/pkg/plugin"
11-
"github.com/ProtobufBot/Go-Mirai-Client/pkg/util"
1211
"github.com/ProtobufBot/Go-Mirai-Client/proto_gen/dto"
1312
"github.com/ProtobufBot/Go-Mirai-Client/service/bot"
1413
"github.com/ProtobufBot/Go-Mirai-Client/service/plugins"
@@ -172,11 +171,19 @@ func CreateBotImpl(uin int64, password string) {
172171
}
173172

174173
log.Infof("刷新好友列表")
175-
util.Check(bot.Cli.ReloadFriendList())
174+
if err := bot.Cli.ReloadFriendList(); err != nil {
175+
log.Errorf("加载好友列表失败")
176+
time.Sleep(5 * time.Second)
177+
os.Exit(0)
178+
}
176179
log.Infof("共加载 %v 个好友.", len(bot.Cli.FriendList))
177180

178181
log.Infof("刷新群列表")
179-
util.Check(bot.Cli.ReloadGroupList())
182+
if err := bot.Cli.ReloadGroupList(); err != nil {
183+
log.Errorf("加载群列表失败")
184+
time.Sleep(5 * time.Second)
185+
os.Exit(0)
186+
}
180187
log.Infof("共加载 %v 个群.", len(bot.Cli.GroupList))
181188

182189
bot.ConnectUniversal(bot.Cli)

0 commit comments

Comments
 (0)