This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
"""Local cooldown for confirmed battle losses."""
|
||||
import math
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
|
||||
def loss_retry_reason(state, now, policy):
|
||||
limit = int(getattr(policy, "stop_after_loss", 0) or 0)
|
||||
if not limit or int(state.get("losses", 0)) < limit:
|
||||
return ""
|
||||
last_loss = state.get("last_loss_at")
|
||||
if type(last_loss) not in (int, float) or not math.isfinite(last_loss) or last_loss <= 0:
|
||||
last_loss = float(now)
|
||||
state["last_loss_at"] = last_loss
|
||||
deadline = last_loss + getattr(policy, "loss_retry_hours", 3) * 3600
|
||||
if now >= deadline:
|
||||
state.update(losses=0, last_loss_at=None)
|
||||
return ""
|
||||
retry_at = datetime.fromtimestamp(deadline, timezone(timedelta(hours=8))).strftime("%m-%d %H:%M:%S")
|
||||
return f"已达战败停止次数,冷却至 {retry_at}(北京时间)后自动重新检查并重试"
|
||||
Reference in New Issue
Block a user