Skip to content

Commit eb3e771

Browse files
committed
real port tip
1 parent b5e22a4 commit eb3e771

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

config/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import (
55
"io/ioutil"
66
)
77

8-
var FRAGMENT = false
8+
var (
9+
Fragment = false // 是否分片
10+
RealPort = "9000" // 最终的端口,0随机端口也会获取到真实端口
11+
)
912

1013
type GmcConfig struct {
1114
Server Server `yaml:"server"`

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-20210107103640-1dfc6a6eaa9b
6+
github.com/Mrs4s/MiraiGo v0.0.0-20210107160254-d55ab63e19a3
77
github.com/a8m/syncmap v0.0.0-20200818084611-4bbbd178de97 // indirect
88
github.com/fanliao/go-promise v0.0.0-20141029170127-1890db352a72
99
github.com/gin-gonic/gin v1.6.3

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ github.com/Mrs4s/MiraiGo v0.0.0-20210105173234-72521dec9b56 h1:U7kObHDk3RfaD81+1
4040
github.com/Mrs4s/MiraiGo v0.0.0-20210105173234-72521dec9b56/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
4141
github.com/Mrs4s/MiraiGo v0.0.0-20210107103640-1dfc6a6eaa9b h1:47W0zzC3aQohx4adX1YnY3p8D7PxQgP1VrA/9rLQvuE=
4242
github.com/Mrs4s/MiraiGo v0.0.0-20210107103640-1dfc6a6eaa9b/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
43+
github.com/Mrs4s/MiraiGo v0.0.0-20210107160254-d55ab63e19a3 h1:803dvcwzOtCIff1lV/+E6tbi4y3SYtcCK8oTJBv0DZ0=
44+
github.com/Mrs4s/MiraiGo v0.0.0-20210107160254-d55ab63e19a3/go.mod h1:HW2e375lCQiRwtuA/LV6ZVTsi7co1TRfBn+L5Ow77Bo=
4345
github.com/a8m/syncmap v0.0.0-20200818084611-4bbbd178de97/go.mod h1:f3iF7/3t9i9hsYF8DPgT0XeIVyNzevhMCKf2445Q6pE=
4446
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4547
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func main() {
7474
if err != nil {
7575
util.FatalError(fmt.Errorf("failed to run gin, err: %+v", err))
7676
}
77+
config.RealPort = realPort
7778
log.Infof("端口号 %s", realPort)
7879
log.Infof(fmt.Sprintf("浏览器打开 http://localhost:%s/ 设置机器人", realPort))
7980
select {}

service/bot/api_handler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ func HandleSendGroupMsg(cli *client.QQClient, req *onebot.SendGroupMsgReq) *oneb
124124
sendingMessage := &message.SendingMessage{Elements: miraiMsg}
125125
log.Infof("Bot(%d) Group(%d) <- %s", cli.Uin, req.GroupId, MiraiMsgToRawMsg(miraiMsg))
126126
preProcessGroupSendingMessage(cli, req.GroupId, sendingMessage)
127-
ret := cli.SendGroupMessage(req.GroupId, sendingMessage, config.FRAGMENT)
127+
ret := cli.SendGroupMessage(req.GroupId, sendingMessage, config.Fragment)
128128
if ret == nil || ret.Id == -1 {
129-
config.FRAGMENT = !config.FRAGMENT
130-
log.Warnf("发送群消息失败,可能被风控,下次发送将改变分片策略,FRAGMENT: %+v", config.FRAGMENT)
129+
config.Fragment = !config.Fragment
130+
log.Warnf("发送群消息失败,可能被风控,下次发送将改变分片策略,Fragment: %+v", config.Fragment)
131131
return nil
132132
}
133133
cache.GroupMessageLru.Add(ret.Id, ret)
@@ -155,10 +155,10 @@ func HandleSendMsg(cli *client.QQClient, req *onebot.SendMsgReq) *onebot.SendMsg
155155

156156
if req.GroupId != 0 { // 群
157157
preProcessGroupSendingMessage(cli, req.GroupId, sendingMessage)
158-
ret := cli.SendGroupMessage(req.GroupId, sendingMessage, config.FRAGMENT)
158+
ret := cli.SendGroupMessage(req.GroupId, sendingMessage, config.Fragment)
159159
if ret == nil || ret.Id == -1 {
160-
config.FRAGMENT = !config.FRAGMENT
161-
log.Warnf("发送群消息失败,可能被风控,下次发送将改变分片策略,FRAGMENT: %+v", config.FRAGMENT)
160+
config.Fragment = !config.Fragment
161+
log.Warnf("发送群消息失败,可能被风控,下次发送将改变分片策略,Fragment: %+v", config.Fragment)
162162
return nil
163163
}
164164
cache.GroupMessageLru.Add(ret.Id, ret)

service/bot/captcha.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/Mrs4s/MiraiGo/client"
10+
"github.com/ProtobufBot/Go-Mirai-Client/config"
1011
"github.com/ProtobufBot/Go-Mirai-Client/pkg/util"
1112
"github.com/ProtobufBot/Go-Mirai-Client/proto_gen/dto"
1213
"github.com/fanliao/go-promise"
@@ -29,6 +30,7 @@ func ProcessLoginRsp(cli *client.QQClient, rsp *client.LoginResponse) (bool, err
2930
rsp.Error = client.UnsafeDeviceError
3031
}
3132
}
33+
log.Infof("验证码处理页面: http://localhost:%s/", config.RealPort)
3234
switch rsp.Error {
3335
case client.SliderNeededError:
3436
log.Infof("遇到滑块验证码,请阅读README(顺便star),根据提示操作 https://github.com/protobufbot/Go-Mirai-Client")

0 commit comments

Comments
 (0)