refactor: 重构RegisterLiveHandler,不再主动注销handler
This commit is contained in:
parent
53da17802a
commit
74cb2d19ca
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user