# Copyright (c) 2026 Krzysztof Rudnicki. MIT licence. """Asking the running bot to rebuild its command table. One function, because two routers need it and each used to carry a copy: the aliases router, which rolls its file back when the bot says no, and the approval queue, which does not (the photo is in the album either way, and the reason the bot gives is worth more on the page than a second copy of the same upload in the queue). """ from __future__ import annotations from typing import TYPE_CHECKING, Any import httpx from fastapi import HTTPException, status if TYPE_CHECKING: from signal_bot.manage.deps import ManageDeps async def reload_bot(deps: ManageDeps) -> dict[str, Any]: """``POST /_reload`` on the bot; anything but ``reloaded`` raises. Raises: HTTPException: 502 when the bot did not answer at all; otherwise the bot's own status -- ``kept`` (409) carries its sentence about the data, ``connecting`` (503) why there is no table yet. Both are the bot's words, passed on. """ try: response = await deps.client.post(f"{deps.bot_url}/_reload", timeout=30.0) except httpx.HTTPError as error: raise HTTPException( status_code=status.HTTP_502_BAD_GATEWAY, detail=f"the bot did not answer: {error}", ) from error body: dict[str, Any] = response.json() if response.status_code != status.HTTP_200_OK: raise HTTPException(status_code=response.status_code, detail=body.get("reason", body)) return body