更新 qiandao/scripts/qiandao.py

This commit is contained in:
lj091715 2026-05-20 21:55:10 +08:00
parent 195d8eca99
commit 22336380ad

View File

@ -1,17 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pyright: reportExplicitAny=false, reportAny=false, reportUnknownMemberType=false, reportUnknownArgumentType=false, reportUnknownVariableType=false, reportUnusedVariable=false, reportUnusedImport=false
"""签到游戏插件 - 支持每日签到、连续签到奖励、排行榜""" """签到游戏插件 - 支持每日签到、连续签到奖励、排行榜"""
from __future__ import annotations from __future__ import annotations
import json import json
import os import os
import sys import sys
import time
import traceback import traceback
from datetime import date, datetime from datetime import date, timedelta
from typing import Any from typing import Any
sys.stderr = sys.stdout
# ---------- 数据存储 ---------- # ---------- 数据存储 ----------
DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data") DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "data")
DATA_FILE = os.path.join(DATA_DIR, "qiandao.json") DATA_FILE = os.path.join(DATA_DIR, "qiandao.json")
@ -172,9 +170,8 @@ def leaderboard(top_n: int = 10) -> str:
def cleanup_old_history(data: dict[str, Any]) -> None: def cleanup_old_history(data: dict[str, Any]) -> None:
"""清理超过 MAX_HISTORY_DAYS 的历史记录。""" """清理超过 MAX_HISTORY_DAYS 的历史记录。"""
today = date.today() today = date.today()
threshold = today.isoformat() cutoff = (today - timedelta(days=MAX_HISTORY_DAYS)).isoformat()
for uid, user in data["users"].items(): for uid, user in data["users"].items():
cutoff = (today - __import__("datetime").timedelta(days=MAX_HISTORY_DAYS)).isoformat()
user["history"] = [d for d in user["history"] if d >= cutoff] user["history"] = [d for d in user["history"] if d >= cutoff]
user["points_history"] = [p for p in user["points_history"] if p.split("|")[0] >= cutoff] user["points_history"] = [p for p in user["points_history"] if p.split("|")[0] >= cutoff]