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

Merge pull request #2 from Mrs4s/master

sync
This commit is contained in:
wdvxdr1123 2020-09-11 19:11:34 +08:00 committed by GitHub
commit ec45d04c81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/Mrs4s/go-cqhttp
go 1.14
require (
github.com/Mrs4s/MiraiGo v0.0.0-20200910013944-236c0f629099
github.com/Mrs4s/MiraiGo v0.0.0-20200911100852-71bc19cd42eb
github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect

2
go.sum
View File

@ -8,6 +8,8 @@ github.com/Mrs4s/MiraiGo v0.0.0-20200910010455-37409b1f6b9c h1:bhVr3W0+WTVN+vgZG
github.com/Mrs4s/MiraiGo v0.0.0-20200910010455-37409b1f6b9c/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200910013944-236c0f629099 h1:b+Tmo9h5leZmQokdUu8c2xSIRkkSYoP1z8G+zcwwyRY=
github.com/Mrs4s/MiraiGo v0.0.0-20200910013944-236c0f629099/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/Mrs4s/MiraiGo v0.0.0-20200911100852-71bc19cd42eb h1:WRj/3obehfAMTNKfNo+X3NVqXjeNurMk2yy6haNl/Yk=
github.com/Mrs4s/MiraiGo v0.0.0-20200911100852-71bc19cd42eb/go.mod h1:cwYPI2uq6nxNbx0nA6YuAKF1V5szSs6FPlGVLQvRUlo=
github.com/bwmarrin/snowflake v0.3.0 h1:xm67bEhkKh6ij1790JB83OujPR5CzNe8QuQqAgISZN0=
github.com/bwmarrin/snowflake v0.3.0/go.mod h1:NdZxfVWX+oR6y2K0o6qAYv6gIOP9rjG0/E9WsDpxqwE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=

23
main.go
View File

@ -10,6 +10,7 @@ import (
"image"
"io"
"io/ioutil"
"net"
"os"
"os/signal"
"path"
@ -224,6 +225,28 @@ func main() {
log.Debug("Protocol -> " + e.Message)
}
})
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) {
log.Infof("收到服务器地址更新通知, 将在下一次重连时应用. 服务器地址: %v:%v 服务器位置: %v", e.Servers[0].Server, e.Servers[0].Port, e.Servers[0].Location)
_ = ioutil.WriteFile("servers.bin", binary.NewWriterF(func(w *binary.Writer) {
w.WriteUInt16(uint16(len(e.Servers)))
for _, s := range e.Servers {
if !strings.Contains(s.Server, "com") {
w.WriteString(s.Server)
w.WriteUInt16(uint16(s.Port))
}
}
}), 0644)
})
if global.PathExists("servers.bin") {
if data, err := ioutil.ReadFile("servers.bin"); err == nil {
r := binary.NewReader(data)
r.ReadUInt16()
cli.CustomServer = &net.TCPAddr{
IP: net.ParseIP(r.ReadString()),
Port: int(r.ReadUInt16()),
}
}
}
rsp, err := cli.Login()
for {
global.Check(err)