feat: 添加忽略等级

This commit is contained in:
lixiangwuxian 2024-10-24 14:33:49 +08:00
parent f840391f97
commit 0fc6e0d52a
3 changed files with 12 additions and 1 deletions

View File

@ -40,6 +40,15 @@ func SetPermission(qqID int64, level constants.PermissionLevel) error {
} }
func TryExecHandler(msg model.Message, level constants.PermissionLevel, handler model.Handler) (reply model.Reply) { func TryExecHandler(msg model.Message, level constants.PermissionLevel, handler model.Handler) (reply model.Reply) {
if permission, err := getAuth(msg.UserId); err != nil {
if permission.Role == constants.LEVEL_IGNORE {
return model.Reply{
ReplyMsg: "",
ReferOriginMsg: false,
FromMsg: msg,
}
}
}
if HasPermission(msg.UserId, level) { if HasPermission(msg.UserId, level) {
return handler(msg) return handler(msg)
} }

View File

@ -8,4 +8,5 @@ const (
LEVEL_TRUSTED = 100 LEVEL_TRUSTED = 100
LEVEL_USER = 200 //default LEVEL_USER = 200 //default
LEVEL_BANNED = 400 LEVEL_BANNED = 400
LEVEL_IGNORE = 1000
) )

View File

@ -13,7 +13,7 @@ import (
func init() { func init() {
handler.RegisterFrontMatchHandler("用户权限", setUserLevel, constants.LEVEL_USER) handler.RegisterFrontMatchHandler("用户权限", setUserLevel, constants.LEVEL_USER)
handler.RegisterHelpInform("用户权限", "用户权限 [用户] [权限] 设置用户权限。允许的权限有:根用户、管理员、信任、用户、拉黑") handler.RegisterHelpInform("用户权限", "用户权限 [用户] [权限] 设置用户权限。允许的权限有:根用户、管理员、信任、用户、拉黑、忽略")
} }
var userLevelMap = map[string]constants.PermissionLevel{ var userLevelMap = map[string]constants.PermissionLevel{
@ -22,6 +22,7 @@ var userLevelMap = map[string]constants.PermissionLevel{
"信任": constants.LEVEL_TRUSTED, "信任": constants.LEVEL_TRUSTED,
"用户": constants.LEVEL_USER, "用户": constants.LEVEL_USER,
"拉黑": constants.LEVEL_BANNED, "拉黑": constants.LEVEL_BANNED,
"忽略": constants.LEVEL_IGNORE,
} }
func setUserLevel(msg model.Message) (reply model.Reply) { func setUserLevel(msg model.Message) (reply model.Reply) {