feat: 为消息发送添加线程安全机制
This commit is contained in:
parent
cfd20cbefe
commit
db054c6a70
@ -3,6 +3,7 @@ package action
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"git.lxtend.com/qqbot/message"
|
"git.lxtend.com/qqbot/message"
|
||||||
"git.lxtend.com/qqbot/model"
|
"git.lxtend.com/qqbot/model"
|
||||||
@ -16,6 +17,7 @@ var ActionManager = actionManager{}
|
|||||||
|
|
||||||
type actionManager struct {
|
type actionManager struct {
|
||||||
botConn *websocket.Conn
|
botConn *websocket.Conn
|
||||||
|
sendMtx sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (am *actionManager) Started() bool {
|
func (am *actionManager) Started() bool {
|
||||||
@ -31,6 +33,8 @@ func (am *actionManager) SendAction(action string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (am *actionManager) SendMsg(reply model.Reply) error {
|
func (am *actionManager) SendMsg(reply model.Reply) error {
|
||||||
|
am.sendMtx.Lock()
|
||||||
|
defer am.sendMtx.Unlock()
|
||||||
if reply.ReferOriginMsg {
|
if reply.ReferOriginMsg {
|
||||||
replyMsg := message.ReplyMessage{
|
replyMsg := message.ReplyMessage{
|
||||||
Type: "reply",
|
Type: "reply",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user