Skip to content

Commit

Permalink
Beta481 (#486)
Browse files Browse the repository at this point in the history
* beta447

* beta448

* beta449

* beta450

* beta451

* beta452

* beta453

* beta454

* beta455

* btea455

* beta456

* beta457

* beta458

* beta460

* beta460

* beta461

* beta462

* beta463

* beta464

* beta465

* beta467

* beta468

* beta469

* beta470

* beta471

* beta472

* beta473

* beta473

* beta475

* beta476

* beta478

* beta479

* beta479

* beta480

* beta481
  • Loading branch information
Hoshinonyaruko authored Aug 18, 2024
1 parent f0414dc commit 09741aa
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 55 deletions.
12 changes: 8 additions & 4 deletions botgo/websocket/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
51 changes: 31 additions & 20 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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中删除已处理的图片项
Expand Down Expand Up @@ -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)
}
}

}
Expand Down Expand Up @@ -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 // 跳过这个项,继续下一个
Expand Down Expand Up @@ -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)
}
}

}
Expand Down
52 changes: 32 additions & 20 deletions handlers/send_group_msg_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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中删除已处理的图片项
Expand Down Expand Up @@ -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)
}
}

}
Expand Down Expand Up @@ -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)
}
}

}
Expand Down Expand Up @@ -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)
}
}

}
Expand Down
34 changes: 23 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand All @@ -715,23 +718,26 @@ func CreateMessageHandler() event.MessageEventHandler {
data.Author.Username = acnode.CheckWordIN(data.Author.Username)
}
}
return p.ProcessGuildNormalMessage(data)
go p.ProcessGuildNormalMessage(data)
return nil
}
}

// InteractionHandler 处理内联交互事件
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
}
}

// ThreadEventHandler 处理帖子事件
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
}
}

Expand All @@ -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
}
}

Expand All @@ -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
}
}

Expand Down
1 change: 1 addition & 0 deletions structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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修改
Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 09741aa

Please sign in to comment.