Smart hit assignation and chain monitoring

This commit is contained in:
2026-01-27 08:26:48 -05:00
parent 5ef8707122
commit 99ffe7f9e9
13 changed files with 188 additions and 42 deletions

View File

@@ -5,9 +5,8 @@ from config import TORN_API_KEY
from .ffscouter import fetch_batch_stats
from .server_state import STATE
# -----------------------------
# Tasks
# -----------------------------
friendly_status_task = None
enemy_status_task = None
@@ -15,9 +14,8 @@ enemy_status_task = None
friendly_lock = asyncio.Lock()
enemy_lock = asyncio.Lock()
# -----------------------------
# Populate faction (memory only)
# -----------------------------
async def populate_faction(faction_id: int, kind: str):
"""
Fetch members + FFScouter estimates once and store in STATE.
@@ -64,9 +62,8 @@ async def populate_faction(faction_id: int, kind: str):
return True
# -----------------------------
# Status refresh loop
# -----------------------------
async def refresh_status_loop(faction_id: int, kind: str, lock: asyncio.Lock, interval: int):
"""
Periodically refresh member statuses in STATE.
@@ -95,10 +92,11 @@ async def refresh_status_loop(faction_id: int, kind: str, lock: asyncio.Lock, in
await asyncio.sleep(interval)
# -----------------------------
# Public API helpers
# -----------------------------
async def populate_friendly(faction_id: int):
# Store friendly faction ID for chain monitoring
STATE.friendly_faction_id = faction_id
return await populate_faction(faction_id, "friendly")
async def populate_enemy(faction_id: int):