diff --git a/botgo/websocket/client/client.go b/botgo/websocket/client/client.go index c1c55275..e8fd77d7 100644 --- a/botgo/websocket/client/client.go +++ b/botgo/websocket/client/client.go @@ -317,10 +317,14 @@ func (c *Client) listenMessageAndHandle() { c.readyHandler(payload) continue } - // 解析具体事件,并投递给业务注册的 handler - if err := event.ParseAndHandle(payload); err != nil { - log.Errorf("%s parseAndHandle failed, %v", c.session, err) - } + + // 性能不够 报错也没用 就扬了 + go event.ParseAndHandle(payload) + + // // 解析具体事件,并投递给业务注册的 handler + // if err := event.ParseAndHandle(payload); err != nil { + // log.Errorf("%s parseAndHandle failed, %v", c.session, err) + // } } log.Infof("%s message queue is closed", c.session) } diff --git a/config/config.go b/config/config.go index e1f395fa..09b5ffbc 100644 --- a/config/config.go +++ b/config/config.go @@ -2460,3 +2460,14 @@ func GetThreadsRetMsg() bool { return instance.Settings.ThreadsRetMsg } +// 获取NoRetMsg的值 +func GetNoRetMsg() bool { + mu.RLock() + defer mu.RUnlock() + + if instance == nil { + fmt.Println("Warning: instance is nil when trying to NoRetMsg value.") + return false + } + return instance.Settings.NoRetMsg +} diff --git a/handlers/send_group_msg.go b/handlers/send_group_msg.go index 62398698..25c7d72d 100644 --- a/handlers/send_group_msg.go +++ b/handlers/send_group_msg.go @@ -377,11 +377,13 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } - if config.GetThreadsRetMsg() { - go SendResponse(client, err, &message, resp, api, apiv2) - } else { - // 发送成功回执 - retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + if !config.GetNoRetMsg() { + if config.GetThreadsRetMsg() { + go SendResponse(client, err, &message, resp, api, apiv2) + } else { + // 发送成功回执 + retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + } } delete(foundItems, imageType) // 从foundItems中删除已处理的图片项 @@ -435,11 +437,14 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } else if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } - //发送成功回执 - if config.GetThreadsRetMsg() { - go SendResponse(client, err, &message, resp, api, apiv2) - } else { - retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + + if !config.GetNoRetMsg() { + //发送成功回执 + if config.GetThreadsRetMsg() { + go SendResponse(client, err, &message, resp, api, apiv2) + } else { + retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + } } } @@ -510,11 +515,14 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap } else if err != nil && strings.Contains(err.Error(), "context deadline exceeded") { postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } - //发送成功回执 - if config.GetThreadsRetMsg() { - go SendResponse(client, err, &message, resp, api, apiv2) - } else { - retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + + if !config.GetNoRetMsg() { + //发送成功回执 + if config.GetThreadsRetMsg() { + go SendResponse(client, err, &message, resp, api, apiv2) + } else { + retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + } } } continue // 跳过这个项,继续下一个 @@ -604,11 +612,14 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap postGroupMessageWithRetry(apiv2, message.Params.GroupID.(string), groupMessage) } } - //发送成功回执 - if config.GetThreadsRetMsg() { - go SendResponse(client, err, &message, resp, api, apiv2) - } else { - retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + + if !config.GetNoRetMsg() { + //发送成功回执 + if config.GetThreadsRetMsg() { + go SendResponse(client, err, &message, resp, api, apiv2) + } else { + retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + } } } diff --git a/handlers/send_group_msg_raw.go b/handlers/send_group_msg_raw.go index 72d97f66..5dcd64e0 100644 --- a/handlers/send_group_msg_raw.go +++ b/handlers/send_group_msg_raw.go @@ -297,11 +297,14 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope echo.PushGlobalStack(pair) } - // 发送成功回执 - if config.GetThreadsRetMsg() { - go SendResponse(client, err, &message, resp, api, apiv2) - } else { - retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + if !config.GetNoRetMsg() { + // 发送成功回执 + if config.GetThreadsRetMsg() { + go SendResponse(client, err, &message, resp, api, apiv2) + } else { + retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + } + } delete(foundItems, imageType) // 从foundItems中删除已处理的图片项 @@ -334,11 +337,14 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope pair.GroupMessage = groupMessage echo.PushGlobalStack(pair) } - //发送成功回执 - if config.GetThreadsRetMsg() { - go SendResponse(client, err, &message, resp, api, apiv2) - } else { - retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + + if !config.GetNoRetMsg() { + //发送成功回执 + if config.GetThreadsRetMsg() { + go SendResponse(client, err, &message, resp, api, apiv2) + } else { + retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + } } } @@ -375,12 +381,15 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope pair.GroupMessage = groupMessage echo.PushGlobalStack(pair) } - //发送成功回执 - if config.GetThreadsRetMsg() { - go SendResponse(client, err, &message, resp, api, apiv2) - } else { + + if !config.GetNoRetMsg() { //发送成功回执 - retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + if config.GetThreadsRetMsg() { + go SendResponse(client, err, &message, resp, api, apiv2) + } else { + //发送成功回执 + retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + } } } @@ -441,12 +450,15 @@ func HandleSendGroupMsgRaw(client callapi.Client, api openapi.OpenAPI, apiv2 ope echo.PushGlobalStack(pair) } } - //发送成功回执 - if config.GetThreadsRetMsg() { - go SendResponse(client, err, &message, resp, api, apiv2) - } else { + + if !config.GetNoRetMsg() { //发送成功回执 - retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + if config.GetThreadsRetMsg() { + go SendResponse(client, err, &message, resp, api, apiv2) + } else { + //发送成功回执 + retmsg, _ = SendResponse(client, err, &message, resp, api, apiv2) + } } } diff --git a/main.go b/main.go index 911e2395..3dc697e1 100644 --- a/main.go +++ b/main.go @@ -663,7 +663,9 @@ func ATMessageEventHandler() event.ATMessageEventHandler { data.Author.Username = acnode.CheckWordIN(data.Author.Username) } } - return p.ProcessGuildATMessage(data) + + go p.ProcessGuildATMessage(data) + return nil } } @@ -701,7 +703,8 @@ func DirectMessageHandler() event.DirectMessageEventHandler { data.Author.Username = acnode.CheckWordIN(data.Author.Username) } } - return p.ProcessChannelDirectMessage(data) + go p.ProcessChannelDirectMessage(data) + return nil } } @@ -715,7 +718,8 @@ func CreateMessageHandler() event.MessageEventHandler { data.Author.Username = acnode.CheckWordIN(data.Author.Username) } } - return p.ProcessGuildNormalMessage(data) + go p.ProcessGuildNormalMessage(data) + return nil } } @@ -723,7 +727,8 @@ func CreateMessageHandler() event.MessageEventHandler { func InteractionHandler() event.InteractionEventHandler { return func(event *dto.WSPayload, data *dto.WSInteractionData) error { mylog.Printf("收到按钮回调:%v", data) - return p.ProcessInlineSearch(data) + go p.ProcessInlineSearch(data) + return nil } } @@ -731,7 +736,8 @@ func InteractionHandler() event.InteractionEventHandler { func ThreadEventHandler() event.ThreadEventHandler { return func(event *dto.WSPayload, data *dto.WSThreadData) error { mylog.Printf("收到帖子事件:%v", data) - return p.ProcessThreadMessage(data) + go p.ProcessThreadMessage(data) + return nil } } @@ -745,7 +751,8 @@ func GroupATMessageEventHandler() event.GroupATMessageEventHandler { data.Author.Username = acnode.CheckWordIN(data.Author.Username) } } - return p.ProcessGroupMessage(data) + go p.ProcessGroupMessage(data) + return nil } } @@ -759,35 +766,40 @@ func C2CMessageEventHandler() event.C2CMessageEventHandler { data.Author.Username = acnode.CheckWordIN(data.Author.Username) } } - return p.ProcessC2CMessage(data) + go p.ProcessC2CMessage(data) + return nil } } // GroupAddRobotEventHandler 实现处理 群机器人新增 事件的回调 func GroupAddRobotEventHandler() event.GroupAddRobotEventHandler { return func(event *dto.WSPayload, data *dto.GroupAddBotEvent) error { - return p.ProcessGroupAddBot(data) + go p.ProcessGroupAddBot(data) + return nil } } // GroupDelRobotEventHandler 实现处理 群机器人删除 事件的回调 func GroupDelRobotEventHandler() event.GroupDelRobotEventHandler { return func(event *dto.WSPayload, data *dto.GroupAddBotEvent) error { - return p.ProcessGroupDelBot(data) + go p.ProcessGroupDelBot(data) + return nil } } // GroupMsgRejectHandler 实现处理 群请求关闭机器人主动推送 事件的回调 func GroupMsgRejectHandler() event.GroupMsgRejectHandler { return func(event *dto.WSPayload, data *dto.GroupMsgRejectEvent) error { - return p.ProcessGroupMsgReject(data) + go p.ProcessGroupMsgReject(data) + return nil } } // GroupMsgReceiveHandler 实现处理 群请求开启机器人主动推送 事件的回调 func GroupMsgReceiveHandler() event.GroupMsgReceiveHandler { return func(event *dto.WSPayload, data *dto.GroupMsgReceiveEvent) error { - return p.ProcessGroupMsgRecive(data) + go p.ProcessGroupMsgRecive(data) + return nil } } diff --git a/structs/structs.go b/structs/structs.go index 24272df2..1bea9414 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -109,6 +109,7 @@ type Settings struct { DowntimeMessage string `yaml:"downtime_message"` MemoryMsgid bool `yaml:"memory_msgid"` ThreadsRetMsg bool `yaml:"threads_ret_msg"` + NoRetMsg bool `yaml:"no_ret_msg"` //增长营销类 SelfIntroduce []string `yaml:"self_introduce"` //api修改 diff --git a/template/config_template.go b/template/config_template.go index 0d6113cd..56064b5b 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -141,6 +141,7 @@ settings: downtime_message : "我正在维护中~请不要担心,维护结束就回来~维护时间:(1小时)" memory_msgid : false #当你的机器人单日信息量超过100万,就需要高性能SSD或者开启这个选项了.部分依赖msgid的功能可能会受影响(如delete_msg) threads_ret_msg : false #异步,并发发送回执信息 仅ws可用. + no_ret_msg : false #当你的信息量达到1000万/天的时候,并且你的业务不需要获取回调信息,此时直接屏蔽是最好的选择,可以提升50%收发性能. 需应用端适配!!! #增长营销类(推荐gensokyo-broadcast项目) self_introduce : ["",""] #自我介绍,可设置多个随机发送,当不为空时,机器人被邀入群会发送自定义自我介绍 需手动添加新textintent - "GroupAddRobotEventHandler" - "GroupDelRobotEventHandler"