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

Merge remote-tracking branch 'upstream/dev' into dev

This commit is contained in:
wdvxdr 2020-11-13 21:03:50 +08:00
commit 80af002668
7 changed files with 51 additions and 13 deletions

View File

@ -807,7 +807,7 @@ func (bot *CQBot) CQGetVersionInfo() MSG {
"version": Version,
"protocol": func() int {
switch client.SystemDeviceInfo.Protocol {
case client.AndroidPad:
case client.IPad:
return 0
case client.AndroidPhone:
return 1

View File

@ -112,8 +112,20 @@ go-cqhttp 支持导入CQHTTP的配置文件, 具体步骤为:
| 值 | 类型 | 限制 |
| ---- | ------------- | ----------------------------------------------------- |
| 0 | Android Pad | 无法接收 `group_notify` 事件、无法接收口令红包 |
| 0 | iPad | 无 |
| 1 | Android Phone | 无 |
| 2 | Android Watch | 除了 `Android Pad` 有的限制外还包括: 无法接收撤回消息 |
| 2 | Android Watch | 无法接收 `group_notify` 事件、无法接收口令红包、无法接收撤回消息 |
> 注意, 根据协议的不同, 各类消息有所限制
> 注意, 根据协议的不同, 各类消息有所限制
## 自定义服务器IP
> 某些海外服务器使用默认地址可能会存在链路问题,此功能可以指定 go-cqhttp 连接哪些地址以达到最优化.
将文件 `address.txt` 创建到 `go-cqhttp` 工作目录, 并键入 `IP:PORT` 以换行符为分割即可.
示例:
````
1.1.1.1:53
1.1.2.2:8899
````

View File

@ -10,10 +10,12 @@ import (
"github.com/dustin/go-humanize"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net"
"net/url"
"os"
"path"
"runtime"
"strconv"
"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 {
Total uint64
}

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-20201113081613-b6a695d43d8e
github.com/Mrs4s/MiraiGo v0.0.0-20201113113825-c1739dba15c9
github.com/dustin/go-humanize v1.0.0
github.com/getlantern/go-update v0.0.0-20190510022740-79c495ab728c
github.com/getlantern/golog v0.0.0-20201105130739-9586b8bde3a9 // indirect

6
go.sum
View File

@ -1,9 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd h1:n1llMhWgT5s/dBWtbg0NwDzXFAKWfwr1ZXxaErZkLfc=
github.com/Mrs4s/MiraiGo v0.0.0-20201112150130-58e7c82fd2dd/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/Mrs4s/MiraiGo v0.0.0-20201113081613-b6a695d43d8e h1:3bXOOf9YxLpoF3jYdd5JB/QXggvvFrRNUyvCQysmIoU=
github.com/Mrs4s/MiraiGo v0.0.0-20201113081613-b6a695d43d8e/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/Mrs4s/MiraiGo v0.0.0-20201113113825-c1739dba15c9 h1:7mFBaoEz2HCIkUqfiW1EtpsZEhxfupEda8+EMeuNS+4=
github.com/Mrs4s/MiraiGo v0.0.0-20201113113825-c1739dba15c9/go.mod h1:pAsWtMIwqkBXr5DkUpTIHoWQJNduVnX9WSBPmPvkuCs=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

12
main.go
View File

@ -226,8 +226,8 @@ func main() {
log.Info("开始尝试登录并同步消息...")
log.Infof("使用协议: %v", func() string {
switch client.SystemDeviceInfo.Protocol {
case client.AndroidPad:
return "Android Pad"
case client.IPad:
return "iPad"
case client.AndroidPhone:
return "Android Phone"
case client.AndroidWatch:
@ -246,6 +246,14 @@ func main() {
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 {
if !conf.UseSSOAddress {
log.Infof("收到服务器地址更新通知, 根据配置文件已忽略.")

View File

@ -340,8 +340,8 @@ func (s *webServer) DoReLogin() { // TODO: 协议层的 ReLogin
log.Info("开始尝试登录并同步消息...")
log.Infof("使用协议: %v", func() string {
switch client.SystemDeviceInfo.Protocol {
case client.AndroidPad:
return "Android Pad"
case client.IPad:
return "iPad"
case client.AndroidPhone:
return "Android Phone"
case client.AndroidWatch: