From 39831cd03eed8c1fb0d04396e9a901206f50e3de Mon Sep 17 00:00:00 2001 From: liuwei Date: Mon, 17 Mar 2025 16:58:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E9=99=A4=E7=BE=A4=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=A4=84=E7=90=86=E9=80=80=E7=BE=A4?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E7=9A=84=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robot_cmd/robot_command.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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():