diff --git a/robot_cmd/robot_command.py b/robot_cmd/robot_command.py index 36460e0..d6bf108 100644 --- a/robot_cmd/robot_command.py +++ b/robot_cmd/robot_command.py @@ -147,7 +147,12 @@ class GroupBotManager: # 如果是GROUP_LIST指令,返回 group:list 清单 if command_str.strip().upper() == "群列表": return GroupBotManager.get_group_list() - + + # 如果是清除群指令 + if command_str.strip().startswith("清除群-"): + target_group_id = command_str.strip().split("-")[1] + return GroupBotManager.remove_group(target_group_id) + if len(command_parts) < 2: return None @@ -223,6 +228,30 @@ class GroupBotManager: """返回所有启用了群机器人的群组清单,格式为集合""" return list(GroupBotManager.local_cache["group_list"]) + @staticmethod + def remove_group(group_id): + """一键清除某个群的所有设置,用于退群或关闭群时处理 + + Args: + group_id: 群ID + + Returns: + str: 操作结果信息 + """ + # 检查群是否在列表中 + if group_id not in GroupBotManager.local_cache["group_list"]: + return f"群 {group_id} 不在机器人管理列表中" + + # 从本地缓存中移除群组 + GroupBotManager.local_cache["group_list"].remove(group_id) + if group_id in GroupBotManager.local_cache["group_permissions"]: + del GroupBotManager.local_cache["group_permissions"][group_id] + + # 从Redis中移除群组 + r.srem("group:list", group_id) + r.delete(f'group:{group_id}:permissions') + + return f"已成功清除群 {group_id} 的所有设置" # 示例命令 def simulate_commands():