This commit is contained in:
2026-01-21 22:24:36 +08:00
parent 6600195a3f
commit 421caca1b7
3 changed files with 335 additions and 1 deletions

View File

@@ -214,6 +214,91 @@ def save_team_json():
return False
def remove_team_by_name(team_name: str) -> bool:
"""从 team.json 中删除指定的 Team
Args:
team_name: Team 名称
Returns:
bool: 是否成功删除
"""
global _raw_teams, TEAMS
# 查找要删除的 team 索引
team_idx = None
for i, team in enumerate(TEAMS):
if team.get("name") == team_name:
team_idx = i
break
if team_idx is None:
return False
# 从 TEAMS 和 _raw_teams 中删除
TEAMS.pop(team_idx)
_raw_teams.pop(team_idx)
# 保存到文件
try:
with open(TEAM_JSON_FILE, "w", encoding="utf-8") as f:
json.dump(_raw_teams, f, ensure_ascii=False, indent=2)
_log_config("INFO", "team.json", f"已删除 Team: {team_name}")
return True
except Exception as e:
_log_config("ERROR", "team.json", "保存失败", str(e))
return False
def batch_remove_teams_by_names(team_names: list) -> dict:
"""批量从 team.json 中删除指定的 Teams
Args:
team_names: Team 名称列表
Returns:
dict: {"success": 成功数, "failed": 失败数, "total": 总数}
"""
global _raw_teams, TEAMS
results = {"success": 0, "failed": 0, "total": len(team_names)}
# 收集要保留的 teams
names_to_remove = set(team_names)
new_teams = []
new_raw_teams = []
removed_count = 0
for i, team in enumerate(TEAMS):
if team.get("name") in names_to_remove:
removed_count += 1
else:
new_teams.append(team)
new_raw_teams.append(_raw_teams[i])
if removed_count == 0:
return results
# 保存到文件
try:
with open(TEAM_JSON_FILE, "w", encoding="utf-8") as f:
json.dump(new_raw_teams, f, ensure_ascii=False, indent=2)
# 更新内存中的数据
TEAMS.clear()
TEAMS.extend(new_teams)
_raw_teams.clear()
_raw_teams.extend(new_raw_teams)
results["success"] = removed_count
_log_config("INFO", "team.json", f"已删除 {removed_count} 个 Team")
except Exception as e:
results["failed"] = len(team_names)
_log_config("ERROR", "team.json", "批量删除失败", str(e))
return results
def reload_config() -> dict:
"""重新加载配置文件 (config.toml 和 team.json)