Add a live status line to the stats panel

Shows what's happening right now underneath the table (connecting,
resolving the friend, discovering targets, fetching channel history,
waiting out a jittered delay before reacting, sending a reaction,
removing a reaction during --undo, etc). Status updates are cheap
and DB-free, using the last fetched stats for re-rendering.
This commit is contained in:
2026-08-01 18:53:48 +02:00
parent ab0afa149a
commit 7b3c358b05
5 changed files with 57 additions and 11 deletions

View File

@@ -44,6 +44,7 @@ class ReactorClient(discord.Client):
await self.close()
async def _run_backlog_then_watch(self):
self.display.set_status(f"Resolving friend id {self.cfg.friend_id}...")
try:
friend = await resolve_friend(self, self.cfg.friend_id)
except discord.NotFound:
@@ -51,10 +52,12 @@ class ReactorClient(discord.Client):
"friend_id %s does not resolve to any Discord user. Check config.json and fix it.",
self.cfg.friend_id,
)
self.display.set_status("Failed: friend_id does not resolve to a Discord user.")
return
log.info("Targeting friend: %s (%s)", friend, friend.id)
self.display.set_friend(str(friend))
self.display.set_status(f"Discovering mutual servers/groups with {friend}...")
await self.display.refresh()
targets = await discover_targets(self, friend, self.cfg.manual_guild_ids)
@@ -65,6 +68,7 @@ class ReactorClient(discord.Client):
pruned = await asyncio.to_thread(self.storage.prune_targets, [t.target_id for t in targets])
if pruned:
log.info("Pruned %d stale target(s) no longer mutual/discovered", pruned)
self.display.set_status(f"Starting backlog scan across {len(targets)} target(s)...")
await self.display.refresh()
cutoff = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=self.cfg.days_back)
@@ -95,6 +99,7 @@ class ReactorClient(discord.Client):
)
log.info("Backlog scan complete. Now watching live.")
self.display.set_status("Backlog scan complete — watching live for new messages...")
async def on_message(self, message: discord.Message):
if self.undo:
@@ -104,6 +109,8 @@ class ReactorClient(discord.Client):
return
if message.author.id != self.cfg.friend_id:
return
chan_label = getattr(message.channel, "name", None) or target.name
self.display.set_status(f"New message from friend in {chan_label}...")
await react_to_message(
self.storage, message, target, self.cfg.friend_id, self.cfg.emoji,
source="live", display=self.display,
@@ -133,6 +140,7 @@ def main():
storage = Storage(cfg.db_path)
display = StatsDisplay(console, storage)
display.set_status("Connecting to Discord...")
with display:
client = ReactorClient(cfg, storage, display, undo=args.undo)