清除群指令,用于处理退群之后的信息。

This commit is contained in:
liuwei
2025-03-17 16:58:01 +08:00
parent d15b8165c8
commit 39831cd03e

View File

@@ -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():