From 54af5892d510d79d9265fb4e988da6209fdaf8fd Mon Sep 17 00:00:00 2001 From: Sergey Korotonozhko <_serezhka_@mail.ru> Date: Fri, 29 May 2026 03:46:41 +0300 Subject: [PATCH] =?UTF-8?q?v1.7.1:=20fix=20all=20P1-P4,=20C1-C6,=20H1-H6,?= =?UTF-8?q?=20M1-M7,=20L1-L3=20from=20error.md=20=E2=80=94=20async=20migra?= =?UTF-8?q?tions,=20CSS=20variables,=20SQL=20validation,=20event=20loop,?= =?UTF-8?q?=20prompt=20injection,=20VCF=20parsing,=20race=20conditions,=20?= =?UTF-8?q?unused=20imports,=20gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + _remote_deploy3.sh | 69 ++++++++++++ error.md | 106 ++++++++++++++++++ max_bot/CHANGELOG.md | 27 +++++ max_bot/app/email_sender.py | 8 +- max_bot/app/handlers/contact.py | 12 +- max_bot/app/handlers/greeting.py | 43 ++++--- max_bot/app/handlers/inquiry.py | 90 +++++++-------- max_bot/app/keyboards.py | 2 +- max_bot/app/main.py | 68 ++++++----- max_bot/app/settings_cache.py | 15 ++- max_bot/app/yandex_gpt.py | 40 +++++-- max_bot/docker-compose.yml | 14 ++- max_bot/version.txt | 2 +- py_service/CHANGELOG.md | 6 + .../app/templates/pages/bot_consent.html | 6 +- py_service/app/templates/pages/bot_kb.html | 6 +- .../app/templates/pages/bot_settings.html | 2 +- py_service/app/templates/pages/bot_test.html | 34 +++--- .../app/templates/pages/bot_tickets.html | 8 +- py_service/version.txt | 2 +- 21 files changed, 406 insertions(+), 156 deletions(-) create mode 100644 _remote_deploy3.sh create mode 100644 error.md diff --git a/.gitignore b/.gitignore index 25887e1..0b32f7e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ __pycache__/ .env logs/ *.tar.gz +.opencode/ +max_bot/.env.example diff --git a/_remote_deploy3.sh b/_remote_deploy3.sh new file mode 100644 index 0000000..aa92cdb --- /dev/null +++ b/_remote_deploy3.sh @@ -0,0 +1,69 @@ +#!/bin/bash +set -e + +echo "=== Deploy: max_bot ===" +cd /opt/projects/aegisone-py/max_bot + +# Stop container first +echo "--- Stopping max_bot ---" +docker stop max_bot 2>/dev/null || true +docker rm max_bot 2>/dev/null || true + +# Recreate container from existing image but don't start +echo "--- Creating temp container for cleanup ---" +docker create --name max_bot_tmp max_bot-max_bot:latest 2>/dev/null || { + echo "Image not available, pulling/building..." + # We need to build the Docker image, let's fix the DNS issue differently + # Copy requirements.txt and install deps on host, then build + + # Alternative: use python:3.12-slim but install DNS config + cat > Dockerfile.build << 'DOCKER' +FROM python:3.12-slim +WORKDIR /app +COPY requirements.txt . +RUN mkdir -p /etc/docker && echo "nameserver 8.8.8.8" > /etc/resolv.conf || true +RUN pip install --no-cache-dir -r requirements.txt --extra-index-url https://pypi.org/simple/ || \ + pip install --no-cache-dir -r requirements.txt --index-url https://pypi.org/simple/ +COPY . . +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8002"] +DOCKER + + docker build -f Dockerfile.build --network host -t max_bot-max_bot:latest . 2>&1 | tail -5 || { + echo "Build failed, trying without network host..." + docker build -f Dockerfile.build --network bridge -t max_bot-max_bot:latest . 2>&1 | tail -5 || { + echo "Build failed again, will use docker cp approach" + } + } +} + +echo "--- Creating max_bot from image ---" +# Remove temp container if exists +docker rm max_bot_tmp 2>/dev/null || true + +# Create new container +docker create --name max_bot --network host \ + -e BOT_DATABASE_URL="postgresql+asyncpg://aegisone:aegisone_pass@localhost:5432/aegisone" \ + -e BOT_MAX_TOKEN="f9LHodD0cOKkk03DYXj906MdIeRs3HdDo0BC5H2fLMVCMz3PA_Vx4aJqt2l2qPLM5zd5EQ1Zh6APxzpw2UYE" \ + -e BOT_WEBHOOK_URL="https://max.aegisone.ru/webhook" \ + -e BOT_WEBHOOK_SECRET="aegisone_bot_secret_2026" \ + -e BOT_CONFIG_PHP_PATH="/var/www/html/config.php" \ + -e BOT_PHP_SENDMAIL_PATH="/usr/sbin/sendmail" \ + --restart always \ + max_bot-max_bot:latest 2>&1 || echo "Image build failed, using alternative..." + +# Check if image exists +if docker image inspect max_bot-max_bot:latest >/dev/null 2>&1; then + echo "Image exists, proceeding..." + docker start max_bot + sleep 3 + echo "--- Health check ---" + curl -s -o /dev/null -w "max.aegisone.ru: %{http_code}\n" https://max.aegisone.ru/health + echo "--- Logs ---" + docker logs --tail 20 max_bot 2>&1 +else + echo "Image not available, using manual copy approach..." + # Use the container that was already created (might not exist) + docker start max_bot 2>/dev/null || true +fi + +echo "=== DEPLOY STEP 1 FINISHED ===" diff --git a/error.md b/error.md new file mode 100644 index 0000000..a0830fe --- /dev/null +++ b/error.md @@ -0,0 +1,106 @@ +Root Causes & Plan +Ошибка 1: column bot_users_1.patronymic does not exist +Причина: _add_column_if_not_exists() — синхронная функция (def), но conn — AsyncConnection. conn.execute() возвращает корутину, которая никогда не awaits: + +max_bot/app/main.py:91: conn.execute(sa_text(...)) — нет await +Лог при запуске: RuntimeWarning: coroutine 'AsyncConnection.execute' was never awaited +Миграции молча не выполняются, колонки не создаются. + +План исправления: + +main.py:88 — сделать async def _add_column_if_not_exists +main.py:91 — добавить await conn.execute(...) +main.py:75-85 — добавить await перед каждым вызовом _add_column_if_not_exists +После деплоя колонки создадутся при следующем рестарте +Ошибка 2: Тёмная тема в тестовом прогоне +Причина: bot_test.html — это полноценный HTML-документ (не наследует base.html), цвета жёстко закодированы в +
diff --git a/py_service/app/templates/pages/bot_tickets.html b/py_service/app/templates/pages/bot_tickets.html index f87ccd6..1a92b58 100644 --- a/py_service/app/templates/pages/bot_tickets.html +++ b/py_service/app/templates/pages/bot_tickets.html @@ -3,12 +3,12 @@