feat: Add a thread-safe account store module for managing accounts and recording statistics, and integrate it into the bot.

This commit is contained in:
2026-02-14 02:36:51 +08:00
parent 302c5e5e89
commit 768963666a
2 changed files with 191 additions and 1 deletions

View File

@@ -180,6 +180,38 @@ def delete_by_email(email: str) -> dict | None:
return removed
def delete_by_emails(emails: list[str]) -> int:
"""批量按邮箱删除账号,返回实际删除数量"""
if not emails:
return 0
email_set = set(emails)
with _lock:
try:
with open(_ACCOUNTS_FILE, "r", encoding="utf-8") as f:
lines = [line.strip() for line in f if line.strip()]
except FileNotFoundError:
return 0
remaining = []
deleted = 0
for line in lines:
parts = line.split("|")
if parts[0] in email_set:
deleted += 1
# 同时从 busy 集合中移除
_busy.discard(line)
else:
remaining.append(line)
if deleted > 0:
with open(_ACCOUNTS_FILE, "w", encoding="utf-8") as f:
for line in remaining:
f.write(line + "\n")
return deleted
# ====== 统计数据 ======
def _load_stats() -> dict: