feat: 为消息发送添加线程安全机制

This commit is contained in:
lixiangwuxian 2025-03-09 14:11:55 +08:00
parent cfd20cbefe
commit db054c6a70

View File

@ -3,6 +3,7 @@ package action
import (
"encoding/json"
"fmt"
"sync"
"git.lxtend.com/qqbot/message"
"git.lxtend.com/qqbot/model"
@ -16,6 +17,7 @@ var ActionManager = actionManager{}
type actionManager struct {
botConn *websocket.Conn
sendMtx sync.Mutex
}
func (am *actionManager) Started() bool {
@ -31,6 +33,8 @@ func (am *actionManager) SendAction(action string) error {
}
func (am *actionManager) SendMsg(reply model.Reply) error {
am.sendMtx.Lock()
defer am.sendMtx.Unlock()
if reply.ReferOriginMsg {
replyMsg := message.ReplyMessage{
Type: "reply",