Skip to content

feat(p): "🔄 Actualizar ahora" button to rebuild the profile live - #11

Merged
joaquinmuzzi merged 1 commit into
masterfrom
claude/project-thread-vre7k8
Oct 23, 2026
Merged

joaquinmuzzi merged 1 commit into
masterfrom
claude/project-thread-vre7k8

Conversation

@joaquinmuzzi

Copy link
Copy Markdown
Owner

Requested by Joaquín · project thread

Why

/p answers from the profile the nightly cron cached (up to 25 h old). Anyone who wanted to see a character as it is right now had to wait for the next cron run.

What

  • New first button on every /p message: 🔄 Actualizar ahora. It rebuilds the profile against the armory and UwU Logs through the same path as an uncached /p (_send_live_profile, which uses _compute_personaje_base, so nothing is duplicated), edits the same message with the result and overwrites the cached copy.
  • While it rebuilds, the old profile stays visible with ⏳ Actualizando perfil de X en Y... above it, followed by the usual ⌛ loading embed and the final one (including the re-read that re-sends the final embed if Discord keeps a loading one).
  • Rate limit protection (src/services/refresh_cooldown.py): anyone can press the button, and each rebuild costs ~15 armory requests out of a budget every user shares, so:
    • a character is rebuilt at most once every 5 min (a live /p also starts this cooldown);
    • each user rebuilds one character per minute;
    • if the armory circuit breaker is open, nothing is requested and the cooldown does not start.
      Blocked clicks get an ephemeral message saying how long to wait.
  • Failures don't wipe the message: if the armory rate-limits, can't find the character or answers incomplete, the message keeps the old profile and only the person who pressed the button sees the warning (ephemeral).
  • The button is handled by a DynamicItem (src/controller/commands/personaje_refresh.py) that reads realm and name from the custom_id (personaje:refresh:<realm>:<name>), so it keeps working on older /p messages and after a restart or deploy, with no view timeout. In the view it is a plain button with no callback: discord.py keeps the sent view for a few minutes and would otherwise handle the click twice.
  • _safe_send_error / _reply_command_error take ephemeral=, defaulting to the old behavior.
  • README: features, end-to-end flow, layout and cache sections.

Tests

tests/test_personaje_refresh.py (11 new tests): button position, label, emoji and custom_id; DynamicItem registration; rebuild in the same message (deferred update, old embed while loading, final embed); the Postgres cache is not read; per-character and per-user cooldown; a live /p starts the cooldown; an armory rate limit keeps the old profile and sends an ephemeral notice; an incomplete armory answer sends an ephemeral notice; an open circuit doesn't touch the armory; cooldowns expire.

Locally on Python 3.11: pytest 148 passed, ruff check, ruff format --check and mypy clean.

Not tested in Discord yet.


Generated by Claude Code

…live

/p answers from the profile the nightly cron cached (up to 25 h old), so
anyone who wanted to see a character as it is right now had to wait for
the next run. The button rebuilds the profile against the armory and UwU
Logs through the same path as an uncached /p and edits the same message
with the result, overwriting the cached copy.

Anyone who sees the message can press it, and each rebuild costs ~15
requests of the armory rate limit that all users share, so a character
is rebuilt at most once every 5 min (live /p runs count too) and each
user rebuilds one character per minute. If the armory is rate-limited or
cannot build the profile, the message keeps the old profile and only the
person who pressed the button sees the warning.

The button is handled by a DynamicItem that reads the realm and the name
from the custom_id, so it also works on older messages and after a
restart. It is sent as a plain button without a callback because
discord.py keeps the sent view for a few minutes and would otherwise
handle the click twice.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018nRgBy4Xz1Cetj6kYRZAnW
@joaquinmuzzi joaquinmuzzi self-assigned this Oct 23, 2026
@joaquinmuzzi
joaquinmuzzi merged commit a052a61 into master Oct 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants