临时调整权限模块,备份

This commit is contained in:
liuwei
2025-06-09 14:12:31 +08:00
parent cedab1cefd
commit 9d15bf965b
30 changed files with 882 additions and 138 deletions

View File

@@ -29,39 +29,77 @@ class PermissionStatus(Enum):
class Feature(Enum):
"""功能权限枚举,带序号"""
ROBOT = 1, "🔧 群机器人 [总开关]"
DAILY_NEWS = 2, "📰 每日新闻自动播报 [每日8:30定时发送]"
DAILY_SUMMARY = 3, "🕤 每日群发言总结 [每日9:30定时发送]"
AI_CAPABILITY = 4, "🤖 AI对话 [ai, 聊天, AI] 用法ai 如何写一个机器人?"
SUMMARY_CAPABILITY = 5, "📝 群总结能力 [#总结]"
PDF_CAPABILITY = 6, "📄 sehuatang PDF能力 [无]"
EPIC = 7, "📊 EPIC自动播报 [每周五自动发送]" # 新增的功能
PIC = 8, "🖼️ 图来能力 [图来, 秀人]"
TASK_GAME = 9, "📚 百科答题 [/t, /s, /a 任务ID 答案]"
MUSIC = 10, "🎵 点歌功能 [点歌, 音乐, 音乐点播, 点播音乐, 音乐点歌]"
SIGNIN = 11, "✅ 签到功能 [签到, 每日签到, qd, Qd, QD, 上班, 牛马]"
POINT_TRADE = 12, "🎁 积分赠送 [积分赠送 1 @XX, 积分排行, 打劫 @XX, 保释 @XX]"
BEAUTY_LEG = 13, "🦵 腿来能力 [美腿, 腿来]"
VIDEO = 14, "🎥 黑丝视频 [黑丝视频, 黑丝, 来个黑丝, 搞个黑丝]"
VIDEO_MAN = 15, "💪 肌肉视频 [猛男, 肌肉, 帅哥]"
# GROUP_ADD = 16, "加群提醒"
DOUYIN_PARSER = 17, "🎥 抖音链接转视频"
GROUP_MEMBER_CHANGE = 18, "👥 群成员变更提醒 [自动触发]"
# KID_PHOTO_EXTRACT = 19, "儿童照片提取转发功能" # 小朋友照片提取功能
NEWS = 20, "🌍 全球政治经济新闻"
WEATHER = 21, "🌤️ 天气查询 [上海天气, 天气上海]"
JD_TOKEN = 22, "🔑 JD_京豆token设置 [设置京东 pt_key=xxx;pt_pin=xxx; 备注名称]"
AI_AUTO = 23, "💬 仿真对话"
GUESS_MUSIC = 24, "🎤 猜歌名游戏 [猜歌名 - 开始 | 猜歌名 歌手名 - 指定歌手 | 猜歌名 歌名 - 提交答案]"
def __new__(cls, value, description):
obj = object.__new__(cls)
obj._value_ = value
obj.description = description # 添加描述
obj.description = description
return obj
def __str__(self):
return self.description
@classmethod
def get_max_value(cls) -> int:
"""获取当前最大的枚举值"""
return max([member.value for member in cls])
@classmethod
def register_feature(cls, key: str, description: str) -> 'Feature':
"""注册新的功能权限
Args:
key: 功能键名
description: 功能描述
Returns:
Feature: 新注册的功能枚举
"""
# 检查是否已经注册过
if key in cls._member_map_:
return cls._member_map_[key]
# 获取当前最大的枚举值并加1
new_value = cls.get_max_value() + 1
# 创建新的枚举成员
new_feature = cls(new_value, description)
cls._member_map_[key] = new_feature
cls._member_names_.append(key)
new_feature._name_ = key
return new_feature
@classmethod
def get_feature(cls, key: str) -> 'Feature':
"""获取已注册的功能
Args:
key: 功能键名
Returns:
Feature: 功能枚举实例
"""
return cls._member_map_.get(key)
@classmethod
def get_all_features(cls) -> List['Feature']:
"""获取所有功能
Returns:
List[Feature]: 所有功能列表
"""
return list(cls)
@classmethod
def _missing_(cls, value):
"""处理未找到的枚举值"""
if isinstance(value, int):
for member in cls:
if member.value == value:
return member
return None
def get_redis_connection():
# 初始化时加载本地缓存
@@ -181,7 +219,7 @@ class GroupBotManager:
if feature_str.isdigit():
feature_num = int(feature_str)
try:
feature = Feature(feature_num) # 使用枚举序号查找功能
feature = Feature(feature_num, "") # 使用枚举序号查找功能
except ValueError:
return "无效的功能序号"
else:
@@ -294,5 +332,56 @@ def simulate_commands():
if __name__ == '__main__':
# 执行模拟命令
simulate_commands()
# 测试新增功能
print("当前功能列表:")
for feature in Feature.get_all_features():
print(f"{feature.name}: {feature.value} - {feature.description}")
# 测试注册新功能
print("\n注册新功能...")
new_feature = Feature.register_feature("TEST_FEATURE", "🧪 测试功能 [测试]")
print(f"新功能: {new_feature.name} = {new_feature.value} - {new_feature.description}")
# 验证新功能是否添加成功
print("\n更新后的功能列表:")
for feature in Feature.get_all_features():
print(f"{feature.name}: {feature.value} - {feature.description}")
# 测试重复注册
print("\n测试重复注册...")
same_feature = Feature.register_feature("TEST_FEATURE", "🧪 测试功能 [测试]")
print(f"重复注册结果: {same_feature.name} = {same_feature.value} - {same_feature.description}")
# 测试获取功能
print("\n测试获取功能...")
retrieved_feature = Feature.get_feature("TEST_FEATURE")
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测试枚举属性访问...")
print(f"ROBOT.name: {Feature.ROBOT.name}")
print(f"ROBOT.value: {Feature.ROBOT.value}")
print(f"ROBOT.description: {Feature.ROBOT.description}")
print(f"TEST_FEATURE.name: {Feature.TEST_FEATURE.name}")
print(f"TEST_FEATURE.value: {Feature.TEST_FEATURE.value}")
print(f"TEST_FEATURE.description: {Feature.TEST_FEATURE.description}")
# 测试枚举比较
print("\n测试枚举比较...")
print(f"ROBOT == TEST_FEATURE: {Feature.ROBOT == Feature.TEST_FEATURE}")
print(f"ROBOT != TEST_FEATURE: {Feature.ROBOT != Feature.TEST_FEATURE}")
print(f"ROBOT == ROBOT: {Feature.ROBOT == Feature.ROBOT}")
print(f"TEST_FEATURE == TEST_FEATURE: {Feature.TEST_FEATURE == Feature.TEST_FEATURE}")
# 测试枚举迭代
print("\n测试枚举迭代...")
print("所有功能:")
for feature in Feature:
print(f" {feature.name}: {feature.value} - {feature.description}")