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
|
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) {
|
func RegisterGroupHandler(groupID int64, trigger string, handler model.Handler, level constants.PermissionLevel) {
|
||||||
if _, ok := GroupHandlers[groupID]; !ok {
|
if _, ok := GroupHandlers[groupID]; !ok {
|
||||||
GroupHandlers[groupID] = make(map[string]model.HandlerInfo[model.Handler])
|
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 handlerUserID, ok := liveHandlers[msg.GroupInfo.GroupId]; ok {
|
||||||
if handler, ok := handlerUserID[msg.UserId]; ok {
|
if handler, ok := handlerUserID[msg.UserId]; ok {
|
||||||
defer func() { liveHandlers[msg.GroupInfo.GroupId][msg.UserId] = nil }()
|
|
||||||
reply, catched := handler(msg)
|
reply, catched := handler(msg)
|
||||||
if catched {
|
if catched {
|
||||||
return reply
|
return reply
|
||||||
@ -101,7 +110,6 @@ func MsgInHandler(msg model.Message) (reply model.Reply) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if handler, ok := livePrivateHandlers[msg.UserId]; ok {
|
if handler, ok := livePrivateHandlers[msg.UserId]; ok {
|
||||||
defer func() { livePrivateHandlers[msg.UserId] = nil }()
|
|
||||||
reply, catched := handler(msg)
|
reply, catched := handler(msg)
|
||||||
if catched {
|
if catched {
|
||||||
return reply
|
return reply
|
||||||
|
Loading…
x
Reference in New Issue
Block a user