mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 03:53:50 +08:00
feature custom server address.
This commit is contained in:
parent
7e3f94ad2e
commit
998b8cb146
20
global/fs.go
20
global/fs.go
@ -10,10 +10,12 @@ import (
|
|||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -110,6 +112,24 @@ func DelFile(path string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ReadAddrFile(path string) []*net.TCPAddr {
|
||||||
|
d, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
str := string(d)
|
||||||
|
lines := strings.Split(str, "\n")
|
||||||
|
var ret []*net.TCPAddr
|
||||||
|
for _, l := range lines {
|
||||||
|
ip := strings.Split(l, ":")
|
||||||
|
if len(ip) == 2 {
|
||||||
|
port, _ := strconv.Atoi(ip[1])
|
||||||
|
ret = append(ret, &net.TCPAddr{IP: net.ParseIP(ip[0]), Port: port})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
type WriteCounter struct {
|
type WriteCounter struct {
|
||||||
Total uint64
|
Total uint64
|
||||||
}
|
}
|
||||||
|
8
main.go
8
main.go
@ -246,6 +246,14 @@ func main() {
|
|||||||
log.Debug("Protocol -> " + e.Message)
|
log.Debug("Protocol -> " + e.Message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if global.PathExists("address.txt") {
|
||||||
|
log.Infof("检测到 address.txt 文件. 将覆盖目标IP.")
|
||||||
|
addr := global.ReadAddrFile("address.txt")
|
||||||
|
if len(addr) > 0 {
|
||||||
|
cli.SetCustomServer(addr)
|
||||||
|
}
|
||||||
|
log.Infof("读取到 %v 个自定义地址.", len(addr))
|
||||||
|
}
|
||||||
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
|
cli.OnServerUpdated(func(bot *client.QQClient, e *client.ServerUpdatedEvent) bool {
|
||||||
if !conf.UseSSOAddress {
|
if !conf.UseSSOAddress {
|
||||||
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
|
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user