新增功能菜单。
This commit is contained in:
@@ -155,18 +155,10 @@ class GroupBotManager:
|
||||
@staticmethod
|
||||
def handle_command(group_id, command_str):
|
||||
"""统一处理群功能指令"""
|
||||
# print(f"PermissionStatus handle_command command_str: {command_str}")
|
||||
# print(f"PermissionStatus robot_menu command_str: {command_str}")
|
||||
# 命令解析
|
||||
command_parts = command_str.strip().split("-")
|
||||
|
||||
# 如果是MENU指令,返回功能列表
|
||||
if command_str.strip().upper() == "菜单":
|
||||
return f"群ID:{group_id} \n {GroupBotManager.get_enabled_features(group_id)}"
|
||||
|
||||
# 如果是MENU-STATUS指令,返回功能列表及其状态
|
||||
if command_str.strip().upper() == "菜单状态":
|
||||
return f"群ID:{group_id} \n {GroupBotManager.display_menu_status(group_id)}"
|
||||
|
||||
# 如果是GROUP_LIST指令,返回 group:list 清单
|
||||
if command_str.strip().upper() == "群列表":
|
||||
return GroupBotManager.get_group_list()
|
||||
@@ -239,53 +231,6 @@ class GroupBotManager:
|
||||
permissions[feature] = status if status else PermissionStatus.DISABLED # 默认为禁用状态
|
||||
return permissions
|
||||
|
||||
@staticmethod
|
||||
def display_menu():
|
||||
"""显示所有功能列表及其当前状态"""
|
||||
menu = []
|
||||
for feature in Feature:
|
||||
menu.append(f"{feature.value}. {feature.description}")
|
||||
return "\n".join(menu)
|
||||
|
||||
@staticmethod
|
||||
def get_enabled_features(group_id):
|
||||
"""获取某个群已启用的功能列表及其描述,并返回格式化的字符串
|
||||
只返回描述中包含指令(方括号[])的功能
|
||||
|
||||
Args:
|
||||
group_id: 群ID
|
||||
|
||||
Returns:
|
||||
str: 格式化的已启用功能列表字符串
|
||||
"""
|
||||
enabled_features = []
|
||||
|
||||
# 检查群是否在列表中
|
||||
if group_id not in GroupBotManager.local_cache["group_list"]:
|
||||
return "该群未启用机器人功能"
|
||||
|
||||
# 遍历所有功能,检查哪些已启用且包含指令
|
||||
for feature in Feature:
|
||||
status = GroupBotManager.get_group_permission(group_id, feature)
|
||||
# 只添加已启用且描述中包含方括号的功能
|
||||
if status == PermissionStatus.ENABLED and "[" in feature.description and "]" in feature.description:
|
||||
enabled_features.append({
|
||||
"id": feature.value,
|
||||
"name": feature.name,
|
||||
"description": feature.description
|
||||
})
|
||||
|
||||
# 如果没有启用任何带指令的功能
|
||||
if not enabled_features:
|
||||
return "该群未启用任何带指令的功能"
|
||||
|
||||
# 构建格式化的字符串
|
||||
result = f"不支持@交互,请通过指令触发\n 群功能菜单:\n"
|
||||
for feature in enabled_features:
|
||||
result += f"{feature['id']}.{feature['description']}\n"
|
||||
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def get_group_list():
|
||||
"""返回所有启用了群机器人的群组清单,格式为集合"""
|
||||
|
||||
Reference in New Issue
Block a user