测试auth动态化
This commit is contained in:
@@ -7,10 +7,8 @@
|
||||
# 4.群总结能力 #启用群总结 #关闭群总结
|
||||
# 5.sehuatang PDF能力 #启用pdf #关闭pdf
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
import redis
|
||||
from enum import Enum
|
||||
from typing import List
|
||||
|
||||
import yaml
|
||||
from loguru import logger
|
||||
@@ -47,28 +45,33 @@ class Feature(Enum):
|
||||
@classmethod
|
||||
def register_feature(cls, key: str, description: str) -> 'Feature':
|
||||
"""注册新的功能权限
|
||||
|
||||
|
||||
Args:
|
||||
key: 功能键名
|
||||
description: 功能描述
|
||||
|
||||
value: 权限值
|
||||
description: 权限描述
|
||||
|
||||
Returns:
|
||||
Feature: 新注册的功能枚举
|
||||
Feature: 新注册的功能权限
|
||||
"""
|
||||
# 检查是否已经注册过
|
||||
if key in cls._member_map_:
|
||||
return cls._member_map_[key]
|
||||
# 检查value是否已存在
|
||||
for feature in cls:
|
||||
if feature.name == key:
|
||||
logger.warning(f"功能权限值 {key} 已存在,将被覆盖")
|
||||
feature.description = description
|
||||
return feature
|
||||
|
||||
# 获取当前最大的枚举值并加1
|
||||
new_value = cls.get_max_value() + 1
|
||||
# 创建新的功能权限
|
||||
feature = cls._member_map_.get(key)
|
||||
if feature is None:
|
||||
feature = object.__new__(cls)
|
||||
feature._value_ = cls.get_max_value() + 1
|
||||
feature._name_ = key # 设置枚举成员名称
|
||||
feature.description = description
|
||||
cls._member_map_[key] = feature
|
||||
cls._member_names_.append(key)
|
||||
|
||||
# 创建新的枚举成员
|
||||
new_feature = cls(new_value, description)
|
||||
cls._member_map_[key] = new_feature
|
||||
cls._member_names_.append(key)
|
||||
new_feature._name_ = key
|
||||
|
||||
return new_feature
|
||||
return feature
|
||||
|
||||
@classmethod
|
||||
def get_feature(cls, key: str) -> 'Feature':
|
||||
@@ -336,10 +339,10 @@ if __name__ == '__main__':
|
||||
print("当前功能列表:")
|
||||
for feature in Feature.get_all_features():
|
||||
print(f"{feature.name}: {feature.value} - {feature.description}")
|
||||
|
||||
print(f"最大VALUE:{Feature.get_max_value()}")
|
||||
# 测试注册新功能
|
||||
print("\n注册新功能...")
|
||||
new_feature = Feature.register_feature("TEST_FEATURE", "🧪 测试功能 [测试]")
|
||||
new_feature = Feature.register_feature("TEST_FEATURE", "🧪 测试功能 [测试]")
|
||||
print(f"新功能: {new_feature.name} = {new_feature.value} - {new_feature.description}")
|
||||
|
||||
# 验证新功能是否添加成功
|
||||
@@ -358,11 +361,11 @@ if __name__ == '__main__':
|
||||
print(f"获取到的功能: {retrieved_feature.name} = {retrieved_feature.value} - {retrieved_feature.description}")
|
||||
|
||||
# 测试通过值查找功能
|
||||
print("\n测试通过值查找功能...")
|
||||
feature_by_value = Feature(1, "") # 查找 ROBOT
|
||||
print(f"通过值1查找: {feature_by_value.name} = {feature_by_value.value} - {feature_by_value.description}")
|
||||
feature_by_value = Feature(2, "") # 查找 TEST_FEATURE
|
||||
print(f"通过值2查找: {feature_by_value.name} = {feature_by_value.value} - {feature_by_value.description}")
|
||||
# print("\n测试通过值查找功能...")
|
||||
# feature_by_value = Feature(1, "") # 查找 ROBOT
|
||||
# print(f"通过值1查找: {feature_by_value.name} = {feature_by_value.value} - {feature_by_value.description}")
|
||||
# feature_by_value = Feature(2, "") # 查找 TEST_FEATURE
|
||||
# print(f"通过值2查找: {feature_by_value.name} = {feature_by_value.value} - {feature_by_value.description}")
|
||||
|
||||
# 测试枚举属性访问
|
||||
print("\n测试枚举属性访问...")
|
||||
|
||||
Reference in New Issue
Block a user