Discord bot fáze B: tlačítka na EV zprávě → patch session + okamžitý replan
All checks were successful
CI and deploy / migration-check (push) Successful in 21s
CI and deploy / deploy (push) Has been skipped

services/discord_bot.py: gateway klient jako lifespan task (spojení ven,
žádný veřejný endpoint; bez DISCORD_BOT_TOKEN tiše spí). Tlačítka
[za 2h][za 4h][ráno][do plna][nenabíjet] s custom_id ev:<site>:<charger>:<akce>
(přežijí restart); whitelist DISCORD_ALLOWED_USER_IDS; akce = fn_ev_session_
apply_patch → run_rolling_replan → export_setpoints → edit zprávy novým plánem.

services/ev_notify.py: sdílený builder souhrnu (vyčleněno z collectoru),
send bot-first s webhook fallbackem. requirements: discord.py>=2.4.
7 testů helperů (parse, deadline akce vč. morning přes Prague TZ).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Dusan Vojacek
2026-06-12 11:41:05 +02:00
parent 08a43aa236
commit 0e7f7b69ae
8 changed files with 435 additions and 88 deletions

View File

@@ -539,6 +539,11 @@ async def lifespan(app: FastAPI):
telemetry_task = asyncio.create_task(run_telemetry_loop_wrapper(app.state.pg_pool))
app.state.telemetry_task = telemetry_task
from services.discord_bot import run_discord_bot, set_pool as discord_set_pool
discord_set_pool(app.state.pg_pool)
discord_task = asyncio.create_task(run_discord_bot())
app.state.discord_task = discord_task
yield
@@ -547,6 +552,11 @@ async def lifespan(app: FastAPI):
logging.getLogger().removeHandler(ws_h)
app.state.ws_log_handler = None
discord_task.cancel()
try:
await discord_task
except (asyncio.CancelledError, Exception):
pass
telemetry_task.cancel()
try:
await telemetry_task