Skip to content

Commit

Permalink
Beta489 (#494)
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

* beta482

* beta483

* beta484

* beta485

* beta486

* beta486

* beta487

* beta487

* beta489
  • Loading branch information
Hoshinonyaruko authored Aug 21, 2024
1 parent e0ce498 commit 42f3f33
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
16 changes: 13 additions & 3 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {

var messageText string
//当屏蔽错误通道时候=性能模式 不解析at 不解析图片
if !config.GetDisableErrorChan() {
GetDisableErrorChan := config.GetDisableErrorChan()

// 判断性能模式
if !GetDisableErrorChan {
//转换at
messageText = handlers.RevertTransformedText(data, "group_private", p.Api, p.Apiv2, 0, 0, config.GetWhiteEnable(5))
if messageText == "" {
Expand Down Expand Up @@ -436,8 +439,15 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {

// Convert OnebotGroupMessage to map and send
groupMsgMap := structToMap(groupMsg)
//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data)

// 不使用性能模式
if !GetDisableErrorChan {
//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data)
} else {
// 性能模式
go p.BroadcastMessageToAllFAF(groupMsgMap, p.Apiv2, data)
}

//组合FriendData
userdata := structs.FriendData{
Expand Down
15 changes: 12 additions & 3 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
}

var messageText string
GetDisableErrorChan := config.GetDisableErrorChan()

//当屏蔽错误通道时候=性能模式 不解析at 不解析图片
if !config.GetDisableErrorChan() {
if !GetDisableErrorChan {
// 转换at
messageText = handlers.RevertTransformedText(data, "group", p.Api, p.Apiv2, GroupID64, userid64, config.GetWhiteEnable(4))
if messageText == "" {
Expand Down Expand Up @@ -327,7 +329,14 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
groupMsgMap = structToMap(groupMsgS)
}

//上报信息到onebotv11应用端(正反ws)
go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data)
// 如果不是性能模式
if !GetDisableErrorChan {
//上报信息到onebotv11应用端(正反ws) 并等待返回
go p.BroadcastMessageToAll(groupMsgMap, p.Apiv2, data)
} else {
// FAF式
go p.BroadcastMessageToAllFAF(groupMsgMap, p.Apiv2, data)
}

return nil
}
20 changes: 20 additions & 0 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,26 @@ func (p *Processors) SendMessageToAllClients(message map[string]interface{}) err
return result.ErrorOrNil()
}

// 方便快捷的发信息函数
func (p *Processors) BroadcastMessageToAllFAF(message map[string]interface{}, api openapi.MessageAPI, data interface{}) error {
// 并发发送到我们作为客户端的Wsclient
for _, client := range p.Wsclient {
go func(c callapi.WebSocketServerClienter) {
_ = c.SendMessage(message) // 忽略错误
}(client)
}

// 并发发送到我们作为服务器连接到我们的WsServerClients
for _, serverClient := range p.WsServerClients {
go func(sc callapi.WebSocketServerClienter) {
_ = sc.SendMessage(message) // 忽略错误
}(serverClient)
}

// 不再等待所有 goroutine 完成,直接返回
return nil
}

// 方便快捷的发信息函数
func (p *Processors) BroadcastMessageToAll(message map[string]interface{}, api openapi.MessageAPI, data interface{}) error {
var wg sync.WaitGroup
Expand Down
2 changes: 1 addition & 1 deletion wsclient/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (client *WebSocketClient) SendMessage(message map[string]interface{}) error
return err
}

// 创建错误通道,用于接收写操作的结果
// 创建专用通道,用于接收写操作的结果
client.writeCh <- writeRequest{
messageType: websocket.TextMessage,
data: msgBytes,
Expand Down

0 comments on commit 42f3f33

Please sign in to comment.