mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 03:53:50 +08:00
ws async supported. close #122
This commit is contained in:
parent
cb9599271a
commit
196cffb099
@ -14,7 +14,6 @@ type JsonConfig struct {
|
|||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
ReLogin bool `json:"relogin"`
|
ReLogin bool `json:"relogin"`
|
||||||
ReLoginDelay int `json:"relogin_delay"`
|
ReLoginDelay int `json:"relogin_delay"`
|
||||||
AsyncLoad bool `json:"async_load"`
|
|
||||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||||
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
||||||
|
2
main.go
2
main.go
@ -200,7 +200,7 @@ func main() {
|
|||||||
global.Check(cli.ReloadFriendList())
|
global.Check(cli.ReloadFriendList())
|
||||||
log.Infof("共加载 %v 个好友.", len(cli.FriendList))
|
log.Infof("共加载 %v 个好友.", len(cli.FriendList))
|
||||||
log.Infof("开始加载群列表...")
|
log.Infof("开始加载群列表...")
|
||||||
global.Check(cli.ReloadGroupList(conf.AsyncLoad))
|
global.Check(cli.ReloadGroupList())
|
||||||
log.Infof("共加载 %v 个群.", len(cli.GroupList))
|
log.Infof("共加载 %v 个群.", len(cli.GroupList))
|
||||||
b := coolq.NewQQBot(cli, conf)
|
b := coolq.NewQQBot(cli, conf)
|
||||||
if conf.PostMessageFormat != "string" && conf.PostMessageFormat != "array" {
|
if conf.PostMessageFormat != "string" && conf.PostMessageFormat != "array" {
|
||||||
|
@ -157,14 +157,16 @@ func (c *websocketClient) listenApi(conn *websocket.Conn, u bool) {
|
|||||||
t := strings.ReplaceAll(j.Get("action").Str, "_async", "")
|
t := strings.ReplaceAll(j.Get("action").Str, "_async", "")
|
||||||
log.Debugf("反向WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
log.Debugf("反向WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
||||||
if f, ok := wsApi[t]; ok {
|
if f, ok := wsApi[t]; ok {
|
||||||
ret := f(c.bot, j.Get("params"))
|
go func() {
|
||||||
if j.Get("echo").Exists() {
|
ret := f(c.bot, j.Get("params"))
|
||||||
ret["echo"] = j.Get("echo").Value()
|
if j.Get("echo").Exists() {
|
||||||
}
|
ret["echo"] = j.Get("echo").Value()
|
||||||
c.pushLock.Lock()
|
}
|
||||||
log.Debugf("准备发送API %v 处理结果: %v", t, ret.ToJson())
|
c.pushLock.Lock()
|
||||||
_ = conn.WriteJSON(ret)
|
log.Debugf("准备发送API %v 处理结果: %v", t, ret.ToJson())
|
||||||
c.pushLock.Unlock()
|
_ = conn.WriteJSON(ret)
|
||||||
|
c.pushLock.Unlock()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.conf.ReverseReconnectInterval != 0 {
|
if c.conf.ReverseReconnectInterval != 0 {
|
||||||
@ -276,13 +278,15 @@ func (s *websocketServer) listenApi(c *websocket.Conn) {
|
|||||||
t := strings.ReplaceAll(j.Get("action").Str, "_async", "") //TODO: async support
|
t := strings.ReplaceAll(j.Get("action").Str, "_async", "") //TODO: async support
|
||||||
log.Debugf("WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
log.Debugf("WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
||||||
if f, ok := wsApi[t]; ok {
|
if f, ok := wsApi[t]; ok {
|
||||||
ret := f(s.bot, j.Get("params"))
|
go func() {
|
||||||
if j.Get("echo").Exists() {
|
ret := f(s.bot, j.Get("params"))
|
||||||
ret["echo"] = j.Get("echo").Value()
|
if j.Get("echo").Exists() {
|
||||||
}
|
ret["echo"] = j.Get("echo").Value()
|
||||||
s.pushLock.Lock()
|
}
|
||||||
_ = c.WriteJSON(ret)
|
s.pushLock.Lock()
|
||||||
s.pushLock.Unlock()
|
_ = c.WriteJSON(ret)
|
||||||
|
s.pushLock.Unlock()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user