Skip to content

Commit 3118354

Browse files
committed
update init device
1 parent 80e662a commit 3118354

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/ProtobufBot/Go-Mirai-Client
33
go 1.15
44

55
require (
6-
github.com/Mrs4s/MiraiGo v0.0.0-20210130140601-bebbc838c8bd
6+
github.com/Mrs4s/MiraiGo v0.0.0-20210130224430-cad8dcb736b4
77
github.com/fanliao/go-promise v0.0.0-20141029170127-1890db352a72
88
github.com/gin-gonic/gin v1.6.3
99
github.com/go-playground/validator/v10 v10.4.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
22
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
33
github.com/Mrs4s/MiraiGo v0.0.0-20210130140601-bebbc838c8bd h1:iOv3KAtOOFPm6vx31yu1aPplBNmb00i5E0aKaOEkP+I=
44
github.com/Mrs4s/MiraiGo v0.0.0-20210130140601-bebbc838c8bd/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
5+
github.com/Mrs4s/MiraiGo v0.0.0-20210130224430-cad8dcb736b4 h1:3Y+C3EGDci0BcWx6xLqQ7L+KZdCGz066NVELl1KJNuY=
6+
github.com/Mrs4s/MiraiGo v0.0.0-20210130224430-cad8dcb736b4/go.mod h1:yhqA0NyKxUf7I/0HR/1OMchveFggX8wde04gqdGrNfU=
57
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
68
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
79
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

service/bot/bot.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package bot
22

33
import (
44
"fmt"
5+
"github.com/Mrs4s/MiraiGo/utils"
56
"io/ioutil"
67
"time"
78

89
"github.com/Mrs4s/MiraiGo/client"
9-
"github.com/Mrs4s/MiraiGo/utils"
1010
"github.com/ProtobufBot/Go-Mirai-Client/pkg/util"
1111
"github.com/fanliao/go-promise"
1212
log "github.com/sirupsen/logrus"
@@ -15,26 +15,31 @@ import (
1515
var Cli *client.QQClient
1616

1717
func InitDevice(path string) {
18-
if !util.PathExists(path) {
19-
log.Warn("虚拟设备信息不存在, 将自动生成随机设备.")
20-
client.GenRandomDevice()
21-
client.SystemDeviceInfo.Display = []byte("GMC." + utils.RandomStringRange(6, "0123456789") + ".001")
22-
client.SystemDeviceInfo.FingerPrint = []byte("pbbot/gmc/gmc:10/PBBOT.200324.001/" + utils.RandomStringRange(7, "0123456789") + ":user/release-keys")
23-
client.SystemDeviceInfo.ProcVersion = []byte("Linux 5.4.0-54-generic" + utils.RandomString(8) + " ([email protected])")
24-
client.SystemDeviceInfo.AndroidId = client.SystemDeviceInfo.Display
25-
client.SystemDeviceInfo.Device = []byte("gmc")
26-
client.SystemDeviceInfo.Board = []byte("gmc")
27-
client.SystemDeviceInfo.Model = []byte("gmc")
28-
client.SystemDeviceInfo.Brand = []byte("pbbot")
29-
client.SystemDeviceInfo.Product = []byte("gmc")
30-
client.SystemDeviceInfo.Protocol = client.IPad
31-
_ = ioutil.WriteFile(path, client.SystemDeviceInfo.ToJson(), 0644)
32-
log.Infof("已生成设备信息并保存到 %s 文件.", path)
33-
}
34-
log.Infof("将使用 %s 内的设备信息运行", path)
18+
log.Info("生成随机设备信息")
19+
client.GenRandomDevice()
20+
client.SystemDeviceInfo.Display = []byte("GMC." + utils.RandomStringRange(6, "0123456789") + ".001")
21+
client.SystemDeviceInfo.FingerPrint = []byte("pbbot/gmc/gmc:10/PBBOT.200324.001/" + utils.RandomStringRange(7, "0123456789") + ":user/release-keys")
22+
client.SystemDeviceInfo.ProcVersion = []byte("Linux 5.4.0-54-generic" + utils.RandomString(8) + " ([email protected])")
23+
client.SystemDeviceInfo.AndroidId = client.SystemDeviceInfo.Display
24+
client.SystemDeviceInfo.Device = []byte("gmc")
25+
client.SystemDeviceInfo.Board = []byte("gmc")
26+
client.SystemDeviceInfo.Model = []byte("gmc")
27+
client.SystemDeviceInfo.Brand = []byte("pbbot")
28+
client.SystemDeviceInfo.Product = []byte("gmc")
29+
client.SystemDeviceInfo.Protocol = client.IPad
3530
client.SystemDeviceInfo.IpAddress = []byte{192, 168, 31, 101}
36-
if err := client.SystemDeviceInfo.ReadJson([]byte(util.ReadAllText(path))); err != nil {
37-
util.FatalError(fmt.Errorf("failed to load device info, err: %+v", err))
31+
32+
if util.PathExists(path) {
33+
log.Infof("使用 %s 内的设备信息覆盖随机设备信息", path)
34+
if err := client.SystemDeviceInfo.ReadJson([]byte(util.ReadAllText(path))); err != nil {
35+
util.FatalError(fmt.Errorf("failed to load device info, err: %+v", err))
36+
}
37+
}
38+
39+
log.Infof("保存设备信息到文件 %s", path)
40+
err := ioutil.WriteFile(path, client.SystemDeviceInfo.ToJson(), 0644)
41+
if err != nil {
42+
log.Warnf("写设备信息文件 %s 失败", path)
3843
}
3944
}
4045

0 commit comments

Comments
 (0)