mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-10 19:37:03 +01:00
A photo sent to the chat no longer enters the album by itself. pack_add strips it, checks it against the album and the queue, and writes it to pending/ with a sidecar naming the people and labels the sender proposed; the reply is "czeka na zatwierdzenie". The management page lists the queue above the tagger, with the proposal pre-ticked, and Approve moves the file in, mints the labels, records approved_at and asks the bot to rebuild its table through /_reload -- the same publish path every other data change takes, so PackHolder.reload is gone. A reload the bot refuses is reported on the page, not rolled back: the photo is in the album either way. The personal-data gate now reads pending/*.json too, so a label that is still waiting for approval is forbidden in the tree already. The e2e run boots the management page beside the bot with the same environment, proves the queue is stripped and never reaches media/, approves it through the real routes, and has !losowe answer with the photo afterwards without a restart; exiftool is found through media_strip.locate() there rather than PATH, which lacks vendor_perl on Arch. !gadaj is dropped from !odcisz: it was within a typo of !dodaj, and the nearest-command suggestion must never be a coin toss. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
# 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
|