From 74cb2d19cafdf44ec353b9c09449c48881313c3f Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Fri, 1 Nov 2024 00:47:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84RegisterLiveHandl?= =?UTF-8?q?er=EF=BC=8C=E4=B8=8D=E5=86=8D=E4=B8=BB=E5=8A=A8=E6=B3=A8?= =?UTF-8?q?=E9=94=80handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/handler.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/handler/handler.go b/handler/handler.go index c69bdc3..e24dff7 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -50,6 +50,16 @@ func RegisterLiveHandler(groupID int64, userID int64, handler model.TryCatchHand liveHandlers[groupID][userID] = handler } +func UnRegisterLiveHandler(groupID int64, userID int64) { + if groupID == 0 { + delete(livePrivateHandlers, userID) + return + } + if _, ok := liveHandlers[groupID]; ok { + delete(liveHandlers[groupID], userID) + } +} + func RegisterGroupHandler(groupID int64, trigger string, handler model.Handler, level constants.PermissionLevel) { if _, ok := GroupHandlers[groupID]; !ok { GroupHandlers[groupID] = make(map[string]model.HandlerInfo[model.Handler]) @@ -93,7 +103,6 @@ func MsgInHandler(msg model.Message) (reply model.Reply) { }() if handlerUserID, ok := liveHandlers[msg.GroupInfo.GroupId]; ok { if handler, ok := handlerUserID[msg.UserId]; ok { - defer func() { liveHandlers[msg.GroupInfo.GroupId][msg.UserId] = nil }() reply, catched := handler(msg) if catched { return reply @@ -101,7 +110,6 @@ func MsgInHandler(msg model.Message) (reply model.Reply) { } } if handler, ok := livePrivateHandlers[msg.UserId]; ok { - defer func() { livePrivateHandlers[msg.UserId] = nil }() reply, catched := handler(msg) if catched { return reply