mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 19:43:49 +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"`
|
||||
ReLogin bool `json:"relogin"`
|
||||
ReLoginDelay int `json:"relogin_delay"`
|
||||
AsyncLoad bool `json:"async_load"`
|
||||
HttpConfig *GoCQHttpConfig `json:"http_config"`
|
||||
WSConfig *GoCQWebsocketConfig `json:"ws_config"`
|
||||
ReverseServers []*GoCQReverseWebsocketConfig `json:"ws_reverse_servers"`
|
||||
|
2
main.go
2
main.go
@ -200,7 +200,7 @@ func main() {
|
||||
global.Check(cli.ReloadFriendList())
|
||||
log.Infof("共加载 %v 个好友.", len(cli.FriendList))
|
||||
log.Infof("开始加载群列表...")
|
||||
global.Check(cli.ReloadGroupList(conf.AsyncLoad))
|
||||
global.Check(cli.ReloadGroupList())
|
||||
log.Infof("共加载 %v 个群.", len(cli.GroupList))
|
||||
b := coolq.NewQQBot(cli, conf)
|
||||
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", "")
|
||||
log.Debugf("反向WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
||||
if f, ok := wsApi[t]; ok {
|
||||
ret := f(c.bot, j.Get("params"))
|
||||
if j.Get("echo").Exists() {
|
||||
ret["echo"] = j.Get("echo").Value()
|
||||
}
|
||||
c.pushLock.Lock()
|
||||
log.Debugf("准备发送API %v 处理结果: %v", t, ret.ToJson())
|
||||
_ = conn.WriteJSON(ret)
|
||||
c.pushLock.Unlock()
|
||||
go func() {
|
||||
ret := f(c.bot, j.Get("params"))
|
||||
if j.Get("echo").Exists() {
|
||||
ret["echo"] = j.Get("echo").Value()
|
||||
}
|
||||
c.pushLock.Lock()
|
||||
log.Debugf("准备发送API %v 处理结果: %v", t, ret.ToJson())
|
||||
_ = conn.WriteJSON(ret)
|
||||
c.pushLock.Unlock()
|
||||
}()
|
||||
}
|
||||
}
|
||||
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
|
||||
log.Debugf("WS接收到API调用: %v 参数: %v", t, j.Get("params").Raw)
|
||||
if f, ok := wsApi[t]; ok {
|
||||
ret := f(s.bot, j.Get("params"))
|
||||
if j.Get("echo").Exists() {
|
||||
ret["echo"] = j.Get("echo").Value()
|
||||
}
|
||||
s.pushLock.Lock()
|
||||
_ = c.WriteJSON(ret)
|
||||
s.pushLock.Unlock()
|
||||
go func() {
|
||||
ret := f(s.bot, j.Get("params"))
|
||||
if j.Get("echo").Exists() {
|
||||
ret["echo"] = j.Get("echo").Value()
|
||||
}
|
||||
s.pushLock.Lock()
|
||||
_ = c.WriteJSON(ret)
|
||||
s.pushLock.Unlock()
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user