Compare commits
11 Commits
1eb7d1c9bc
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 77ae161b1a | |||
| 35a977536b | |||
| 713eadc643 | |||
| 5ea3e8c1f3 | |||
| 85027a7747 | |||
| e275a9856b | |||
| bdd7d0424f | |||
| 856bf3ca2a | |||
| e3baa9be63 | |||
| a3fb88e91e | |||
| c5a0593222 |
50
.env.example
50
.env.example
@@ -1,30 +1,58 @@
|
|||||||
# Telegram Bot Configuration
|
# Telegram Tinder Bot Configuration
|
||||||
|
# Rename this file to .env before starting the application
|
||||||
|
|
||||||
|
# === REQUIRED SETTINGS ===
|
||||||
|
|
||||||
|
# Telegram Bot Token (Get from @BotFather)
|
||||||
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
|
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
|
||||||
|
|
||||||
# Database Configuration
|
# Database Configuration
|
||||||
|
# For local development (when running the bot directly)
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_PORT=5432
|
DB_PORT=5432
|
||||||
DB_NAME=telegram_tinder_bot
|
DB_NAME=telegram_tinder_bot
|
||||||
DB_USERNAME=postgres
|
DB_USERNAME=postgres
|
||||||
DB_PASSWORD=your_password_here
|
DB_PASSWORD=your_password_here
|
||||||
|
|
||||||
# Application Settings
|
# === APPLICATION SETTINGS ===
|
||||||
|
|
||||||
|
# Environment (development, production)
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
|
|
||||||
|
# Port for health checks
|
||||||
PORT=3000
|
PORT=3000
|
||||||
|
|
||||||
# Optional: Redis for caching (if using)
|
# === FILE UPLOAD SETTINGS ===
|
||||||
REDIS_HOST=localhost
|
|
||||||
REDIS_PORT=6379
|
|
||||||
REDIS_PASSWORD=
|
|
||||||
|
|
||||||
# Optional: File upload settings
|
# Path for storing uploaded files
|
||||||
UPLOAD_PATH=./uploads
|
UPLOAD_PATH=./uploads
|
||||||
|
|
||||||
|
# Maximum file size for uploads (in bytes, default: 5MB)
|
||||||
MAX_FILE_SIZE=5242880
|
MAX_FILE_SIZE=5242880
|
||||||
|
|
||||||
# Optional: External services
|
# === LOGGING ===
|
||||||
GOOGLE_MAPS_API_KEY=your_google_maps_key
|
|
||||||
CLOUDINARY_URL=your_cloudinary_url
|
|
||||||
|
|
||||||
# Security
|
# Log level (error, warn, info, debug)
|
||||||
|
LOG_LEVEL=info
|
||||||
|
|
||||||
|
# Path for storing log files
|
||||||
|
LOG_PATH=./logs
|
||||||
|
|
||||||
|
# === SECURITY ===
|
||||||
|
|
||||||
|
# Secret key for JWT tokens
|
||||||
JWT_SECRET=your_jwt_secret_here
|
JWT_SECRET=your_jwt_secret_here
|
||||||
|
|
||||||
|
# Encryption key for sensitive data
|
||||||
ENCRYPTION_KEY=your_encryption_key_here
|
ENCRYPTION_KEY=your_encryption_key_here
|
||||||
|
|
||||||
|
# === ADVANCED SETTINGS ===
|
||||||
|
|
||||||
|
# Notification check interval in milliseconds (default: 60000 - 1 minute)
|
||||||
|
NOTIFICATION_CHECK_INTERVAL=60000
|
||||||
|
|
||||||
|
# Number of matches to show per page
|
||||||
|
MATCHES_PER_PAGE=10
|
||||||
|
|
||||||
|
# Number of profiles to load at once
|
||||||
|
PROFILES_BATCH_SIZE=5
|
||||||
|
|||||||
68
.env.production
Normal file
68
.env.production
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# Конфигурация Telegram Tinder Bot для Production
|
||||||
|
|
||||||
|
# === НЕОБХОДИМЫЕ НАСТРОЙКИ ===
|
||||||
|
|
||||||
|
# Токен Telegram бота (получить у @BotFather)
|
||||||
|
TELEGRAM_BOT_TOKEN=your_bot_token_here
|
||||||
|
|
||||||
|
# Настройки базы данных PostgreSQL
|
||||||
|
DB_HOST=db
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_NAME=telegram_tinder_bot
|
||||||
|
DB_USERNAME=postgres
|
||||||
|
DB_PASSWORD=your_secure_password_here
|
||||||
|
|
||||||
|
# === НАСТРОЙКИ ПРИЛОЖЕНИЯ ===
|
||||||
|
|
||||||
|
# Окружение
|
||||||
|
NODE_ENV=production
|
||||||
|
|
||||||
|
# Порт для проверок работоспособности
|
||||||
|
PORT=3000
|
||||||
|
|
||||||
|
# === НАСТРОЙКИ ЗАГРУЗКИ ФАЙЛОВ ===
|
||||||
|
|
||||||
|
# Путь для хранения загруженных файлов
|
||||||
|
UPLOAD_PATH=./uploads
|
||||||
|
|
||||||
|
# Максимальный размер загружаемого файла (в байтах, по умолчанию: 5MB)
|
||||||
|
MAX_FILE_SIZE=5242880
|
||||||
|
|
||||||
|
# Разрешенные типы файлов
|
||||||
|
ALLOWED_FILE_TYPES=image/jpeg,image/png,image/gif
|
||||||
|
|
||||||
|
# === ЛОГИРОВАНИЕ ===
|
||||||
|
|
||||||
|
# Уровень логирования (error, warn, info, debug)
|
||||||
|
LOG_LEVEL=info
|
||||||
|
|
||||||
|
# Путь для хранения лог-файлов
|
||||||
|
LOG_PATH=./logs
|
||||||
|
|
||||||
|
# === БЕЗОПАСНОСТЬ ===
|
||||||
|
|
||||||
|
# Секретный ключ для JWT токенов
|
||||||
|
JWT_SECRET=your_jwt_secret_here
|
||||||
|
|
||||||
|
# Ключ шифрования для чувствительных данных
|
||||||
|
ENCRYPTION_KEY=your_encryption_key_here
|
||||||
|
|
||||||
|
# === РАСШИРЕННЫЕ НАСТРОЙКИ ===
|
||||||
|
|
||||||
|
# Интервал проверки уведомлений в миллисекундах (по умолчанию: 60000 - 1 минута)
|
||||||
|
NOTIFICATION_CHECK_INTERVAL=60000
|
||||||
|
|
||||||
|
# Количество матчей для отображения на странице
|
||||||
|
MATCHES_PER_PAGE=10
|
||||||
|
|
||||||
|
# Количество профилей для загрузки за один раз
|
||||||
|
PROFILES_BATCH_SIZE=5
|
||||||
|
|
||||||
|
# === НАСТРОЙКИ DOCKER ===
|
||||||
|
|
||||||
|
# Имя хоста для доступа извне
|
||||||
|
EXTERNAL_HOSTNAME=your_domain.com
|
||||||
|
|
||||||
|
# Настройки кеширования (Redis, если используется)
|
||||||
|
CACHE_HOST=redis
|
||||||
|
CACHE_PORT=6379
|
||||||
29
Dockerfile
29
Dockerfile
@@ -8,14 +8,15 @@ WORKDIR /app
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
COPY tsconfig.json ./
|
COPY tsconfig.json ./
|
||||||
|
|
||||||
# Install dependencies
|
# Install all dependencies (including devDependencies for build)
|
||||||
RUN npm ci --only=production && npm cache clean --force
|
RUN npm ci && npm cache clean --force
|
||||||
|
|
||||||
# Copy source code
|
# Copy source code
|
||||||
COPY src/ ./src/
|
COPY src/ ./src/
|
||||||
|
COPY .env.example ./
|
||||||
|
|
||||||
# Build the application
|
# Build the application (using Linux-compatible build command)
|
||||||
RUN npm run build
|
RUN npm run build:linux
|
||||||
|
|
||||||
# Production stage
|
# Production stage
|
||||||
FROM node:18-alpine AS production
|
FROM node:18-alpine AS production
|
||||||
@@ -31,11 +32,19 @@ RUN npm ci --only=production && npm cache clean --force
|
|||||||
|
|
||||||
# Copy built application from builder stage
|
# Copy built application from builder stage
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
|
COPY --from=builder /app/.env.example ./.env.example
|
||||||
|
|
||||||
# Copy configuration files
|
# Copy database migrations
|
||||||
COPY config/ ./config/
|
COPY src/database/migrations/ ./dist/database/migrations/
|
||||||
|
|
||||||
# Create uploads directory
|
# Copy locales
|
||||||
|
COPY src/locales/ ./dist/locales/
|
||||||
|
|
||||||
|
# Copy scripts
|
||||||
|
COPY scripts/startup.sh ./startup.sh
|
||||||
|
RUN chmod +x ./startup.sh
|
||||||
|
|
||||||
|
# Create directories
|
||||||
RUN mkdir -p uploads logs
|
RUN mkdir -p uploads logs
|
||||||
|
|
||||||
# Create non-root user for security
|
# Create non-root user for security
|
||||||
@@ -53,7 +62,7 @@ EXPOSE 3000
|
|||||||
|
|
||||||
# Health check
|
# Health check
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||||
CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })" || exit 1
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
|
||||||
|
|
||||||
# Start the application
|
# Start the application with migration script
|
||||||
CMD ["node", "dist/bot.js"]
|
CMD ["./startup.sh"]
|
||||||
|
|||||||
224
README.md
224
README.md
@@ -2,6 +2,71 @@
|
|||||||
|
|
||||||
Полнофункциональный Telegram бот для знакомств в стиле Tinder с инлайн-кнопками и красивым интерфейсом. Пользователи могут создавать профили, просматривать анкеты других пользователей, ставить лайки, получать матчи и общаться друг с другом.
|
Полнофункциональный Telegram бот для знакомств в стиле Tinder с инлайн-кнопками и красивым интерфейсом. Пользователи могут создавать профили, просматривать анкеты других пользователей, ставить лайки, получать матчи и общаться друг с другом.
|
||||||
|
|
||||||
|
## 🗂️ Структура проекта
|
||||||
|
|
||||||
|
```
|
||||||
|
telegram-tinder-bot/
|
||||||
|
├── bin/ # Исполняемые скрипты и утилиты
|
||||||
|
│ ├── start_bot.bat # Скрипт запуска для Windows
|
||||||
|
│ ├── install_ubuntu.sh # Скрипт установки для Ubuntu
|
||||||
|
│ ├── update.sh # Скрипт обновления для Linux/macOS
|
||||||
|
│ ├── update.bat # Скрипт обновления для Windows
|
||||||
|
│ └── setup.sh # Скрипт настройки окружения
|
||||||
|
│
|
||||||
|
├── docs/ # Документация проекта
|
||||||
|
│ ├── ARCHITECTURE.md # Архитектура приложения
|
||||||
|
│ ├── DEPLOYMENT.md # Инструкции по развертыванию
|
||||||
|
│ ├── DEPLOY_UBUNTU.md # Инструкции по развертыванию на Ubuntu
|
||||||
|
│ ├── LOCALIZATION.md # Информация о локализации
|
||||||
|
│ ├── NATIVE_CHAT_SYSTEM.md # Документация по системе чата
|
||||||
|
│ ├── PROJECT_SUMMARY.md # Общее описание проекта
|
||||||
|
│ └── VIP_FUNCTIONS.md # Описание премиум функций
|
||||||
|
│
|
||||||
|
├── migrations/ # Миграции базы данных
|
||||||
|
│ ├── 1758144488937_initial-schema.js # Начальная схема БД
|
||||||
|
│ └── 1758144618548_add-missing-profile-columns.js # Дополнительные колонки
|
||||||
|
│
|
||||||
|
├── scripts/ # Вспомогательные скрипты
|
||||||
|
│ ├── add-hobbies-column.js # Скрипт добавления колонки hobbies
|
||||||
|
│ ├── add-premium-columns.js # Скрипт добавления премиум колонок
|
||||||
|
│ ├── add-premium-columns.ts # TypeScript версия скрипта
|
||||||
|
│ ├── create_profile_fix.js # Исправление профилей
|
||||||
|
│ └── migrate-sync.js # Синхронизация миграций
|
||||||
|
│
|
||||||
|
├── sql/ # SQL скрипты
|
||||||
|
│ ├── add_looking_for.sql # Добавление колонки looking_for
|
||||||
|
│ ├── add_missing_columns.sql # Добавление недостающих колонок
|
||||||
|
│ ├── add_premium_columns.sql # Добавление премиум колонок
|
||||||
|
│ ├── add_updated_at.sql # Добавление колонки updated_at
|
||||||
|
│ ├── clear_database.sql # Очистка базы данных
|
||||||
|
│ └── recreate_tables.sql # Пересоздание таблиц
|
||||||
|
│
|
||||||
|
├── src/ # Исходный код приложения
|
||||||
|
│ ├── bot.ts # Основной файл бота
|
||||||
|
│ ├── controllers/ # Контроллеры
|
||||||
|
│ ├── database/ # Функции для работы с БД
|
||||||
|
│ ├── handlers/ # Обработчики сообщений и команд
|
||||||
|
│ ├── locales/ # Локализация
|
||||||
|
│ ├── models/ # Модели данных
|
||||||
|
│ ├── scripts/ # Скрипты для запуска
|
||||||
|
│ │ └── initDb.ts # Инициализация базы данных
|
||||||
|
│ ├── services/ # Сервисы и бизнес-логика
|
||||||
|
│ ├── types/ # TypeScript типы
|
||||||
|
│ └── utils/ # Утилиты и вспомогательные функции
|
||||||
|
│
|
||||||
|
├── tests/ # Тесты
|
||||||
|
│ └── test-bot.ts # Тестовая версия бота
|
||||||
|
│
|
||||||
|
├── .dockerignore # Игнорируемые Docker файлы
|
||||||
|
├── .env # Переменные окружения (локальные)
|
||||||
|
├── .env.example # Пример файла переменных окружения
|
||||||
|
├── database.json # Конфигурация базы данных
|
||||||
|
├── docker-compose.yml # Настройка Docker Compose
|
||||||
|
├── Dockerfile # Docker-образ приложения
|
||||||
|
├── package.json # Зависимости и скрипты NPM
|
||||||
|
└── tsconfig.json # Настройки TypeScript
|
||||||
|
```
|
||||||
|
|
||||||
## ✨ Функционал
|
## ✨ Функционал
|
||||||
|
|
||||||
### 🎯 Основные возможности
|
### 🎯 Основные возможности
|
||||||
@@ -74,82 +139,84 @@
|
|||||||
[💬 Написать] [👤 Профиль] [🔍 Продолжить поиск]
|
[💬 Написать] [👤 Профиль] [🔍 Продолжить поиск]
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🗂️ Структура проекта
|
|
||||||
|
|
||||||
```
|
|
||||||
telegram-tinder-bot/
|
|
||||||
├── src/
|
|
||||||
│ ├── bot.ts # Основной файл бота
|
|
||||||
│ ├── handlers/ # Обработчики событий
|
|
||||||
│ │ ├── commandHandlers.ts # Команды (/start, /profile, etc.)
|
|
||||||
│ │ ├── callbackHandlers.ts # Инлайн-кнопки (лайки, просмотр)
|
|
||||||
│ │ └── messageHandlers.ts # Текстовые сообщения
|
|
||||||
│ ├── services/ # Бизнес-логика
|
|
||||||
│ │ ├── profileService.ts # Управление профилями
|
|
||||||
│ │ ├── matchingService.ts # Алгоритм совпадений
|
|
||||||
│ │ └── notificationService.ts # Уведомления
|
|
||||||
│ ├── models/ # Модели данных
|
|
||||||
│ │ ├── User.ts # Пользователь Telegram
|
|
||||||
│ │ ├── Profile.ts # Профиль знакомств
|
|
||||||
│ │ ├── Swipe.ts # Лайки/дислайки
|
|
||||||
│ │ └── Match.ts # Совпадения
|
|
||||||
│ └── database/ # База данных
|
|
||||||
│ ├── connection.ts # Подключение к PostgreSQL
|
|
||||||
│ └── migrations/init.sql # Создание таблиц
|
|
||||||
├── config/ # Конфигурация
|
|
||||||
│ └── default.json # Настройки по умолчанию
|
|
||||||
├── docker-compose.yml # Docker Compose
|
|
||||||
├── Dockerfile # Docker контейнер
|
|
||||||
└── package.json # Зависимости npm
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🚀 Развертывание
|
## 🚀 Быстрый старт
|
||||||
|
|
||||||
### 📦 Docker (Рекомендуется)
|
### 1. Предварительные требования
|
||||||
|
|
||||||
|
- Node.js 16+
|
||||||
|
- PostgreSQL 12+
|
||||||
|
- Telegram Bot Token (получить у [@BotFather](https://t.me/BotFather))
|
||||||
|
|
||||||
|
### 2. Установка
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Клонировать репозиторий
|
# Клонировать репозиторий
|
||||||
git clone <repository-url>
|
git clone <repository-url>
|
||||||
cd telegram-tinder-bot
|
cd telegram-tinder-bot
|
||||||
|
|
||||||
# Настроить переменные окружения
|
|
||||||
cp .env.example .env
|
|
||||||
# Отредактируйте .env файл
|
|
||||||
|
|
||||||
# Запустить с Docker Compose
|
|
||||||
docker-compose up -d
|
|
||||||
|
|
||||||
# Применить миграции БД
|
|
||||||
docker-compose exec app npm run db:migrate
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🖥️ Обычная установка
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Установить зависимости
|
# Установить зависимости
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
# Создать базу данных
|
# Скомпилировать TypeScript
|
||||||
createdb telegram_tinder_bot
|
|
||||||
psql -d telegram_tinder_bot -f src/database/migrations/init.sql
|
|
||||||
|
|
||||||
# Запустить бота
|
|
||||||
npm run build
|
npm run build
|
||||||
npm start
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### ☁️ Продакшен
|
### 3. Настройка базы данных
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Установить PM2
|
# Создать базу данных PostgreSQL
|
||||||
npm install -g pm2
|
createdb telegram_tinder_bot
|
||||||
|
|
||||||
# Запустить через PM2
|
# Инициализация базы данных
|
||||||
pm2 start ecosystem.config.js
|
npm run init:db
|
||||||
|
```
|
||||||
|
|
||||||
# Мониторинг
|
### 4. Запуск бота
|
||||||
pm2 monit
|
|
||||||
pm2 logs telegram-tinder-bot
|
```bash
|
||||||
|
# Запуск на Windows
|
||||||
|
.\bin\start_bot.bat
|
||||||
|
|
||||||
|
# Запуск на Linux/macOS
|
||||||
|
npm run start
|
||||||
|
```
|
||||||
|
|
||||||
|
## <20> Развертывание на Ubuntu
|
||||||
|
|
||||||
|
Для развертывания на Ubuntu 24.04 используйте скрипт установки:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Сделать скрипт исполняемым
|
||||||
|
chmod +x ./bin/install_ubuntu.sh
|
||||||
|
|
||||||
|
# Запустить установку
|
||||||
|
sudo ./bin/install_ubuntu.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Подробные инструкции по развертыванию на Ubuntu находятся в [docs/DEPLOY_UBUNTU.md](docs/DEPLOY_UBUNTU.md).
|
||||||
|
|
||||||
|
## 🔄 Обновление бота
|
||||||
|
|
||||||
|
### На Windows:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Обновление с ветки main
|
||||||
|
npm run update:win
|
||||||
|
|
||||||
|
# Обновление с определенной ветки
|
||||||
|
.\bin\update.bat develop
|
||||||
|
```
|
||||||
|
|
||||||
|
### На Linux/macOS:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Обновление с ветки main
|
||||||
|
npm run update
|
||||||
|
|
||||||
|
# Обновление с определенной ветки и перезапуском сервиса
|
||||||
|
./bin/update.sh develop --restart-service
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🔧 Настройка переменных окружения
|
## 🔧 Настройка переменных окружения
|
||||||
@@ -201,8 +268,32 @@ npm run dev
|
|||||||
- Node.js 16+
|
- Node.js 16+
|
||||||
- PostgreSQL 12+
|
- PostgreSQL 12+
|
||||||
- Telegram Bot Token (получить у [@BotFather](https://t.me/BotFather))
|
- Telegram Bot Token (получить у [@BotFather](https://t.me/BotFather))
|
||||||
|
- Docker и Docker Compose (опционально)
|
||||||
|
|
||||||
### 2. Установка
|
### 2. Установка и запуск
|
||||||
|
|
||||||
|
#### С использованием стартовых скриптов (рекомендуется)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Клонировать репозиторий
|
||||||
|
git clone <repository-url>
|
||||||
|
cd telegram-tinder-bot
|
||||||
|
|
||||||
|
# На Windows:
|
||||||
|
.\start.bat
|
||||||
|
|
||||||
|
# На Linux/macOS:
|
||||||
|
chmod +x start.sh
|
||||||
|
./start.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Скрипт автоматически:
|
||||||
|
- Проверит наличие файла .env и создаст его из шаблона при необходимости
|
||||||
|
- Предложит выбор между запуском с локальной БД или подключением к внешней
|
||||||
|
- Настроит все необходимые параметры окружения
|
||||||
|
- Запустит контейнеры Docker
|
||||||
|
|
||||||
|
#### Без Docker
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Клонировать репозиторий
|
# Клонировать репозиторий
|
||||||
@@ -212,24 +303,17 @@ cd telegram-tinder-bot
|
|||||||
# Установить зависимости
|
# Установить зависимости
|
||||||
npm install
|
npm install
|
||||||
|
|
||||||
# Скомпилировать TypeScript
|
# Скопировать файл конфигурации
|
||||||
npm run build
|
cp .env.example .env
|
||||||
```
|
# Отредактируйте файл .env и укажите свой TELEGRAM_BOT_TOKEN
|
||||||
|
|
||||||
### 3. Настройка базы данных
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Создать базу данных PostgreSQL
|
# Создать базу данных PostgreSQL
|
||||||
createdb telegram_tinder_bot
|
createdb telegram_tinder_bot
|
||||||
|
|
||||||
# Запустить миграции
|
# Запустить миграции
|
||||||
psql -d telegram_tinder_bot -f src/database/migrations/init.sql
|
npm run migrate:up
|
||||||
```
|
|
||||||
|
|
||||||
### 4. Запуск бота
|
# Скомпилировать TypeScript
|
||||||
|
|
||||||
```bash
|
|
||||||
# Компиляция TypeScript
|
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
# Запуск бота
|
# Запуск бота
|
||||||
|
|||||||
84
bin/README.md
Normal file
84
bin/README.md
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
# Автоматическое обновление Telegram Tinder Bot
|
||||||
|
|
||||||
|
Этот документ описывает процесс автоматического обновления бота с помощью созданных скриптов.
|
||||||
|
|
||||||
|
## Скрипт обновления
|
||||||
|
|
||||||
|
Скрипт обновления выполняет следующие действия:
|
||||||
|
|
||||||
|
1. Получает последние изменения из Git-репозитория
|
||||||
|
2. Устанавливает зависимости
|
||||||
|
3. Применяет миграции базы данных
|
||||||
|
4. Собирает проект
|
||||||
|
5. Проверяет наличие файла .env
|
||||||
|
6. Проверяет наличие Docker-сервисов
|
||||||
|
7. При запуске на Ubuntu: проверяет и перезапускает PM2 сервис
|
||||||
|
|
||||||
|
## Подробные инструкции по развертыванию
|
||||||
|
|
||||||
|
Для подробных инструкций по развертыванию бота на сервере Ubuntu 24.04, пожалуйста, обратитесь к файлу `DEPLOY_UBUNTU.md` в корне проекта.
|
||||||
|
|
||||||
|
## Как использовать
|
||||||
|
|
||||||
|
### На Linux/macOS:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Обновление с ветки main (по умолчанию)
|
||||||
|
npm run update
|
||||||
|
|
||||||
|
# Обновление с определенной ветки
|
||||||
|
bash ./bin/update.sh develop
|
||||||
|
|
||||||
|
# Обновление с определенной ветки и перезапуском сервиса PM2 (для Ubuntu)
|
||||||
|
bash ./bin/update.sh develop --restart-service
|
||||||
|
```
|
||||||
|
|
||||||
|
### На Windows:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# Обновление с ветки main (по умолчанию)
|
||||||
|
npm run update:win
|
||||||
|
|
||||||
|
# Обновление с определенной ветки
|
||||||
|
.\bin\update.bat develop
|
||||||
|
```
|
||||||
|
|
||||||
|
## Добавление прав на выполнение (только для Linux/macOS)
|
||||||
|
|
||||||
|
Если у вас возникают проблемы с запуском скрипта, добавьте права на выполнение:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod +x ./bin/update.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Автоматизация обновлений
|
||||||
|
|
||||||
|
Для автоматизации регулярных обновлений вы можете использовать cron (Linux/macOS) или Планировщик заданий (Windows).
|
||||||
|
|
||||||
|
### Пример cron-задания для Ubuntu (ежедневное обновление в 4:00 с перезапуском сервиса):
|
||||||
|
|
||||||
|
```
|
||||||
|
0 4 * * * cd /opt/tg_tinder_bot && ./bin/update.sh --restart-service >> /var/log/tg_bot_update.log 2>&1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Пример cron-задания (ежедневное обновление в 4:00 без перезапуска):
|
||||||
|
|
||||||
|
```
|
||||||
|
0 4 * * * cd /path/to/bot && ./bin/update.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Для Windows:
|
||||||
|
|
||||||
|
Создайте задачу в Планировщике заданий, которая запускает:
|
||||||
|
|
||||||
|
```
|
||||||
|
cmd.exe /c "cd /d D:\Projects\tg_tinder_bot && .\bin\update.bat"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Что делать после обновления
|
||||||
|
|
||||||
|
После обновления вы можете:
|
||||||
|
|
||||||
|
1. Запустить бота: `npm run start`
|
||||||
|
2. Запустить бота в режиме разработки: `npm run dev`
|
||||||
|
3. Перезапустить Docker-контейнеры, если используете Docker: `docker-compose down && docker-compose up -d`
|
||||||
54
bin/backup_db.sh
Normal file
54
bin/backup_db.sh
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# backup_db.sh - Script for backing up the PostgreSQL database
|
||||||
|
|
||||||
|
echo "📦 Backing up PostgreSQL database..."
|
||||||
|
|
||||||
|
# Default backup directory
|
||||||
|
BACKUP_DIR="${BACKUP_DIR:-/var/backups/tg_tinder_bot}"
|
||||||
|
BACKUP_FILENAME="tg_tinder_bot_$(date +%Y%m%d_%H%M%S).sql"
|
||||||
|
BACKUP_PATH="$BACKUP_DIR/$BACKUP_FILENAME"
|
||||||
|
|
||||||
|
# Create backup directory if it doesn't exist
|
||||||
|
mkdir -p "$BACKUP_DIR"
|
||||||
|
|
||||||
|
# Check if running in docker-compose environment
|
||||||
|
if [ -f /.dockerenv ] || [ -f /proc/self/cgroup ] && grep -q docker /proc/self/cgroup; then
|
||||||
|
echo "🐳 Running in Docker environment, using docker-compose exec..."
|
||||||
|
docker-compose exec -T db pg_dump -U postgres telegram_tinder_bot > "$BACKUP_PATH"
|
||||||
|
else
|
||||||
|
# Check if PGPASSWORD is set in environment
|
||||||
|
if [ -z "$PGPASSWORD" ]; then
|
||||||
|
# If .env file exists, try to get password from there
|
||||||
|
if [ -f .env ]; then
|
||||||
|
DB_PASSWORD=$(grep DB_PASSWORD .env | cut -d '=' -f2)
|
||||||
|
export PGPASSWORD="$DB_PASSWORD"
|
||||||
|
else
|
||||||
|
echo "⚠️ No DB_PASSWORD found in environment or .env file."
|
||||||
|
echo "Please enter PostgreSQL password:"
|
||||||
|
read -s PGPASSWORD
|
||||||
|
export PGPASSWORD
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "💾 Backing up database to $BACKUP_PATH..."
|
||||||
|
pg_dump -h localhost -U postgres -d telegram_tinder_bot > "$BACKUP_PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if backup was successful
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "✅ Backup completed successfully: $BACKUP_PATH"
|
||||||
|
echo "📊 Backup size: $(du -h $BACKUP_PATH | cut -f1)"
|
||||||
|
|
||||||
|
# Compress the backup
|
||||||
|
gzip -f "$BACKUP_PATH"
|
||||||
|
echo "🗜️ Compressed backup: $BACKUP_PATH.gz"
|
||||||
|
|
||||||
|
# Keep only the last 7 backups
|
||||||
|
echo "🧹 Cleaning up old backups..."
|
||||||
|
find "$BACKUP_DIR" -name "tg_tinder_bot_*.sql.gz" -type f -mtime +7 -delete
|
||||||
|
|
||||||
|
echo "🎉 Backup process completed!"
|
||||||
|
else
|
||||||
|
echo "❌ Backup failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
72
bin/create_release.sh
Normal file
72
bin/create_release.sh
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Скрипт для создания релиза Telegram Tinder Bot
|
||||||
|
|
||||||
|
# Получение версии из package.json
|
||||||
|
VERSION=$(grep -m1 "version" package.json | cut -d'"' -f4)
|
||||||
|
RELEASE_NAME="tg-tinder-bot-v$VERSION"
|
||||||
|
RELEASE_DIR="bin/releases/$RELEASE_NAME"
|
||||||
|
|
||||||
|
echo "🚀 Создание релиза $RELEASE_NAME"
|
||||||
|
|
||||||
|
# Создание директории релиза
|
||||||
|
mkdir -p "$RELEASE_DIR"
|
||||||
|
|
||||||
|
# Очистка временных файлов
|
||||||
|
echo "🧹 Очистка временных файлов..."
|
||||||
|
rm -rf dist node_modules
|
||||||
|
|
||||||
|
# Установка зависимостей
|
||||||
|
echo "📦 Установка зависимостей production..."
|
||||||
|
npm ci --only=production
|
||||||
|
|
||||||
|
# Сборка проекта
|
||||||
|
echo "🔧 Сборка проекта..."
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# Копирование файлов релиза
|
||||||
|
echo "📋 Копирование файлов..."
|
||||||
|
cp -r dist "$RELEASE_DIR/"
|
||||||
|
cp -r src/locales "$RELEASE_DIR/dist/"
|
||||||
|
cp package.json package-lock.json .env.example "$RELEASE_DIR/"
|
||||||
|
cp -r bin/start_bot.* bin/install_ubuntu.sh "$RELEASE_DIR/"
|
||||||
|
cp README.md LICENSE "$RELEASE_DIR/" 2>/dev/null || echo "Файлы документации не найдены"
|
||||||
|
cp sql/consolidated.sql "$RELEASE_DIR/"
|
||||||
|
cp docker-compose.yml Dockerfile "$RELEASE_DIR/"
|
||||||
|
cp deploy.sh "$RELEASE_DIR/" && chmod +x "$RELEASE_DIR/deploy.sh"
|
||||||
|
|
||||||
|
# Создание README для релиза
|
||||||
|
cat > "$RELEASE_DIR/RELEASE.md" << EOL
|
||||||
|
# Telegram Tinder Bot v$VERSION
|
||||||
|
|
||||||
|
Эта папка содержит релиз Telegram Tinder Bot версии $VERSION.
|
||||||
|
|
||||||
|
## Содержимое
|
||||||
|
|
||||||
|
- \`dist/\` - Скомпилированный код
|
||||||
|
- \`package.json\` - Зависимости и скрипты
|
||||||
|
- \`.env.example\` - Пример конфигурации
|
||||||
|
- \`docker-compose.yml\` и \`Dockerfile\` - Для запуска через Docker
|
||||||
|
- \`consolidated.sql\` - SQL-скрипт для инициализации базы данных
|
||||||
|
- \`deploy.sh\` - Скрипт для простого деплоя
|
||||||
|
|
||||||
|
## Быстрый старт
|
||||||
|
|
||||||
|
1. Создайте файл \`.env\` на основе \`.env.example\`
|
||||||
|
2. Запустите бота одним из способов:
|
||||||
|
- Через Docker: \`./deploy.sh\`
|
||||||
|
- Через Node.js: \`node dist/bot.js\`
|
||||||
|
|
||||||
|
## Дата релиза
|
||||||
|
|
||||||
|
$(date "+%d.%m.%Y %H:%M")
|
||||||
|
EOL
|
||||||
|
|
||||||
|
# Архивирование релиза
|
||||||
|
echo "📦 Создание архива..."
|
||||||
|
cd bin/releases
|
||||||
|
zip -r "$RELEASE_NAME.zip" "$RELEASE_NAME"
|
||||||
|
cd ../..
|
||||||
|
|
||||||
|
echo "✅ Релиз создан успешно!"
|
||||||
|
echo "📂 Релиз доступен в: bin/releases/$RELEASE_NAME"
|
||||||
|
echo "📦 Архив релиза: bin/releases/$RELEASE_NAME.zip"
|
||||||
58
bin/install_docker.sh
Normal file
58
bin/install_docker.sh
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# install_docker.sh - Script for installing Docker and Docker Compose
|
||||||
|
|
||||||
|
echo "🚀 Installing Docker and Docker Compose..."
|
||||||
|
|
||||||
|
# Check if script is run as root
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
echo "❌ This script must be run as root. Please run with sudo."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update package lists
|
||||||
|
echo "📦 Updating package lists..."
|
||||||
|
apt update
|
||||||
|
|
||||||
|
# Install required packages
|
||||||
|
echo "📦 Installing required packages..."
|
||||||
|
apt install -y apt-transport-https ca-certificates curl software-properties-common
|
||||||
|
|
||||||
|
# Add Docker GPG key
|
||||||
|
echo "🔑 Adding Docker GPG key..."
|
||||||
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
||||||
|
|
||||||
|
# Add Docker repository
|
||||||
|
echo "📁 Adding Docker repository..."
|
||||||
|
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||||
|
|
||||||
|
# Update package lists again
|
||||||
|
apt update
|
||||||
|
|
||||||
|
# Install Docker
|
||||||
|
echo "🐳 Installing Docker..."
|
||||||
|
apt install -y docker-ce docker-ce-cli containerd.io
|
||||||
|
|
||||||
|
# Enable and start Docker service
|
||||||
|
systemctl enable docker
|
||||||
|
systemctl start docker
|
||||||
|
|
||||||
|
# Install Docker Compose
|
||||||
|
echo "🐳 Installing Docker Compose..."
|
||||||
|
curl -L "https://github.com/docker/compose/releases/download/v2.24.6/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||||||
|
chmod +x /usr/local/bin/docker-compose
|
||||||
|
|
||||||
|
# Check versions
|
||||||
|
echo "✅ Installation complete!"
|
||||||
|
echo "Docker version:"
|
||||||
|
docker --version
|
||||||
|
echo "Docker Compose version:"
|
||||||
|
docker-compose --version
|
||||||
|
|
||||||
|
# Add current user to docker group if not root
|
||||||
|
if [ -n "$SUDO_USER" ]; then
|
||||||
|
echo "👤 Adding user $SUDO_USER to docker group..."
|
||||||
|
usermod -aG docker $SUDO_USER
|
||||||
|
echo "⚠️ Please log out and log back in for group changes to take effect."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🎉 Docker installation completed successfully!"
|
||||||
190
bin/install_ubuntu.sh
Normal file
190
bin/install_ubuntu.sh
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script for installing Telegram Tinder Bot on Ubuntu
|
||||||
|
# This script automates the deployment process on a fresh Ubuntu server
|
||||||
|
# Usage: ./bin/install_ubuntu.sh [--with-nginx] [--with-ssl domain.com]
|
||||||
|
|
||||||
|
set -e # Exit immediately if a command exits with a non-zero status
|
||||||
|
|
||||||
|
# Define colors for pretty output
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
YELLOW='\033[0;33m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Default settings
|
||||||
|
INSTALL_NGINX=false
|
||||||
|
INSTALL_SSL=false
|
||||||
|
DOMAIN=""
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [[ "$arg" == "--with-nginx" ]]; then
|
||||||
|
INSTALL_NGINX=true
|
||||||
|
elif [[ "$arg" == "--with-ssl" ]]; then
|
||||||
|
INSTALL_SSL=true
|
||||||
|
# Next argument should be domain
|
||||||
|
shift
|
||||||
|
DOMAIN="$1"
|
||||||
|
if [[ -z "$DOMAIN" || "$DOMAIN" == --* ]]; then
|
||||||
|
echo -e "${RED}Error: Domain name required after --with-ssl${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "${BLUE}========================================${NC}"
|
||||||
|
echo -e "${BLUE} Telegram Tinder Bot Ubuntu Installer ${NC}"
|
||||||
|
echo -e "${BLUE}========================================${NC}"
|
||||||
|
|
||||||
|
# Check if running on Ubuntu
|
||||||
|
if [ -f /etc/os-release ]; then
|
||||||
|
source /etc/os-release
|
||||||
|
if [[ "$ID" != "ubuntu" ]]; then
|
||||||
|
echo -e "${RED}Error: This script is designed for Ubuntu. Current OS: $ID${NC}"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}Detected Ubuntu ${VERSION_ID}${NC}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -e "${RED}Error: Could not detect operating system${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for root privileges
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
echo -e "${RED}Error: This script must be run as root${NC}"
|
||||||
|
echo -e "Please run: ${YELLOW}sudo $0 $*${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 1: Updating system packages...${NC}"
|
||||||
|
apt update && apt upgrade -y
|
||||||
|
echo -e "${GREEN}✓ System packages updated${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 2: Installing dependencies...${NC}"
|
||||||
|
apt install -y curl wget git build-essential postgresql postgresql-contrib
|
||||||
|
echo -e "${GREEN}✓ Basic dependencies installed${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 3: Installing Node.js...${NC}"
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
|
||||||
|
apt install -y nodejs
|
||||||
|
echo -e "${GREEN}✓ Node.js $(node --version) installed${NC}"
|
||||||
|
echo -e "${GREEN}✓ npm $(npm --version) installed${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 4: Setting up PostgreSQL...${NC}"
|
||||||
|
systemctl start postgresql
|
||||||
|
systemctl enable postgresql
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Please enter a strong password for the database user:${NC}"
|
||||||
|
read -s DB_PASSWORD
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Create database and user
|
||||||
|
su - postgres -c "psql -c \"CREATE DATABASE tg_tinder_bot;\""
|
||||||
|
su - postgres -c "psql -c \"CREATE USER tg_bot WITH PASSWORD '$DB_PASSWORD';\""
|
||||||
|
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE tg_tinder_bot TO tg_bot;\""
|
||||||
|
echo -e "${GREEN}✓ PostgreSQL configured${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 5: Setting up application directory...${NC}"
|
||||||
|
mkdir -p /opt/tg_tinder_bot
|
||||||
|
chown $SUDO_USER:$SUDO_USER /opt/tg_tinder_bot
|
||||||
|
echo -e "${GREEN}✓ Application directory created${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 6: Installing PM2...${NC}"
|
||||||
|
npm install -g pm2
|
||||||
|
echo -e "${GREEN}✓ PM2 installed${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 7: Please enter your Telegram Bot Token:${NC}"
|
||||||
|
read BOT_TOKEN
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 8: Creating environment file...${NC}"
|
||||||
|
cat > /opt/tg_tinder_bot/.env << EOL
|
||||||
|
# Bot settings
|
||||||
|
BOT_TOKEN=${BOT_TOKEN}
|
||||||
|
LOG_LEVEL=info
|
||||||
|
|
||||||
|
# Database settings
|
||||||
|
DB_HOST=localhost
|
||||||
|
DB_PORT=5432
|
||||||
|
DB_USER=tg_bot
|
||||||
|
DB_PASSWORD=${DB_PASSWORD}
|
||||||
|
DB_NAME=tg_tinder_bot
|
||||||
|
EOL
|
||||||
|
chmod 600 /opt/tg_tinder_bot/.env
|
||||||
|
chown $SUDO_USER:$SUDO_USER /opt/tg_tinder_bot/.env
|
||||||
|
echo -e "${GREEN}✓ Environment file created${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 9: Setting up systemd service...${NC}"
|
||||||
|
cat > /etc/systemd/system/tg-tinder-bot.service << EOL
|
||||||
|
[Unit]
|
||||||
|
Description=Telegram Tinder Bot
|
||||||
|
After=network.target postgresql.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=${SUDO_USER}
|
||||||
|
WorkingDirectory=/opt/tg_tinder_bot
|
||||||
|
ExecStart=/usr/bin/node dist/bot.js
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=10
|
||||||
|
StandardOutput=syslog
|
||||||
|
StandardError=syslog
|
||||||
|
SyslogIdentifier=tg-tinder-bot
|
||||||
|
Environment=NODE_ENV=production
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOL
|
||||||
|
echo -e "${GREEN}✓ Systemd service created${NC}"
|
||||||
|
|
||||||
|
if [ "$INSTALL_NGINX" = true ]; then
|
||||||
|
echo -e "\n${BLUE}Step 10: Installing and configuring Nginx...${NC}"
|
||||||
|
apt install -y nginx
|
||||||
|
|
||||||
|
# Create Nginx configuration
|
||||||
|
cat > /etc/nginx/sites-available/tg_tinder_bot << EOL
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name ${DOMAIN:-_};
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade \$http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host \$host;
|
||||||
|
proxy_cache_bypass \$http_upgrade;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOL
|
||||||
|
|
||||||
|
# Enable site
|
||||||
|
ln -sf /etc/nginx/sites-available/tg_tinder_bot /etc/nginx/sites-enabled/
|
||||||
|
nginx -t && systemctl restart nginx
|
||||||
|
echo -e "${GREEN}✓ Nginx configured${NC}"
|
||||||
|
|
||||||
|
if [ "$INSTALL_SSL" = true ] && [ ! -z "$DOMAIN" ]; then
|
||||||
|
echo -e "\n${BLUE}Step 11: Setting up SSL with Certbot...${NC}"
|
||||||
|
apt install -y certbot python3-certbot-nginx
|
||||||
|
certbot --nginx --non-interactive --agree-tos --email admin@${DOMAIN} -d ${DOMAIN}
|
||||||
|
echo -e "${GREEN}✓ SSL certificate installed${NC}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 12: Clone your repository${NC}"
|
||||||
|
echo -e "Now you should clone your repository to /opt/tg_tinder_bot"
|
||||||
|
echo -e "Example: ${YELLOW}git clone https://your-git-repo-url.git /opt/tg_tinder_bot${NC}"
|
||||||
|
echo -e "Then run the update script: ${YELLOW}cd /opt/tg_tinder_bot && ./bin/update.sh${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${GREEN}========================================${NC}"
|
||||||
|
echo -e "${GREEN} Installation completed! ${NC}"
|
||||||
|
echo -e "${GREEN}========================================${NC}"
|
||||||
|
echo -e "Next steps:"
|
||||||
|
echo -e "1. Clone your repository to ${YELLOW}/opt/tg_tinder_bot${NC}"
|
||||||
|
echo -e "2. Run the update script to set up the application"
|
||||||
|
echo -e "3. Start the service with: ${YELLOW}sudo systemctl start tg-tinder-bot${NC}"
|
||||||
|
echo -e "4. Enable auto-start with: ${YELLOW}sudo systemctl enable tg-tinder-bot${NC}"
|
||||||
|
echo -e "5. Check status with: ${YELLOW}sudo systemctl status tg-tinder-bot${NC}"
|
||||||
0
setup.sh → bin/setup.sh
Executable file → Normal file
0
setup.sh → bin/setup.sh
Executable file → Normal file
27
bin/start_bot.bat
Normal file
27
bin/start_bot.bat
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
@echo off
|
||||||
|
REM Скрипт для запуска Telegram Tinder Bot в производственном режиме на Windows
|
||||||
|
REM Запускает собранный JavaScript из dist/bot.js
|
||||||
|
|
||||||
|
echo 🚀 Запуск Telegram Tinder Bot в производственном режиме...
|
||||||
|
|
||||||
|
REM Добавляем Node.js в PATH, если нужно
|
||||||
|
set PATH=%PATH%;C:\Program Files\nodejs
|
||||||
|
|
||||||
|
REM Переходим в корневую директорию проекта
|
||||||
|
cd /d %~dp0..
|
||||||
|
|
||||||
|
REM Проверяем, существует ли собранный файл
|
||||||
|
if not exist ".\dist\bot.js" (
|
||||||
|
echo ❌ Ошибка: Собранный файл не найден. Сначала выполните 'npm run build'.
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Устанавливаем переменную окружения для производственного режима
|
||||||
|
set NODE_ENV=production
|
||||||
|
|
||||||
|
REM Запускаем бот
|
||||||
|
echo 🤖 Запуск Telegram Tinder Bot...
|
||||||
|
node .\dist\bot.js
|
||||||
|
|
||||||
|
REM Если скрипт дойдет до этой точки, значит бот завершил работу
|
||||||
|
echo 👋 Бот был остановлен.
|
||||||
24
bin/start_bot.sh
Normal file
24
bin/start_bot.sh
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Скрипт для запуска бота в производственном режиме
|
||||||
|
# Запускает собранный JavaScript из dist/bot.js
|
||||||
|
|
||||||
|
# Переходим в корневую директорию проекта (предполагается, что скрипт находится в bin/)
|
||||||
|
PROJECT_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
|
||||||
|
cd "$PROJECT_DIR" || { echo "❌ Error: Could not change directory to $PROJECT_DIR"; exit 1; }
|
||||||
|
|
||||||
|
# Проверяем, существует ли собранный файл
|
||||||
|
if [ ! -f "./dist/bot.js" ]; then
|
||||||
|
echo "❌ Error: Built file not found. Please run 'npm run build' first."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Устанавливаем переменную окружения для производственного режима
|
||||||
|
export NODE_ENV=production
|
||||||
|
|
||||||
|
# Запускаем бот
|
||||||
|
echo "🚀 Starting Telegram Tinder Bot in production mode..."
|
||||||
|
node ./dist/bot.js
|
||||||
|
|
||||||
|
# Если скрипт дойдет до этой точки, значит бот завершил работу
|
||||||
|
echo "👋 Bot has been stopped."
|
||||||
18
bin/tg-tinder-bot.service
Normal file
18
bin/tg-tinder-bot.service
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Telegram Tinder Bot
|
||||||
|
After=network.target postgresql.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
User=ubuntu
|
||||||
|
WorkingDirectory=/opt/tg_tinder_bot
|
||||||
|
ExecStart=/usr/bin/node dist/bot.js
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=10
|
||||||
|
StandardOutput=syslog
|
||||||
|
StandardError=syslog
|
||||||
|
SyslogIdentifier=tg-tinder-bot
|
||||||
|
Environment=NODE_ENV=production
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
113
bin/update.bat
Normal file
113
bin/update.bat
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
@echo off
|
||||||
|
REM Script for updating the Telegram Tinder Bot on Windows
|
||||||
|
REM This script updates the code from Git, applies migrations, and prepares the bot for running
|
||||||
|
REM Usage: .\bin\update.bat [branch]
|
||||||
|
REM If branch is not specified, 'main' is used
|
||||||
|
|
||||||
|
setlocal enableextensions enabledelayedexpansion
|
||||||
|
|
||||||
|
echo ========================================
|
||||||
|
echo Telegram Tinder Bot Updater
|
||||||
|
echo ========================================
|
||||||
|
|
||||||
|
REM Get the branch name from the command line arguments
|
||||||
|
set BRANCH=%1
|
||||||
|
if "%BRANCH%"=="" set BRANCH=main
|
||||||
|
echo Updating from branch: %BRANCH%
|
||||||
|
|
||||||
|
REM Store the current directory
|
||||||
|
set CURRENT_DIR=%CD%
|
||||||
|
set SCRIPT_DIR=%~dp0
|
||||||
|
set PROJECT_DIR=%SCRIPT_DIR%..
|
||||||
|
|
||||||
|
REM Navigate to the project directory
|
||||||
|
cd /d %PROJECT_DIR%
|
||||||
|
echo Working directory: %PROJECT_DIR%
|
||||||
|
|
||||||
|
REM Check if we're in a git repository
|
||||||
|
if not exist .git (
|
||||||
|
echo Error: Not a git repository
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Step 1: Pulling latest changes from Git repository...
|
||||||
|
REM Save any local changes
|
||||||
|
git stash save "Auto-stash before update: %DATE% %TIME%"
|
||||||
|
|
||||||
|
REM Fetch all branches
|
||||||
|
git fetch --all
|
||||||
|
|
||||||
|
REM Check if the branch exists
|
||||||
|
git rev-parse --verify %BRANCH% >nul 2>&1
|
||||||
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
git rev-parse --verify origin/%BRANCH% >nul 2>&1
|
||||||
|
if %ERRORLEVEL% NEQ 0 (
|
||||||
|
echo Error: Branch '%BRANCH%' does not exist locally or remotely
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
REM Checkout the specified branch
|
||||||
|
git checkout %BRANCH%
|
||||||
|
|
||||||
|
REM Pull the latest changes
|
||||||
|
git pull origin %BRANCH%
|
||||||
|
echo ✓ Successfully pulled latest changes
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Step 2: Installing dependencies...
|
||||||
|
call npm ci
|
||||||
|
echo ✓ Dependencies installed
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Step 3: Running database migrations...
|
||||||
|
REM Check if migrations directory exists
|
||||||
|
if exist migrations (
|
||||||
|
echo Applying database migrations...
|
||||||
|
call npm run migrate:up
|
||||||
|
echo ✓ Migrations applied successfully
|
||||||
|
) else (
|
||||||
|
echo ⚠ No migrations directory found, running database initialization script...
|
||||||
|
call npm run init:db
|
||||||
|
echo ✓ Database initialized
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Step 4: Building the project...
|
||||||
|
call npm run build
|
||||||
|
echo ✓ Project built successfully
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Step 5: Checking for .env file...
|
||||||
|
if exist .env (
|
||||||
|
echo ✓ .env file exists
|
||||||
|
) else (
|
||||||
|
echo ⚠ .env file not found
|
||||||
|
if exist .env.example (
|
||||||
|
echo Creating .env from .env.example
|
||||||
|
copy .env.example .env
|
||||||
|
echo ⚠ Please update the .env file with your configuration!
|
||||||
|
) else (
|
||||||
|
echo Error: .env.example file not found
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Step 6: Checking for services...
|
||||||
|
REM Check if Docker is being used
|
||||||
|
if exist docker-compose.yml (
|
||||||
|
echo Docker Compose configuration found
|
||||||
|
echo You might want to restart containers with: docker-compose down ^&^& docker-compose up -d
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ========================================
|
||||||
|
echo Update completed successfully!
|
||||||
|
echo ========================================
|
||||||
|
echo To start the bot, run: npm run start
|
||||||
|
echo For development mode: npm run dev
|
||||||
|
|
||||||
|
REM Return to the original directory
|
||||||
|
cd /d %CURRENT_DIR%
|
||||||
155
bin/update.sh
Normal file
155
bin/update.sh
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script for updating the Telegram Tinder Bot
|
||||||
|
# This script updates the code from Git, applies migrations, and prepares the bot for running
|
||||||
|
# Usage: ./bin/update.sh [branch] [--restart-service]
|
||||||
|
# If branch is not specified, 'main' is used
|
||||||
|
# Use --restart-service flag to restart PM2 service after update (for production deployments)
|
||||||
|
|
||||||
|
set -e # Exit immediately if a command exits with a non-zero status
|
||||||
|
|
||||||
|
# Define colors for pretty output
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
YELLOW='\033[0;33m'
|
||||||
|
RED='\033[0;31m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
echo -e "${BLUE}========================================${NC}"
|
||||||
|
echo -e "${BLUE} Telegram Tinder Bot Updater ${NC}"
|
||||||
|
echo -e "${BLUE}========================================${NC}"
|
||||||
|
|
||||||
|
# Parse command line arguments
|
||||||
|
BRANCH="main"
|
||||||
|
RESTART_SERVICE=false
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [[ "$arg" == "--restart-service" ]]; then
|
||||||
|
RESTART_SERVICE=true
|
||||||
|
elif [[ "$arg" != --* ]]; then
|
||||||
|
BRANCH="$arg"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -e "${YELLOW}Updating from branch: ${BRANCH}${NC}"
|
||||||
|
if [ "$RESTART_SERVICE" = true ]; then
|
||||||
|
echo -e "${YELLOW}Will restart service after update${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Store the current directory
|
||||||
|
CURRENT_DIR=$(pwd)
|
||||||
|
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
|
||||||
|
PROJECT_DIR=$(dirname "$SCRIPT_DIR")
|
||||||
|
|
||||||
|
# Check if running on Ubuntu
|
||||||
|
IS_UBUNTU=false
|
||||||
|
if [ -f /etc/os-release ]; then
|
||||||
|
source /etc/os-release
|
||||||
|
if [[ "$ID" == "ubuntu" ]]; then
|
||||||
|
IS_UBUNTU=true
|
||||||
|
echo -e "${BLUE}Detected Ubuntu: ${VERSION_ID}${NC}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Navigate to the project directory
|
||||||
|
cd "$PROJECT_DIR"
|
||||||
|
echo -e "${BLUE}Working directory: ${PROJECT_DIR}${NC}"
|
||||||
|
|
||||||
|
# Check if we're in a git repository
|
||||||
|
if [ ! -d ".git" ]; then
|
||||||
|
echo -e "${RED}Error: Not a git repository${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 1: Pulling latest changes from Git repository...${NC}"
|
||||||
|
# Save any local changes
|
||||||
|
git stash save "Auto-stash before update: $(date)"
|
||||||
|
|
||||||
|
# Fetch all branches
|
||||||
|
git fetch --all
|
||||||
|
|
||||||
|
# Check if the branch exists
|
||||||
|
if ! git rev-parse --verify "$BRANCH" &>/dev/null && ! git rev-parse --verify "origin/$BRANCH" &>/dev/null; then
|
||||||
|
echo -e "${RED}Error: Branch '$BRANCH' does not exist locally or remotely${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Checkout the specified branch
|
||||||
|
git checkout "$BRANCH"
|
||||||
|
|
||||||
|
# Pull the latest changes
|
||||||
|
git pull origin "$BRANCH"
|
||||||
|
echo -e "${GREEN}✓ Successfully pulled latest changes${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 2: Installing dependencies...${NC}"
|
||||||
|
npm ci
|
||||||
|
echo -e "${GREEN}✓ Dependencies installed${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 3: Running database migrations...${NC}"
|
||||||
|
# Check if migrations directory exists
|
||||||
|
if [ -d "./migrations" ]; then
|
||||||
|
echo "Applying database migrations..."
|
||||||
|
npm run migrate:up
|
||||||
|
echo -e "${GREEN}✓ Migrations applied successfully${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}⚠ No migrations directory found, running database initialization script...${NC}"
|
||||||
|
npm run init:db
|
||||||
|
echo -e "${GREEN}✓ Database initialized${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 4: Building the project...${NC}"
|
||||||
|
npm run build
|
||||||
|
echo -e "${GREEN}✓ Project built successfully${NC}"
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 5: Checking for .env file...${NC}"
|
||||||
|
if [ -f .env ]; then
|
||||||
|
echo -e "${GREEN}✓ .env file exists${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}⚠ .env file not found${NC}"
|
||||||
|
if [ -f .env.example ]; then
|
||||||
|
echo "Creating .env from .env.example"
|
||||||
|
cp .env.example .env
|
||||||
|
echo -e "${YELLOW}⚠ Please update the .env file with your configuration!${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}Error: .env.example file not found${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n${BLUE}Step 6: Checking for services...${NC}"
|
||||||
|
# Check if Docker is being used
|
||||||
|
if [ -f docker-compose.yml ]; then
|
||||||
|
echo "Docker Compose configuration found"
|
||||||
|
echo "You might want to restart containers with: docker-compose down && docker-compose up -d"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for PM2 process on Ubuntu
|
||||||
|
if [ "$IS_UBUNTU" = true ] && command -v pm2 &>/dev/null; then
|
||||||
|
echo -e "\n${BLUE}Step 7: Checking PM2 service...${NC}"
|
||||||
|
if pm2 list | grep -q "tg_tinder_bot"; then
|
||||||
|
echo "PM2 service for tg_tinder_bot found"
|
||||||
|
if [ "$RESTART_SERVICE" = true ]; then
|
||||||
|
echo "Restarting PM2 service..."
|
||||||
|
pm2 restart tg_tinder_bot
|
||||||
|
echo -e "${GREEN}✓ PM2 service restarted${NC}"
|
||||||
|
else
|
||||||
|
echo "To restart the service, run: ${YELLOW}pm2 restart tg_tinder_bot${NC}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo -e "\n${GREEN}========================================${NC}"
|
||||||
|
echo -e "${GREEN} Update completed successfully! ${NC}"
|
||||||
|
echo -e "${GREEN}========================================${NC}"
|
||||||
|
|
||||||
|
if [ "$IS_UBUNTU" = true ] && command -v pm2 &>/dev/null; then
|
||||||
|
echo -e "To start the bot with PM2, run: ${YELLOW}pm2 start dist/bot.js --name tg_tinder_bot${NC}"
|
||||||
|
echo -e "To restart the bot, run: ${YELLOW}pm2 restart tg_tinder_bot${NC}"
|
||||||
|
echo -e "To view logs, run: ${YELLOW}pm2 logs tg_tinder_bot${NC}"
|
||||||
|
else
|
||||||
|
echo -e "To start the bot, run: ${YELLOW}npm run start${NC}"
|
||||||
|
echo -e "For development mode: ${YELLOW}npm run dev${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Return to the original directory
|
||||||
|
cd "$CURRENT_DIR"
|
||||||
7
database.json
Normal file
7
database.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"connectionString": {
|
||||||
|
"ENV": "DATABASE_URL"
|
||||||
|
},
|
||||||
|
"migrationsTable": "pgmigrations",
|
||||||
|
"migrationsDirectory": "./migrations"
|
||||||
|
}
|
||||||
63
deploy.sh
Normal file
63
deploy.sh
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# deploy.sh - Скрипт для деплоя Telegram Tinder Bot
|
||||||
|
|
||||||
|
echo "🚀 Деплой Telegram Tinder Bot..."
|
||||||
|
|
||||||
|
# Проверяем наличие Docker
|
||||||
|
if ! command -v docker &> /dev/null || ! command -v docker-compose &> /dev/null; then
|
||||||
|
echo "❌ Docker и Docker Compose должны быть установлены!"
|
||||||
|
echo "Для установки на Ubuntu выполните:"
|
||||||
|
echo "sudo apt update && sudo apt install -y docker.io docker-compose"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Определяем рабочую директорию
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||||
|
cd "$SCRIPT_DIR"
|
||||||
|
|
||||||
|
# Получаем последние изменения
|
||||||
|
echo "📥 Получение последних изменений..."
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# Проверяем наличие .env файла
|
||||||
|
if [ ! -f .env ]; then
|
||||||
|
echo "📝 Создание .env файла из .env.production..."
|
||||||
|
cp .env.production .env
|
||||||
|
echo "⚠️ Пожалуйста, отредактируйте файл .env и укажите свои настройки!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Проверяем и исправляем проблему с командой сборки в Dockerfile
|
||||||
|
echo "🔧 Проверка конфигурации Dockerfile..."
|
||||||
|
if grep -q "RUN npm run build" Dockerfile; then
|
||||||
|
echo "⚠️ Исправление команды сборки в Dockerfile для совместимости с Linux..."
|
||||||
|
sed -i 's/RUN npm run build/RUN npm run build:linux/g' Dockerfile
|
||||||
|
echo "✅ Dockerfile обновлен"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Запускаем Docker Compose
|
||||||
|
echo "🐳 Сборка и запуск контейнеров Docker..."
|
||||||
|
docker-compose down
|
||||||
|
docker-compose build
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# Проверяем статус контейнеров
|
||||||
|
echo "🔍 Проверка статуса контейнеров..."
|
||||||
|
docker-compose ps
|
||||||
|
|
||||||
|
echo "✅ Деплой успешно завершен! Бот должен быть доступен через Telegram."
|
||||||
|
echo ""
|
||||||
|
echo "📊 Полезные команды:"
|
||||||
|
echo "- Просмотр логов: docker-compose logs -f"
|
||||||
|
echo "- Перезапуск сервисов: docker-compose restart"
|
||||||
|
echo "- Остановка всех сервисов: docker-compose down"
|
||||||
|
echo "- Доступ к базе данных: docker-compose exec db psql -U postgres -d telegram_tinder_bot"
|
||||||
|
echo "- Проверка состояния бота: curl http://localhost:3000/health"
|
||||||
|
echo ""
|
||||||
|
echo "🌟 Для администрирования базы данных:"
|
||||||
|
echo "Adminer доступен по адресу: http://ваш_сервер:8080"
|
||||||
|
echo " - Система: PostgreSQL"
|
||||||
|
echo " - Сервер: db"
|
||||||
|
echo " - Пользователь: postgres"
|
||||||
|
echo " - Пароль: (из переменной DB_PASSWORD в .env)"
|
||||||
|
echo " - База данных: telegram_tinder_bot"
|
||||||
69
docker-compose.override.yml.example
Normal file
69
docker-compose.override.yml.example
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Используем версию Docker Compose для локальной разработки
|
||||||
|
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
bot:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
args:
|
||||||
|
- NODE_ENV=development
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=development
|
||||||
|
- DB_HOST=db
|
||||||
|
- DB_PORT=5432
|
||||||
|
- DB_NAME=telegram_tinder_bot
|
||||||
|
- DB_USERNAME=postgres
|
||||||
|
- DB_PASSWORD=dev_password
|
||||||
|
volumes:
|
||||||
|
# Монтируем исходный код для горячей перезагрузки
|
||||||
|
- ./src:/app/src
|
||||||
|
- ./dist:/app/dist
|
||||||
|
- ./.env:/app/.env
|
||||||
|
ports:
|
||||||
|
# Открываем порт для отладки
|
||||||
|
- "9229:9229"
|
||||||
|
command: npm run dev
|
||||||
|
networks:
|
||||||
|
- bot-network
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
# Используем последнюю версию PostgreSQL для разработки
|
||||||
|
image: postgres:16-alpine
|
||||||
|
environment:
|
||||||
|
- POSTGRES_DB=telegram_tinder_bot
|
||||||
|
- POSTGRES_USER=postgres
|
||||||
|
- POSTGRES_PASSWORD=dev_password
|
||||||
|
volumes:
|
||||||
|
# Хранение данных локально для быстрого сброса
|
||||||
|
- postgres_data_dev:/var/lib/postgresql/data
|
||||||
|
# Монтируем скрипты инициализации
|
||||||
|
- ./sql:/docker-entrypoint-initdb.d
|
||||||
|
ports:
|
||||||
|
# Открываем порт для доступа к БД напрямую
|
||||||
|
- "5433:5432"
|
||||||
|
networks:
|
||||||
|
- bot-network
|
||||||
|
|
||||||
|
adminer:
|
||||||
|
image: adminer:latest
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
networks:
|
||||||
|
- bot-network
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
environment:
|
||||||
|
- ADMINER_DEFAULT_SERVER=db
|
||||||
|
- ADMINER_DEFAULT_USER=postgres
|
||||||
|
- ADMINER_DEFAULT_PASSWORD=dev_password
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data_dev:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
bot-network:
|
||||||
|
driver: bridge
|
||||||
45
docker-compose.temp.yml
Normal file
45
docker-compose.temp.yml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
[36mВведите параметры подключения к внешней базе данных:[0m
|
||||||
|
Хост (например, localhost): Порт (например, 5432): Имя базы данных: Имя пользователя: Пароль: [33mМодифицируем docker-compose.yml для работы с внешней базой данных...[0m
|
||||||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 䠩<><E4A0A9><EFBFBD>: 0.
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
bot:
|
||||||
|
build: .
|
||||||
|
container_name: telegram-tinder-bot
|
||||||
|
restart: unless-stopped
|
||||||
|
env_file: .env
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
- DB_HOST=
|
||||||
|
- DB_PORT=
|
||||||
|
- DB_NAME=
|
||||||
|
- DB_USERNAME=
|
||||||
|
- DB_PASSWORD=
|
||||||
|
volumes:
|
||||||
|
- ./uploads:/app/uploads
|
||||||
|
- ./logs:/app/logs
|
||||||
|
networks:
|
||||||
|
- bot-network
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
start_period: 10s
|
||||||
|
|
||||||
|
adminer:
|
||||||
|
image: adminer:latest
|
||||||
|
container_name: adminer-tinder
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
networks:
|
||||||
|
- bot-network
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
bot-network:
|
||||||
|
driver: bridge
|
||||||
@@ -6,19 +6,26 @@ services:
|
|||||||
container_name: telegram-tinder-bot
|
container_name: telegram-tinder-bot
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
db:
|
||||||
|
condition: service_healthy
|
||||||
|
env_file: .env
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
- DB_HOST=db
|
- DB_HOST=db
|
||||||
- DB_PORT=5432
|
- DB_PORT=5432
|
||||||
- DB_NAME=telegram_tinder_bot
|
- DB_NAME=telegram_tinder_bot
|
||||||
- DB_USERNAME=postgres
|
- DB_USERNAME=postgres
|
||||||
- DB_PASSWORD=${DB_PASSWORD}
|
|
||||||
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
|
|
||||||
volumes:
|
volumes:
|
||||||
- ./uploads:/app/uploads
|
- ./uploads:/app/uploads
|
||||||
|
- ./logs:/app/logs
|
||||||
networks:
|
networks:
|
||||||
- bot-network
|
- bot-network
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 3
|
||||||
|
start_period: 10s
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres:15-alpine
|
image: postgres:15-alpine
|
||||||
@@ -27,14 +34,18 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- POSTGRES_DB=telegram_tinder_bot
|
- POSTGRES_DB=telegram_tinder_bot
|
||||||
- POSTGRES_USER=postgres
|
- POSTGRES_USER=postgres
|
||||||
- POSTGRES_PASSWORD=password123
|
- POSTGRES_PASSWORD=${DB_PASSWORD:-password123}
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
- ./src/database/migrations/init.sql:/docker-entrypoint-initdb.d/init.sql
|
|
||||||
ports:
|
ports:
|
||||||
- "5433:5432"
|
- "5433:5432"
|
||||||
networks:
|
networks:
|
||||||
- bot-network
|
- bot-network
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
|
||||||
adminer:
|
adminer:
|
||||||
image: adminer:latest
|
image: adminer:latest
|
||||||
|
|||||||
221
docs/DEPLOY_UBUNTU.md
Normal file
221
docs/DEPLOY_UBUNTU.md
Normal file
@@ -0,0 +1,221 @@
|
|||||||
|
# Деплой Telegram Tinder Bot на Ubuntu 24.04
|
||||||
|
|
||||||
|
Это руководство поможет вам настроить и развернуть Telegram Tinder Bot на сервере с Ubuntu 24.04.
|
||||||
|
|
||||||
|
## Предварительные требования
|
||||||
|
|
||||||
|
- Сервер с Ubuntu 24.04
|
||||||
|
- Права администратора (sudo)
|
||||||
|
- Доменное имя (опционально, для SSL)
|
||||||
|
|
||||||
|
## Шаг 1: Подготовка сервера
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Обновите систему
|
||||||
|
sudo apt update && sudo apt upgrade -y
|
||||||
|
|
||||||
|
# Установите необходимые пакеты
|
||||||
|
sudo apt install -y curl wget git build-essential postgresql postgresql-contrib nginx
|
||||||
|
|
||||||
|
# Установите Node.js и npm
|
||||||
|
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
|
||||||
|
sudo apt install -y nodejs
|
||||||
|
|
||||||
|
# Проверьте установку
|
||||||
|
node --version
|
||||||
|
npm --version
|
||||||
|
```
|
||||||
|
|
||||||
|
## Шаг 2: Настройка PostgreSQL
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Запустите и включите PostgreSQL
|
||||||
|
sudo systemctl start postgresql
|
||||||
|
sudo systemctl enable postgresql
|
||||||
|
|
||||||
|
# Подключитесь к PostgreSQL
|
||||||
|
sudo -u postgres psql
|
||||||
|
|
||||||
|
# В консоли PostgreSQL создайте базу данных и пользователя
|
||||||
|
CREATE DATABASE tg_tinder_bot;
|
||||||
|
CREATE USER tg_bot WITH PASSWORD 'сложный_пароль';
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE tg_tinder_bot TO tg_bot;
|
||||||
|
\q
|
||||||
|
|
||||||
|
# Проверьте подключение
|
||||||
|
psql -h localhost -U tg_bot -d tg_tinder_bot
|
||||||
|
# Введите пароль, когда будет запрошено
|
||||||
|
```
|
||||||
|
|
||||||
|
## Шаг 3: Клонирование репозитория и установка зависимостей
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Создайте директорию для бота
|
||||||
|
sudo mkdir -p /opt/tg_tinder_bot
|
||||||
|
sudo chown $USER:$USER /opt/tg_tinder_bot
|
||||||
|
|
||||||
|
# Клонируйте репозиторий
|
||||||
|
git clone https://your-git-repo-url.git /opt/tg_tinder_bot
|
||||||
|
cd /opt/tg_tinder_bot
|
||||||
|
|
||||||
|
# Установите зависимости
|
||||||
|
npm ci
|
||||||
|
|
||||||
|
# Сделайте скрипты исполняемыми
|
||||||
|
chmod +x bin/update.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Шаг 4: Настройка окружения
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Создайте файл .env из примера
|
||||||
|
cp .env.example .env
|
||||||
|
|
||||||
|
# Отредактируйте файл .env
|
||||||
|
nano .env
|
||||||
|
|
||||||
|
# Укажите следующие параметры:
|
||||||
|
# BOT_TOKEN=your_telegram_bot_token
|
||||||
|
# DB_HOST=localhost
|
||||||
|
# DB_PORT=5432
|
||||||
|
# DB_USER=tg_bot
|
||||||
|
# DB_PASSWORD=сложный_пароль
|
||||||
|
# DB_NAME=tg_tinder_bot
|
||||||
|
# и другие необходимые параметры
|
||||||
|
```
|
||||||
|
|
||||||
|
## Шаг 5: Инициализация базы данных и сборка проекта
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Запустите миграции
|
||||||
|
npm run migrate:up
|
||||||
|
|
||||||
|
# Соберите проект
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
## Шаг 6: Настройка PM2 для управления процессами
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Установите PM2 глобально
|
||||||
|
sudo npm install -g pm2
|
||||||
|
|
||||||
|
# Запустите бота через PM2
|
||||||
|
pm2 start dist/bot.js --name tg_tinder_bot
|
||||||
|
|
||||||
|
# Настройте автозапуск PM2
|
||||||
|
pm2 startup
|
||||||
|
# Выполните команду, которую выдаст предыдущая команда
|
||||||
|
|
||||||
|
# Сохраните конфигурацию PM2
|
||||||
|
pm2 save
|
||||||
|
```
|
||||||
|
|
||||||
|
## Шаг 7: Настройка Nginx (если нужен веб-интерфейс)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Создайте конфигурационный файл Nginx
|
||||||
|
sudo nano /etc/nginx/sites-available/tg_tinder_bot
|
||||||
|
|
||||||
|
# Добавьте следующее содержимое
|
||||||
|
# server {
|
||||||
|
# listen 80;
|
||||||
|
# server_name ваш-домен.com;
|
||||||
|
#
|
||||||
|
# location / {
|
||||||
|
# proxy_pass http://localhost:3000; # Замените на порт вашего веб-интерфейса
|
||||||
|
# proxy_http_version 1.1;
|
||||||
|
# proxy_set_header Upgrade $http_upgrade;
|
||||||
|
# proxy_set_header Connection 'upgrade';
|
||||||
|
# proxy_set_header Host $host;
|
||||||
|
# proxy_cache_bypass $http_upgrade;
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
|
# Создайте символьную ссылку
|
||||||
|
sudo ln -s /etc/nginx/sites-available/tg_tinder_bot /etc/nginx/sites-enabled/
|
||||||
|
|
||||||
|
# Проверьте конфигурацию Nginx
|
||||||
|
sudo nginx -t
|
||||||
|
|
||||||
|
# Перезапустите Nginx
|
||||||
|
sudo systemctl restart nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
## Шаг 8: Настройка SSL с Certbot (опционально, но рекомендуется)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Установите Certbot
|
||||||
|
sudo apt install -y certbot python3-certbot-nginx
|
||||||
|
|
||||||
|
# Получите SSL-сертификат
|
||||||
|
sudo certbot --nginx -d ваш-домен.com
|
||||||
|
|
||||||
|
# Certbot автоматически обновит конфигурацию Nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
## Шаг 9: Настройка автоматического обновления
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Отредактируйте crontab
|
||||||
|
crontab -e
|
||||||
|
|
||||||
|
# Добавьте строку для ежедневного обновления в 4:00
|
||||||
|
0 4 * * * cd /opt/tg_tinder_bot && ./bin/update.sh >> /var/log/tg_bot_update.log 2>&1
|
||||||
|
```
|
||||||
|
|
||||||
|
## Управление ботом
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Перезапустить бота
|
||||||
|
pm2 restart tg_tinder_bot
|
||||||
|
|
||||||
|
# Остановить бота
|
||||||
|
pm2 stop tg_tinder_bot
|
||||||
|
|
||||||
|
# Посмотреть логи
|
||||||
|
pm2 logs tg_tinder_bot
|
||||||
|
|
||||||
|
# Посмотреть статус
|
||||||
|
pm2 status
|
||||||
|
```
|
||||||
|
|
||||||
|
## Обновление вручную
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/tg_tinder_bot
|
||||||
|
./bin/update.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Резервное копирование базы данных
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Создайте директорию для резервных копий
|
||||||
|
mkdir -p ~/backups
|
||||||
|
|
||||||
|
# Создайте резервную копию
|
||||||
|
pg_dump -U tg_bot tg_tinder_bot > ~/backups/tg_tinder_bot_$(date +%Y%m%d).sql
|
||||||
|
|
||||||
|
# Автоматическое резервное копирование (добавьте в crontab)
|
||||||
|
# 0 3 * * * pg_dump -U tg_bot tg_tinder_bot > ~/backups/tg_tinder_bot_$(date +%Y%m%d).sql && find ~/backups -name "tg_tinder_bot_*.sql" -mtime +7 -delete
|
||||||
|
```
|
||||||
|
|
||||||
|
## Решение проблем
|
||||||
|
|
||||||
|
### Проблемы с базой данных
|
||||||
|
Проверьте журналы PostgreSQL:
|
||||||
|
```bash
|
||||||
|
sudo tail -f /var/log/postgresql/postgresql-*.log
|
||||||
|
```
|
||||||
|
|
||||||
|
### Проблемы с ботом
|
||||||
|
Проверьте журналы PM2:
|
||||||
|
```bash
|
||||||
|
pm2 logs tg_tinder_bot
|
||||||
|
```
|
||||||
|
|
||||||
|
### Проблемы с Nginx
|
||||||
|
Проверьте журналы Nginx:
|
||||||
|
```bash
|
||||||
|
sudo tail -f /var/log/nginx/error.log
|
||||||
|
```
|
||||||
264
docs/PRODUCTION_DEPLOYMENT.md
Normal file
264
docs/PRODUCTION_DEPLOYMENT.md
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
# Инструкция по развертыванию Telegram Tinder Bot в Production
|
||||||
|
|
||||||
|
Это подробное руководство по развертыванию Telegram Tinder Bot в production-окружении с использованием Docker и Docker Compose.
|
||||||
|
|
||||||
|
## 📋 Требования
|
||||||
|
|
||||||
|
- **Операционная система**: Ubuntu 20.04 или выше (рекомендуется) / Windows Server с Docker
|
||||||
|
- **Программное обеспечение**:
|
||||||
|
- Docker (последняя версия)
|
||||||
|
- Docker Compose (последняя версия)
|
||||||
|
- Git
|
||||||
|
|
||||||
|
## 🚀 Быстрое развертывание
|
||||||
|
|
||||||
|
### 1. Клонирование репозитория
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/your-username/telegram-tinder-bot.git
|
||||||
|
cd telegram-tinder-bot
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Настройка конфигурации
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Создание файла конфигурации из шаблона
|
||||||
|
cp .env.production .env
|
||||||
|
|
||||||
|
# Редактирование конфигурационного файла
|
||||||
|
nano .env
|
||||||
|
```
|
||||||
|
|
||||||
|
Важно указать следующие параметры:
|
||||||
|
- `TELEGRAM_BOT_TOKEN`: токен от @BotFather
|
||||||
|
- `DB_PASSWORD`: надежный пароль для базы данных
|
||||||
|
- `JWT_SECRET`: случайная строка для JWT
|
||||||
|
- `ENCRYPTION_KEY`: случайная строка для шифрования
|
||||||
|
|
||||||
|
### 3. Запуск деплоя
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Сделайте скрипт исполняемым
|
||||||
|
chmod +x deploy.sh
|
||||||
|
|
||||||
|
# Запустите деплой
|
||||||
|
./deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Подробное руководство по установке
|
||||||
|
|
||||||
|
### Подготовка сервера Ubuntu
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Обновление системы
|
||||||
|
sudo apt update && sudo apt upgrade -y
|
||||||
|
|
||||||
|
# Установка необходимых пакетов
|
||||||
|
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common git
|
||||||
|
|
||||||
|
# Установка Docker
|
||||||
|
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||||
|
sudo sh get-docker.sh
|
||||||
|
|
||||||
|
# Добавление текущего пользователя в группу docker
|
||||||
|
sudo usermod -aG docker ${USER}
|
||||||
|
|
||||||
|
# Установка Docker Compose
|
||||||
|
sudo apt install -y docker-compose
|
||||||
|
```
|
||||||
|
|
||||||
|
### Клонирование и настройка проекта
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Создание директории для проекта
|
||||||
|
mkdir -p /opt/telegram-tinder
|
||||||
|
cd /opt/telegram-tinder
|
||||||
|
|
||||||
|
# Клонирование репозитория
|
||||||
|
git clone https://github.com/your-username/telegram-tinder-bot.git .
|
||||||
|
|
||||||
|
# Настройка .env файла
|
||||||
|
cp .env.production .env
|
||||||
|
nano .env
|
||||||
|
|
||||||
|
# Создание директорий для данных и логов
|
||||||
|
mkdir -p uploads logs
|
||||||
|
chmod 777 uploads logs
|
||||||
|
```
|
||||||
|
|
||||||
|
### Запуск проекта
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Запуск в фоновом режиме
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
# Проверка статуса контейнеров
|
||||||
|
docker-compose ps
|
||||||
|
|
||||||
|
# Просмотр логов
|
||||||
|
docker-compose logs -f
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔄 Обновление бота
|
||||||
|
|
||||||
|
Для обновления бота выполните:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /путь/к/telegram-tinder-bot
|
||||||
|
./deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Скрипт автоматически выполнит:
|
||||||
|
1. Получение последних изменений из репозитория
|
||||||
|
2. Перезапуск контейнеров с новой версией кода
|
||||||
|
3. Применение миграций базы данных
|
||||||
|
|
||||||
|
## 🛡️ Обеспечение безопасности
|
||||||
|
|
||||||
|
### Настройка файрвола
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Разрешение только необходимых портов
|
||||||
|
sudo ufw allow 22/tcp
|
||||||
|
sudo ufw allow 80/tcp
|
||||||
|
sudo ufw allow 443/tcp
|
||||||
|
sudo ufw enable
|
||||||
|
```
|
||||||
|
|
||||||
|
### Настройка HTTPS с Let's Encrypt (опционально)
|
||||||
|
|
||||||
|
Для использования HTTPS с Let's Encrypt и Nginx:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Установка Certbot
|
||||||
|
sudo apt install -y certbot python3-certbot-nginx
|
||||||
|
|
||||||
|
# Получение SSL-сертификата
|
||||||
|
sudo certbot --nginx -d your-domain.com
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📊 Мониторинг и управление
|
||||||
|
|
||||||
|
### Просмотр логов
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Логи всех контейнеров
|
||||||
|
docker-compose logs -f
|
||||||
|
|
||||||
|
# Логи конкретного контейнера (например, бота)
|
||||||
|
docker-compose logs -f bot
|
||||||
|
|
||||||
|
# Последние 100 строк логов
|
||||||
|
docker-compose logs --tail=100 bot
|
||||||
|
```
|
||||||
|
|
||||||
|
### Управление сервисами
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Остановка всех контейнеров
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
# Перезапуск всех контейнеров
|
||||||
|
docker-compose restart
|
||||||
|
|
||||||
|
# Перезапуск только бота
|
||||||
|
docker-compose restart bot
|
||||||
|
```
|
||||||
|
|
||||||
|
### Доступ к базе данных
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Вход в консоль PostgreSQL
|
||||||
|
docker-compose exec db psql -U postgres -d telegram_tinder_bot
|
||||||
|
|
||||||
|
# Резервное копирование базы данных
|
||||||
|
docker-compose exec db pg_dump -U postgres telegram_tinder_bot > backup_$(date +%Y%m%d).sql
|
||||||
|
|
||||||
|
# Восстановление базы из резервной копии
|
||||||
|
cat backup.sql | docker-compose exec -T db psql -U postgres -d telegram_tinder_bot
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔍 Устранение неполадок
|
||||||
|
|
||||||
|
### Проверка работоспособности
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Проверка API бота
|
||||||
|
curl http://localhost:3000/health
|
||||||
|
|
||||||
|
# Проверка подключения к базе данных
|
||||||
|
docker-compose exec bot node -e "const { Client } = require('pg'); const client = new Client({ host: 'db', port: 5432, database: 'telegram_tinder_bot', user: 'postgres', password: process.env.DB_PASSWORD }); client.connect().then(() => { console.log('Connected to DB!'); client.end(); }).catch(e => console.error(e));"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Общие проблемы и решения
|
||||||
|
|
||||||
|
**Проблема**: Бот не отвечает в Telegram
|
||||||
|
**Решение**:
|
||||||
|
- Проверьте валидность токена бота
|
||||||
|
- Проверьте логи на наличие ошибок: `docker-compose logs -f bot`
|
||||||
|
|
||||||
|
**Проблема**: Ошибки подключения к базе данных
|
||||||
|
**Решение**:
|
||||||
|
- Проверьте настройки подключения в `.env`
|
||||||
|
- Убедитесь, что контейнер с базой данных запущен: `docker-compose ps`
|
||||||
|
- Проверьте логи базы данных: `docker-compose logs db`
|
||||||
|
|
||||||
|
**Проблема**: Недостаточно свободного места на диске
|
||||||
|
**Решение**:
|
||||||
|
- Очистите неиспользуемые Docker образы: `docker image prune -a`
|
||||||
|
- Очистите неиспользуемые Docker тома: `docker volume prune`
|
||||||
|
|
||||||
|
## 🔁 Настройка автоматического обновления
|
||||||
|
|
||||||
|
### Настройка автообновления через Cron
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Редактирование crontab
|
||||||
|
crontab -e
|
||||||
|
|
||||||
|
# Добавление задачи (обновление каждую ночь в 3:00)
|
||||||
|
0 3 * * * cd /путь/к/telegram-tinder-bot && ./deploy.sh > /tmp/tg-tinder-update.log 2>&1
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📝 Рекомендации по обслуживанию
|
||||||
|
|
||||||
|
1. **Регулярное резервное копирование**:
|
||||||
|
```bash
|
||||||
|
# Ежедневное резервное копирование через cron
|
||||||
|
0 2 * * * docker-compose exec -T db pg_dump -U postgres telegram_tinder_bot > /path/to/backups/tg_$(date +\%Y\%m\%d).sql
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Мониторинг использования ресурсов**:
|
||||||
|
```bash
|
||||||
|
# Просмотр использования ресурсов контейнерами
|
||||||
|
docker stats
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Обновление Docker образов**:
|
||||||
|
```bash
|
||||||
|
# Обновление образов
|
||||||
|
docker-compose pull
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Проверка журналов на наличие ошибок**:
|
||||||
|
```bash
|
||||||
|
# Поиск ошибок в логах
|
||||||
|
docker-compose logs | grep -i error
|
||||||
|
docker-compose logs | grep -i exception
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📋 Контрольный список деплоя
|
||||||
|
|
||||||
|
- [ ] Установлены Docker и Docker Compose
|
||||||
|
- [ ] Клонирован репозиторий
|
||||||
|
- [ ] Настроен файл .env с реальными данными
|
||||||
|
- [ ] Запущены контейнеры через docker-compose
|
||||||
|
- [ ] Проверено подключение бота к Telegram API
|
||||||
|
- [ ] Настроено резервное копирование
|
||||||
|
- [ ] Настроен файрвол и безопасность сервера
|
||||||
|
- [ ] Проверены и настроены логи
|
||||||
|
- [ ] (Опционально) Настроен SSL для веб-интерфейса
|
||||||
|
- [ ] (Опционально) Настроено автоматическое обновление
|
||||||
44
migrations/1631980000000_add_profile_views_table.ts
Normal file
44
migrations/1631980000000_add_profile_views_table.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import { MigrationBuilder, ColumnDefinitions } from 'node-pg-migrate';
|
||||||
|
|
||||||
|
export const shorthands: ColumnDefinitions | undefined = undefined;
|
||||||
|
|
||||||
|
export async function up(pgm: MigrationBuilder): Promise<void> {
|
||||||
|
// Создание таблицы profile_views для хранения информации о просмотренных профилях
|
||||||
|
pgm.createTable('profile_views', {
|
||||||
|
id: { type: 'uuid', primaryKey: true, default: pgm.func('uuid_generate_v4()') },
|
||||||
|
viewer_id: {
|
||||||
|
type: 'uuid',
|
||||||
|
notNull: true,
|
||||||
|
references: 'users',
|
||||||
|
onDelete: 'CASCADE'
|
||||||
|
},
|
||||||
|
viewed_profile_id: {
|
||||||
|
type: 'uuid',
|
||||||
|
notNull: true,
|
||||||
|
references: 'profiles(user_id)',
|
||||||
|
onDelete: 'CASCADE'
|
||||||
|
},
|
||||||
|
view_date: { type: 'timestamp', notNull: true, default: pgm.func('now()') },
|
||||||
|
view_type: { type: 'varchar(20)', notNull: true, default: 'browse' }, // browse, match, like, etc.
|
||||||
|
});
|
||||||
|
|
||||||
|
// Создание индекса для быстрого поиска по паре (просмотревший - просмотренный)
|
||||||
|
pgm.createIndex('profile_views', ['viewer_id', 'viewed_profile_id'], {
|
||||||
|
unique: true,
|
||||||
|
name: 'profile_views_viewer_viewed_idx'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Индекс для быстрого поиска по viewer_id
|
||||||
|
pgm.createIndex('profile_views', ['viewer_id'], {
|
||||||
|
name: 'profile_views_viewer_idx'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Индекс для быстрого поиска по viewed_profile_id
|
||||||
|
pgm.createIndex('profile_views', ['viewed_profile_id'], {
|
||||||
|
name: 'profile_views_viewed_idx'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(pgm: MigrationBuilder): Promise<void> {
|
||||||
|
pgm.dropTable('profile_views', { cascade: true });
|
||||||
|
}
|
||||||
152
migrations/1758144488937_initial-schema.js
Normal file
152
migrations/1758144488937_initial-schema.js
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||||||
|
*/
|
||||||
|
export const shorthands = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const up = (pgm) => {
|
||||||
|
// Создание расширения для генерации UUID
|
||||||
|
pgm.createExtension('pgcrypto', { ifNotExists: true });
|
||||||
|
|
||||||
|
// Таблица пользователей
|
||||||
|
pgm.createTable('users', {
|
||||||
|
id: { type: 'uuid', primaryKey: true, default: pgm.func('gen_random_uuid()') },
|
||||||
|
telegram_id: { type: 'bigint', notNull: true, unique: true },
|
||||||
|
username: { type: 'varchar(255)' },
|
||||||
|
first_name: { type: 'varchar(255)' },
|
||||||
|
last_name: { type: 'varchar(255)' },
|
||||||
|
language_code: { type: 'varchar(10)', default: 'en' },
|
||||||
|
is_active: { type: 'boolean', default: true },
|
||||||
|
created_at: { type: 'timestamp', default: pgm.func('NOW()') },
|
||||||
|
last_active_at: { type: 'timestamp', default: pgm.func('NOW()') },
|
||||||
|
updated_at: { type: 'timestamp', default: pgm.func('NOW()') },
|
||||||
|
premium: { type: 'boolean', default: false },
|
||||||
|
premium_expires_at: { type: 'timestamp' }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Таблица профилей
|
||||||
|
pgm.createTable('profiles', {
|
||||||
|
id: { type: 'uuid', primaryKey: true, default: pgm.func('gen_random_uuid()') },
|
||||||
|
user_id: { type: 'uuid', references: 'users(id)', onDelete: 'CASCADE' },
|
||||||
|
name: { type: 'varchar(255)', notNull: true },
|
||||||
|
age: {
|
||||||
|
type: 'integer',
|
||||||
|
notNull: true,
|
||||||
|
check: 'age >= 18 AND age <= 100'
|
||||||
|
},
|
||||||
|
gender: {
|
||||||
|
type: 'varchar(10)',
|
||||||
|
notNull: true,
|
||||||
|
check: "gender IN ('male', 'female', 'other')"
|
||||||
|
},
|
||||||
|
interested_in: {
|
||||||
|
type: 'varchar(10)',
|
||||||
|
notNull: true,
|
||||||
|
check: "interested_in IN ('male', 'female', 'both')"
|
||||||
|
},
|
||||||
|
looking_for: {
|
||||||
|
type: 'varchar(20)',
|
||||||
|
default: 'both',
|
||||||
|
check: "looking_for IN ('male', 'female', 'both')"
|
||||||
|
},
|
||||||
|
bio: { type: 'text' },
|
||||||
|
photos: { type: 'jsonb', default: '[]' },
|
||||||
|
interests: { type: 'jsonb', default: '[]' },
|
||||||
|
city: { type: 'varchar(255)' },
|
||||||
|
education: { type: 'varchar(255)' },
|
||||||
|
job: { type: 'varchar(255)' },
|
||||||
|
height: { type: 'integer' },
|
||||||
|
religion: { type: 'varchar(255)' },
|
||||||
|
dating_goal: { type: 'varchar(255)' },
|
||||||
|
smoking: { type: 'boolean' },
|
||||||
|
drinking: { type: 'boolean' },
|
||||||
|
has_kids: { type: 'boolean' },
|
||||||
|
location_lat: { type: 'decimal(10,8)' },
|
||||||
|
location_lon: { type: 'decimal(11,8)' },
|
||||||
|
search_min_age: { type: 'integer', default: 18 },
|
||||||
|
search_max_age: { type: 'integer', default: 50 },
|
||||||
|
search_max_distance: { type: 'integer', default: 50 },
|
||||||
|
is_verified: { type: 'boolean', default: false },
|
||||||
|
is_visible: { type: 'boolean', default: true },
|
||||||
|
created_at: { type: 'timestamp', default: pgm.func('NOW()') },
|
||||||
|
updated_at: { type: 'timestamp', default: pgm.func('NOW()') }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Таблица свайпов
|
||||||
|
pgm.createTable('swipes', {
|
||||||
|
id: { type: 'uuid', primaryKey: true, default: pgm.func('gen_random_uuid()') },
|
||||||
|
user_id: { type: 'uuid', references: 'users(id)', onDelete: 'CASCADE' },
|
||||||
|
target_user_id: { type: 'uuid', references: 'users(id)', onDelete: 'CASCADE' },
|
||||||
|
type: {
|
||||||
|
type: 'varchar(20)',
|
||||||
|
notNull: true,
|
||||||
|
check: "type IN ('like', 'pass', 'superlike')"
|
||||||
|
},
|
||||||
|
created_at: { type: 'timestamp', default: pgm.func('NOW()') },
|
||||||
|
is_match: { type: 'boolean', default: false }
|
||||||
|
});
|
||||||
|
pgm.addConstraint('swipes', 'unique_swipe', {
|
||||||
|
unique: ['user_id', 'target_user_id']
|
||||||
|
});
|
||||||
|
|
||||||
|
// Таблица матчей
|
||||||
|
pgm.createTable('matches', {
|
||||||
|
id: { type: 'uuid', primaryKey: true, default: pgm.func('gen_random_uuid()') },
|
||||||
|
user_id_1: { type: 'uuid', references: 'users(id)', onDelete: 'CASCADE' },
|
||||||
|
user_id_2: { type: 'uuid', references: 'users(id)', onDelete: 'CASCADE' },
|
||||||
|
created_at: { type: 'timestamp', default: pgm.func('NOW()') },
|
||||||
|
last_message_at: { type: 'timestamp' },
|
||||||
|
is_active: { type: 'boolean', default: true },
|
||||||
|
is_super_match: { type: 'boolean', default: false },
|
||||||
|
unread_count_1: { type: 'integer', default: 0 },
|
||||||
|
unread_count_2: { type: 'integer', default: 0 }
|
||||||
|
});
|
||||||
|
pgm.addConstraint('matches', 'unique_match', {
|
||||||
|
unique: ['user_id_1', 'user_id_2']
|
||||||
|
});
|
||||||
|
|
||||||
|
// Таблица сообщений
|
||||||
|
pgm.createTable('messages', {
|
||||||
|
id: { type: 'uuid', primaryKey: true, default: pgm.func('gen_random_uuid()') },
|
||||||
|
match_id: { type: 'uuid', references: 'matches(id)', onDelete: 'CASCADE' },
|
||||||
|
sender_id: { type: 'uuid', references: 'users(id)', onDelete: 'CASCADE' },
|
||||||
|
receiver_id: { type: 'uuid', references: 'users(id)', onDelete: 'CASCADE' },
|
||||||
|
content: { type: 'text', notNull: true },
|
||||||
|
message_type: {
|
||||||
|
type: 'varchar(20)',
|
||||||
|
default: 'text',
|
||||||
|
check: "message_type IN ('text', 'photo', 'gif', 'sticker')"
|
||||||
|
},
|
||||||
|
created_at: { type: 'timestamp', default: pgm.func('NOW()') },
|
||||||
|
is_read: { type: 'boolean', default: false }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Создание индексов
|
||||||
|
pgm.createIndex('users', 'telegram_id');
|
||||||
|
pgm.createIndex('profiles', 'user_id');
|
||||||
|
pgm.createIndex('profiles', ['location_lat', 'location_lon'], {
|
||||||
|
where: 'location_lat IS NOT NULL AND location_lon IS NOT NULL'
|
||||||
|
});
|
||||||
|
pgm.createIndex('profiles', ['age', 'gender', 'interested_in']);
|
||||||
|
pgm.createIndex('swipes', ['user_id', 'target_user_id']);
|
||||||
|
pgm.createIndex('matches', ['user_id_1', 'user_id_2']);
|
||||||
|
pgm.createIndex('messages', ['match_id', 'created_at']);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const down = (pgm) => {
|
||||||
|
pgm.dropTable('messages');
|
||||||
|
pgm.dropTable('matches');
|
||||||
|
pgm.dropTable('swipes');
|
||||||
|
pgm.dropTable('profiles');
|
||||||
|
pgm.dropTable('users');
|
||||||
|
pgm.dropExtension('pgcrypto');
|
||||||
|
};
|
||||||
25
migrations/1758144618548_add-missing-profile-columns.js
Normal file
25
migrations/1758144618548_add-missing-profile-columns.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||||||
|
*/
|
||||||
|
export const shorthands = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const up = (pgm) => {
|
||||||
|
// Добавляем колонки, которые могли быть пропущены в схеме
|
||||||
|
pgm.addColumns('profiles', {
|
||||||
|
hobbies: { type: 'text' }
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const down = (pgm) => {
|
||||||
|
pgm.dropColumns('profiles', ['hobbies']);
|
||||||
|
};
|
||||||
18
migrations/1758147898012_add-missing-religion-columns.js
Normal file
18
migrations/1758147898012_add-missing-religion-columns.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||||||
|
*/
|
||||||
|
export const shorthands = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const up = (pgm) => {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const down = (pgm) => {};
|
||||||
29
migrations/1758147903378_add-missing-religion-columns.js
Normal file
29
migrations/1758147903378_add-missing-religion-columns.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||||||
|
*/
|
||||||
|
export const shorthands = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const up = (pgm) => {
|
||||||
|
// Добавляем отсутствующие колонки в таблицу profiles
|
||||||
|
pgm.addColumns('profiles', {
|
||||||
|
religion: { type: 'varchar(255)' },
|
||||||
|
dating_goal: { type: 'varchar(255)' },
|
||||||
|
smoking: { type: 'boolean' },
|
||||||
|
drinking: { type: 'boolean' },
|
||||||
|
has_kids: { type: 'boolean' }
|
||||||
|
}, { ifNotExists: true });
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const down = (pgm) => {
|
||||||
|
pgm.dropColumns('profiles', ['religion', 'dating_goal', 'smoking', 'drinking', 'has_kids'], { ifExists: true });
|
||||||
|
};
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||||||
|
*/
|
||||||
|
export const shorthands = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const up = (pgm) => {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const down = (pgm) => {};
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||||||
|
*/
|
||||||
|
export const shorthands = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const up = (pgm) => {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const down = (pgm) => {};
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||||||
|
*/
|
||||||
|
export const shorthands = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const up = (pgm) => {
|
||||||
|
// Изменяем тип столбцов с boolean на varchar для хранения строковых значений
|
||||||
|
pgm.alterColumn('profiles', 'smoking', {
|
||||||
|
type: 'varchar(50)',
|
||||||
|
using: 'smoking::text'
|
||||||
|
});
|
||||||
|
|
||||||
|
pgm.alterColumn('profiles', 'drinking', {
|
||||||
|
type: 'varchar(50)',
|
||||||
|
using: 'drinking::text'
|
||||||
|
});
|
||||||
|
|
||||||
|
// has_kids оставляем boolean, так как у него всего два состояния
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const down = (pgm) => {
|
||||||
|
// Возвращаем столбцы к типу boolean
|
||||||
|
pgm.alterColumn('profiles', 'smoking', {
|
||||||
|
type: 'boolean',
|
||||||
|
using: "CASE WHEN smoking = 'regularly' OR smoking = 'sometimes' THEN true ELSE false END"
|
||||||
|
});
|
||||||
|
|
||||||
|
pgm.alterColumn('profiles', 'drinking', {
|
||||||
|
type: 'boolean',
|
||||||
|
using: "CASE WHEN drinking = 'regularly' OR drinking = 'sometimes' THEN true ELSE false END"
|
||||||
|
});
|
||||||
|
};
|
||||||
50
migrations/1758149087361_add-column-synonyms.js
Normal file
50
migrations/1758149087361_add-column-synonyms.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* @type {import('node-pg-migrate').ColumnDefinitions | undefined}
|
||||||
|
*/
|
||||||
|
export const shorthands = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const up = (pgm) => {
|
||||||
|
// Создание представления для совместимости со старым кодом (swipes)
|
||||||
|
pgm.sql(`
|
||||||
|
CREATE OR REPLACE VIEW swipes_view AS
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
user_id AS swiper_id,
|
||||||
|
target_user_id AS swiped_id,
|
||||||
|
type AS direction,
|
||||||
|
created_at,
|
||||||
|
is_match
|
||||||
|
FROM swipes;
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Создание представления для совместимости со старым кодом (matches)
|
||||||
|
pgm.sql(`
|
||||||
|
CREATE OR REPLACE VIEW matches_view AS
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
user_id_1 AS user1_id,
|
||||||
|
user_id_2 AS user2_id,
|
||||||
|
created_at AS matched_at,
|
||||||
|
is_active AS status,
|
||||||
|
last_message_at,
|
||||||
|
is_super_match,
|
||||||
|
unread_count_1,
|
||||||
|
unread_count_2
|
||||||
|
FROM matches;
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pgm {import('node-pg-migrate').MigrationBuilder}
|
||||||
|
* @param run {() => void | undefined}
|
||||||
|
* @returns {Promise<void> | void}
|
||||||
|
*/
|
||||||
|
export const down = (pgm) => {
|
||||||
|
pgm.sql(`DROP VIEW IF EXISTS swipes_view;`);
|
||||||
|
pgm.sql(`DROP VIEW IF EXISTS matches_view;`);
|
||||||
|
};
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/* eslint-disable camelcase */
|
||||||
|
|
||||||
|
exports.shorthands = undefined;
|
||||||
|
|
||||||
|
exports.up = pgm => {
|
||||||
|
// Проверяем существование таблицы scheduled_notifications
|
||||||
|
pgm.sql(`
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF EXISTS (
|
||||||
|
SELECT 1 FROM information_schema.tables
|
||||||
|
WHERE table_name = 'scheduled_notifications'
|
||||||
|
) THEN
|
||||||
|
-- Проверяем, нет ли уже столбца processed
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM information_schema.columns
|
||||||
|
WHERE table_name = 'scheduled_notifications' AND column_name = 'processed'
|
||||||
|
) THEN
|
||||||
|
-- Добавляем столбец processed
|
||||||
|
ALTER TABLE scheduled_notifications ADD COLUMN processed BOOLEAN DEFAULT FALSE;
|
||||||
|
END IF;
|
||||||
|
ELSE
|
||||||
|
-- Создаем таблицу, если она не существует
|
||||||
|
CREATE TABLE scheduled_notifications (
|
||||||
|
id UUID PRIMARY KEY,
|
||||||
|
user_id UUID REFERENCES users(id),
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
data JSONB,
|
||||||
|
scheduled_at TIMESTAMP NOT NULL,
|
||||||
|
processed BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
`);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = pgm => {
|
||||||
|
pgm.sql(`
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF EXISTS (
|
||||||
|
SELECT 1 FROM information_schema.columns
|
||||||
|
WHERE table_name = 'scheduled_notifications' AND column_name = 'processed'
|
||||||
|
) THEN
|
||||||
|
ALTER TABLE scheduled_notifications DROP COLUMN processed;
|
||||||
|
END IF;
|
||||||
|
END
|
||||||
|
$$;
|
||||||
|
`);
|
||||||
|
};
|
||||||
14
migrations/add_user_state_columns.sql
Normal file
14
migrations/add_user_state_columns.sql
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
-- Добавление столбцов state и state_data в таблицу users для обработки состояний пользователя
|
||||||
|
|
||||||
|
-- Добавляем столбец state для хранения текущего состояния пользователя
|
||||||
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS state VARCHAR(255) NULL;
|
||||||
|
|
||||||
|
-- Добавляем столбец state_data для хранения дополнительных данных о состоянии
|
||||||
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS state_data JSONB DEFAULT '{}'::jsonb;
|
||||||
|
|
||||||
|
-- Добавляем индекс для быстрого поиска по state
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_state ON users(state);
|
||||||
|
|
||||||
|
-- Комментарий к столбцам
|
||||||
|
COMMENT ON COLUMN users.state IS 'Текущее состояние пользователя (например, ожидание ввода)';
|
||||||
|
COMMENT ON COLUMN users.state_data IS 'Дополнительные данные о состоянии пользователя в формате JSON';
|
||||||
345
package-lock.json
generated
345
package-lock.json
generated
@@ -13,8 +13,9 @@
|
|||||||
"axios": "^1.12.1",
|
"axios": "^1.12.1",
|
||||||
"dotenv": "^16.6.1",
|
"dotenv": "^16.6.1",
|
||||||
"i18next": "^25.5.2",
|
"i18next": "^25.5.2",
|
||||||
|
"node-pg-migrate": "^8.0.3",
|
||||||
"node-telegram-bot-api": "^0.64.0",
|
"node-telegram-bot-api": "^0.64.0",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.16.3",
|
||||||
"sharp": "^0.32.6",
|
"sharp": "^0.32.6",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
@@ -599,6 +600,123 @@
|
|||||||
"uuid": "dist/bin/uuid"
|
"uuid": "dist/bin/uuid"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@isaacs/balanced-match": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@isaacs/balanced-match/-/balanced-match-4.0.1.tgz",
|
||||||
|
"integrity": "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": "20 || >=22"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@isaacs/brace-expansion": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@isaacs/brace-expansion/-/brace-expansion-5.0.0.tgz",
|
||||||
|
"integrity": "sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@isaacs/balanced-match": "^4.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "20 || >=22"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@isaacs/cliui": {
|
||||||
|
"version": "8.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
|
||||||
|
"integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"string-width": "^5.1.2",
|
||||||
|
"string-width-cjs": "npm:string-width@^4.2.0",
|
||||||
|
"strip-ansi": "^7.0.1",
|
||||||
|
"strip-ansi-cjs": "npm:strip-ansi@^6.0.1",
|
||||||
|
"wrap-ansi": "^8.1.0",
|
||||||
|
"wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@isaacs/cliui/node_modules/ansi-regex": {
|
||||||
|
"version": "6.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz",
|
||||||
|
"integrity": "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@isaacs/cliui/node_modules/ansi-styles": {
|
||||||
|
"version": "6.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
|
||||||
|
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@isaacs/cliui/node_modules/emoji-regex": {
|
||||||
|
"version": "9.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz",
|
||||||
|
"integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@isaacs/cliui/node_modules/string-width": {
|
||||||
|
"version": "5.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
|
||||||
|
"integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"eastasianwidth": "^0.2.0",
|
||||||
|
"emoji-regex": "^9.2.2",
|
||||||
|
"strip-ansi": "^7.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@isaacs/cliui/node_modules/strip-ansi": {
|
||||||
|
"version": "7.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.2.tgz",
|
||||||
|
"integrity": "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-regex": "^6.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@isaacs/cliui/node_modules/wrap-ansi": {
|
||||||
|
"version": "8.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz",
|
||||||
|
"integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^6.1.0",
|
||||||
|
"string-width": "^5.0.1",
|
||||||
|
"strip-ansi": "^7.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@istanbuljs/load-nyc-config": {
|
"node_modules/@istanbuljs/load-nyc-config": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz",
|
||||||
@@ -1105,7 +1223,7 @@
|
|||||||
"version": "8.15.5",
|
"version": "8.15.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.15.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.15.5.tgz",
|
||||||
"integrity": "sha512-LF7lF6zWEKxuT3/OR8wAZGzkg4ENGXFNyiV/JeOt9z5B+0ZVwbql9McqX5c/WStFq1GaGso7H1AzP/qSzmlCKQ==",
|
"integrity": "sha512-LF7lF6zWEKxuT3/OR8wAZGzkg4ENGXFNyiV/JeOt9z5B+0ZVwbql9McqX5c/WStFq1GaGso7H1AzP/qSzmlCKQ==",
|
||||||
"dev": true,
|
"devOptional": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "*",
|
"@types/node": "*",
|
||||||
"pg-protocol": "*",
|
"pg-protocol": "*",
|
||||||
@@ -1202,7 +1320,6 @@
|
|||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
@@ -1211,7 +1328,6 @@
|
|||||||
"version": "4.3.0",
|
"version": "4.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"color-convert": "^2.0.1"
|
"color-convert": "^2.0.1"
|
||||||
},
|
},
|
||||||
@@ -1876,7 +1992,6 @@
|
|||||||
"version": "8.0.1",
|
"version": "8.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
|
||||||
"integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
|
"integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"string-width": "^4.2.0",
|
"string-width": "^4.2.0",
|
||||||
"strip-ansi": "^6.0.1",
|
"strip-ansi": "^6.0.1",
|
||||||
@@ -1998,7 +2113,6 @@
|
|||||||
"version": "7.0.6",
|
"version": "7.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
||||||
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"path-key": "^3.1.0",
|
"path-key": "^3.1.0",
|
||||||
"shebang-command": "^2.0.0",
|
"shebang-command": "^2.0.0",
|
||||||
@@ -2228,6 +2342,12 @@
|
|||||||
"node": ">= 0.4"
|
"node": ">= 0.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/eastasianwidth": {
|
||||||
|
"version": "0.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
|
||||||
|
"integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/ecc-jsbn": {
|
"node_modules/ecc-jsbn": {
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||||
@@ -2258,8 +2378,7 @@
|
|||||||
"node_modules/emoji-regex": {
|
"node_modules/emoji-regex": {
|
||||||
"version": "8.0.0",
|
"version": "8.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||||
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
|
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/end-of-stream": {
|
"node_modules/end-of-stream": {
|
||||||
"version": "1.4.5",
|
"version": "1.4.5",
|
||||||
@@ -2417,7 +2536,6 @@
|
|||||||
"version": "3.2.0",
|
"version": "3.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz",
|
||||||
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
|
"integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
@@ -2609,6 +2727,34 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/foreground-child": {
|
||||||
|
"version": "3.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz",
|
||||||
|
"integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"cross-spawn": "^7.0.6",
|
||||||
|
"signal-exit": "^4.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/foreground-child/node_modules/signal-exit": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/forever-agent": {
|
"node_modules/forever-agent": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
|
||||||
@@ -2706,7 +2852,6 @@
|
|||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
||||||
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
|
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "6.* || 8.* || >= 10.*"
|
"node": "6.* || 8.* || >= 10.*"
|
||||||
}
|
}
|
||||||
@@ -3257,7 +3402,6 @@
|
|||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
||||||
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
@@ -3486,8 +3630,7 @@
|
|||||||
"node_modules/isexe": {
|
"node_modules/isexe": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
||||||
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/isstream": {
|
"node_modules/isstream": {
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
@@ -3572,6 +3715,21 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/jackspeak": {
|
||||||
|
"version": "4.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-4.1.1.tgz",
|
||||||
|
"integrity": "sha512-zptv57P3GpL+O0I7VdMJNBZCu+BPHVQUk55Ft8/QCJjTVxrnJHuVuX/0Bl2A6/+2oyR/ZMEuFKwmzqqZ/U5nPQ==",
|
||||||
|
"license": "BlueOak-1.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@isaacs/cliui": "^8.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "20 || >=22"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/jest": {
|
"node_modules/jest": {
|
||||||
"version": "29.7.0",
|
"version": "29.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz",
|
||||||
@@ -4418,6 +4576,15 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/minipass": {
|
||||||
|
"version": "7.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz",
|
||||||
|
"integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=16 || 14 >=14.17"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/mkdirp-classic": {
|
"node_modules/mkdirp-classic": {
|
||||||
"version": "0.5.3",
|
"version": "0.5.3",
|
||||||
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
|
"resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz",
|
||||||
@@ -4478,6 +4645,69 @@
|
|||||||
"integrity": "sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==",
|
"integrity": "sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/node-pg-migrate": {
|
||||||
|
"version": "8.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-pg-migrate/-/node-pg-migrate-8.0.3.tgz",
|
||||||
|
"integrity": "sha512-oKzZyzTULTryO1jehX19VnyPCGf3G/3oWZg3gODphvID56T0WjPOShTVPVnxGdlcueaIW3uAVrr7M8xLZq5TcA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"glob": "~11.0.0",
|
||||||
|
"yargs": "~17.7.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"node-pg-migrate": "bin/node-pg-migrate.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.11.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/pg": ">=6.0.0 <9.0.0",
|
||||||
|
"pg": ">=4.3.0 <9.0.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/pg": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/node-pg-migrate/node_modules/glob": {
|
||||||
|
"version": "11.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/glob/-/glob-11.0.3.tgz",
|
||||||
|
"integrity": "sha512-2Nim7dha1KVkaiF4q6Dj+ngPPMdfvLJEOpZk/jKiUAkqKebpGAWQXAq9z1xu9HKu5lWfqw/FASuccEjyznjPaA==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"foreground-child": "^3.3.1",
|
||||||
|
"jackspeak": "^4.1.1",
|
||||||
|
"minimatch": "^10.0.3",
|
||||||
|
"minipass": "^7.1.2",
|
||||||
|
"package-json-from-dist": "^1.0.0",
|
||||||
|
"path-scurry": "^2.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"glob": "dist/esm/bin.mjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "20 || >=22"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/node-pg-migrate/node_modules/minimatch": {
|
||||||
|
"version": "10.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.0.3.tgz",
|
||||||
|
"integrity": "sha512-IPZ167aShDZZUMdRk66cyQAW3qr0WzbHkPdMYa8bzZhlHhO3jALbKdxcaak7W9FfT2rZNpQuUu4Od7ILEpXSaw==",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@isaacs/brace-expansion": "^5.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "20 || >=22"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/node-releases": {
|
"node_modules/node-releases": {
|
||||||
"version": "2.0.20",
|
"version": "2.0.20",
|
||||||
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.20.tgz",
|
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.20.tgz",
|
||||||
@@ -4669,6 +4899,12 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/package-json-from-dist": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz",
|
||||||
|
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
|
||||||
|
"license": "BlueOak-1.0.0"
|
||||||
|
},
|
||||||
"node_modules/parse-json": {
|
"node_modules/parse-json": {
|
||||||
"version": "5.2.0",
|
"version": "5.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz",
|
||||||
@@ -4709,7 +4945,6 @@
|
|||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
|
||||||
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
|
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
@@ -4720,6 +4955,31 @@
|
|||||||
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
|
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/path-scurry": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==",
|
||||||
|
"license": "BlueOak-1.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
"lru-cache": "^11.0.0",
|
||||||
|
"minipass": "^7.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "20 || >=22"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/path-scurry/node_modules/lru-cache": {
|
||||||
|
"version": "11.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.2.1.tgz",
|
||||||
|
"integrity": "sha512-r8LA6i4LP4EeWOhqBaZZjDWwehd1xUJPCJd9Sv300H0ZmcUER4+JPh7bqqZeqs1o5pgtgvXm+d9UGrB5zZGDiQ==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": "20 || >=22"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/performance-now": {
|
"node_modules/performance-now": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||||
@@ -4729,6 +4989,7 @@
|
|||||||
"version": "8.16.3",
|
"version": "8.16.3",
|
||||||
"resolved": "https://registry.npmjs.org/pg/-/pg-8.16.3.tgz",
|
"resolved": "https://registry.npmjs.org/pg/-/pg-8.16.3.tgz",
|
||||||
"integrity": "sha512-enxc1h0jA/aq5oSDMvqyW3q89ra6XIIDZgCX9vkMrnz5DFTw/Ny3Li2lFQ+pt3L6MCgm/5o2o8HW9hiJji+xvw==",
|
"integrity": "sha512-enxc1h0jA/aq5oSDMvqyW3q89ra6XIIDZgCX9vkMrnz5DFTw/Ny3Li2lFQ+pt3L6MCgm/5o2o8HW9hiJji+xvw==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pg-connection-string": "^2.9.1",
|
"pg-connection-string": "^2.9.1",
|
||||||
"pg-pool": "^3.10.1",
|
"pg-pool": "^3.10.1",
|
||||||
@@ -5296,7 +5557,6 @@
|
|||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||||
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
|
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
@@ -5528,7 +5788,6 @@
|
|||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||||
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
|
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"shebang-regex": "^3.0.0"
|
"shebang-regex": "^3.0.0"
|
||||||
},
|
},
|
||||||
@@ -5540,7 +5799,6 @@
|
|||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
||||||
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
@@ -5821,7 +6079,21 @@
|
|||||||
"version": "4.2.3",
|
"version": "4.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||||
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||||
"dev": true,
|
"dependencies": {
|
||||||
|
"emoji-regex": "^8.0.0",
|
||||||
|
"is-fullwidth-code-point": "^3.0.0",
|
||||||
|
"strip-ansi": "^6.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/string-width-cjs": {
|
||||||
|
"name": "string-width",
|
||||||
|
"version": "4.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||||
|
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"emoji-regex": "^8.0.0",
|
"emoji-regex": "^8.0.0",
|
||||||
"is-fullwidth-code-point": "^3.0.0",
|
"is-fullwidth-code-point": "^3.0.0",
|
||||||
@@ -5888,7 +6160,19 @@
|
|||||||
"version": "6.0.1",
|
"version": "6.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||||
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
||||||
"dev": true,
|
"dependencies": {
|
||||||
|
"ansi-regex": "^5.0.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/strip-ansi-cjs": {
|
||||||
|
"name": "strip-ansi",
|
||||||
|
"version": "6.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||||
|
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ansi-regex": "^5.0.1"
|
"ansi-regex": "^5.0.1"
|
||||||
},
|
},
|
||||||
@@ -6462,7 +6746,6 @@
|
|||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||||
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"isexe": "^2.0.0"
|
"isexe": "^2.0.0"
|
||||||
},
|
},
|
||||||
@@ -6569,7 +6852,24 @@
|
|||||||
"version": "7.0.0",
|
"version": "7.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
||||||
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
||||||
"dev": true,
|
"dependencies": {
|
||||||
|
"ansi-styles": "^4.0.0",
|
||||||
|
"string-width": "^4.1.0",
|
||||||
|
"strip-ansi": "^6.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/wrap-ansi-cjs": {
|
||||||
|
"name": "wrap-ansi",
|
||||||
|
"version": "7.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
|
||||||
|
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ansi-styles": "^4.0.0",
|
"ansi-styles": "^4.0.0",
|
||||||
"string-width": "^4.1.0",
|
"string-width": "^4.1.0",
|
||||||
@@ -6612,7 +6912,6 @@
|
|||||||
"version": "5.0.8",
|
"version": "5.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
||||||
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
|
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
@@ -6627,7 +6926,6 @@
|
|||||||
"version": "17.7.2",
|
"version": "17.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
||||||
"integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
|
"integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cliui": "^8.0.1",
|
"cliui": "^8.0.1",
|
||||||
"escalade": "^3.1.1",
|
"escalade": "^3.1.1",
|
||||||
@@ -6645,7 +6943,6 @@
|
|||||||
"version": "21.1.1",
|
"version": "21.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
|
||||||
"integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
|
"integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
}
|
}
|
||||||
|
|||||||
24
package.json
24
package.json
@@ -5,18 +5,36 @@
|
|||||||
"main": "dist/bot.js",
|
"main": "dist/bot.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node dist/bot.js",
|
"start": "node dist/bot.js",
|
||||||
|
"start:prod": "NODE_ENV=production node dist/bot.js",
|
||||||
|
"start:win:prod": "set NODE_ENV=production&& node dist/bot.js",
|
||||||
"dev": "ts-node src/bot.ts",
|
"dev": "ts-node src/bot.ts",
|
||||||
"build": "tsc && cp -r src/locales dist/",
|
"build": "tsc && xcopy /E /I src\\locales dist\\locales",
|
||||||
|
"build:linux": "tsc && cp -R src/locales dist/",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"db:init": "ts-node src/scripts/initDb.ts"
|
"test:bot": "ts-node tests/test-bot.ts",
|
||||||
|
"db:init": "ts-node src/scripts/initDb.ts",
|
||||||
|
"init:db": "ts-node src/scripts/initDb.ts",
|
||||||
|
"migrate": "node-pg-migrate",
|
||||||
|
"migrate:up": "node-pg-migrate up",
|
||||||
|
"migrate:down": "node-pg-migrate down",
|
||||||
|
"migrate:create": "node-pg-migrate create",
|
||||||
|
"premium:set-all": "ts-node src/scripts/setPremiumForAll.ts",
|
||||||
|
"premium:direct": "ts-node src/scripts/setPremiumDirectConnect.ts",
|
||||||
|
"db:info": "ts-node src/scripts/getDatabaseInfo.ts",
|
||||||
|
"db:test-data": "ts-node src/scripts/createTestData.ts",
|
||||||
|
"enhance-notifications": "ts-node src/scripts/enhanceNotifications.ts",
|
||||||
|
"update": "bash ./bin/update.sh",
|
||||||
|
"update:win": ".\\bin\\update.bat",
|
||||||
|
"start:sh": "bash ./bin/start_bot.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node-telegram-bot-api": "^0.64.11",
|
"@types/node-telegram-bot-api": "^0.64.11",
|
||||||
"axios": "^1.12.1",
|
"axios": "^1.12.1",
|
||||||
"dotenv": "^16.6.1",
|
"dotenv": "^16.6.1",
|
||||||
"i18next": "^25.5.2",
|
"i18next": "^25.5.2",
|
||||||
|
"node-pg-migrate": "^8.0.3",
|
||||||
"node-telegram-bot-api": "^0.64.0",
|
"node-telegram-bot-api": "^0.64.0",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.16.3",
|
||||||
"sharp": "^0.32.6",
|
"sharp": "^0.32.6",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
|
|||||||
49
scripts/README.md
Normal file
49
scripts/README.md
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# Структура скриптов в директории `/scripts`
|
||||||
|
|
||||||
|
Эта директория содержит вспомогательные скрипты для работы с Telegram Tinder Bot.
|
||||||
|
|
||||||
|
## Основные скрипты
|
||||||
|
|
||||||
|
- `startup.sh` - Скрипт запуска бота в Docker-контейнере
|
||||||
|
- `migrate-sync.js` - Синхронизация миграций базы данных
|
||||||
|
- `createNotificationTables.js` - Создание таблиц для системы уведомлений
|
||||||
|
- `add-hobbies-column.js` - Добавление колонки интересов в профиль
|
||||||
|
- `create_profile_fix.js` - Исправление профилей пользователей
|
||||||
|
- `createProfileViewsTable.js` - Создание таблицы для учета просмотров профилей
|
||||||
|
- `update_bot_with_notifications.js` - Обновление бота с поддержкой уведомлений
|
||||||
|
|
||||||
|
## Директории
|
||||||
|
|
||||||
|
- `/legacy` - Устаревшие и тестовые скрипты, сохраненные для истории
|
||||||
|
|
||||||
|
## Использование скриптов
|
||||||
|
|
||||||
|
Скрипты JavaScript можно запускать с помощью Node.js:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node scripts/script-name.js
|
||||||
|
```
|
||||||
|
|
||||||
|
Bash скрипты должны быть сделаны исполняемыми:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod +x scripts/script-name.sh
|
||||||
|
./scripts/script-name.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Добавление новых скриптов
|
||||||
|
|
||||||
|
При добавлении новых скриптов соблюдайте следующие правила:
|
||||||
|
1. Используйте понятное имя файла, отражающее его назначение
|
||||||
|
2. Добавьте комментарии в начало файла с описанием его функциональности
|
||||||
|
3. Добавьте запись об этом скрипте в текущий файл README.md
|
||||||
|
|
||||||
|
## Скрипты миграций
|
||||||
|
|
||||||
|
Миграции базы данных следует создавать с помощью команды:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run migrate:create your_migration_name
|
||||||
|
```
|
||||||
|
|
||||||
|
Это создаст файл миграции в директории `/migrations`.
|
||||||
43
scripts/add-hobbies-column.js
Normal file
43
scripts/add-hobbies-column.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// add-hobbies-column.js
|
||||||
|
// Скрипт для добавления колонки hobbies в таблицу profiles
|
||||||
|
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
// Настройки подключения к базе данных
|
||||||
|
const pool = new Pool({
|
||||||
|
host: '192.168.0.102',
|
||||||
|
port: 5432,
|
||||||
|
database: 'telegram_tinder_bot',
|
||||||
|
user: 'trevor',
|
||||||
|
password: 'Cl0ud_1985!'
|
||||||
|
});
|
||||||
|
|
||||||
|
async function addHobbiesColumn() {
|
||||||
|
try {
|
||||||
|
console.log('Подключение к базе данных...');
|
||||||
|
const client = await pool.connect();
|
||||||
|
|
||||||
|
console.log('Добавление колонки hobbies в таблицу profiles...');
|
||||||
|
|
||||||
|
// SQL запрос для добавления колонки
|
||||||
|
const sql = `
|
||||||
|
ALTER TABLE profiles
|
||||||
|
ADD COLUMN IF NOT EXISTS hobbies TEXT;
|
||||||
|
`;
|
||||||
|
|
||||||
|
await client.query(sql);
|
||||||
|
console.log('✅ Колонка hobbies успешно добавлена в таблицу profiles');
|
||||||
|
|
||||||
|
// Закрытие соединения
|
||||||
|
client.release();
|
||||||
|
await pool.end();
|
||||||
|
console.log('Подключение к базе данных закрыто');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при добавлении колонки:', error);
|
||||||
|
await pool.end();
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запуск функции
|
||||||
|
addHobbiesColumn();
|
||||||
259
scripts/createNotificationTables.js
Normal file
259
scripts/createNotificationTables.js
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
const { Pool } = require('pg');
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
const uuid = require('uuid');
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
connectionString: process.env.DATABASE_URL,
|
||||||
|
});
|
||||||
|
|
||||||
|
async function createNotificationTables() {
|
||||||
|
const client = await pool.connect();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.query('BEGIN');
|
||||||
|
|
||||||
|
console.log('Creating UUID extension if not exists...');
|
||||||
|
await client.query(`
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Проверяем существование таблицы notifications
|
||||||
|
const notificationsExists = await client.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_name = 'notifications'
|
||||||
|
) as exists
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!notificationsExists.rows[0].exists) {
|
||||||
|
console.log('Creating notifications table...');
|
||||||
|
await client.query(`
|
||||||
|
CREATE TABLE notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
data JSONB,
|
||||||
|
is_read BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('Creating index on notifications...');
|
||||||
|
await client.query(`
|
||||||
|
CREATE INDEX idx_notifications_user_id ON notifications (user_id);
|
||||||
|
CREATE INDEX idx_notifications_type ON notifications (type);
|
||||||
|
CREATE INDEX idx_notifications_created_at ON notifications (created_at);
|
||||||
|
`);
|
||||||
|
} else {
|
||||||
|
console.log('Notifications table already exists.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем существование таблицы scheduled_notifications
|
||||||
|
const scheduledExists = await client.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_name = 'scheduled_notifications'
|
||||||
|
) as exists
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!scheduledExists.rows[0].exists) {
|
||||||
|
console.log('Creating scheduled_notifications table...');
|
||||||
|
await client.query(`
|
||||||
|
CREATE TABLE scheduled_notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
data JSONB,
|
||||||
|
scheduled_at TIMESTAMP NOT NULL,
|
||||||
|
processed BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('Creating index on scheduled_notifications...');
|
||||||
|
await client.query(`
|
||||||
|
CREATE INDEX idx_scheduled_notifications_user_id ON scheduled_notifications (user_id);
|
||||||
|
CREATE INDEX idx_scheduled_notifications_scheduled_at ON scheduled_notifications (scheduled_at);
|
||||||
|
CREATE INDEX idx_scheduled_notifications_processed ON scheduled_notifications (processed);
|
||||||
|
`);
|
||||||
|
} else {
|
||||||
|
console.log('Scheduled_notifications table already exists.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем существование таблицы notification_templates
|
||||||
|
const templatesExists = await client.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_name = 'notification_templates'
|
||||||
|
) as exists
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!templatesExists.rows[0].exists) {
|
||||||
|
console.log('Creating notification_templates table...');
|
||||||
|
await client.query(`
|
||||||
|
CREATE TABLE notification_templates (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
type VARCHAR(50) NOT NULL UNIQUE,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
message_template TEXT NOT NULL,
|
||||||
|
button_template JSONB,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
} else {
|
||||||
|
console.log('Notification_templates table already exists.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем наличие колонки notification_settings в таблице users
|
||||||
|
const settingsColumnExists = await client.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.columns
|
||||||
|
WHERE table_name = 'users' AND column_name = 'notification_settings'
|
||||||
|
) as exists
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!settingsColumnExists.rows[0].exists) {
|
||||||
|
console.log('Adding notification_settings column to users table...');
|
||||||
|
await client.query(`
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN notification_settings JSONB DEFAULT '{
|
||||||
|
"newMatches": true,
|
||||||
|
"newMessages": true,
|
||||||
|
"newLikes": true,
|
||||||
|
"reminders": true,
|
||||||
|
"dailySummary": true,
|
||||||
|
"timePreference": "evening",
|
||||||
|
"doNotDisturb": false
|
||||||
|
}'::jsonb
|
||||||
|
`);
|
||||||
|
} else {
|
||||||
|
console.log('Notification_settings column already exists in users table.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Заполнение таблицы шаблонов уведомлений базовыми шаблонами
|
||||||
|
if (!templatesExists.rows[0].exists) {
|
||||||
|
console.log('Populating notification templates...');
|
||||||
|
|
||||||
|
const templates = [
|
||||||
|
{
|
||||||
|
type: 'new_like',
|
||||||
|
title: 'Новый лайк!',
|
||||||
|
message_template: '❤️ *{{name}}* поставил(а) вам лайк!\n\nВозраст: {{age}}\n{{city}}\n\nОтветьте взаимностью или посмотрите профиль.',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '❤️ Лайк в ответ', callback_data: 'like_back:{{userId}}' },
|
||||||
|
{ text: '⛔️ Пропустить', callback_data: 'dislike_profile:{{userId}}' }
|
||||||
|
],
|
||||||
|
[{ text: '💕 Открыть все лайки', callback_data: 'view_likes' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'super_like',
|
||||||
|
title: 'Супер-лайк!',
|
||||||
|
message_template: '⭐️ *{{name}}* отправил(а) вам супер-лайк!\n\nВозраст: {{age}}\n{{city}}\n\nВы произвели особое впечатление! Ответьте взаимностью или посмотрите профиль.',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '❤️ Лайк в ответ', callback_data: 'like_back:{{userId}}' },
|
||||||
|
{ text: '⛔️ Пропустить', callback_data: 'dislike_profile:{{userId}}' }
|
||||||
|
],
|
||||||
|
[{ text: '💕 Открыть все лайки', callback_data: 'view_likes' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'new_match',
|
||||||
|
title: 'Новый матч!',
|
||||||
|
message_template: '🎊 *Ура! Это взаимно!* 🎊\n\nВы и *{{name}}* понравились друг другу!\nВозраст: {{age}}\n{{city}}\n\nСделайте первый шаг - напишите сообщение!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '💬 Начать общение', callback_data: 'open_chat:{{matchId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' },
|
||||||
|
{ text: '📋 Все матчи', callback_data: 'view_matches' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'new_message',
|
||||||
|
title: 'Новое сообщение!',
|
||||||
|
message_template: '💌 *Новое сообщение!*\n\nОт: *{{name}}*\n\n"{{message}}"\n\nОтветьте на сообщение прямо сейчас!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '📩 Ответить', callback_data: 'open_chat:{{matchId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '👤 Профиль', callback_data: 'view_profile:{{userId}}' },
|
||||||
|
{ text: '📋 Все чаты', callback_data: 'view_matches' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'match_reminder',
|
||||||
|
title: 'Напоминание о матче',
|
||||||
|
message_template: '💕 У вас есть матч с *{{name}}*, но вы еще не начали общение!\n\nНе упустите шанс познакомиться поближе!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '💬 Начать общение', callback_data: 'open_chat:{{matchId}}' }],
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'inactive_matches',
|
||||||
|
title: 'Неактивные матчи',
|
||||||
|
message_template: '⏰ У вас {{count}} неактивных матчей!\n\nПродолжите общение, чтобы не упустить интересные знакомства!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '📋 Открыть матчи', callback_data: 'view_matches' }],
|
||||||
|
[{ text: '💕 Смотреть новые анкеты', callback_data: 'start_browsing' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'like_summary',
|
||||||
|
title: 'Сводка лайков',
|
||||||
|
message_template: '💖 У вас {{count}} новых лайков!\n\nПосмотрите, кто проявил к вам интерес сегодня!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '👀 Посмотреть лайки', callback_data: 'view_likes' }],
|
||||||
|
[{ text: '💕 Начать знакомиться', callback_data: 'start_browsing' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const template of templates) {
|
||||||
|
await client.query(`
|
||||||
|
INSERT INTO notification_templates (id, type, title, message_template, button_template)
|
||||||
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
|
`, [
|
||||||
|
uuid.v4(),
|
||||||
|
template.type,
|
||||||
|
template.title,
|
||||||
|
template.message_template,
|
||||||
|
JSON.stringify(template.button_template)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await client.query('COMMIT');
|
||||||
|
console.log('Successfully created notification tables');
|
||||||
|
} catch (err) {
|
||||||
|
await client.query('ROLLBACK');
|
||||||
|
console.error('Error creating notification tables:', err);
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createNotificationTables().catch(err => console.error('Failed to create notification tables:', err));
|
||||||
86
scripts/createProfileViewsTable.js
Normal file
86
scripts/createProfileViewsTable.js
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
const { Pool } = require('pg');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
async function createProfileViewsTable() {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
console.log('Creating profile_views table...');
|
||||||
|
await client.query('BEGIN');
|
||||||
|
|
||||||
|
// Включаем расширение uuid-ossp, если оно еще не включено
|
||||||
|
await client.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
|
||||||
|
|
||||||
|
// Создаем таблицу profile_views, если она не существует
|
||||||
|
await client.query(`
|
||||||
|
CREATE TABLE IF NOT EXISTS profile_views (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
viewer_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
viewed_profile_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
view_date TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
|
view_type VARCHAR(20) NOT NULL DEFAULT 'browse'
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Создаем уникальный индекс для пары (просмотревший - просмотренный)
|
||||||
|
await client.query(`
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM pg_indexes
|
||||||
|
WHERE indexname = 'profile_views_viewer_viewed_idx'
|
||||||
|
) THEN
|
||||||
|
CREATE UNIQUE INDEX profile_views_viewer_viewed_idx
|
||||||
|
ON profile_views (viewer_id, viewed_profile_id);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Создаем индекс для быстрого поиска по viewer_id
|
||||||
|
await client.query(`
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM pg_indexes
|
||||||
|
WHERE indexname = 'profile_views_viewer_idx'
|
||||||
|
) THEN
|
||||||
|
CREATE INDEX profile_views_viewer_idx
|
||||||
|
ON profile_views (viewer_id);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Создаем индекс для быстрого поиска по viewed_profile_id
|
||||||
|
await client.query(`
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (
|
||||||
|
SELECT 1 FROM pg_indexes
|
||||||
|
WHERE indexname = 'profile_views_viewed_idx'
|
||||||
|
) THEN
|
||||||
|
CREATE INDEX profile_views_viewed_idx
|
||||||
|
ON profile_views (viewed_profile_id);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
`);
|
||||||
|
|
||||||
|
await client.query('COMMIT');
|
||||||
|
console.log('Table profile_views created successfully');
|
||||||
|
} catch (e) {
|
||||||
|
await client.query('ROLLBACK');
|
||||||
|
console.error('Error creating table:', e);
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем функцию создания таблицы
|
||||||
|
createProfileViewsTable();
|
||||||
101
scripts/create_profile_fix.js
Normal file
101
scripts/create_profile_fix.js
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
// Исправленный код для создания профиля
|
||||||
|
const { Client } = require('pg');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
|
// Получаем аргументы из командной строки
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const telegramId = args[0];
|
||||||
|
const name = args[1];
|
||||||
|
const age = parseInt(args[2]);
|
||||||
|
const gender = args[3];
|
||||||
|
const city = args[4];
|
||||||
|
const bio = args[5];
|
||||||
|
const photoFileId = args[6];
|
||||||
|
|
||||||
|
// Проверяем, что все необходимые аргументы предоставлены
|
||||||
|
if (!telegramId || !name || !age || !gender || !city || !bio || !photoFileId) {
|
||||||
|
console.error('Необходимо указать все параметры: telegramId, name, age, gender, city, bio, photoFileId');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Устанавливаем соединение с базой данных
|
||||||
|
const client = new Client({
|
||||||
|
host: '192.168.0.102',
|
||||||
|
port: 5432,
|
||||||
|
user: 'trevor',
|
||||||
|
password: 'Cl0ud_1985!',
|
||||||
|
database: 'telegram_tinder_bot'
|
||||||
|
});
|
||||||
|
|
||||||
|
async function createProfile() {
|
||||||
|
try {
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
// Шаг 1: Создаем или обновляем пользователя
|
||||||
|
const userResult = await client.query(`
|
||||||
|
INSERT INTO users (telegram_id, username, first_name, last_name)
|
||||||
|
VALUES ($1, $2, $3, $4)
|
||||||
|
ON CONFLICT (telegram_id) DO UPDATE SET
|
||||||
|
username = EXCLUDED.username,
|
||||||
|
first_name = EXCLUDED.first_name,
|
||||||
|
last_name = EXCLUDED.last_name
|
||||||
|
RETURNING id
|
||||||
|
`, [parseInt(telegramId), null, name, null]);
|
||||||
|
|
||||||
|
const userId = userResult.rows[0].id;
|
||||||
|
|
||||||
|
// Шаг 2: Создаем профиль
|
||||||
|
const profileId = uuidv4();
|
||||||
|
const now = new Date();
|
||||||
|
const interestedIn = gender === 'male' ? 'female' : 'male';
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
'id', 'user_id', 'name', 'age', 'gender', 'interested_in',
|
||||||
|
'bio', 'city', 'photos', 'is_verified',
|
||||||
|
'is_visible', 'created_at', 'updated_at'
|
||||||
|
].join(', ');
|
||||||
|
|
||||||
|
const values = [
|
||||||
|
profileId, userId, name, age, gender, interestedIn,
|
||||||
|
bio, city, JSON.stringify([photoFileId]),
|
||||||
|
false, true, now, now
|
||||||
|
];
|
||||||
|
|
||||||
|
const placeholders = values.map((_, i) => `$${i + 1}`).join(', ');
|
||||||
|
|
||||||
|
await client.query(`
|
||||||
|
INSERT INTO profiles (${columns})
|
||||||
|
VALUES (${placeholders})
|
||||||
|
`, values);
|
||||||
|
|
||||||
|
console.log('Профиль успешно создан!');
|
||||||
|
|
||||||
|
// Возвращаем информацию о созданном профиле
|
||||||
|
return {
|
||||||
|
userId,
|
||||||
|
profileId,
|
||||||
|
name,
|
||||||
|
age,
|
||||||
|
gender,
|
||||||
|
interestedIn,
|
||||||
|
bio,
|
||||||
|
city,
|
||||||
|
photos: [photoFileId]
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при создании профиля:', error);
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await client.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createProfile()
|
||||||
|
.then(profile => {
|
||||||
|
console.log('Созданный профиль:', profile);
|
||||||
|
process.exit(0);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Создание профиля не удалось:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
88
scripts/legacy/checkCallbackHandlers.js
Normal file
88
scripts/legacy/checkCallbackHandlers.js
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
// Скрипт для анализа и отладки проблем с обработчиками коллбэков
|
||||||
|
require('dotenv').config();
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
function analyzeCallbackHandlers() {
|
||||||
|
const filePath = path.join(__dirname, '..', 'src', 'handlers', 'callbackHandlers.ts');
|
||||||
|
const content = fs.readFileSync(filePath, 'utf-8');
|
||||||
|
|
||||||
|
// Проверяем наличие реализаций методов
|
||||||
|
const methodsToCheck = [
|
||||||
|
'handleCreateProfile',
|
||||||
|
'handleGenderSelection',
|
||||||
|
'handleViewMyProfile',
|
||||||
|
'handleEditProfile',
|
||||||
|
'handleManagePhotos',
|
||||||
|
'handleStartBrowsing',
|
||||||
|
'handleSettings'
|
||||||
|
];
|
||||||
|
|
||||||
|
const issues = [];
|
||||||
|
let debugInfo = [];
|
||||||
|
|
||||||
|
methodsToCheck.forEach(method => {
|
||||||
|
debugInfo.push(`Проверяем метод: ${method}`);
|
||||||
|
|
||||||
|
// Проверяем наличие полной реализации метода (не только сигнатуры)
|
||||||
|
const methodSignatureRegex = new RegExp(`async\\s+${method}\\s*\\([^)]*\\)\\s*:\\s*Promise<void>\\s*{`, 'g');
|
||||||
|
const hasSignature = methodSignatureRegex.test(content);
|
||||||
|
|
||||||
|
const methodBodyRegex = new RegExp(`async\\s+${method}\\s*\\([^)]*\\)\\s*:\\s*Promise<void>\\s*{[\\s\\S]+?}`, 'g');
|
||||||
|
const methodMatch = content.match(methodBodyRegex);
|
||||||
|
|
||||||
|
debugInfo.push(` Сигнатура найдена: ${hasSignature}`);
|
||||||
|
debugInfo.push(` Реализация найдена: ${methodMatch !== null}`);
|
||||||
|
|
||||||
|
if (methodMatch) {
|
||||||
|
const methodContent = methodMatch[0];
|
||||||
|
debugInfo.push(` Длина метода: ${methodContent.length} символов`);
|
||||||
|
|
||||||
|
// Проверяем, содержит ли метод только заглушку
|
||||||
|
const isStub = methodContent.includes('// Заглушка метода') ||
|
||||||
|
(!methodContent.includes('await') && methodContent.split('\n').length <= 3);
|
||||||
|
|
||||||
|
if (isStub) {
|
||||||
|
issues.push(`❌ Метод ${method} содержит только заглушку, нет реальной реализации`);
|
||||||
|
} else {
|
||||||
|
debugInfo.push(` Метод ${method} имеет полную реализацию`);
|
||||||
|
}
|
||||||
|
} else if (hasSignature) {
|
||||||
|
issues.push(`❌ Метод ${method} имеет только сигнатуру, но нет реализации`);
|
||||||
|
} else {
|
||||||
|
issues.push(`❌ Метод ${method} не найден в файле`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Проверяем регистрацию обработчиков для NotificationHandlers
|
||||||
|
const notificationHandlersRegex = /this\.notificationHandlers\s*=\s*new\s+NotificationHandlers\(bot\);/g;
|
||||||
|
const hasNotificationHandlers = notificationHandlersRegex.test(content);
|
||||||
|
debugInfo.push(`NotificationHandlers инициализирован: ${hasNotificationHandlers}`);
|
||||||
|
|
||||||
|
// Проверяем обработку коллбэка notifications
|
||||||
|
const notificationsCallbackRegex = /if\s*\(data\s*===\s*['"]notifications['"].*?\)/g;
|
||||||
|
const hasNotificationsCallback = notificationsCallbackRegex.test(content);
|
||||||
|
debugInfo.push(`Обработчик для callback 'notifications' найден: ${hasNotificationsCallback}`);
|
||||||
|
|
||||||
|
// Выводим результаты
|
||||||
|
console.log('\n=== Анализ CallbackHandlers.ts ===\n');
|
||||||
|
if (issues.length > 0) {
|
||||||
|
console.log('НАЙДЕНЫ ПРОБЛЕМЫ:');
|
||||||
|
issues.forEach(issue => console.log(issue));
|
||||||
|
console.log('\nРЕКОМЕНДАЦИИ:');
|
||||||
|
console.log('1. Восстановите оригинальные реализации методов вместо заглушек');
|
||||||
|
console.log('2. Убедитесь, что методы содержат необходимую бизнес-логику');
|
||||||
|
console.log('3. Проверьте, что все коллбэки правильно обрабатываются');
|
||||||
|
} else {
|
||||||
|
console.log('✅ Проблем не обнаружено');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n=== Отладочная информация ===\n');
|
||||||
|
debugInfo.forEach(info => console.log(info));
|
||||||
|
|
||||||
|
// Проверяем количество методов в файле
|
||||||
|
const asyncMethodsCount = (content.match(/async\s+handle[A-Za-z]+\s*\(/g) || []).length;
|
||||||
|
console.log(`\nВсего async методов в файле: ${asyncMethodsCount}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
analyzeCallbackHandlers();
|
||||||
66
scripts/legacy/checkDatabase.js
Normal file
66
scripts/legacy/checkDatabase.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
const { Pool } = require('pg');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
async function checkDatabase() {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
console.log('\n===== ПРОВЕРКА СОСТОЯНИЯ БАЗЫ ДАННЫХ =====');
|
||||||
|
|
||||||
|
// Проверка таблицы users
|
||||||
|
const usersResult = await client.query('SELECT COUNT(*) as count FROM users');
|
||||||
|
console.log(`Пользователей в БД: ${usersResult.rows[0].count}`);
|
||||||
|
if (parseInt(usersResult.rows[0].count) > 0) {
|
||||||
|
const users = await client.query('SELECT id, telegram_id, username, first_name FROM users LIMIT 10');
|
||||||
|
console.log('Последние пользователи:');
|
||||||
|
users.rows.forEach(user => {
|
||||||
|
console.log(` - ID: ${user.id.substring(0, 8)}... | Telegram: ${user.telegram_id} | Имя: ${user.first_name || user.username}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка таблицы profiles
|
||||||
|
const profilesResult = await client.query('SELECT COUNT(*) as count FROM profiles');
|
||||||
|
console.log(`\nПрофилей в БД: ${profilesResult.rows[0].count}`);
|
||||||
|
if (parseInt(profilesResult.rows[0].count) > 0) {
|
||||||
|
const profiles = await client.query(`
|
||||||
|
SELECT p.id, p.user_id, p.name, p.age, p.gender, p.interested_in, p.is_visible
|
||||||
|
FROM profiles p
|
||||||
|
ORDER BY p.created_at DESC
|
||||||
|
LIMIT 10
|
||||||
|
`);
|
||||||
|
console.log('Последние профили:');
|
||||||
|
profiles.rows.forEach(profile => {
|
||||||
|
console.log(` - ID: ${profile.id.substring(0, 8)}... | UserID: ${profile.user_id.substring(0, 8)}... | Имя: ${profile.name} | Возраст: ${profile.age} | Пол: ${profile.gender} | Интересы: ${profile.interested_in} | Виден: ${profile.is_visible}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка таблицы swipes
|
||||||
|
const swipesResult = await client.query('SELECT COUNT(*) as count FROM swipes');
|
||||||
|
console.log(`\nСвайпов в БД: ${swipesResult.rows[0].count}`);
|
||||||
|
|
||||||
|
// Проверка таблицы profile_views
|
||||||
|
const viewsResult = await client.query('SELECT COUNT(*) as count FROM profile_views');
|
||||||
|
console.log(`Просмотров профилей в БД: ${viewsResult.rows[0].count}`);
|
||||||
|
|
||||||
|
// Проверка таблицы matches
|
||||||
|
const matchesResult = await client.query('SELECT COUNT(*) as count FROM matches');
|
||||||
|
console.log(`Матчей в БД: ${matchesResult.rows[0].count}`);
|
||||||
|
|
||||||
|
console.log('\n===== ПРОВЕРКА ЗАВЕРШЕНА =====\n');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Ошибка при проверке базы данных:', e);
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем проверку
|
||||||
|
checkDatabase();
|
||||||
64
scripts/legacy/checkProfileViews.js
Normal file
64
scripts/legacy/checkProfileViews.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
// Скрипт для проверки таблицы profile_views
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
async function checkProfileViewsTable() {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
console.log('Проверка таблицы profile_views...');
|
||||||
|
|
||||||
|
// Проверяем наличие таблицы
|
||||||
|
const tableCheck = await client.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = 'profile_views'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
const tableExists = tableCheck.rows[0].exists;
|
||||||
|
console.log(`Таблица profile_views ${tableExists ? 'существует' : 'не существует'}`);
|
||||||
|
|
||||||
|
if (tableExists) {
|
||||||
|
// Проверяем количество записей в таблице
|
||||||
|
const countResult = await client.query('SELECT COUNT(*) FROM profile_views');
|
||||||
|
console.log(`Количество записей в таблице: ${countResult.rows[0].count}`);
|
||||||
|
|
||||||
|
// Получаем данные из таблицы
|
||||||
|
const dataResult = await client.query(`
|
||||||
|
SELECT pv.*,
|
||||||
|
v.telegram_id as viewer_telegram_id,
|
||||||
|
vp.telegram_id as viewed_telegram_id
|
||||||
|
FROM profile_views pv
|
||||||
|
LEFT JOIN users v ON pv.viewer_id = v.id
|
||||||
|
LEFT JOIN users vp ON pv.viewed_profile_id = vp.id
|
||||||
|
LIMIT 10
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (dataResult.rows.length > 0) {
|
||||||
|
console.log('Данные из таблицы profile_views:');
|
||||||
|
dataResult.rows.forEach((row, index) => {
|
||||||
|
console.log(`${index + 1}. Просмотр: ${row.viewer_telegram_id || 'Неизвестно'} → ${row.viewed_telegram_id || 'Неизвестно'}, дата: ${row.view_date}`);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log('Таблица profile_views пуста');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при проверке таблицы profile_views:', error);
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем проверку
|
||||||
|
checkProfileViewsTable();
|
||||||
74
scripts/legacy/checkUserTable.js
Normal file
74
scripts/legacy/checkUserTable.js
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
const { Pool } = require('pg');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
user: process.env.DB_USER || 'postgres',
|
||||||
|
host: process.env.DB_HOST || 'localhost',
|
||||||
|
database: process.env.DB_NAME || 'telegram_tinder_db',
|
||||||
|
password: process.env.DB_PASSWORD || 'postgres',
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432')
|
||||||
|
});
|
||||||
|
|
||||||
|
async function checkUserTableStructure() {
|
||||||
|
try {
|
||||||
|
// Получаем информацию о структуре таблицы users
|
||||||
|
const result = await pool.query(`
|
||||||
|
SELECT column_name, data_type, is_nullable
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = 'users'
|
||||||
|
ORDER BY ordinal_position;
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('=== Структура таблицы users ===');
|
||||||
|
console.table(result.rows);
|
||||||
|
|
||||||
|
// Проверяем наличие столбцов state и state_data
|
||||||
|
const stateColumn = result.rows.find(row => row.column_name === 'state');
|
||||||
|
const stateDataColumn = result.rows.find(row => row.column_name === 'state_data');
|
||||||
|
|
||||||
|
if (!stateColumn) {
|
||||||
|
console.log('❌ Столбец state отсутствует в таблице users');
|
||||||
|
} else {
|
||||||
|
console.log('✅ Столбец state присутствует в таблице users');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stateDataColumn) {
|
||||||
|
console.log('❌ Столбец state_data отсутствует в таблице users');
|
||||||
|
} else {
|
||||||
|
console.log('✅ Столбец state_data присутствует в таблице users');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавляем эти столбцы, если их нет
|
||||||
|
if (!stateColumn || !stateDataColumn) {
|
||||||
|
console.log('🔄 Добавление отсутствующих столбцов...');
|
||||||
|
|
||||||
|
await pool.query(`
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS state VARCHAR(255) NULL,
|
||||||
|
ADD COLUMN IF NOT EXISTS state_data JSONB DEFAULT '{}'::jsonb;
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('✅ Столбцы успешно добавлены');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем наличие других таблиц, связанных с уведомлениями
|
||||||
|
const tablesResult = await pool.query(`
|
||||||
|
SELECT tablename
|
||||||
|
FROM pg_catalog.pg_tables
|
||||||
|
WHERE schemaname = 'public'
|
||||||
|
AND tablename IN ('notifications', 'notification_settings', 'scheduled_notifications');
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('\n=== Таблицы для уведомлений ===');
|
||||||
|
console.table(tablesResult.rows);
|
||||||
|
|
||||||
|
// Закрываем соединение
|
||||||
|
await pool.end();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при проверке структуры таблицы:', error);
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkUserTableStructure();
|
||||||
55
scripts/legacy/cleanDatabase.js
Normal file
55
scripts/legacy/cleanDatabase.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
const { Pool } = require('pg');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
async function cleanDatabase() {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
console.log('Очистка базы данных...');
|
||||||
|
await client.query('BEGIN');
|
||||||
|
|
||||||
|
// Отключаем временно foreign key constraints
|
||||||
|
await client.query('SET CONSTRAINTS ALL DEFERRED');
|
||||||
|
|
||||||
|
// Очищаем таблицы в правильном порядке
|
||||||
|
console.log('Очистка таблицы messages...');
|
||||||
|
await client.query('DELETE FROM messages');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы profile_views...');
|
||||||
|
await client.query('DELETE FROM profile_views');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы matches...');
|
||||||
|
await client.query('DELETE FROM matches');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы swipes...');
|
||||||
|
await client.query('DELETE FROM swipes');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы profiles...');
|
||||||
|
await client.query('DELETE FROM profiles');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы users...');
|
||||||
|
await client.query('DELETE FROM users');
|
||||||
|
|
||||||
|
// Возвращаем foreign key constraints
|
||||||
|
await client.query('SET CONSTRAINTS ALL IMMEDIATE');
|
||||||
|
|
||||||
|
await client.query('COMMIT');
|
||||||
|
console.log('✅ База данных успешно очищена');
|
||||||
|
} catch (e) {
|
||||||
|
await client.query('ROLLBACK');
|
||||||
|
console.error('❌ Ошибка при очистке базы данных:', e);
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем функцию очистки
|
||||||
|
cleanDatabase();
|
||||||
66
scripts/legacy/clearDatabase.js
Normal file
66
scripts/legacy/clearDatabase.js
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
// Скрипт для очистки всех таблиц в базе данных
|
||||||
|
import { Pool } from 'pg';
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
|
// Загружаем переменные окружения из .env файла
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
async function clearDatabase() {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
console.log('Начинаем очистку базы данных...');
|
||||||
|
|
||||||
|
// Начинаем транзакцию
|
||||||
|
await client.query('BEGIN');
|
||||||
|
|
||||||
|
// Отключаем внешние ключи на время выполнения (если они используются)
|
||||||
|
// await client.query('SET session_replication_role = \'replica\'');
|
||||||
|
|
||||||
|
// Очистка таблиц в порядке, учитывающем зависимости
|
||||||
|
console.log('Очистка таблицы сообщений...');
|
||||||
|
await client.query('TRUNCATE TABLE messages CASCADE');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы просмотров профилей...');
|
||||||
|
await client.query('TRUNCATE TABLE profile_views CASCADE');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы свайпов...');
|
||||||
|
await client.query('TRUNCATE TABLE swipes CASCADE');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы матчей...');
|
||||||
|
await client.query('TRUNCATE TABLE matches CASCADE');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы профилей...');
|
||||||
|
await client.query('TRUNCATE TABLE profiles CASCADE');
|
||||||
|
|
||||||
|
console.log('Очистка таблицы пользователей...');
|
||||||
|
await client.query('TRUNCATE TABLE users CASCADE');
|
||||||
|
|
||||||
|
// Возвращаем внешние ключи (если они использовались)
|
||||||
|
// await client.query('SET session_replication_role = \'origin\'');
|
||||||
|
|
||||||
|
// Фиксируем транзакцию
|
||||||
|
await client.query('COMMIT');
|
||||||
|
|
||||||
|
console.log('Все таблицы успешно очищены!');
|
||||||
|
} catch (error) {
|
||||||
|
// В случае ошибки откатываем транзакцию
|
||||||
|
await client.query('ROLLBACK');
|
||||||
|
console.error('Произошла ошибка при очистке базы данных:', error);
|
||||||
|
} finally {
|
||||||
|
// Освобождаем клиента
|
||||||
|
client.release();
|
||||||
|
// Закрываем пул соединений
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем функцию очистки
|
||||||
|
clearDatabase();
|
||||||
81
scripts/legacy/clearDatabase.mjs
Normal file
81
scripts/legacy/clearDatabase.mjs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
// Скрипт для очистки всех таблиц в базе данных
|
||||||
|
import { Pool } from 'pg';
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
|
// Загружаем переменные окружения из .env файла
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
async function clearDatabase() {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
console.log('Начинаем очистку базы данных...');
|
||||||
|
|
||||||
|
// Начинаем транзакцию
|
||||||
|
await client.query('BEGIN');
|
||||||
|
|
||||||
|
// Получаем список существующих таблиц
|
||||||
|
const tablesResult = await client.query(`
|
||||||
|
SELECT table_name
|
||||||
|
FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_type = 'BASE TABLE'
|
||||||
|
`);
|
||||||
|
|
||||||
|
const tables = tablesResult.rows.map(row => row.table_name);
|
||||||
|
console.log('Найдены таблицы:', tables.join(', '));
|
||||||
|
|
||||||
|
// Очистка таблиц в порядке, учитывающем зависимости
|
||||||
|
if (tables.includes('messages')) {
|
||||||
|
console.log('Очистка таблицы messages...');
|
||||||
|
await client.query('TRUNCATE TABLE messages CASCADE');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tables.includes('swipes')) {
|
||||||
|
console.log('Очистка таблицы swipes...');
|
||||||
|
await client.query('TRUNCATE TABLE swipes CASCADE');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tables.includes('matches')) {
|
||||||
|
console.log('Очистка таблицы matches...');
|
||||||
|
await client.query('TRUNCATE TABLE matches CASCADE');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tables.includes('profiles')) {
|
||||||
|
console.log('Очистка таблицы profiles...');
|
||||||
|
await client.query('TRUNCATE TABLE profiles CASCADE');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tables.includes('users')) {
|
||||||
|
console.log('Очистка таблицы users...');
|
||||||
|
await client.query('TRUNCATE TABLE users CASCADE');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Возвращаем внешние ключи (если они использовались)
|
||||||
|
// await client.query('SET session_replication_role = \'origin\'');
|
||||||
|
|
||||||
|
// Фиксируем транзакцию
|
||||||
|
await client.query('COMMIT');
|
||||||
|
|
||||||
|
console.log('Все таблицы успешно очищены!');
|
||||||
|
} catch (error) {
|
||||||
|
// В случае ошибки откатываем транзакцию
|
||||||
|
await client.query('ROLLBACK');
|
||||||
|
console.error('Произошла ошибка при очистке базы данных:', error);
|
||||||
|
} finally {
|
||||||
|
// Освобождаем клиента
|
||||||
|
client.release();
|
||||||
|
// Закрываем пул соединений
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем функцию очистки
|
||||||
|
clearDatabase();
|
||||||
26
scripts/legacy/clear_database.sql
Normal file
26
scripts/legacy/clear_database.sql
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- Скрипт для очистки всех таблиц в базе данных
|
||||||
|
-- Важно: таблицы очищаются в порядке, учитывающем зависимости между ними
|
||||||
|
|
||||||
|
-- Отключаем внешние ключи на время выполнения (если они используются)
|
||||||
|
-- SET session_replication_role = 'replica';
|
||||||
|
|
||||||
|
-- Очистка таблицы сообщений
|
||||||
|
TRUNCATE TABLE messages CASCADE;
|
||||||
|
|
||||||
|
-- Очистка таблицы просмотров профилей
|
||||||
|
TRUNCATE TABLE profile_views CASCADE;
|
||||||
|
|
||||||
|
-- Очистка таблицы свайпов
|
||||||
|
TRUNCATE TABLE swipes CASCADE;
|
||||||
|
|
||||||
|
-- Очистка таблицы матчей
|
||||||
|
TRUNCATE TABLE matches CASCADE;
|
||||||
|
|
||||||
|
-- Очистка таблицы профилей
|
||||||
|
TRUNCATE TABLE profiles CASCADE;
|
||||||
|
|
||||||
|
-- Очистка таблицы пользователей
|
||||||
|
TRUNCATE TABLE users CASCADE;
|
||||||
|
|
||||||
|
-- Возвращаем внешние ключи (если они использовались)
|
||||||
|
-- SET session_replication_role = 'origin';
|
||||||
70
scripts/legacy/createProfileViewsTable.ts
Normal file
70
scripts/legacy/createProfileViewsTable.ts
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
// Скрипт для создания таблицы profile_views
|
||||||
|
|
||||||
|
// Функция для ручного запуска создания таблицы profile_views
|
||||||
|
async function createProfileViewsTable() {
|
||||||
|
const client = await require('../database/connection').pool.connect();
|
||||||
|
try {
|
||||||
|
console.log('Создание таблицы profile_views...');
|
||||||
|
|
||||||
|
// Проверяем, существует ли уже таблица profile_views
|
||||||
|
const tableCheck = await client.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = 'profile_views'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (tableCheck.rows[0].exists) {
|
||||||
|
console.log('Таблица profile_views уже существует, пропускаем создание');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Начинаем транзакцию
|
||||||
|
await client.query('BEGIN');
|
||||||
|
|
||||||
|
// Создаем таблицу profile_views
|
||||||
|
await client.query(`
|
||||||
|
CREATE TABLE profile_views (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
viewer_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
viewed_profile_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
view_date TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
|
view_type VARCHAR(20) NOT NULL DEFAULT 'browse'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Создаем индекс для быстрого поиска по паре (просмотревший - просмотренный)
|
||||||
|
await client.query(`
|
||||||
|
CREATE UNIQUE INDEX profile_views_viewer_viewed_idx ON profile_views (viewer_id, viewed_profile_id);
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Индекс для быстрого поиска по viewer_id
|
||||||
|
await client.query(`
|
||||||
|
CREATE INDEX profile_views_viewer_idx ON profile_views (viewer_id);
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Индекс для быстрого поиска по viewed_profile_id
|
||||||
|
await client.query(`
|
||||||
|
CREATE INDEX profile_views_viewed_idx ON profile_views (viewed_profile_id);
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Фиксируем транзакцию
|
||||||
|
await client.query('COMMIT');
|
||||||
|
|
||||||
|
console.log('Таблица profile_views успешно создана!');
|
||||||
|
} catch (error) {
|
||||||
|
// В случае ошибки откатываем транзакцию
|
||||||
|
await client.query('ROLLBACK');
|
||||||
|
console.error('Произошла ошибка при создании таблицы profile_views:', error);
|
||||||
|
} finally {
|
||||||
|
// Освобождаем клиента
|
||||||
|
client.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем функцию создания таблицы
|
||||||
|
createProfileViewsTable()
|
||||||
|
.then(() => console.log('Скрипт выполнен'))
|
||||||
|
.catch(err => console.error('Ошибка выполнения скрипта:', err))
|
||||||
|
.finally(() => process.exit());
|
||||||
142
scripts/legacy/fixCallbackHandlers.js
Normal file
142
scripts/legacy/fixCallbackHandlers.js
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
// Скрипт для восстановления оригинальной функциональности callbackHandlers.ts
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// Находим самую последнюю версию файла callbackHandlers.ts в репозитории
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('Поиск оригинальной версии CallbackHandlers.ts с полной функциональностью...');
|
||||||
|
|
||||||
|
// Находим коммиты, содержащие значительные изменения в файле (более 1000 символов)
|
||||||
|
const commits = execSync('git log --format="%H" -- src/handlers/callbackHandlers.ts')
|
||||||
|
.toString()
|
||||||
|
.trim()
|
||||||
|
.split('\n');
|
||||||
|
|
||||||
|
console.log(`Найдено ${commits.length} коммитов с изменениями файла`);
|
||||||
|
|
||||||
|
// Пробуем разные коммиты, начиная с последнего, чтобы найти полную реализацию
|
||||||
|
let foundFullImplementation = false;
|
||||||
|
let fullImplementationContent = '';
|
||||||
|
|
||||||
|
for (const commit of commits) {
|
||||||
|
console.log(`Проверяем коммит ${commit.substring(0, 8)}...`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const fileContent = execSync(`git show ${commit}:src/handlers/callbackHandlers.ts`).toString();
|
||||||
|
|
||||||
|
// Проверяем, содержит ли файл полные реализации методов
|
||||||
|
const hasFullImplementations = !fileContent.includes('// Заглушка метода') &&
|
||||||
|
fileContent.includes('await this.bot.sendMessage');
|
||||||
|
|
||||||
|
if (hasFullImplementations) {
|
||||||
|
console.log(`✅ Найдена полная реализация в коммите ${commit.substring(0, 8)}`);
|
||||||
|
fullImplementationContent = fileContent;
|
||||||
|
foundFullImplementation = true;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
console.log(`❌ Коммит ${commit.substring(0, 8)} не содержит полной реализации`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Ошибка при проверке коммита ${commit}:`, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundFullImplementation) {
|
||||||
|
console.error('❌ Не удалось найти полную реализацию в истории коммитов');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Теперь получаем текущую версию файла с поддержкой уведомлений
|
||||||
|
console.log('Получаем текущую версию с поддержкой уведомлений...');
|
||||||
|
const currentFilePath = path.join(__dirname, '..', 'src', 'handlers', 'callbackHandlers.ts');
|
||||||
|
const currentContent = fs.readFileSync(currentFilePath, 'utf-8');
|
||||||
|
|
||||||
|
// Сначала создаем бэкап текущего файла
|
||||||
|
const backupPath = currentFilePath + '.backup-' + Date.now();
|
||||||
|
fs.writeFileSync(backupPath, currentContent);
|
||||||
|
console.log(`✅ Создан бэкап текущей версии: ${path.basename(backupPath)}`);
|
||||||
|
|
||||||
|
// Извлекаем код для поддержки уведомлений из текущей версии
|
||||||
|
console.log('Извлекаем код для поддержки уведомлений...');
|
||||||
|
|
||||||
|
// Находим импорт NotificationHandlers
|
||||||
|
const notificationImportRegex = /import\s+{\s*NotificationHandlers\s*}\s*from\s*['"]\.\/notificationHandlers['"]\s*;/;
|
||||||
|
const notificationImport = currentContent.match(notificationImportRegex)?.[0] || '';
|
||||||
|
|
||||||
|
// Находим объявление поля notificationHandlers
|
||||||
|
const notificationFieldRegex = /private\s+notificationHandlers\?\s*:\s*NotificationHandlers\s*;/;
|
||||||
|
const notificationField = currentContent.match(notificationFieldRegex)?.[0] || '';
|
||||||
|
|
||||||
|
// Находим инициализацию notificationHandlers в конструкторе
|
||||||
|
const notificationInitRegex = /\/\/\s*Создаем экземпляр NotificationHandlers[\s\S]*?try\s*{[\s\S]*?this\.notificationHandlers\s*=\s*new\s*NotificationHandlers[\s\S]*?}\s*catch[\s\S]*?}/;
|
||||||
|
const notificationInit = currentContent.match(notificationInitRegex)?.[0] || '';
|
||||||
|
|
||||||
|
// Находим метод handleNotificationSettings
|
||||||
|
const notificationSettingsMethodRegex = /async\s+handleNotificationSettings[\s\S]*?}\s*}/;
|
||||||
|
const notificationSettingsMethod = currentContent.match(notificationSettingsMethodRegex)?.[0] || '';
|
||||||
|
|
||||||
|
// Находим обработку callback для notifications в handleCallback
|
||||||
|
const notificationCallbackRegex = /\/\/\s*Настройки уведомлений[\s\S]*?else\s+if\s*\(data\s*===\s*['"]notifications['"][\s\S]*?}\s*}/;
|
||||||
|
const notificationCallback = currentContent.match(notificationCallbackRegex)?.[0] || '';
|
||||||
|
|
||||||
|
// Получаем часть обработки коллбэков для уведомлений
|
||||||
|
const notificationToggleRegex = /\/\/\s*Обработка переключения настроек уведомлений[\s\S]*?else\s+if[\s\S]*?notif_[\s\S]*?}\s*}/;
|
||||||
|
const notificationToggle = currentContent.match(notificationToggleRegex)?.[0] || '';
|
||||||
|
|
||||||
|
console.log(`✅ Извлечены блоки кода для уведомлений`);
|
||||||
|
|
||||||
|
// Интегрируем код уведомлений в оригинальную версию
|
||||||
|
console.log('Интегрируем код уведомлений в оригинальную версию...');
|
||||||
|
|
||||||
|
// 1. Добавляем импорт
|
||||||
|
let newContent = fullImplementationContent;
|
||||||
|
if (notificationImport) {
|
||||||
|
newContent = newContent.replace(/import\s*{[^}]*}\s*from\s*['"]\.\/messageHandlers['"]\s*;/,
|
||||||
|
match => match + '\n' + notificationImport);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Добавляем объявление поля
|
||||||
|
if (notificationField) {
|
||||||
|
newContent = newContent.replace(/private\s+translationController\s*:\s*TranslationController\s*;/,
|
||||||
|
match => match + '\n ' + notificationField);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Добавляем инициализацию в конструкторе
|
||||||
|
if (notificationInit) {
|
||||||
|
newContent = newContent.replace(/this\.translationController\s*=\s*new\s*TranslationController\(\);/,
|
||||||
|
match => match + '\n ' + notificationInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Добавляем обработку коллбэков для уведомлений
|
||||||
|
if (notificationCallback) {
|
||||||
|
newContent = newContent.replace(/else\s+{\s*await\s+this\.bot\.answerCallbackQuery\(query\.id[\s\S]*?return;/,
|
||||||
|
match => notificationCallback + '\n ' + match);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Добавляем обработку переключения настроек уведомлений
|
||||||
|
if (notificationToggle) {
|
||||||
|
newContent = newContent.replace(/else\s+{\s*await\s+this\.bot\.answerCallbackQuery\(query\.id[\s\S]*?return;/,
|
||||||
|
match => notificationToggle + '\n ' + match);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Добавляем метод handleNotificationSettings в конец класса
|
||||||
|
if (notificationSettingsMethod) {
|
||||||
|
newContent = newContent.replace(/}(\s*)$/, notificationSettingsMethod + '\n}$1');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Сохраняем обновленный файл
|
||||||
|
const outputPath = currentFilePath + '.fixed';
|
||||||
|
fs.writeFileSync(outputPath, newContent);
|
||||||
|
console.log(`✅ Создана исправленная версия файла: ${path.basename(outputPath)}`);
|
||||||
|
|
||||||
|
console.log('\nИнструкция по восстановлению:');
|
||||||
|
console.log(`1. Проверьте файл ${path.basename(outputPath)}`);
|
||||||
|
console.log('2. Если все выглядит правильно, выполните команду:');
|
||||||
|
console.log(` Move-Item -Force "${path.basename(outputPath)}" "${path.basename(currentFilePath)}"`);
|
||||||
|
console.log('3. Перезапустите бота');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Произошла ошибка:', error);
|
||||||
|
}
|
||||||
170
scripts/legacy/fixDatabaseStructure.js
Normal file
170
scripts/legacy/fixDatabaseStructure.js
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
// Скрипт для исправления проблемы с ботом
|
||||||
|
require('dotenv').config();
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
// Получаем данные подключения из .env
|
||||||
|
console.log('Параметры подключения к БД:');
|
||||||
|
console.log('DB_USERNAME:', process.env.DB_USERNAME);
|
||||||
|
console.log('DB_HOST:', process.env.DB_HOST);
|
||||||
|
console.log('DB_NAME:', process.env.DB_NAME);
|
||||||
|
console.log('DB_PASSWORD:', process.env.DB_PASSWORD ? '[указан]' : '[не указан]');
|
||||||
|
console.log('DB_PORT:', process.env.DB_PORT);
|
||||||
|
|
||||||
|
// Создаем пул соединений
|
||||||
|
const pool = new Pool({
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432')
|
||||||
|
});
|
||||||
|
|
||||||
|
async function fixDatabase() {
|
||||||
|
try {
|
||||||
|
console.log('Начинаем исправление базы данных...');
|
||||||
|
|
||||||
|
// Проверяем существование таблицы users
|
||||||
|
const tableResult = await pool.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = 'users'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!tableResult.rows[0].exists) {
|
||||||
|
console.error('Таблица users не найдена!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ Таблица users существует');
|
||||||
|
|
||||||
|
// Проверяем и добавляем столбцы state и state_data, если они отсутствуют
|
||||||
|
console.log('Проверяем наличие столбцов state и state_data...');
|
||||||
|
|
||||||
|
const stateColumnResult = await pool.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.columns
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = 'users'
|
||||||
|
AND column_name = 'state'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
const stateDataColumnResult = await pool.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.columns
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = 'users'
|
||||||
|
AND column_name = 'state_data'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!stateColumnResult.rows[0].exists) {
|
||||||
|
console.log('🔄 Добавляем столбец state...');
|
||||||
|
await pool.query(`ALTER TABLE users ADD COLUMN state VARCHAR(255) NULL;`);
|
||||||
|
console.log('✅ Столбец state успешно добавлен');
|
||||||
|
} else {
|
||||||
|
console.log('✅ Столбец state уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stateDataColumnResult.rows[0].exists) {
|
||||||
|
console.log('🔄 Добавляем столбец state_data...');
|
||||||
|
await pool.query(`ALTER TABLE users ADD COLUMN state_data JSONB DEFAULT '{}'::jsonb;`);
|
||||||
|
console.log('✅ Столбец state_data успешно добавлен');
|
||||||
|
} else {
|
||||||
|
console.log('✅ Столбец state_data уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка наличия таблиц для уведомлений
|
||||||
|
console.log('Проверяем наличие таблиц для уведомлений...');
|
||||||
|
|
||||||
|
const tablesCheck = await Promise.all([
|
||||||
|
checkTableExists('notifications'),
|
||||||
|
checkTableExists('notification_settings'),
|
||||||
|
checkTableExists('scheduled_notifications')
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Создаем отсутствующие таблицы
|
||||||
|
if (!tablesCheck[0]) {
|
||||||
|
console.log('🔄 Создаем таблицу notifications...');
|
||||||
|
await pool.query(`
|
||||||
|
CREATE TABLE notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
content JSONB NOT NULL DEFAULT '{}',
|
||||||
|
is_read BOOLEAN DEFAULT false,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
CREATE INDEX idx_notifications_user_id ON notifications(user_id);
|
||||||
|
CREATE INDEX idx_notifications_type ON notifications(type);
|
||||||
|
CREATE INDEX idx_notifications_created_at ON notifications(created_at);
|
||||||
|
`);
|
||||||
|
console.log('✅ Таблица notifications успешно создана');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tablesCheck[1]) {
|
||||||
|
console.log('🔄 Создаем таблицу notification_settings...');
|
||||||
|
await pool.query(`
|
||||||
|
CREATE TABLE notification_settings (
|
||||||
|
user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
new_matches BOOLEAN DEFAULT true,
|
||||||
|
new_messages BOOLEAN DEFAULT true,
|
||||||
|
new_likes BOOLEAN DEFAULT true,
|
||||||
|
reminders BOOLEAN DEFAULT true,
|
||||||
|
daily_summary BOOLEAN DEFAULT false,
|
||||||
|
time_preference VARCHAR(20) DEFAULT 'evening',
|
||||||
|
do_not_disturb BOOLEAN DEFAULT false,
|
||||||
|
do_not_disturb_start TIME,
|
||||||
|
do_not_disturb_end TIME,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
console.log('✅ Таблица notification_settings успешно создана');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tablesCheck[2]) {
|
||||||
|
console.log('🔄 Создаем таблицу scheduled_notifications...');
|
||||||
|
await pool.query(`
|
||||||
|
CREATE TABLE scheduled_notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
content JSONB NOT NULL DEFAULT '{}',
|
||||||
|
scheduled_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
|
processed BOOLEAN DEFAULT false,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
CREATE INDEX idx_scheduled_notifications_user_id ON scheduled_notifications(user_id);
|
||||||
|
CREATE INDEX idx_scheduled_notifications_scheduled_at ON scheduled_notifications(scheduled_at);
|
||||||
|
CREATE INDEX idx_scheduled_notifications_processed ON scheduled_notifications(processed);
|
||||||
|
`);
|
||||||
|
console.log('✅ Таблица scheduled_notifications успешно создана');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ Исправление базы данных завершено успешно');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при исправлении базы данных:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkTableExists(tableName) {
|
||||||
|
const result = await pool.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = $1
|
||||||
|
);
|
||||||
|
`, [tableName]);
|
||||||
|
|
||||||
|
const exists = result.rows[0].exists;
|
||||||
|
console.log(`${exists ? '✅' : '❌'} Таблица ${tableName} ${exists ? 'существует' : 'отсутствует'}`);
|
||||||
|
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
fixDatabase();
|
||||||
48
scripts/legacy/fix_all_notifications.js
Normal file
48
scripts/legacy/fix_all_notifications.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* Комплексный скрипт для исправления всех проблем с уведомлениями
|
||||||
|
* Запускает последовательно оба скрипта исправления
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { exec } = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
console.log('🔧 Запуск комплексного исправления проблем с уведомлениями...');
|
||||||
|
|
||||||
|
// Путь к скриптам
|
||||||
|
const fixNotificationCallbacksScript = path.join(__dirname, 'fix_notification_callbacks.js');
|
||||||
|
const updateBotWithNotificationsScript = path.join(__dirname, 'update_bot_with_notifications.js');
|
||||||
|
|
||||||
|
// Запуск первого скрипта для исправления таблиц и колонок
|
||||||
|
console.log('\n📊 Шаг 1/2: Проверка и исправление таблиц базы данных...');
|
||||||
|
exec(`node ${fixNotificationCallbacksScript}`, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(`❌ Ошибка при запуске скрипта исправления таблиц: ${error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(stdout);
|
||||||
|
|
||||||
|
if (stderr) {
|
||||||
|
console.error(`❌ Ошибки при выполнении скрипта: ${stderr}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запуск второго скрипта для обновления bot.ts
|
||||||
|
console.log('\n📝 Шаг 2/2: Обновление файла bot.ts для регистрации обработчиков уведомлений...');
|
||||||
|
exec(`node ${updateBotWithNotificationsScript}`, (error2, stdout2, stderr2) => {
|
||||||
|
if (error2) {
|
||||||
|
console.error(`❌ Ошибка при запуске скрипта обновления bot.ts: ${error2}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(stdout2);
|
||||||
|
|
||||||
|
if (stderr2) {
|
||||||
|
console.error(`❌ Ошибки при выполнении скрипта: ${stderr2}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n✅ Все исправления успешно выполнены!');
|
||||||
|
console.log('🔄 Пожалуйста, перезапустите бота для применения изменений:');
|
||||||
|
console.log(' npm run start');
|
||||||
|
console.log('\n💡 Уведомления должны теперь работать корректно!');
|
||||||
|
});
|
||||||
|
});
|
||||||
332
scripts/legacy/fix_notification_callbacks.js
Normal file
332
scripts/legacy/fix_notification_callbacks.js
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
/**
|
||||||
|
* Скрипт для проверки и исправления проблем с обработчиками уведомлений в боте
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { Client } = require('pg');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
// Конфигурация базы данных
|
||||||
|
const dbConfig = {
|
||||||
|
host: 'localhost',
|
||||||
|
port: 5432,
|
||||||
|
database: 'telegram_tinder',
|
||||||
|
user: 'postgres',
|
||||||
|
password: 'postgres'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Подключение к базе данных
|
||||||
|
const client = new Client(dbConfig);
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
console.log('Подключение к базе данных...');
|
||||||
|
await client.connect();
|
||||||
|
console.log('Успешно подключено к базе данных');
|
||||||
|
|
||||||
|
// Шаг 1: Проверка существования необходимых таблиц для уведомлений
|
||||||
|
console.log('\n=== Проверка таблиц для уведомлений ===');
|
||||||
|
|
||||||
|
// Проверяем таблицу notifications
|
||||||
|
let notificationsTableExists = await checkTableExists('notifications');
|
||||||
|
if (!notificationsTableExists) {
|
||||||
|
console.log('Таблица notifications не найдена. Создаем...');
|
||||||
|
await createNotificationsTable();
|
||||||
|
console.log('Таблица notifications успешно создана');
|
||||||
|
} else {
|
||||||
|
console.log('Таблица notifications уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем таблицу scheduled_notifications
|
||||||
|
let scheduledNotificationsTableExists = await checkTableExists('scheduled_notifications');
|
||||||
|
if (!scheduledNotificationsTableExists) {
|
||||||
|
console.log('Таблица scheduled_notifications не найдена. Создаем...');
|
||||||
|
await createScheduledNotificationsTable();
|
||||||
|
console.log('Таблица scheduled_notifications успешно создана');
|
||||||
|
} else {
|
||||||
|
console.log('Таблица scheduled_notifications уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем таблицу notification_templates
|
||||||
|
let notificationTemplatesTableExists = await checkTableExists('notification_templates');
|
||||||
|
if (!notificationTemplatesTableExists) {
|
||||||
|
console.log('Таблица notification_templates не найдена. Создаем...');
|
||||||
|
await createNotificationTemplatesTable();
|
||||||
|
console.log('Таблица notification_templates успешно создана');
|
||||||
|
console.log('Заполняем таблицу базовыми шаблонами...');
|
||||||
|
await populateDefaultTemplates();
|
||||||
|
console.log('Шаблоны успешно добавлены');
|
||||||
|
} else {
|
||||||
|
console.log('Таблица notification_templates уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Шаг 2: Проверка существования столбца notification_settings в таблице users
|
||||||
|
console.log('\n=== Проверка столбца notification_settings в таблице users ===');
|
||||||
|
|
||||||
|
const notificationSettingsColumnExists = await checkColumnExists('users', 'notification_settings');
|
||||||
|
if (!notificationSettingsColumnExists) {
|
||||||
|
console.log('Столбец notification_settings не найден. Добавляем...');
|
||||||
|
await addNotificationSettingsColumn();
|
||||||
|
console.log('Столбец notification_settings успешно добавлен');
|
||||||
|
} else {
|
||||||
|
console.log('Столбец notification_settings уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Шаг 3: Проверка существования столбцов state и state_data в таблице users
|
||||||
|
console.log('\n=== Проверка столбцов state и state_data в таблице users ===');
|
||||||
|
|
||||||
|
const stateColumnExists = await checkColumnExists('users', 'state');
|
||||||
|
if (!stateColumnExists) {
|
||||||
|
console.log('Столбец state не найден. Добавляем...');
|
||||||
|
await addStateColumn();
|
||||||
|
console.log('Столбец state успешно добавлен');
|
||||||
|
} else {
|
||||||
|
console.log('Столбец state уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
const stateDataColumnExists = await checkColumnExists('users', 'state_data');
|
||||||
|
if (!stateDataColumnExists) {
|
||||||
|
console.log('Столбец state_data не найден. Добавляем...');
|
||||||
|
await addStateDataColumn();
|
||||||
|
console.log('Столбец state_data успешно добавлен');
|
||||||
|
} else {
|
||||||
|
console.log('Столбец state_data уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\nВсе таблицы и столбцы успешно проверены и созданы при необходимости.');
|
||||||
|
console.log('Механизм уведомлений должен работать корректно.');
|
||||||
|
|
||||||
|
console.log('\n=== Проверка регистрации обработчиков уведомлений ===');
|
||||||
|
console.log('Подсказка: убедитесь, что в файле bot.ts создается экземпляр NotificationHandlers и регистрируются его обработчики:');
|
||||||
|
console.log(`
|
||||||
|
// Настройка обработчиков уведомлений
|
||||||
|
const notificationHandlers = new NotificationHandlers(bot);
|
||||||
|
notificationHandlers.register();
|
||||||
|
|
||||||
|
// Запуск обработчика запланированных уведомлений
|
||||||
|
setInterval(() => {
|
||||||
|
const notificationService = new NotificationService(bot);
|
||||||
|
notificationService.processScheduledNotifications();
|
||||||
|
}, 60000); // Проверяем каждую минуту
|
||||||
|
`);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка выполнения скрипта:', error);
|
||||||
|
} finally {
|
||||||
|
await client.end();
|
||||||
|
console.log('\nСоединение с базой данных закрыто.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkTableExists(tableName) {
|
||||||
|
const query = `
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_name = $1
|
||||||
|
) as exists
|
||||||
|
`;
|
||||||
|
|
||||||
|
const result = await client.query(query, [tableName]);
|
||||||
|
return result.rows[0].exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkColumnExists(tableName, columnName) {
|
||||||
|
const query = `
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.columns
|
||||||
|
WHERE table_name = $1 AND column_name = $2
|
||||||
|
) as exists
|
||||||
|
`;
|
||||||
|
|
||||||
|
const result = await client.query(query, [tableName, columnName]);
|
||||||
|
return result.rows[0].exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createNotificationsTable() {
|
||||||
|
await client.query(`
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
|
CREATE TABLE notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
data JSONB,
|
||||||
|
is_read BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createScheduledNotificationsTable() {
|
||||||
|
await client.query(`
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
|
CREATE TABLE scheduled_notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
data JSONB,
|
||||||
|
scheduled_at TIMESTAMP NOT NULL,
|
||||||
|
processed BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createNotificationTemplatesTable() {
|
||||||
|
await client.query(`
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
|
CREATE TABLE notification_templates (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
type VARCHAR(50) NOT NULL UNIQUE,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
message_template TEXT NOT NULL,
|
||||||
|
button_template JSONB,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addNotificationSettingsColumn() {
|
||||||
|
await client.query(`
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN notification_settings JSONB DEFAULT '{
|
||||||
|
"newMatches": true,
|
||||||
|
"newMessages": true,
|
||||||
|
"newLikes": true,
|
||||||
|
"reminders": true,
|
||||||
|
"dailySummary": true,
|
||||||
|
"timePreference": "evening",
|
||||||
|
"doNotDisturb": false
|
||||||
|
}'::jsonb
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addStateColumn() {
|
||||||
|
await client.query(`
|
||||||
|
ALTER TABLE users ADD COLUMN state VARCHAR(255) NULL
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addStateDataColumn() {
|
||||||
|
await client.query(`
|
||||||
|
ALTER TABLE users ADD COLUMN state_data JSONB DEFAULT '{}'::jsonb
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function populateDefaultTemplates() {
|
||||||
|
const templates = [
|
||||||
|
{
|
||||||
|
type: 'new_like',
|
||||||
|
title: 'Новый лайк!',
|
||||||
|
message_template: '❤️ *{{name}}* поставил(а) вам лайк!\n\nВозраст: {{age}}\n{{city}}\n\nОтветьте взаимностью или посмотрите профиль.',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '❤️ Лайк в ответ', callback_data: 'like_back:{{userId}}' },
|
||||||
|
{ text: '⛔️ Пропустить', callback_data: 'dislike_profile:{{userId}}' }
|
||||||
|
],
|
||||||
|
[{ text: '💕 Открыть все лайки', callback_data: 'view_likes' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'super_like',
|
||||||
|
title: 'Супер-лайк!',
|
||||||
|
message_template: '⭐️ *{{name}}* отправил(а) вам супер-лайк!\n\nВозраст: {{age}}\n{{city}}\n\nВы произвели особое впечатление! Ответьте взаимностью или посмотрите профиль.',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '❤️ Лайк в ответ', callback_data: 'like_back:{{userId}}' },
|
||||||
|
{ text: '⛔️ Пропустить', callback_data: 'dislike_profile:{{userId}}' }
|
||||||
|
],
|
||||||
|
[{ text: '💕 Открыть все лайки', callback_data: 'view_likes' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'new_match',
|
||||||
|
title: 'Новый матч!',
|
||||||
|
message_template: '🎊 *Ура! Это взаимно!* 🎊\n\nВы и *{{name}}* понравились друг другу!\nВозраст: {{age}}\n{{city}}\n\nСделайте первый шаг - напишите сообщение!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '💬 Начать общение', callback_data: 'open_chat:{{matchId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' },
|
||||||
|
{ text: '📋 Все матчи', callback_data: 'view_matches' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'new_message',
|
||||||
|
title: 'Новое сообщение!',
|
||||||
|
message_template: '💌 *Новое сообщение!*\n\nОт: *{{name}}*\n\n"{{message}}"\n\nОтветьте на сообщение прямо сейчас!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '📩 Ответить', callback_data: 'open_chat:{{matchId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '👤 Профиль', callback_data: 'view_profile:{{userId}}' },
|
||||||
|
{ text: '📋 Все чаты', callback_data: 'view_matches' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'match_reminder',
|
||||||
|
title: 'Напоминание о матче',
|
||||||
|
message_template: '💕 У вас есть матч с *{{name}}*, но вы еще не начали общение!\n\nНе упустите шанс познакомиться поближе!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '💬 Начать общение', callback_data: 'open_chat:{{matchId}}' }],
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'inactive_matches',
|
||||||
|
title: 'Неактивные матчи',
|
||||||
|
message_template: '⏰ У вас {{count}} неактивных матчей!\n\nПродолжите общение, чтобы не упустить интересные знакомства!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '📋 Открыть матчи', callback_data: 'view_matches' }],
|
||||||
|
[{ text: '💕 Смотреть новые анкеты', callback_data: 'start_browsing' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'like_summary',
|
||||||
|
title: 'Сводка лайков',
|
||||||
|
message_template: '💖 У вас {{count}} новых лайков!\n\nПосмотрите, кто проявил к вам интерес сегодня!',
|
||||||
|
button_template: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '👀 Посмотреть лайки', callback_data: 'view_likes' }],
|
||||||
|
[{ text: '💕 Начать знакомиться', callback_data: 'start_browsing' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const template of templates) {
|
||||||
|
await client.query(`
|
||||||
|
INSERT INTO notification_templates (type, title, message_template, button_template)
|
||||||
|
VALUES ($1, $2, $3, $4)
|
||||||
|
ON CONFLICT (type) DO UPDATE
|
||||||
|
SET title = EXCLUDED.title,
|
||||||
|
message_template = EXCLUDED.message_template,
|
||||||
|
button_template = EXCLUDED.button_template,
|
||||||
|
updated_at = NOW()
|
||||||
|
`, [
|
||||||
|
template.type,
|
||||||
|
template.title,
|
||||||
|
template.message_template,
|
||||||
|
JSON.stringify(template.button_template)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запуск скрипта
|
||||||
|
main();
|
||||||
85
scripts/legacy/testCallbacks.js
Normal file
85
scripts/legacy/testCallbacks.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
// Скрипт для проверки работы callback-хэндлеров и уведомлений
|
||||||
|
require('dotenv').config();
|
||||||
|
const TelegramBot = require('node-telegram-bot-api');
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
// Создаем пул соединений
|
||||||
|
const pool = new Pool({
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432')
|
||||||
|
});
|
||||||
|
|
||||||
|
// Функция для имитации callback-запроса к боту
|
||||||
|
async function testCallback() {
|
||||||
|
try {
|
||||||
|
console.log('Начинаем тестирование callback-хэндлеров и уведомлений...');
|
||||||
|
|
||||||
|
// Используем последнего пользователя из базы данных
|
||||||
|
const userResult = await pool.query(`
|
||||||
|
SELECT * FROM users ORDER BY last_active_at DESC NULLS LAST LIMIT 1
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (userResult.rows.length === 0) {
|
||||||
|
console.error('❌ Пользователи не найдены в базе данных');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = userResult.rows[0];
|
||||||
|
console.log(`Выбран тестовый пользователь: ${user.first_name || 'Без имени'} (ID: ${user.telegram_id})`);
|
||||||
|
|
||||||
|
// Получаем токен бота из переменных окружения
|
||||||
|
const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||||
|
if (!token) {
|
||||||
|
console.error('❌ Токен бота не найден в переменных окружения');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создаем экземпляр бота
|
||||||
|
const bot = new TelegramBot(token);
|
||||||
|
|
||||||
|
// Отправляем тестовое уведомление пользователю
|
||||||
|
console.log(`Отправляем тестовое уведомление пользователю ID: ${user.telegram_id}...`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await bot.sendMessage(
|
||||||
|
user.telegram_id,
|
||||||
|
`🔔 *Тестовое уведомление*\n\nЭто проверка работы уведомлений и callback-хэндлеров.\n\nВаш премиум-статус: ${user.premium ? '✅ Активен' : '❌ Не активен'}`,
|
||||||
|
{
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[
|
||||||
|
{ text: '🔔 Уведомления', callback_data: 'notification_settings' },
|
||||||
|
{ text: '❤️ Профиль', callback_data: 'view_profile' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '⚙️ Настройки', callback_data: 'settings' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('✅ Тестовое сообщение успешно отправлено!');
|
||||||
|
console.log('Информация о сообщении:', JSON.stringify(result, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при отправке тестового сообщения:', error.message);
|
||||||
|
if (error.response && error.response.body) {
|
||||||
|
console.error('Детали ошибки:', JSON.stringify(error.response.body, null, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при тестировании:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
console.log('Соединение с базой данных закрыто');
|
||||||
|
console.log('Тестирование завершено!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем тестирование
|
||||||
|
testCallback();
|
||||||
102
scripts/legacy/testMatching.js
Normal file
102
scripts/legacy/testMatching.js
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
require('dotenv').config();
|
||||||
|
const { MatchingService } = require('../dist/services/matchingService');
|
||||||
|
const { ProfileService } = require('../dist/services/profileService');
|
||||||
|
|
||||||
|
// Функция для создания тестовых пользователей
|
||||||
|
async function createTestUsers() {
|
||||||
|
const profileService = new ProfileService();
|
||||||
|
|
||||||
|
console.log('Создание тестовых пользователей...');
|
||||||
|
|
||||||
|
// Создаем мужской профиль
|
||||||
|
const maleUserId = await profileService.ensureUser('123456', {
|
||||||
|
username: 'test_male',
|
||||||
|
first_name: 'Иван',
|
||||||
|
last_name: 'Тестов'
|
||||||
|
});
|
||||||
|
|
||||||
|
await profileService.createProfile(maleUserId, {
|
||||||
|
name: 'Иван',
|
||||||
|
age: 30,
|
||||||
|
gender: 'male',
|
||||||
|
interestedIn: 'female',
|
||||||
|
bio: 'Тестовый мужской профиль',
|
||||||
|
photos: ['photo1.jpg'],
|
||||||
|
city: 'Москва',
|
||||||
|
searchPreferences: {
|
||||||
|
minAge: 18,
|
||||||
|
maxAge: 45,
|
||||||
|
maxDistance: 50
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(`Создан мужской профиль: userId=${maleUserId}, telegramId=123456`);
|
||||||
|
|
||||||
|
// Создаем женский профиль
|
||||||
|
const femaleUserId = await profileService.ensureUser('654321', {
|
||||||
|
username: 'test_female',
|
||||||
|
first_name: 'Анна',
|
||||||
|
last_name: 'Тестова'
|
||||||
|
});
|
||||||
|
|
||||||
|
await profileService.createProfile(femaleUserId, {
|
||||||
|
name: 'Анна',
|
||||||
|
age: 28,
|
||||||
|
gender: 'female',
|
||||||
|
interestedIn: 'male',
|
||||||
|
bio: 'Тестовый женский профиль',
|
||||||
|
photos: ['photo2.jpg'],
|
||||||
|
city: 'Москва',
|
||||||
|
searchPreferences: {
|
||||||
|
minAge: 25,
|
||||||
|
maxAge: 40,
|
||||||
|
maxDistance: 30
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log(`Создан женский профиль: userId=${femaleUserId}, telegramId=654321`);
|
||||||
|
|
||||||
|
console.log('Тестовые пользователи созданы успешно');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Функция для тестирования подбора анкет
|
||||||
|
async function testMatching() {
|
||||||
|
console.log('\n===== ТЕСТИРОВАНИЕ ПОДБОРА АНКЕТ =====');
|
||||||
|
|
||||||
|
const matchingService = new MatchingService();
|
||||||
|
|
||||||
|
console.log('\nТест 1: Получение анкеты для мужского профиля (должна вернуться женская анкета)');
|
||||||
|
const femaleProfile = await matchingService.getNextCandidate('123456', true);
|
||||||
|
if (femaleProfile) {
|
||||||
|
console.log(`✓ Получена анкета: ${femaleProfile.name}, возраст: ${femaleProfile.age}, пол: ${femaleProfile.gender}`);
|
||||||
|
} else {
|
||||||
|
console.log('✗ Анкета не найдена');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\nТест 2: Получение анкеты для женского профиля (должна вернуться мужская анкета)');
|
||||||
|
const maleProfile = await matchingService.getNextCandidate('654321', true);
|
||||||
|
if (maleProfile) {
|
||||||
|
console.log(`✓ Получена анкета: ${maleProfile.name}, возраст: ${maleProfile.age}, пол: ${maleProfile.gender}`);
|
||||||
|
} else {
|
||||||
|
console.log('✗ Анкета не найдена');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n===== ТЕСТИРОВАНИЕ ЗАВЕРШЕНО =====\n');
|
||||||
|
|
||||||
|
// Завершение работы скрипта
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Главная функция
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
// Создаем тестовых пользователей
|
||||||
|
await createTestUsers();
|
||||||
|
|
||||||
|
// Тестируем подбор анкет
|
||||||
|
await testMatching();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при выполнении тестов:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
98
scripts/legacy/testProfileViews.js
Normal file
98
scripts/legacy/testProfileViews.js
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
// Тестирование работы с таблицей profile_views
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
// Функция для тестирования записи просмотра профиля
|
||||||
|
async function testRecordProfileView(viewerId, viewedProfileId) {
|
||||||
|
const client = await pool.connect();
|
||||||
|
try {
|
||||||
|
console.log(`Запись просмотра профиля: ${viewerId} просмотрел ${viewedProfileId}`);
|
||||||
|
|
||||||
|
// Получаем UUID пользователей
|
||||||
|
const viewerResult = await client.query('SELECT id FROM users WHERE telegram_id = $1', [viewerId]);
|
||||||
|
if (viewerResult.rows.length === 0) {
|
||||||
|
console.log(`Пользователь с telegram_id ${viewerId} не найден, создаём нового пользователя`);
|
||||||
|
const newUserResult = await client.query(`
|
||||||
|
INSERT INTO users (telegram_id, username, first_name, last_name)
|
||||||
|
VALUES ($1, $2, $3, $4) RETURNING id
|
||||||
|
`, [viewerId, `user_${viewerId}`, `Имя ${viewerId}`, `Фамилия ${viewerId}`]);
|
||||||
|
|
||||||
|
var viewerUuid = newUserResult.rows[0].id;
|
||||||
|
} else {
|
||||||
|
var viewerUuid = viewerResult.rows[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
const viewedResult = await client.query('SELECT id FROM users WHERE telegram_id = $1', [viewedProfileId]);
|
||||||
|
if (viewedResult.rows.length === 0) {
|
||||||
|
console.log(`Пользователь с telegram_id ${viewedProfileId} не найден, создаём нового пользователя`);
|
||||||
|
const newUserResult = await client.query(`
|
||||||
|
INSERT INTO users (telegram_id, username, first_name, last_name)
|
||||||
|
VALUES ($1, $2, $3, $4) RETURNING id
|
||||||
|
`, [viewedProfileId, `user_${viewedProfileId}`, `Имя ${viewedProfileId}`, `Фамилия ${viewedProfileId}`]);
|
||||||
|
|
||||||
|
var viewedUuid = newUserResult.rows[0].id;
|
||||||
|
} else {
|
||||||
|
var viewedUuid = viewedResult.rows[0].id;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`UUID просматривающего: ${viewerUuid}`);
|
||||||
|
console.log(`UUID просматриваемого: ${viewedUuid}`);
|
||||||
|
|
||||||
|
// Записываем просмотр
|
||||||
|
await client.query(`
|
||||||
|
INSERT INTO profile_views (viewer_id, viewed_profile_id, view_type, view_date)
|
||||||
|
VALUES ($1, $2, $3, NOW())
|
||||||
|
ON CONFLICT (viewer_id, viewed_profile_id) DO UPDATE
|
||||||
|
SET view_date = NOW(), view_type = $3
|
||||||
|
`, [viewerUuid, viewedUuid, 'browse']);
|
||||||
|
|
||||||
|
console.log('Просмотр профиля успешно записан');
|
||||||
|
|
||||||
|
// Получаем список просмотренных профилей
|
||||||
|
const viewedProfiles = await client.query(`
|
||||||
|
SELECT v.viewed_profile_id, v.view_date, u.telegram_id
|
||||||
|
FROM profile_views v
|
||||||
|
JOIN users u ON u.id = v.viewed_profile_id
|
||||||
|
WHERE v.viewer_id = $1
|
||||||
|
ORDER BY v.view_date DESC
|
||||||
|
`, [viewerUuid]);
|
||||||
|
|
||||||
|
console.log('Список просмотренных профилей:');
|
||||||
|
viewedProfiles.rows.forEach((row, index) => {
|
||||||
|
console.log(`${index + 1}. ID: ${row.telegram_id}, просмотрен: ${row.view_date}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка записи просмотра профиля:', error);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
client.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем тест
|
||||||
|
async function runTest() {
|
||||||
|
try {
|
||||||
|
// Тестируем запись просмотра профиля
|
||||||
|
await testRecordProfileView(123456, 789012);
|
||||||
|
await testRecordProfileView(123456, 345678);
|
||||||
|
await testRecordProfileView(789012, 123456);
|
||||||
|
|
||||||
|
console.log('Тесты завершены успешно');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при выполнении тестов:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runTest();
|
||||||
81
scripts/legacy/testVipMethod.js
Normal file
81
scripts/legacy/testVipMethod.js
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
// Скрипт для тестирования метода checkPremiumStatus
|
||||||
|
require('dotenv').config();
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
// Создаем пул соединений
|
||||||
|
const pool = new Pool({
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432')
|
||||||
|
});
|
||||||
|
|
||||||
|
async function testCheckPremiumMethod() {
|
||||||
|
try {
|
||||||
|
console.log('Тестирование метода checkPremiumStatus...');
|
||||||
|
|
||||||
|
// Получаем пользователя для тестирования
|
||||||
|
const userResult = await pool.query(`
|
||||||
|
SELECT id, telegram_id, first_name, username, premium
|
||||||
|
FROM users
|
||||||
|
ORDER BY last_active_at DESC NULLS LAST
|
||||||
|
LIMIT 1
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (userResult.rows.length === 0) {
|
||||||
|
console.error('❌ Пользователи не найдены в базе данных');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = userResult.rows[0];
|
||||||
|
console.log(`Выбран тестовый пользователь: ${user.first_name || user.username || 'Без имени'} (Telegram ID: ${user.telegram_id})`);
|
||||||
|
console.log(`Текущий премиум-статус: ${user.premium ? '✅ Активен' : '❌ Не активен'}`);
|
||||||
|
|
||||||
|
// Проверка работы метода checkPremiumStatus
|
||||||
|
console.log('\nЭмулируем вызов метода checkPremiumStatus из vipService:');
|
||||||
|
const result = await pool.query(`
|
||||||
|
SELECT id, premium
|
||||||
|
FROM users
|
||||||
|
WHERE telegram_id = $1
|
||||||
|
`, [user.telegram_id]);
|
||||||
|
|
||||||
|
if (result.rows.length === 0) {
|
||||||
|
console.log('❌ Пользователь не найден');
|
||||||
|
} else {
|
||||||
|
const isPremium = result.rows[0].premium || false;
|
||||||
|
console.log(`Результат метода: isPremium = ${isPremium ? '✅ true' : '❌ false'}`);
|
||||||
|
|
||||||
|
if (!isPremium) {
|
||||||
|
console.log('\nПремиум-статус отсутствует. Устанавливаем премиум...');
|
||||||
|
await pool.query(`
|
||||||
|
UPDATE users
|
||||||
|
SET premium = true
|
||||||
|
WHERE telegram_id = $1
|
||||||
|
`, [user.telegram_id]);
|
||||||
|
|
||||||
|
// Проверяем обновление
|
||||||
|
const updatedResult = await pool.query(`
|
||||||
|
SELECT premium
|
||||||
|
FROM users
|
||||||
|
WHERE telegram_id = $1
|
||||||
|
`, [user.telegram_id]);
|
||||||
|
|
||||||
|
const updatedPremium = updatedResult.rows[0].premium;
|
||||||
|
console.log(`Обновленный статус: isPremium = ${updatedPremium ? '✅ true' : '❌ false'}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('\n✅ Тестирование завершено');
|
||||||
|
console.log('🔧 Теперь проверьте функциональность VIP поиска в боте');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при тестировании:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
console.log('Соединение с базой данных закрыто');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем тест
|
||||||
|
testCheckPremiumMethod();
|
||||||
75
scripts/legacy/testVipStatus.js
Normal file
75
scripts/legacy/testVipStatus.js
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
// Скрипт для тестирования VIP функционала
|
||||||
|
require('dotenv').config();
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
// Создаем пул соединений
|
||||||
|
const pool = new Pool({
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432')
|
||||||
|
});
|
||||||
|
|
||||||
|
async function testVipStatus() {
|
||||||
|
try {
|
||||||
|
console.log('Тестирование функционала VIP статуса...');
|
||||||
|
|
||||||
|
// Получаем список пользователей с информацией о premium статусе
|
||||||
|
const users = await pool.query(`
|
||||||
|
SELECT id, telegram_id, username, first_name, premium
|
||||||
|
FROM users
|
||||||
|
ORDER BY last_active_at DESC
|
||||||
|
LIMIT 5
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('Список пользователей и их премиум статус:');
|
||||||
|
users.rows.forEach(user => {
|
||||||
|
console.log(`ID: ${user.id.substr(0, 8)}... | Telegram ID: ${user.telegram_id} | Имя: ${user.first_name || user.username || 'Не указано'} | Premium: ${user.premium ? '✅' : '❌'}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Если premium у всех false, устанавливаем premium = true
|
||||||
|
const nonPremiumUsers = users.rows.filter(user => !user.premium);
|
||||||
|
if (nonPremiumUsers.length > 0) {
|
||||||
|
console.log('\nОбнаружены пользователи без премиум статуса. Устанавливаем премиум...');
|
||||||
|
|
||||||
|
for (const user of nonPremiumUsers) {
|
||||||
|
await pool.query(`
|
||||||
|
UPDATE users
|
||||||
|
SET premium = true
|
||||||
|
WHERE id = $1
|
||||||
|
RETURNING id, telegram_id, premium
|
||||||
|
`, [user.id]);
|
||||||
|
|
||||||
|
console.log(`✅ Установлен премиум для пользователя ${user.first_name || user.username || user.telegram_id}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('\nВсе пользователи уже имеют премиум-статус!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем результат
|
||||||
|
const updatedUsers = await pool.query(`
|
||||||
|
SELECT id, telegram_id, username, first_name, premium
|
||||||
|
FROM users
|
||||||
|
ORDER BY last_active_at DESC
|
||||||
|
LIMIT 5
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('\nОбновленный список пользователей и их премиум статус:');
|
||||||
|
updatedUsers.rows.forEach(user => {
|
||||||
|
console.log(`ID: ${user.id.substr(0, 8)}... | Telegram ID: ${user.telegram_id} | Имя: ${user.first_name || user.username || 'Не указано'} | Premium: ${user.premium ? '✅' : '❌'}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('\n✅ Тестирование VIP функционала завершено');
|
||||||
|
console.log('🔧 Проверьте доступность VIP поиска в боте через меню или команды');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при тестировании VIP статуса:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
console.log('Соединение с базой данных закрыто');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запускаем тест
|
||||||
|
testVipStatus();
|
||||||
62
scripts/migrate-sync.js
Normal file
62
scripts/migrate-sync.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
// migrate-sync.js
|
||||||
|
// Этот скрипт создает записи о миграциях в таблице pgmigrations без применения изменений
|
||||||
|
// Используется для синхронизации существующей базы с миграциями
|
||||||
|
|
||||||
|
const { Client } = require('pg');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// Подключение к базе данных
|
||||||
|
const client = new Client({
|
||||||
|
host: '192.168.0.102',
|
||||||
|
port: 5432,
|
||||||
|
database: 'telegram_tinder_bot',
|
||||||
|
user: 'trevor',
|
||||||
|
password: 'Cl0ud_1985!'
|
||||||
|
});
|
||||||
|
|
||||||
|
async function syncMigrations() {
|
||||||
|
try {
|
||||||
|
console.log('Подключение к базе данных...');
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
// Создаем таблицу миграций, если её нет
|
||||||
|
await client.query(`
|
||||||
|
CREATE TABLE IF NOT EXISTS pgmigrations (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
run_on TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Получаем список файлов миграций
|
||||||
|
const migrationsDir = path.join(__dirname, '../migrations');
|
||||||
|
const files = fs.readdirSync(migrationsDir)
|
||||||
|
.filter(file => file.endsWith('.js'))
|
||||||
|
.sort();
|
||||||
|
|
||||||
|
// Проверяем, какие миграции уже записаны
|
||||||
|
const { rows: existingMigrations } = await client.query('SELECT name FROM pgmigrations');
|
||||||
|
const existingNames = existingMigrations.map(m => m.name);
|
||||||
|
|
||||||
|
// Записываем новые миграции
|
||||||
|
for (const file of files) {
|
||||||
|
const migrationName = file.replace('.js', '');
|
||||||
|
if (!existingNames.includes(migrationName)) {
|
||||||
|
console.log(`Добавление записи о миграции: ${migrationName}`);
|
||||||
|
await client.query('INSERT INTO pgmigrations(name) VALUES($1)', [migrationName]);
|
||||||
|
} else {
|
||||||
|
console.log(`Миграция ${migrationName} уже записана`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ Синхронизация миграций завершена успешно');
|
||||||
|
await client.end();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при синхронизации миграций:', error);
|
||||||
|
await client.end();
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
syncMigrations();
|
||||||
34
scripts/startup.sh
Normal file
34
scripts/startup.sh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# startup.sh - Script to run migrations and start the bot
|
||||||
|
|
||||||
|
echo "🚀 Starting Telegram Tinder Bot..."
|
||||||
|
|
||||||
|
# Check for locales directory
|
||||||
|
if [ ! -d "dist/locales" ]; then
|
||||||
|
echo "⚠️ Locales directory not found in dist/locales"
|
||||||
|
echo "🔍 Checking source directory structure..."
|
||||||
|
ls -la dist/ || echo "Error listing dist directory"
|
||||||
|
|
||||||
|
# If src/locales exists, copy it to dist/locales
|
||||||
|
if [ -d "src/locales" ]; then
|
||||||
|
echo "📂 Found src/locales directory. Copying to dist/locales..."
|
||||||
|
mkdir -p dist/locales
|
||||||
|
cp -R src/locales/* dist/locales/
|
||||||
|
echo "✅ Locales copied successfully"
|
||||||
|
else
|
||||||
|
echo "❌ src/locales directory not found either. Creating empty locales directory..."
|
||||||
|
mkdir -p dist/locales
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Wait for database to be ready
|
||||||
|
echo "⏳ Waiting for database to be ready..."
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# Run database migrations
|
||||||
|
echo "🔄 Running database migrations..."
|
||||||
|
node dist/database/migrateOnStartup.js
|
||||||
|
|
||||||
|
# Start the bot
|
||||||
|
echo "✅ Starting the bot..."
|
||||||
|
node dist/bot.js
|
||||||
104
scripts/update_bot_with_notifications.js
Normal file
104
scripts/update_bot_with_notifications.js
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/**
|
||||||
|
* Скрипт для проверки и исправления регистрации NotificationHandlers в bot.ts
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const botFilePath = path.join(__dirname, '../src/bot.ts');
|
||||||
|
|
||||||
|
// Проверка существования файла bot.ts
|
||||||
|
if (!fs.existsSync(botFilePath)) {
|
||||||
|
console.error(`❌ Файл ${botFilePath} не найден`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Чтение содержимого файла bot.ts
|
||||||
|
let botContent = fs.readFileSync(botFilePath, 'utf8');
|
||||||
|
|
||||||
|
// Проверка импорта NotificationHandlers
|
||||||
|
if (!botContent.includes('import { NotificationHandlers }')) {
|
||||||
|
console.log('Добавляем импорт NotificationHandlers в bot.ts...');
|
||||||
|
|
||||||
|
// Находим последний импорт
|
||||||
|
const importRegex = /^import.*?;/gms;
|
||||||
|
const matches = [...botContent.matchAll(importRegex)];
|
||||||
|
|
||||||
|
if (matches.length > 0) {
|
||||||
|
const lastImport = matches[matches.length - 1][0];
|
||||||
|
const lastImportIndex = botContent.lastIndexOf(lastImport) + lastImport.length;
|
||||||
|
|
||||||
|
// Добавляем импорт NotificationHandlers
|
||||||
|
botContent =
|
||||||
|
botContent.slice(0, lastImportIndex) +
|
||||||
|
'\nimport { NotificationHandlers } from \'./handlers/notificationHandlers\';\n' +
|
||||||
|
botContent.slice(lastImportIndex);
|
||||||
|
|
||||||
|
console.log('✅ Импорт NotificationHandlers добавлен');
|
||||||
|
} else {
|
||||||
|
console.error('❌ Не удалось найти место для добавления импорта');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка объявления NotificationHandlers в классе
|
||||||
|
if (!botContent.includes('private notificationHandlers')) {
|
||||||
|
console.log('Добавляем объявление notificationHandlers в класс...');
|
||||||
|
|
||||||
|
const classPropertiesRegex = /class TelegramTinderBot {([^}]+?)constructor/s;
|
||||||
|
const classPropertiesMatch = botContent.match(classPropertiesRegex);
|
||||||
|
|
||||||
|
if (classPropertiesMatch) {
|
||||||
|
const classProperties = classPropertiesMatch[1];
|
||||||
|
const updatedProperties = classProperties + ' private notificationHandlers: NotificationHandlers;\n ';
|
||||||
|
|
||||||
|
botContent = botContent.replace(classPropertiesRegex, `class TelegramTinderBot {${updatedProperties}constructor`);
|
||||||
|
|
||||||
|
console.log('✅ Объявление notificationHandlers добавлено');
|
||||||
|
} else {
|
||||||
|
console.error('❌ Не удалось найти место для добавления объявления notificationHandlers');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка создания экземпляра NotificationHandlers в конструкторе
|
||||||
|
if (!botContent.includes('this.notificationHandlers = new NotificationHandlers')) {
|
||||||
|
console.log('Добавляем инициализацию notificationHandlers в конструктор...');
|
||||||
|
|
||||||
|
const initializationRegex = /(this\.callbackHandlers = new CallbackHandlers[^;]+;)/;
|
||||||
|
const initializationMatch = botContent.match(initializationRegex);
|
||||||
|
|
||||||
|
if (initializationMatch) {
|
||||||
|
const callbackHandlersInit = initializationMatch[1];
|
||||||
|
const updatedInit = callbackHandlersInit + '\n this.notificationHandlers = new NotificationHandlers(this.bot);';
|
||||||
|
|
||||||
|
botContent = botContent.replace(initializationRegex, updatedInit);
|
||||||
|
|
||||||
|
console.log('✅ Инициализация notificationHandlers добавлена');
|
||||||
|
} else {
|
||||||
|
console.error('❌ Не удалось найти место для добавления инициализации notificationHandlers');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка регистрации notificationHandlers в методе registerHandlers
|
||||||
|
if (!botContent.includes('this.notificationHandlers.register()')) {
|
||||||
|
console.log('Добавляем регистрацию notificationHandlers...');
|
||||||
|
|
||||||
|
const registerHandlersRegex = /(private registerHandlers\(\): void {[^}]+?)}/s;
|
||||||
|
const registerHandlersMatch = botContent.match(registerHandlersRegex);
|
||||||
|
|
||||||
|
if (registerHandlersMatch) {
|
||||||
|
const registerHandlersBody = registerHandlersMatch[1];
|
||||||
|
const updatedBody = registerHandlersBody + '\n // Обработчики уведомлений\n this.notificationHandlers.register();\n }';
|
||||||
|
|
||||||
|
botContent = botContent.replace(registerHandlersRegex, updatedBody);
|
||||||
|
|
||||||
|
console.log('✅ Регистрация notificationHandlers добавлена');
|
||||||
|
} else {
|
||||||
|
console.error('❌ Не удалось найти место для добавления регистрации notificationHandlers');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запись обновленного содержимого в файл
|
||||||
|
fs.writeFileSync(botFilePath, botContent, 'utf8');
|
||||||
|
|
||||||
|
console.log('✅ Файл bot.ts успешно обновлен');
|
||||||
|
console.log('🔔 Перезапустите бота для применения изменений');
|
||||||
2
sql/add_looking_for.sql
Normal file
2
sql/add_looking_for.sql
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- Добавление колонки looking_for в таблицу profiles
|
||||||
|
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS looking_for VARCHAR(20) DEFAULT 'both' CHECK (looking_for IN ('male', 'female', 'both'));
|
||||||
7
sql/add_missing_columns.sql
Normal file
7
sql/add_missing_columns.sql
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
-- Добавление недостающих колонок в таблицу profiles
|
||||||
|
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS hobbies TEXT[];
|
||||||
|
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS religion VARCHAR(255);
|
||||||
|
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS dating_goal VARCHAR(50);
|
||||||
|
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS smoking VARCHAR(20) CHECK (smoking IS NULL OR smoking IN ('never', 'sometimes', 'regularly'));
|
||||||
|
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS drinking VARCHAR(20) CHECK (drinking IS NULL OR drinking IN ('never', 'sometimes', 'regularly'));
|
||||||
|
ALTER TABLE profiles ADD COLUMN IF NOT EXISTS has_kids BOOLEAN DEFAULT FALSE;
|
||||||
4
sql/add_premium_columns.sql
Normal file
4
sql/add_premium_columns.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
-- Добавление колонок premium и premium_expires_at в таблицу users
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS premium BOOLEAN DEFAULT FALSE,
|
||||||
|
ADD COLUMN IF NOT EXISTS premium_expires_at TIMESTAMP;
|
||||||
21
sql/add_updated_at.sql
Normal file
21
sql/add_updated_at.sql
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
-- Добавление колонки updated_at в таблицу users
|
||||||
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
|
-- Обновление триггера для автоматического обновления updated_at
|
||||||
|
CREATE OR REPLACE FUNCTION update_updated_at()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Проверка и создание триггера, если он не существует
|
||||||
|
DO $$
|
||||||
|
BEGIN
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM pg_trigger WHERE tgname = 'users_updated_at') THEN
|
||||||
|
CREATE TRIGGER users_updated_at
|
||||||
|
BEFORE UPDATE ON users
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION update_updated_at();
|
||||||
|
END IF;
|
||||||
|
END$$;
|
||||||
404
sql/consolidated.sql
Normal file
404
sql/consolidated.sql
Normal file
@@ -0,0 +1,404 @@
|
|||||||
|
# Consolidated SQL файл для миграции базы данных Telegram Tinder Bot
|
||||||
|
# Этот файл содержит все необходимые SQL-запросы для создания базы данных с нуля
|
||||||
|
|
||||||
|
-- Создание расширения для UUID
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
|
-- Создание перечислений
|
||||||
|
CREATE TYPE gender_type AS ENUM ('male', 'female', 'other');
|
||||||
|
CREATE TYPE swipe_action AS ENUM ('like', 'dislike', 'superlike');
|
||||||
|
|
||||||
|
-- Создание таблицы пользователей
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
telegram_id BIGINT UNIQUE NOT NULL,
|
||||||
|
username VARCHAR(255),
|
||||||
|
first_name VARCHAR(255) NOT NULL,
|
||||||
|
last_name VARCHAR(255),
|
||||||
|
language_code VARCHAR(10),
|
||||||
|
is_premium BOOLEAN DEFAULT FALSE,
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание таблицы профилей
|
||||||
|
CREATE TABLE IF NOT EXISTS profiles (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
age INTEGER NOT NULL CHECK (age >= 18),
|
||||||
|
gender gender_type NOT NULL,
|
||||||
|
bio TEXT,
|
||||||
|
photos TEXT[], -- JSON array of photo file_ids
|
||||||
|
location VARCHAR(255),
|
||||||
|
job VARCHAR(255),
|
||||||
|
interests TEXT[], -- JSON array of interests
|
||||||
|
last_active TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
is_completed BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT unique_user_profile UNIQUE (user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание индекса для поиска по возрасту и полу
|
||||||
|
CREATE INDEX idx_profiles_age_gender ON profiles(age, gender);
|
||||||
|
|
||||||
|
-- Создание таблицы предпочтений поиска
|
||||||
|
CREATE TABLE IF NOT EXISTS search_preferences (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
age_min INTEGER NOT NULL DEFAULT 18 CHECK (age_min >= 18),
|
||||||
|
age_max INTEGER NOT NULL DEFAULT 99 CHECK (age_max >= age_min),
|
||||||
|
looking_for gender_type NOT NULL,
|
||||||
|
distance_max INTEGER, -- max distance in km, NULL means no limit
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT unique_user_preferences UNIQUE (user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание таблицы действий (лайки/дизлайки)
|
||||||
|
CREATE TABLE IF NOT EXISTS swipes (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
target_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
action swipe_action NOT NULL,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT unique_swipe UNIQUE (user_id, target_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание индекса для быстрого поиска матчей
|
||||||
|
CREATE INDEX idx_swipes_user_target ON swipes(user_id, target_id);
|
||||||
|
|
||||||
|
-- Создание таблицы матчей
|
||||||
|
CREATE TABLE IF NOT EXISTS matches (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id_1 UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
user_id_2 UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
CONSTRAINT unique_match UNIQUE (user_id_1, user_id_2)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание индекса для быстрого поиска матчей по пользователю
|
||||||
|
CREATE INDEX idx_matches_user_id_1 ON matches(user_id_1);
|
||||||
|
CREATE INDEX idx_matches_user_id_2 ON matches(user_id_2);
|
||||||
|
|
||||||
|
-- Создание таблицы блокировок
|
||||||
|
CREATE TABLE IF NOT EXISTS blocks (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
blocker_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
blocked_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT unique_block UNIQUE (blocker_id, blocked_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание таблицы сообщений
|
||||||
|
CREATE TABLE IF NOT EXISTS messages (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
match_id UUID NOT NULL REFERENCES matches(id) ON DELETE CASCADE,
|
||||||
|
sender_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
text TEXT NOT NULL,
|
||||||
|
is_read BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание индекса для быстрого поиска сообщений
|
||||||
|
CREATE INDEX idx_messages_match_id ON messages(match_id);
|
||||||
|
|
||||||
|
-- Создание таблицы уведомлений
|
||||||
|
CREATE TABLE IF NOT EXISTS notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL, -- new_match, new_message, etc.
|
||||||
|
content TEXT NOT NULL,
|
||||||
|
is_read BOOLEAN DEFAULT FALSE,
|
||||||
|
reference_id UUID, -- Can reference a match_id, message_id, etc.
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание индекса для быстрого поиска уведомлений
|
||||||
|
CREATE INDEX idx_notifications_user_id ON notifications(user_id);
|
||||||
|
|
||||||
|
-- Создание таблицы настроек
|
||||||
|
CREATE TABLE IF NOT EXISTS settings (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
notifications_enabled BOOLEAN DEFAULT TRUE,
|
||||||
|
show_online_status BOOLEAN DEFAULT TRUE,
|
||||||
|
visibility BOOLEAN DEFAULT TRUE, -- whether profile is visible in search
|
||||||
|
theme VARCHAR(20) DEFAULT 'light',
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT unique_user_settings UNIQUE (user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание таблицы просмотров профиля
|
||||||
|
CREATE TABLE IF NOT EXISTS profile_views (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
viewer_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
viewed_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
view_count INTEGER DEFAULT 1,
|
||||||
|
last_viewed_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT unique_view UNIQUE (viewer_id, viewed_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создание таблицы для премиум-пользователей
|
||||||
|
CREATE TABLE IF NOT EXISTS premium_features (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
is_premium BOOLEAN DEFAULT FALSE,
|
||||||
|
superlike_quota INTEGER DEFAULT 1,
|
||||||
|
spotlight_quota INTEGER DEFAULT 0,
|
||||||
|
see_likes BOOLEAN DEFAULT FALSE, -- Can see who liked their profile
|
||||||
|
unlimited_likes BOOLEAN DEFAULT FALSE,
|
||||||
|
expires_at TIMESTAMP WITH TIME ZONE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT unique_user_premium UNIQUE (user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Функция для обновления поля updated_at
|
||||||
|
CREATE OR REPLACE FUNCTION update_updated_at()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Триггеры для обновления поля updated_at
|
||||||
|
CREATE TRIGGER update_users_updated_at
|
||||||
|
BEFORE UPDATE ON users
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_updated_at();
|
||||||
|
|
||||||
|
CREATE TRIGGER update_profiles_updated_at
|
||||||
|
BEFORE UPDATE ON profiles
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_updated_at();
|
||||||
|
|
||||||
|
CREATE TRIGGER update_search_preferences_updated_at
|
||||||
|
BEFORE UPDATE ON search_preferences
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_updated_at();
|
||||||
|
|
||||||
|
CREATE TRIGGER update_settings_updated_at
|
||||||
|
BEFORE UPDATE ON settings
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_updated_at();
|
||||||
|
|
||||||
|
CREATE TRIGGER update_premium_features_updated_at
|
||||||
|
BEFORE UPDATE ON premium_features
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_updated_at();
|
||||||
|
|
||||||
|
-- Индекс для поиска пользователей по Telegram ID (часто используемый запрос)
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_telegram_id ON users(telegram_id);
|
||||||
|
|
||||||
|
-- Индекс для статуса профиля (активный/неактивный, завершенный/незавершенный)
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_profiles_is_completed ON profiles(is_completed);
|
||||||
|
|
||||||
|
-- Представление для статистики
|
||||||
|
CREATE OR REPLACE VIEW user_statistics AS
|
||||||
|
SELECT
|
||||||
|
u.id,
|
||||||
|
u.telegram_id,
|
||||||
|
(SELECT COUNT(*) FROM swipes WHERE user_id = u.id AND action = 'like') AS likes_given,
|
||||||
|
(SELECT COUNT(*) FROM swipes WHERE user_id = u.id AND action = 'dislike') AS dislikes_given,
|
||||||
|
(SELECT COUNT(*) FROM swipes WHERE target_id = u.id AND action = 'like') AS likes_received,
|
||||||
|
(SELECT COUNT(*) FROM matches WHERE user_id_1 = u.id OR user_id_2 = u.id) AS matches_count,
|
||||||
|
(SELECT COUNT(*) FROM messages WHERE sender_id = u.id) AS messages_sent,
|
||||||
|
(SELECT COUNT(*) FROM profile_views WHERE viewed_id = u.id) AS profile_views
|
||||||
|
FROM users u;
|
||||||
|
|
||||||
|
-- Функция для создания матча при взаимных лайках
|
||||||
|
CREATE OR REPLACE FUNCTION create_match_on_mutual_like()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
DECLARE
|
||||||
|
reverse_like_exists BOOLEAN;
|
||||||
|
BEGIN
|
||||||
|
-- Check if there is a reverse like
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM swipes
|
||||||
|
WHERE user_id = NEW.target_id
|
||||||
|
AND target_id = NEW.user_id
|
||||||
|
AND action = 'like'
|
||||||
|
) INTO reverse_like_exists;
|
||||||
|
|
||||||
|
-- If there is a reverse like, create a match
|
||||||
|
IF reverse_like_exists AND NEW.action = 'like' THEN
|
||||||
|
INSERT INTO matches (user_id_1, user_id_2)
|
||||||
|
VALUES (
|
||||||
|
LEAST(NEW.user_id, NEW.target_id),
|
||||||
|
GREATEST(NEW.user_id, NEW.target_id)
|
||||||
|
)
|
||||||
|
ON CONFLICT (user_id_1, user_id_2) DO NOTHING;
|
||||||
|
|
||||||
|
-- Create notifications for both users
|
||||||
|
INSERT INTO notifications (user_id, type, content, reference_id)
|
||||||
|
VALUES (
|
||||||
|
NEW.user_id,
|
||||||
|
'new_match',
|
||||||
|
'У вас новый матч!',
|
||||||
|
(SELECT id FROM matches WHERE
|
||||||
|
(user_id_1 = LEAST(NEW.user_id, NEW.target_id) AND user_id_2 = GREATEST(NEW.user_id, NEW.target_id))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO notifications (user_id, type, content, reference_id)
|
||||||
|
VALUES (
|
||||||
|
NEW.target_id,
|
||||||
|
'new_match',
|
||||||
|
'У вас новый матч!',
|
||||||
|
(SELECT id FROM matches WHERE
|
||||||
|
(user_id_1 = LEAST(NEW.user_id, NEW.target_id) AND user_id_2 = GREATEST(NEW.user_id, NEW.target_id))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Триггер для создания матча при взаимных лайках
|
||||||
|
CREATE TRIGGER create_match_trigger
|
||||||
|
AFTER INSERT ON swipes
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION create_match_on_mutual_like();
|
||||||
|
|
||||||
|
-- Функция для создания уведомления о новом сообщении
|
||||||
|
CREATE OR REPLACE FUNCTION notify_new_message()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
DECLARE
|
||||||
|
recipient_id UUID;
|
||||||
|
match_record RECORD;
|
||||||
|
BEGIN
|
||||||
|
-- Get the match record
|
||||||
|
SELECT * INTO match_record FROM matches WHERE id = NEW.match_id;
|
||||||
|
|
||||||
|
-- Determine the recipient
|
||||||
|
IF match_record.user_id_1 = NEW.sender_id THEN
|
||||||
|
recipient_id := match_record.user_id_2;
|
||||||
|
ELSE
|
||||||
|
recipient_id := match_record.user_id_1;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- Create notification
|
||||||
|
INSERT INTO notifications (user_id, type, content, reference_id)
|
||||||
|
VALUES (
|
||||||
|
recipient_id,
|
||||||
|
'new_message',
|
||||||
|
'У вас новое сообщение!',
|
||||||
|
NEW.id
|
||||||
|
);
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Триггер для создания уведомления о новом сообщении
|
||||||
|
CREATE TRIGGER notify_new_message_trigger
|
||||||
|
AFTER INSERT ON messages
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION notify_new_message();
|
||||||
|
|
||||||
|
-- Функция для обновления времени последней активности пользователя
|
||||||
|
CREATE OR REPLACE FUNCTION update_last_active()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
UPDATE profiles
|
||||||
|
SET last_active = CURRENT_TIMESTAMP
|
||||||
|
WHERE user_id = NEW.user_id;
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Триггер для обновления времени последней активности при свайпах
|
||||||
|
CREATE TRIGGER update_last_active_on_swipe
|
||||||
|
AFTER INSERT ON swipes
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_last_active();
|
||||||
|
|
||||||
|
-- Триггер для обновления времени последней активности при отправке сообщений
|
||||||
|
CREATE TRIGGER update_last_active_on_message
|
||||||
|
AFTER INSERT ON messages
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_last_active();
|
||||||
|
|
||||||
|
-- Создание функции для автоматического создания профиля при создании пользователя
|
||||||
|
CREATE OR REPLACE FUNCTION create_initial_profile()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO profiles (user_id, name, age, gender)
|
||||||
|
VALUES (NEW.id, COALESCE(NEW.first_name, 'User'), 18, 'other');
|
||||||
|
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
-- Триггер для автоматического создания профиля при создании пользователя
|
||||||
|
CREATE TRIGGER create_profile_trigger
|
||||||
|
AFTER INSERT ON users
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION create_initial_profile();
|
||||||
|
|
||||||
|
-- Индексы для оптимизации частых запросов
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_profiles_last_active ON profiles(last_active);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_swipes_action ON swipes(action);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_notifications_is_read ON notifications(is_read);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_messages_is_read ON messages(is_read);
|
||||||
|
|
||||||
|
-- Добавление ограничений для проверки возраста
|
||||||
|
ALTER TABLE profiles DROP CONSTRAINT IF EXISTS age_check;
|
||||||
|
ALTER TABLE profiles ADD CONSTRAINT age_check CHECK (age >= 18 AND age <= 99);
|
||||||
|
|
||||||
|
-- Добавление ограничений для предпочтений
|
||||||
|
ALTER TABLE search_preferences DROP CONSTRAINT IF EXISTS age_range_check;
|
||||||
|
ALTER TABLE search_preferences ADD CONSTRAINT age_range_check CHECK (age_min >= 18 AND age_max >= age_min AND age_max <= 99);
|
||||||
|
|
||||||
|
-- Комментарии к таблицам для документации
|
||||||
|
COMMENT ON TABLE users IS 'Таблица пользователей Telegram';
|
||||||
|
COMMENT ON TABLE profiles IS 'Профили пользователей для знакомств';
|
||||||
|
COMMENT ON TABLE search_preferences IS 'Предпочтения поиска пользователей';
|
||||||
|
COMMENT ON TABLE swipes IS 'История лайков/дислайков';
|
||||||
|
COMMENT ON TABLE matches IS 'Совпадения (матчи) между пользователями';
|
||||||
|
COMMENT ON TABLE messages IS 'Сообщения между пользователями';
|
||||||
|
COMMENT ON TABLE notifications IS 'Уведомления для пользователей';
|
||||||
|
COMMENT ON TABLE settings IS 'Настройки пользователей';
|
||||||
|
COMMENT ON TABLE profile_views IS 'История просмотров профилей';
|
||||||
|
COMMENT ON TABLE premium_features IS 'Премиум-функции для пользователей';
|
||||||
|
|
||||||
|
-- Представление для быстрого получения активных матчей с информацией о пользователе
|
||||||
|
CREATE OR REPLACE VIEW active_matches AS
|
||||||
|
SELECT
|
||||||
|
m.id AS match_id,
|
||||||
|
m.created_at AS match_date,
|
||||||
|
CASE
|
||||||
|
WHEN m.user_id_1 = u1.id THEN u2.id
|
||||||
|
ELSE u1.id
|
||||||
|
END AS partner_id,
|
||||||
|
CASE
|
||||||
|
WHEN m.user_id_1 = u1.id THEN u2.telegram_id
|
||||||
|
ELSE u1.telegram_id
|
||||||
|
END AS partner_telegram_id,
|
||||||
|
CASE
|
||||||
|
WHEN m.user_id_1 = u1.id THEN p2.name
|
||||||
|
ELSE p1.name
|
||||||
|
END AS partner_name,
|
||||||
|
CASE
|
||||||
|
WHEN m.user_id_1 = u1.id THEN p2.photos[1]
|
||||||
|
ELSE p1.photos[1]
|
||||||
|
END AS partner_photo,
|
||||||
|
(SELECT COUNT(*) FROM messages WHERE match_id = m.id) AS message_count,
|
||||||
|
(SELECT COUNT(*) FROM messages WHERE match_id = m.id AND is_read = false AND sender_id != u1.id) AS unread_count,
|
||||||
|
m.is_active
|
||||||
|
FROM matches m
|
||||||
|
JOIN users u1 ON m.user_id_1 = u1.id
|
||||||
|
JOIN users u2 ON m.user_id_2 = u2.id
|
||||||
|
JOIN profiles p1 ON u1.id = p1.user_id
|
||||||
|
JOIN profiles p2 ON u2.id = p2.user_id
|
||||||
|
WHERE m.is_active = true;
|
||||||
67
sql/recreate_tables.sql
Normal file
67
sql/recreate_tables.sql
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
-- Сначала создаем таблицы заново
|
||||||
|
DROP TABLE IF EXISTS profiles CASCADE;
|
||||||
|
DROP TABLE IF EXISTS users CASCADE;
|
||||||
|
|
||||||
|
-- Users table
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
telegram_id BIGINT UNIQUE NOT NULL,
|
||||||
|
username VARCHAR(255),
|
||||||
|
first_name VARCHAR(255),
|
||||||
|
last_name VARCHAR(255),
|
||||||
|
language_code VARCHAR(10) DEFAULT 'en',
|
||||||
|
is_premium BOOLEAN DEFAULT FALSE,
|
||||||
|
is_blocked BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Profiles table
|
||||||
|
CREATE TABLE IF NOT EXISTS profiles (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
age INTEGER NOT NULL CHECK (age >= 18 AND age <= 100),
|
||||||
|
gender VARCHAR(20) NOT NULL CHECK (gender IN ('male', 'female', 'other')),
|
||||||
|
looking_for VARCHAR(20) NOT NULL CHECK (looking_for IN ('male', 'female', 'both')),
|
||||||
|
bio TEXT,
|
||||||
|
location VARCHAR(255),
|
||||||
|
latitude DECIMAL(10, 8),
|
||||||
|
longitude DECIMAL(11, 8),
|
||||||
|
photos TEXT[], -- Array of photo URLs/file IDs
|
||||||
|
interests TEXT[], -- Array of interests
|
||||||
|
hobbies TEXT[],
|
||||||
|
education VARCHAR(255),
|
||||||
|
occupation VARCHAR(255),
|
||||||
|
height INTEGER, -- in cm
|
||||||
|
religion VARCHAR(255),
|
||||||
|
dating_goal VARCHAR(50),
|
||||||
|
smoking VARCHAR(20) CHECK (smoking IN ('never', 'sometimes', 'regularly')),
|
||||||
|
drinking VARCHAR(20) CHECK (drinking IN ('never', 'sometimes', 'regularly')),
|
||||||
|
has_kids BOOLEAN DEFAULT FALSE,
|
||||||
|
relationship_type VARCHAR(30) CHECK (relationship_type IN ('casual', 'serious', 'friendship', 'anything')),
|
||||||
|
verification_status VARCHAR(20) DEFAULT 'unverified' CHECK (verification_status IN ('unverified', 'pending', 'verified')),
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
is_visible BOOLEAN DEFAULT TRUE,
|
||||||
|
last_active TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
UNIQUE(user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Создаем тригеры для автоматического обновления updated_at
|
||||||
|
CREATE OR REPLACE FUNCTION update_updated_at()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
CREATE TRIGGER users_updated_at
|
||||||
|
BEFORE UPDATE ON users
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION update_updated_at();
|
||||||
|
|
||||||
|
CREATE TRIGGER profiles_updated_at
|
||||||
|
BEFORE UPDATE ON profiles
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION update_updated_at();
|
||||||
51
src/bot.ts
51
src/bot.ts
@@ -8,6 +8,8 @@ import LocalizationService from './services/localizationService';
|
|||||||
import { CommandHandlers } from './handlers/commandHandlers';
|
import { CommandHandlers } from './handlers/commandHandlers';
|
||||||
import { CallbackHandlers } from './handlers/callbackHandlers';
|
import { CallbackHandlers } from './handlers/callbackHandlers';
|
||||||
import { MessageHandlers } from './handlers/messageHandlers';
|
import { MessageHandlers } from './handlers/messageHandlers';
|
||||||
|
import { NotificationHandlers } from './handlers/notificationHandlers';
|
||||||
|
|
||||||
|
|
||||||
class TelegramTinderBot {
|
class TelegramTinderBot {
|
||||||
private bot: TelegramBot;
|
private bot: TelegramBot;
|
||||||
@@ -18,7 +20,7 @@ class TelegramTinderBot {
|
|||||||
private commandHandlers: CommandHandlers;
|
private commandHandlers: CommandHandlers;
|
||||||
private callbackHandlers: CallbackHandlers;
|
private callbackHandlers: CallbackHandlers;
|
||||||
private messageHandlers: MessageHandlers;
|
private messageHandlers: MessageHandlers;
|
||||||
|
private notificationHandlers: NotificationHandlers;
|
||||||
constructor() {
|
constructor() {
|
||||||
const token = process.env.TELEGRAM_BOT_TOKEN;
|
const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
@@ -34,6 +36,7 @@ class TelegramTinderBot {
|
|||||||
this.commandHandlers = new CommandHandlers(this.bot);
|
this.commandHandlers = new CommandHandlers(this.bot);
|
||||||
this.messageHandlers = new MessageHandlers(this.bot);
|
this.messageHandlers = new MessageHandlers(this.bot);
|
||||||
this.callbackHandlers = new CallbackHandlers(this.bot, this.messageHandlers);
|
this.callbackHandlers = new CallbackHandlers(this.bot, this.messageHandlers);
|
||||||
|
this.notificationHandlers = new NotificationHandlers(this.bot);
|
||||||
|
|
||||||
this.setupErrorHandling();
|
this.setupErrorHandling();
|
||||||
this.setupPeriodicTasks();
|
this.setupPeriodicTasks();
|
||||||
@@ -78,6 +81,7 @@ class TelegramTinderBot {
|
|||||||
{ command: 'browse', description: '💕 Смотреть анкеты' },
|
{ command: 'browse', description: '💕 Смотреть анкеты' },
|
||||||
{ command: 'matches', description: '💖 Мои матчи' },
|
{ command: 'matches', description: '💖 Мои матчи' },
|
||||||
{ command: 'settings', description: '⚙️ Настройки' },
|
{ command: 'settings', description: '⚙️ Настройки' },
|
||||||
|
{ command: 'notifications', description: '🔔 Настройки уведомлений' },
|
||||||
{ command: 'help', description: '❓ Помощь' }
|
{ command: 'help', description: '❓ Помощь' }
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -94,6 +98,9 @@ class TelegramTinderBot {
|
|||||||
|
|
||||||
// Сообщения
|
// Сообщения
|
||||||
this.messageHandlers.register();
|
this.messageHandlers.register();
|
||||||
|
|
||||||
|
// Обработчики уведомлений
|
||||||
|
this.notificationHandlers.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Обработка ошибок
|
// Обработка ошибок
|
||||||
@@ -137,14 +144,31 @@ class TelegramTinderBot {
|
|||||||
}
|
}
|
||||||
}, 5 * 60 * 1000);
|
}, 5 * 60 * 1000);
|
||||||
|
|
||||||
// Очистка старых данных каждый день
|
// Планирование периодических уведомлений раз в день в 00:05
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
await this.cleanupOldData();
|
const now = new Date();
|
||||||
|
if (now.getHours() === 0 && now.getMinutes() >= 5 && now.getMinutes() < 10) {
|
||||||
|
console.log('🔔 Scheduling periodic notifications...');
|
||||||
|
await this.notificationService.schedulePeriodicNotifications();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error scheduling periodic notifications:', error);
|
||||||
|
}
|
||||||
|
}, 5 * 60 * 1000);
|
||||||
|
|
||||||
|
// Очистка старых данных каждый день в 03:00
|
||||||
|
setInterval(async () => {
|
||||||
|
try {
|
||||||
|
const now = new Date();
|
||||||
|
if (now.getHours() === 3 && now.getMinutes() < 5) {
|
||||||
|
console.log('🧹 Running scheduled cleanup...');
|
||||||
|
await this.cleanupOldData();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error cleaning up old data:', error);
|
console.error('Error cleaning up old data:', error);
|
||||||
}
|
}
|
||||||
}, 24 * 60 * 60 * 1000);
|
}, 5 * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Очистка старых данных
|
// Очистка старых данных
|
||||||
@@ -152,11 +176,18 @@ class TelegramTinderBot {
|
|||||||
console.log('🧹 Running cleanup tasks...');
|
console.log('🧹 Running cleanup tasks...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Очистка старых уведомлений (старше 30 дней)
|
// Очистка старых запланированных уведомлений (старше 30 дней или обработанных)
|
||||||
const notificationsResult = await query(`
|
const scheduledNotificationsResult = await query(`
|
||||||
DELETE FROM scheduled_notifications
|
DELETE FROM scheduled_notifications
|
||||||
WHERE processed = true
|
WHERE (processed = true AND created_at < CURRENT_TIMESTAMP - INTERVAL '30 days')
|
||||||
AND created_at < CURRENT_TIMESTAMP - INTERVAL '30 days'
|
OR (scheduled_at < CURRENT_TIMESTAMP - INTERVAL '7 days')
|
||||||
|
`);
|
||||||
|
console.log(`🗑️ Cleaned up ${scheduledNotificationsResult.rowCount} old scheduled notifications`);
|
||||||
|
|
||||||
|
// Очистка старых уведомлений (старше 90 дней)
|
||||||
|
const notificationsResult = await query(`
|
||||||
|
DELETE FROM notifications
|
||||||
|
WHERE created_at < CURRENT_TIMESTAMP - INTERVAL '90 days'
|
||||||
`);
|
`);
|
||||||
console.log(`🗑️ Cleaned up ${notificationsResult.rowCount} old notifications`);
|
console.log(`🗑️ Cleaned up ${notificationsResult.rowCount} old notifications`);
|
||||||
|
|
||||||
@@ -186,7 +217,7 @@ class TelegramTinderBot {
|
|||||||
console.log(`💬 Cleaned up ${messagesResult.rowCount} old messages`);
|
console.log(`💬 Cleaned up ${messagesResult.rowCount} old messages`);
|
||||||
|
|
||||||
// Обновление статистики таблиц после очистки
|
// Обновление статистики таблиц после очистки
|
||||||
await query('VACUUM ANALYZE scheduled_notifications, profile_views, swipes, messages');
|
await query('VACUUM ANALYZE notifications, scheduled_notifications, profile_views, swipes, messages');
|
||||||
|
|
||||||
console.log('✅ Cleanup completed successfully');
|
console.log('✅ Cleanup completed successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -229,4 +260,4 @@ if (require.main === module) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { TelegramTinderBot };
|
export { TelegramTinderBot };
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import { Pool, PoolConfig } from 'pg';
|
|||||||
|
|
||||||
// Конфигурация пула соединений PostgreSQL
|
// Конфигурация пула соединений PostgreSQL
|
||||||
const poolConfig: PoolConfig = {
|
const poolConfig: PoolConfig = {
|
||||||
host: process.env.DB_HOST || 'localhost',
|
host: process.env.DB_HOST,
|
||||||
port: parseInt(process.env.DB_PORT || '5433'),
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
database: process.env.DB_NAME || 'telegram_tinder_bot',
|
database: process.env.DB_NAME || 'telegram_tinder_bot',
|
||||||
user: process.env.DB_USERNAME || 'postgres',
|
user: process.env.DB_USERNAME,
|
||||||
...(process.env.DB_PASSWORD && { password: process.env.DB_PASSWORD }),
|
...(process.env.DB_PASSWORD && { password: process.env.DB_PASSWORD }),
|
||||||
max: 20, // максимальное количество соединений в пуле
|
max: 20, // максимальное количество соединений в пуле
|
||||||
idleTimeoutMillis: 30000, // закрыть соединения, простаивающие 30 секунд
|
idleTimeoutMillis: 30000, // закрыть соединения, простаивающие 30 секунд
|
||||||
@@ -154,10 +154,10 @@ export async function initializeDatabase(): Promise<void> {
|
|||||||
await query(`
|
await query(`
|
||||||
CREATE INDEX IF NOT EXISTS idx_users_telegram_id ON users(telegram_id);
|
CREATE INDEX IF NOT EXISTS idx_users_telegram_id ON users(telegram_id);
|
||||||
CREATE INDEX IF NOT EXISTS idx_profiles_user_id ON profiles(user_id);
|
CREATE INDEX IF NOT EXISTS idx_profiles_user_id ON profiles(user_id);
|
||||||
CREATE INDEX IF NOT EXISTS idx_profiles_location ON profiles(latitude, longitude);
|
CREATE INDEX IF NOT EXISTS idx_profiles_location ON profiles(location_lat, location_lon) WHERE location_lat IS NOT NULL AND location_lon IS NOT NULL;
|
||||||
CREATE INDEX IF NOT EXISTS idx_profiles_age_gender ON profiles(age, gender, looking_for);
|
CREATE INDEX IF NOT EXISTS idx_profiles_age_gender ON profiles(age, gender, interested_in);
|
||||||
CREATE INDEX IF NOT EXISTS idx_swipes_swiper_swiped ON swipes(swiper_id, swiped_id);
|
CREATE INDEX IF NOT EXISTS idx_swipes_user ON swipes(user_id, target_user_id);
|
||||||
CREATE INDEX IF NOT EXISTS idx_matches_users ON matches(user1_id, user2_id);
|
CREATE INDEX IF NOT EXISTS idx_matches_users ON matches(user_id_1, user_id_2);
|
||||||
CREATE INDEX IF NOT EXISTS idx_messages_match ON messages(match_id, created_at);
|
CREATE INDEX IF NOT EXISTS idx_messages_match ON messages(match_id, created_at);
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|||||||
108
src/database/migrateOnStartup.ts
Normal file
108
src/database/migrateOnStartup.ts
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
// Script to run migrations on startup
|
||||||
|
import { Pool } from 'pg';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
|
import 'dotenv/config';
|
||||||
|
|
||||||
|
async function runMigrations() {
|
||||||
|
console.log('Starting database migration...');
|
||||||
|
|
||||||
|
// Create a connection pool
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST || 'localhost',
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME || 'telegram_tinder_bot',
|
||||||
|
user: process.env.DB_USERNAME || 'postgres',
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
max: 20,
|
||||||
|
idleTimeoutMillis: 30000,
|
||||||
|
connectionTimeoutMillis: 2000,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Test connection
|
||||||
|
const testRes = await pool.query('SELECT NOW()');
|
||||||
|
console.log(`Database connection successful at ${testRes.rows[0].now}`);
|
||||||
|
|
||||||
|
// Create migrations table if not exists
|
||||||
|
await pool.query(`
|
||||||
|
CREATE TABLE IF NOT EXISTS migrations (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
executed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Get list of executed migrations
|
||||||
|
const migrationRes = await pool.query('SELECT name FROM migrations');
|
||||||
|
const executedMigrations = migrationRes.rows.map(row => row.name);
|
||||||
|
console.log(`Found ${executedMigrations.length} executed migrations`);
|
||||||
|
|
||||||
|
// Get migration files
|
||||||
|
const migrationsPath = path.join(__dirname, 'migrations');
|
||||||
|
let migrationFiles = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
migrationFiles = fs.readdirSync(migrationsPath)
|
||||||
|
.filter(file => file.endsWith('.sql'))
|
||||||
|
.sort();
|
||||||
|
console.log(`Found ${migrationFiles.length} migration files`);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(`Error reading migrations directory: ${error.message}`);
|
||||||
|
console.log('Continuing with built-in consolidated migration...');
|
||||||
|
|
||||||
|
// If no external files found, use consolidated.sql
|
||||||
|
const consolidatedSQL = fs.readFileSync(path.join(__dirname, 'migrations', 'consolidated.sql'), 'utf8');
|
||||||
|
|
||||||
|
console.log('Executing consolidated migration...');
|
||||||
|
await pool.query(consolidatedSQL);
|
||||||
|
|
||||||
|
if (!executedMigrations.includes('consolidated.sql')) {
|
||||||
|
await pool.query(
|
||||||
|
'INSERT INTO migrations (name) VALUES ($1)',
|
||||||
|
['consolidated.sql']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Consolidated migration completed successfully');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run each migration that hasn't been executed yet
|
||||||
|
for (const file of migrationFiles) {
|
||||||
|
if (!executedMigrations.includes(file)) {
|
||||||
|
console.log(`Executing migration: ${file}`);
|
||||||
|
const sql = fs.readFileSync(path.join(migrationsPath, file), 'utf8');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await pool.query('BEGIN');
|
||||||
|
await pool.query(sql);
|
||||||
|
await pool.query(
|
||||||
|
'INSERT INTO migrations (name) VALUES ($1)',
|
||||||
|
[file]
|
||||||
|
);
|
||||||
|
await pool.query('COMMIT');
|
||||||
|
console.log(`Migration ${file} completed successfully`);
|
||||||
|
} catch (error: any) {
|
||||||
|
await pool.query('ROLLBACK');
|
||||||
|
console.error(`Error executing migration ${file}: ${error.message}`);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(`Migration ${file} already executed, skipping`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('All migrations completed successfully!');
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error(`Migration failed: ${error.message}`);
|
||||||
|
process.exit(1);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runMigrations().catch((error: any) => {
|
||||||
|
console.error('Unhandled error during migration:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
182
src/database/migrations/consolidated.sql
Normal file
182
src/database/migrations/consolidated.sql
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
-- Consolidated migrations for Telegram Tinder Bot
|
||||||
|
|
||||||
|
-- Create extension for UUID if not exists
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
|
||||||
|
|
||||||
|
----------------------------------------------
|
||||||
|
-- Core Tables
|
||||||
|
----------------------------------------------
|
||||||
|
|
||||||
|
-- Users table
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
telegram_id BIGINT UNIQUE NOT NULL,
|
||||||
|
username VARCHAR(255),
|
||||||
|
first_name VARCHAR(255),
|
||||||
|
last_name VARCHAR(255),
|
||||||
|
language_code VARCHAR(10) DEFAULT 'ru',
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
last_active_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
premium BOOLEAN DEFAULT FALSE,
|
||||||
|
state VARCHAR(255),
|
||||||
|
state_data JSONB DEFAULT '{}'::jsonb
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Profiles table
|
||||||
|
CREATE TABLE IF NOT EXISTS profiles (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
age INTEGER NOT NULL CHECK (age >= 18 AND age <= 100),
|
||||||
|
gender VARCHAR(10) NOT NULL CHECK (gender IN ('male', 'female', 'other')),
|
||||||
|
interested_in VARCHAR(10) NOT NULL CHECK (interested_in IN ('male', 'female', 'both')),
|
||||||
|
bio TEXT,
|
||||||
|
photos JSONB DEFAULT '[]',
|
||||||
|
interests JSONB DEFAULT '[]',
|
||||||
|
city VARCHAR(255),
|
||||||
|
education VARCHAR(255),
|
||||||
|
job VARCHAR(255),
|
||||||
|
height INTEGER,
|
||||||
|
location_lat DECIMAL(10, 8),
|
||||||
|
location_lon DECIMAL(11, 8),
|
||||||
|
search_min_age INTEGER DEFAULT 18,
|
||||||
|
search_max_age INTEGER DEFAULT 50,
|
||||||
|
search_max_distance INTEGER DEFAULT 50,
|
||||||
|
is_verified BOOLEAN DEFAULT FALSE,
|
||||||
|
is_visible BOOLEAN DEFAULT TRUE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
religion VARCHAR(255),
|
||||||
|
dating_goal VARCHAR(50),
|
||||||
|
smoking VARCHAR(20),
|
||||||
|
drinking VARCHAR(20),
|
||||||
|
has_kids BOOLEAN DEFAULT FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Swipes table
|
||||||
|
CREATE TABLE IF NOT EXISTS swipes (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
target_user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(20) NOT NULL CHECK (type IN ('like', 'pass', 'superlike')),
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
is_match BOOLEAN DEFAULT FALSE,
|
||||||
|
UNIQUE(user_id, target_user_id)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Matches table
|
||||||
|
CREATE TABLE IF NOT EXISTS matches (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id_1 UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
user_id_2 UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
last_message_at TIMESTAMP,
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
is_super_match BOOLEAN DEFAULT FALSE,
|
||||||
|
unread_count_1 INTEGER DEFAULT 0,
|
||||||
|
unread_count_2 INTEGER DEFAULT 0,
|
||||||
|
UNIQUE(user_id_1, user_id_2)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Messages table
|
||||||
|
CREATE TABLE IF NOT EXISTS messages (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
match_id UUID REFERENCES matches(id) ON DELETE CASCADE,
|
||||||
|
sender_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
receiver_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
content TEXT NOT NULL,
|
||||||
|
message_type VARCHAR(20) DEFAULT 'text' CHECK (message_type IN ('text', 'photo', 'gif', 'sticker')),
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
is_read BOOLEAN DEFAULT FALSE
|
||||||
|
);
|
||||||
|
|
||||||
|
----------------------------------------------
|
||||||
|
-- Profile Views Table
|
||||||
|
----------------------------------------------
|
||||||
|
|
||||||
|
-- Table for tracking profile views
|
||||||
|
CREATE TABLE IF NOT EXISTS profile_views (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
viewer_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
viewed_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
view_type VARCHAR(20) DEFAULT 'browse' CHECK (view_type IN ('browse', 'search', 'recommended')),
|
||||||
|
viewed_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
CONSTRAINT unique_profile_view UNIQUE (viewer_id, viewed_id, view_type)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Index for profile views
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_profile_views_viewer ON profile_views(viewer_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_profile_views_viewed ON profile_views(viewed_id);
|
||||||
|
|
||||||
|
----------------------------------------------
|
||||||
|
-- Notification Tables
|
||||||
|
----------------------------------------------
|
||||||
|
|
||||||
|
-- Notifications table
|
||||||
|
CREATE TABLE IF NOT EXISTS notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
content JSONB NOT NULL DEFAULT '{}',
|
||||||
|
is_read BOOLEAN DEFAULT FALSE,
|
||||||
|
processed BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Notification settings table
|
||||||
|
CREATE TABLE IF NOT EXISTS notification_settings (
|
||||||
|
user_id UUID PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
new_matches BOOLEAN DEFAULT TRUE,
|
||||||
|
new_messages BOOLEAN DEFAULT TRUE,
|
||||||
|
new_likes BOOLEAN DEFAULT TRUE,
|
||||||
|
reminders BOOLEAN DEFAULT TRUE,
|
||||||
|
daily_summary BOOLEAN DEFAULT FALSE,
|
||||||
|
time_preference VARCHAR(20) DEFAULT 'evening',
|
||||||
|
do_not_disturb BOOLEAN DEFAULT FALSE,
|
||||||
|
do_not_disturb_start TIME,
|
||||||
|
do_not_disturb_end TIME,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Scheduled notifications table
|
||||||
|
CREATE TABLE IF NOT EXISTS scheduled_notifications (
|
||||||
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
|
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
type VARCHAR(50) NOT NULL,
|
||||||
|
content JSONB NOT NULL DEFAULT '{}',
|
||||||
|
scheduled_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
|
processed BOOLEAN DEFAULT FALSE,
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
----------------------------------------------
|
||||||
|
-- Indexes for better performance
|
||||||
|
----------------------------------------------
|
||||||
|
|
||||||
|
-- User Indexes
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_users_telegram_id ON users(telegram_id);
|
||||||
|
|
||||||
|
-- Profile Indexes
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_profiles_user_id ON profiles(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_profiles_location ON profiles(location_lat, location_lon)
|
||||||
|
WHERE location_lat IS NOT NULL AND location_lon IS NOT NULL;
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_profiles_age_gender ON profiles(age, gender, interested_in);
|
||||||
|
|
||||||
|
-- Swipe Indexes
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_swipes_user ON swipes(user_id, target_user_id);
|
||||||
|
|
||||||
|
-- Match Indexes
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_matches_users ON matches(user_id_1, user_id_2);
|
||||||
|
|
||||||
|
-- Message Indexes
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_messages_match ON messages(match_id, created_at);
|
||||||
|
|
||||||
|
-- Notification Indexes
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_notifications_user_id ON notifications(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_notifications_type ON notifications(type);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_notifications_created_at ON notifications(created_at);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_scheduled_notifications_user_id ON scheduled_notifications(user_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_scheduled_notifications_scheduled_at ON scheduled_notifications(scheduled_at);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_scheduled_notifications_processed ON scheduled_notifications(processed);
|
||||||
@@ -4,12 +4,14 @@ import { MatchingService } from '../services/matchingService';
|
|||||||
import { ChatService } from '../services/chatService';
|
import { ChatService } from '../services/chatService';
|
||||||
import { Profile } from '../models/Profile';
|
import { Profile } from '../models/Profile';
|
||||||
import { MessageHandlers } from './messageHandlers';
|
import { MessageHandlers } from './messageHandlers';
|
||||||
|
import { NotificationHandlers } from './notificationHandlers';
|
||||||
import { ProfileEditController } from '../controllers/profileEditController';
|
import { ProfileEditController } from '../controllers/profileEditController';
|
||||||
import { EnhancedChatHandlers } from './enhancedChatHandlers';
|
import { EnhancedChatHandlers } from './enhancedChatHandlers';
|
||||||
import { VipController } from '../controllers/vipController';
|
import { VipController } from '../controllers/vipController';
|
||||||
import { VipService } from '../services/vipService';
|
import { VipService } from '../services/vipService';
|
||||||
import { TranslationController } from '../controllers/translationController';
|
import { TranslationController } from '../controllers/translationController';
|
||||||
import { t } from '../services/localizationService';
|
import { t } from '../services/localizationService';
|
||||||
|
import { LikeBackHandler } from './likeBackHandler';
|
||||||
|
|
||||||
export class CallbackHandlers {
|
export class CallbackHandlers {
|
||||||
private bot: TelegramBot;
|
private bot: TelegramBot;
|
||||||
@@ -22,6 +24,8 @@ export class CallbackHandlers {
|
|||||||
private vipController: VipController;
|
private vipController: VipController;
|
||||||
private vipService: VipService;
|
private vipService: VipService;
|
||||||
private translationController: TranslationController;
|
private translationController: TranslationController;
|
||||||
|
private notificationHandlers?: NotificationHandlers;
|
||||||
|
private likeBackHandler: LikeBackHandler;
|
||||||
|
|
||||||
constructor(bot: TelegramBot, messageHandlers: MessageHandlers) {
|
constructor(bot: TelegramBot, messageHandlers: MessageHandlers) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
@@ -34,6 +38,13 @@ export class CallbackHandlers {
|
|||||||
this.vipController = new VipController(bot);
|
this.vipController = new VipController(bot);
|
||||||
this.vipService = new VipService();
|
this.vipService = new VipService();
|
||||||
this.translationController = new TranslationController();
|
this.translationController = new TranslationController();
|
||||||
|
// Создаем экземпляр NotificationHandlers
|
||||||
|
try {
|
||||||
|
this.notificationHandlers = new NotificationHandlers(bot);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to initialize NotificationHandlers:', error);
|
||||||
|
}
|
||||||
|
this.likeBackHandler = new LikeBackHandler(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
register(): void {
|
register(): void {
|
||||||
@@ -139,7 +150,10 @@ export class CallbackHandlers {
|
|||||||
|
|
||||||
// Просмотр анкет и свайпы
|
// Просмотр анкет и свайпы
|
||||||
else if (data === 'start_browsing') {
|
else if (data === 'start_browsing') {
|
||||||
await this.handleStartBrowsing(chatId, telegramId);
|
await this.handleStartBrowsing(chatId, telegramId, false);
|
||||||
|
} else if (data === 'start_browsing_first') {
|
||||||
|
// Показываем всех пользователей для нового пользователя
|
||||||
|
await this.handleStartBrowsing(chatId, telegramId, true);
|
||||||
} else if (data === 'vip_search') {
|
} else if (data === 'vip_search') {
|
||||||
await this.handleVipSearch(chatId, telegramId);
|
await this.handleVipSearch(chatId, telegramId);
|
||||||
} else if (data.startsWith('search_by_goal_')) {
|
} else if (data.startsWith('search_by_goal_')) {
|
||||||
@@ -164,6 +178,12 @@ export class CallbackHandlers {
|
|||||||
await this.handleMorePhotos(chatId, telegramId, targetUserId);
|
await this.handleMorePhotos(chatId, telegramId, targetUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Обработка лайков и ответных лайков из уведомлений
|
||||||
|
else if (data.startsWith('like_back:')) {
|
||||||
|
const targetUserId = data.replace('like_back:', '');
|
||||||
|
await this.likeBackHandler.handleLikeBack(chatId, telegramId, targetUserId);
|
||||||
|
}
|
||||||
|
|
||||||
// Матчи и чаты
|
// Матчи и чаты
|
||||||
else if (data === 'view_matches') {
|
else if (data === 'view_matches') {
|
||||||
await this.handleViewMatches(chatId, telegramId);
|
await this.handleViewMatches(chatId, telegramId);
|
||||||
@@ -260,6 +280,41 @@ export class CallbackHandlers {
|
|||||||
await this.handleSettings(chatId, telegramId);
|
await this.handleSettings(chatId, telegramId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Настройки уведомлений
|
||||||
|
else if (data === 'notifications') {
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
const userId = await this.profileService.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.answerCallbackQuery(query.id, { text: '❌ Вы не зарегистрированы.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = await this.notificationHandlers.getNotificationService().getNotificationSettings(userId);
|
||||||
|
await this.notificationHandlers.sendNotificationSettings(chatId, settings);
|
||||||
|
} else {
|
||||||
|
await this.handleNotificationSettings(chatId, telegramId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Обработка переключения настроек уведомлений
|
||||||
|
else if (data.startsWith('notif_toggle:') ||
|
||||||
|
data === 'notif_time' ||
|
||||||
|
data.startsWith('notif_time_set:') ||
|
||||||
|
data === 'notif_dnd' ||
|
||||||
|
data.startsWith('notif_dnd_set:') ||
|
||||||
|
data === 'notif_dnd_time' ||
|
||||||
|
data.startsWith('notif_dnd_time_set:') ||
|
||||||
|
data === 'notif_dnd_time_custom') {
|
||||||
|
// Делегируем обработку в NotificationHandlers, если он доступен
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
// Эти коллбэки уже обрабатываются в NotificationHandlers, поэтому здесь ничего не делаем
|
||||||
|
// NotificationHandlers уже зарегистрировал свои обработчики в register()
|
||||||
|
} else {
|
||||||
|
await this.bot.answerCallbackQuery(query.id, {
|
||||||
|
text: 'Функция настройки уведомлений недоступна.',
|
||||||
|
show_alert: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
await this.bot.answerCallbackQuery(query.id, {
|
await this.bot.answerCallbackQuery(query.id, {
|
||||||
text: 'Функция в разработке!',
|
text: 'Функция в разработке!',
|
||||||
@@ -330,7 +385,7 @@ export class CallbackHandlers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Начать просмотр анкет
|
// Начать просмотр анкет
|
||||||
async handleStartBrowsing(chatId: number, telegramId: string): Promise<void> {
|
async handleStartBrowsing(chatId: number, telegramId: string, isNewUser: boolean = false): Promise<void> {
|
||||||
const profile = await this.profileService.getProfileByTelegramId(telegramId);
|
const profile = await this.profileService.getProfileByTelegramId(telegramId);
|
||||||
|
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
@@ -338,7 +393,7 @@ export class CallbackHandlers {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.showNextCandidate(chatId, telegramId);
|
await this.showNextCandidate(chatId, telegramId, isNewUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Следующий кандидат
|
// Следующий кандидат
|
||||||
@@ -382,9 +437,15 @@ export class CallbackHandlers {
|
|||||||
await this.bot.sendMessage(chatId, '👍 Лайк отправлен!');
|
await this.bot.sendMessage(chatId, '👍 Лайк отправлен!');
|
||||||
await this.showNextCandidate(chatId, telegramId);
|
await this.showNextCandidate(chatId, telegramId);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
await this.bot.sendMessage(chatId, '❌ Ошибка при отправке лайка');
|
// Проверяем, связана ли ошибка с уже существующим свайпом
|
||||||
console.error('Like error:', error);
|
if (error.message === 'Already swiped this profile' || error.code === 'ALREADY_SWIPED') {
|
||||||
|
await this.bot.sendMessage(chatId, '❓ Вы уже оценивали этот профиль ранее');
|
||||||
|
await this.showNextCandidate(chatId, telegramId);
|
||||||
|
} else {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Ошибка при отправке лайка');
|
||||||
|
console.error('Like error:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,9 +460,15 @@ export class CallbackHandlers {
|
|||||||
|
|
||||||
await this.matchingService.performSwipe(telegramId, targetTelegramId, 'pass');
|
await this.matchingService.performSwipe(telegramId, targetTelegramId, 'pass');
|
||||||
await this.showNextCandidate(chatId, telegramId);
|
await this.showNextCandidate(chatId, telegramId);
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
await this.bot.sendMessage(chatId, '❌ Ошибка при отправке дизлайка');
|
// Проверяем, связана ли ошибка с уже существующим свайпом
|
||||||
console.error('Dislike error:', error);
|
if (error.message === 'Already swiped this profile' || error.code === 'ALREADY_SWIPED') {
|
||||||
|
await this.bot.sendMessage(chatId, '❓ Вы уже оценивали этот профиль ранее');
|
||||||
|
await this.showNextCandidate(chatId, telegramId);
|
||||||
|
} else {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Ошибка при отправке дизлайка');
|
||||||
|
console.error('Dislike error:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,9 +507,73 @@ export class CallbackHandlers {
|
|||||||
await this.bot.sendMessage(chatId, '💖 Супер лайк отправлен!');
|
await this.bot.sendMessage(chatId, '💖 Супер лайк отправлен!');
|
||||||
await this.showNextCandidate(chatId, telegramId);
|
await this.showNextCandidate(chatId, telegramId);
|
||||||
}
|
}
|
||||||
|
} catch (error: any) {
|
||||||
|
// Проверяем, связана ли ошибка с уже существующим свайпом
|
||||||
|
if (error.message === 'Already swiped this profile' || error.code === 'ALREADY_SWIPED') {
|
||||||
|
await this.bot.sendMessage(chatId, '❓ Вы уже оценивали этот профиль ранее');
|
||||||
|
await this.showNextCandidate(chatId, telegramId);
|
||||||
|
} else {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Ошибка при отправке супер лайка');
|
||||||
|
console.error('Superlike error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка обратного лайка из уведомления
|
||||||
|
async handleLikeBack(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
// Получаем информацию о пользователях
|
||||||
|
const targetProfile = await this.profileService.getProfileByUserId(targetUserId);
|
||||||
|
|
||||||
|
if (!targetProfile) {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Не удалось найти профиль');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получаем telegram ID целевого пользователя для свайпа
|
||||||
|
const targetTelegramId = await this.profileService.getTelegramIdByUserId(targetUserId);
|
||||||
|
if (!targetTelegramId) {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Не удалось найти пользователя');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Выполняем свайп
|
||||||
|
const result = await this.matchingService.performSwipe(telegramId, targetTelegramId, 'like');
|
||||||
|
|
||||||
|
if (result.isMatch) {
|
||||||
|
// Это матч!
|
||||||
|
await this.bot.sendMessage(
|
||||||
|
chatId,
|
||||||
|
'🎉 *Поздравляем! Это взаимно!*\n\n' +
|
||||||
|
`Вы и *${targetProfile.name}* понравились друг другу!\n` +
|
||||||
|
'Теперь вы можете начать общение.',
|
||||||
|
{
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '💬 Начать общение', callback_data: `start_chat:${targetUserId}` }],
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: `view_profile:${targetUserId}` }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await this.bot.sendMessage(
|
||||||
|
chatId,
|
||||||
|
'❤️ Вам понравился профиль ' + targetProfile.name + '!\n\n' +
|
||||||
|
'Если вы также понравитесь этому пользователю, будет создан матч.',
|
||||||
|
{
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '🔍 Продолжить поиск', callback_data: 'start_browsing' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await this.bot.sendMessage(chatId, '❌ Ошибка при отправке супер лайка');
|
console.error('Error in handleLikeBack:', error);
|
||||||
console.error('Superlike error:', error);
|
await this.bot.sendMessage(chatId, '❌ Произошла ошибка при обработке лайка');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,9 +604,28 @@ export class CallbackHandlers {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 1; i < targetProfile.photos.length; i++) {
|
// Отправляем фотографии в виде медиа-группы (коллажа)
|
||||||
const photoFileId = targetProfile.photos[i];
|
// Создаем массив объектов медиа для группового отправления
|
||||||
await this.bot.sendPhoto(chatId, photoFileId);
|
const mediaGroup = targetProfile.photos.slice(1).map((photoFileId, index) => ({
|
||||||
|
type: 'photo' as const,
|
||||||
|
media: photoFileId,
|
||||||
|
caption: index === 0 ? `📸 Дополнительные фото ${targetProfile.name}` : undefined
|
||||||
|
}));
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Отправляем все фото одним сообщением (медиа-группой)
|
||||||
|
await this.bot.sendMediaGroup(chatId, mediaGroup);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error sending media group:', error);
|
||||||
|
|
||||||
|
// Если не получилось отправить медиа-группой, отправляем по одной
|
||||||
|
for (let i = 1; i < targetProfile.photos.length; i++) {
|
||||||
|
try {
|
||||||
|
await this.bot.sendPhoto(chatId, targetProfile.photos[i]);
|
||||||
|
} catch (photoError) {
|
||||||
|
console.error(`Error sending photo ${i}:`, photoError);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const keyboard: InlineKeyboardMarkup = {
|
const keyboard: InlineKeyboardMarkup = {
|
||||||
@@ -763,13 +913,7 @@ export class CallbackHandlers {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Настройки уведомлений
|
// Настройки уведомлений - реализация перенесена в расширенную версию
|
||||||
async handleNotificationSettings(chatId: number, telegramId: string): Promise<void> {
|
|
||||||
await this.bot.sendMessage(
|
|
||||||
chatId,
|
|
||||||
'🔔 Настройки уведомлений будут доступны в следующем обновлении!'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Как это работает
|
// Как это работает
|
||||||
async handleHowItWorks(chatId: number): Promise<void> {
|
async handleHowItWorks(chatId: number): Promise<void> {
|
||||||
@@ -804,6 +948,7 @@ export class CallbackHandlers {
|
|||||||
|
|
||||||
// Вспомогательные методы
|
// Вспомогательные методы
|
||||||
async showProfile(chatId: number, profile: Profile, isOwner: boolean = false, viewerId?: string): Promise<void> {
|
async showProfile(chatId: number, profile: Profile, isOwner: boolean = false, viewerId?: string): Promise<void> {
|
||||||
|
const hasMultiplePhotos = profile.photos.length > 1;
|
||||||
const mainPhotoFileId = profile.photos[0]; // Первое фото - главное
|
const mainPhotoFileId = profile.photos[0]; // Первое фото - главное
|
||||||
|
|
||||||
let profileText = '👤 ' + profile.name + ', ' + profile.age + '\n';
|
let profileText = '👤 ' + profile.name + ', ' + profile.age + '\n';
|
||||||
@@ -873,26 +1018,49 @@ export class CallbackHandlers {
|
|||||||
|
|
||||||
if (hasValidPhoto) {
|
if (hasValidPhoto) {
|
||||||
try {
|
try {
|
||||||
await this.bot.sendPhoto(chatId, mainPhotoFileId, {
|
if (hasMultiplePhotos) {
|
||||||
caption: profileText,
|
// Если есть несколько фото, отправляем их как медиа-группу (коллаж)
|
||||||
reply_markup: keyboard
|
const mediaGroup = profile.photos.map((photoFileId, index) => ({
|
||||||
});
|
type: 'photo' as const,
|
||||||
|
media: photoFileId,
|
||||||
|
caption: index === 0 ? profileText : undefined,
|
||||||
|
parse_mode: index === 0 ? 'Markdown' as const : undefined
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Сначала отправляем медиа-группу
|
||||||
|
await this.bot.sendMediaGroup(chatId, mediaGroup);
|
||||||
|
|
||||||
|
// Затем отправляем отдельное сообщение с кнопками
|
||||||
|
await this.bot.sendMessage(chatId, '📸 Выберите действие:', {
|
||||||
|
reply_markup: keyboard
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Если только одно фото, отправляем его с текстом
|
||||||
|
await this.bot.sendPhoto(chatId, mainPhotoFileId, {
|
||||||
|
caption: profileText,
|
||||||
|
reply_markup: keyboard,
|
||||||
|
parse_mode: 'Markdown'
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Error sending profile photos:', error);
|
||||||
// Если не удалось отправить фото, отправляем текст
|
// Если не удалось отправить фото, отправляем текст
|
||||||
await this.bot.sendMessage(chatId, '🖼 Фото недоступно\n\n' + profileText, {
|
await this.bot.sendMessage(chatId, '🖼 Фото недоступно\n\n' + profileText, {
|
||||||
reply_markup: keyboard
|
reply_markup: keyboard,
|
||||||
|
parse_mode: 'Markdown'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Отправляем как текстовое сообщение
|
// Отправляем как текстовое сообщение
|
||||||
await this.bot.sendMessage(chatId, profileText, {
|
await this.bot.sendMessage(chatId, profileText, {
|
||||||
reply_markup: keyboard
|
reply_markup: keyboard,
|
||||||
|
parse_mode: 'Markdown'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async showNextCandidate(chatId: number, telegramId: string): Promise<void> {
|
async showNextCandidate(chatId: number, telegramId: string, isNewUser: boolean = false): Promise<void> {
|
||||||
const candidate = await this.matchingService.getNextCandidate(telegramId);
|
const candidate = await this.matchingService.getNextCandidate(telegramId, isNewUser);
|
||||||
|
|
||||||
if (!candidate) {
|
if (!candidate) {
|
||||||
const keyboard: InlineKeyboardMarkup = {
|
const keyboard: InlineKeyboardMarkup = {
|
||||||
@@ -1370,12 +1538,28 @@ export class CallbackHandlers {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lifestyle = profile.lifestyle || {};
|
// Обновляем отдельные колонки напрямую, а не через объект lifestyle
|
||||||
lifestyle[type as keyof typeof lifestyle] = value as any;
|
const updates: any = {};
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case 'smoking':
|
||||||
|
updates.smoking = value;
|
||||||
|
break;
|
||||||
|
case 'drinking':
|
||||||
|
updates.drinking = value;
|
||||||
|
break;
|
||||||
|
case 'kids':
|
||||||
|
// Для поля has_kids, которое имеет тип boolean, преобразуем строковые значения
|
||||||
|
if (value === 'have') {
|
||||||
|
updates.has_kids = true;
|
||||||
|
} else {
|
||||||
|
// Для 'want', 'dont_want', 'unsure' ставим false
|
||||||
|
updates.has_kids = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
await this.profileService.updateProfile(profile.userId, {
|
await this.profileService.updateProfile(profile.userId, updates);
|
||||||
lifestyle: lifestyle
|
|
||||||
});
|
|
||||||
|
|
||||||
const typeTexts: { [key: string]: string } = {
|
const typeTexts: { [key: string]: string } = {
|
||||||
'smoking': 'курение',
|
'smoking': 'курение',
|
||||||
@@ -1431,7 +1615,7 @@ export class CallbackHandlers {
|
|||||||
try {
|
try {
|
||||||
// Проверяем VIP статус пользователя
|
// Проверяем VIP статус пользователя
|
||||||
const user = await this.profileService.getUserByTelegramId(telegramId);
|
const user = await this.profileService.getUserByTelegramId(telegramId);
|
||||||
if (!user || !user.isPremium) {
|
if (!user || !user.premium) { // Изменено с isPremium на premium, чтобы соответствовать названию колонки в базе данных
|
||||||
const keyboard = {
|
const keyboard = {
|
||||||
inline_keyboard: [
|
inline_keyboard: [
|
||||||
[
|
[
|
||||||
@@ -2093,4 +2277,27 @@ export class CallbackHandlers {
|
|||||||
await this.bot.sendMessage(chatId, t('translation.error'));
|
await this.bot.sendMessage(chatId, t('translation.error'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleNotificationSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
const userId = await this.profileService.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Вы не зарегистрированы. Используйте команду /start для регистрации.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Вызываем метод из notificationHandlers для получения настроек и отображения меню
|
||||||
|
const settings = await this.notificationHandlers.getNotificationService().getNotificationSettings(userId);
|
||||||
|
await this.notificationHandlers.sendNotificationSettings(chatId, settings);
|
||||||
|
} else {
|
||||||
|
// Если NotificationHandlers недоступен, показываем сообщение об ошибке
|
||||||
|
await this.bot.sendMessage(chatId, '⚙️ Настройки уведомлений временно недоступны. Попробуйте позже.');
|
||||||
|
await this.handleSettings(chatId, telegramId);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Notification settings error:', error);
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Произошла ошибка при загрузке настроек уведомлений. Попробуйте позже.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
606
src/handlers/callbackHandlers.ts.backup-1758166633763
Normal file
606
src/handlers/callbackHandlers.ts.backup-1758166633763
Normal file
@@ -0,0 +1,606 @@
|
|||||||
|
import TelegramBot, { CallbackQuery, InlineKeyboardMarkup } from 'node-telegram-bot-api';
|
||||||
|
import { ProfileService } from '../services/profileService';
|
||||||
|
import { MatchingService } from '../services/matchingService';
|
||||||
|
import { ChatService } from '../services/chatService';
|
||||||
|
import { Profile } from '../models/Profile';
|
||||||
|
import { MessageHandlers } from './messageHandlers';
|
||||||
|
import { ProfileEditController } from '../controllers/profileEditController';
|
||||||
|
import { EnhancedChatHandlers } from './enhancedChatHandlers';
|
||||||
|
import { VipController } from '../controllers/vipController';
|
||||||
|
import { VipService } from '../services/vipService';
|
||||||
|
import { TranslationController } from '../controllers/translationController';
|
||||||
|
import { t } from '../services/localizationService';
|
||||||
|
import { LikeBackHandler } from './likeBackHandler';
|
||||||
|
import { NotificationHandlers } from './notificationHandlers';
|
||||||
|
|
||||||
|
export class CallbackHandlers {
|
||||||
|
private bot: TelegramBot;
|
||||||
|
private profileService: ProfileService;
|
||||||
|
private matchingService: MatchingService;
|
||||||
|
private chatService: ChatService;
|
||||||
|
private messageHandlers: MessageHandlers;
|
||||||
|
private profileEditController: ProfileEditController;
|
||||||
|
private enhancedChatHandlers: EnhancedChatHandlers;
|
||||||
|
private vipController: VipController;
|
||||||
|
private vipService: VipService;
|
||||||
|
private translationController: TranslationController;
|
||||||
|
private likeBackHandler: LikeBackHandler;
|
||||||
|
private notificationHandlers?: NotificationHandlers;
|
||||||
|
|
||||||
|
constructor(bot: TelegramBot, messageHandlers: MessageHandlers) {
|
||||||
|
this.bot = bot;
|
||||||
|
this.profileService = new ProfileService();
|
||||||
|
this.matchingService = new MatchingService();
|
||||||
|
this.chatService = new ChatService();
|
||||||
|
this.messageHandlers = messageHandlers;
|
||||||
|
this.profileEditController = new ProfileEditController(this.profileService);
|
||||||
|
this.enhancedChatHandlers = new EnhancedChatHandlers(bot);
|
||||||
|
this.vipController = new VipController(bot);
|
||||||
|
this.vipService = new VipService();
|
||||||
|
this.translationController = new TranslationController();
|
||||||
|
this.likeBackHandler = new LikeBackHandler(bot);
|
||||||
|
|
||||||
|
// Создаем экземпляр NotificationHandlers
|
||||||
|
try {
|
||||||
|
this.notificationHandlers = new NotificationHandlers(bot);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to initialize NotificationHandlers:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
register(): void {
|
||||||
|
this.bot.on('callback_query', (query) => this.handleCallback(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleCallback(query: CallbackQuery): Promise<void> {
|
||||||
|
if (!query.data || !query.from || !query.message) return;
|
||||||
|
|
||||||
|
const telegramId = query.from.id.toString();
|
||||||
|
const chatId = query.message.chat.id;
|
||||||
|
const data = query.data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Основные действия профиля
|
||||||
|
if (data === 'create_profile') {
|
||||||
|
await this.handleCreateProfile(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('gender_')) {
|
||||||
|
const gender = data.replace('gender_', '');
|
||||||
|
await this.handleGenderSelection(chatId, telegramId, gender);
|
||||||
|
} else if (data === 'view_my_profile') {
|
||||||
|
await this.handleViewMyProfile(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_profile') {
|
||||||
|
await this.handleEditProfile(chatId, telegramId);
|
||||||
|
} else if (data === 'manage_photos') {
|
||||||
|
await this.handleManagePhotos(chatId, telegramId);
|
||||||
|
} else if (data === 'preview_profile') {
|
||||||
|
await this.handlePreviewProfile(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Редактирование полей профиля
|
||||||
|
else if (data === 'edit_name') {
|
||||||
|
await this.handleEditName(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_age') {
|
||||||
|
await this.handleEditAge(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_bio') {
|
||||||
|
await this.handleEditBio(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_hobbies') {
|
||||||
|
await this.handleEditHobbies(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_city') {
|
||||||
|
await this.handleEditCity(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_job') {
|
||||||
|
await this.handleEditJob(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_education') {
|
||||||
|
await this.handleEditEducation(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_height') {
|
||||||
|
await this.handleEditHeight(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_religion') {
|
||||||
|
await this.handleEditReligion(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_dating_goal') {
|
||||||
|
await this.handleEditDatingGoal(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_lifestyle') {
|
||||||
|
await this.handleEditLifestyle(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_search_preferences') {
|
||||||
|
await this.handleEditSearchPreferences(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Управление фотографиями
|
||||||
|
else if (data === 'add_photo') {
|
||||||
|
await this.handleAddPhoto(chatId, telegramId);
|
||||||
|
} else if (data === 'delete_photo') {
|
||||||
|
await this.handleDeletePhoto(chatId, telegramId);
|
||||||
|
} else if (data === 'set_main_photo') {
|
||||||
|
await this.handleSetMainPhoto(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('delete_photo_')) {
|
||||||
|
const photoIndex = parseInt(data.replace('delete_photo_', ''));
|
||||||
|
await this.handleDeletePhotoByIndex(chatId, telegramId, photoIndex);
|
||||||
|
} else if (data.startsWith('set_main_photo_')) {
|
||||||
|
const photoIndex = parseInt(data.replace('set_main_photo_', ''));
|
||||||
|
await this.handleSetMainPhotoByIndex(chatId, telegramId, photoIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Цели знакомства
|
||||||
|
else if (data.startsWith('set_dating_goal_')) {
|
||||||
|
const goal = data.replace('set_dating_goal_', '');
|
||||||
|
await this.handleSetDatingGoal(chatId, telegramId, goal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Образ жизни
|
||||||
|
else if (data === 'edit_smoking') {
|
||||||
|
await this.handleEditSmoking(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_drinking') {
|
||||||
|
await this.handleEditDrinking(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_kids') {
|
||||||
|
await this.handleEditKids(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('set_smoking_')) {
|
||||||
|
const value = data.replace('set_smoking_', '');
|
||||||
|
await this.handleSetLifestyle(chatId, telegramId, 'smoking', value);
|
||||||
|
} else if (data.startsWith('set_drinking_')) {
|
||||||
|
const value = data.replace('set_drinking_', '');
|
||||||
|
await this.handleSetLifestyle(chatId, telegramId, 'drinking', value);
|
||||||
|
} else if (data.startsWith('set_kids_')) {
|
||||||
|
const value = data.replace('set_kids_', '');
|
||||||
|
await this.handleSetLifestyle(chatId, telegramId, 'kids', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройки поиска
|
||||||
|
else if (data === 'edit_age_range') {
|
||||||
|
await this.handleEditAgeRange(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_distance') {
|
||||||
|
await this.handleEditDistance(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Просмотр анкет и свайпы
|
||||||
|
else if (data === 'start_browsing') {
|
||||||
|
await this.handleStartBrowsing(chatId, telegramId, false);
|
||||||
|
} else if (data === 'start_browsing_first') {
|
||||||
|
// Показываем всех пользователей для нового пользователя
|
||||||
|
await this.handleStartBrowsing(chatId, telegramId, true);
|
||||||
|
} else if (data === 'vip_search') {
|
||||||
|
await this.handleVipSearch(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('search_by_goal_')) {
|
||||||
|
const goal = data.replace('search_by_goal_', '');
|
||||||
|
await this.handleSearchByGoal(chatId, telegramId, goal);
|
||||||
|
} else if (data === 'next_candidate') {
|
||||||
|
await this.handleNextCandidate(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('like_')) {
|
||||||
|
const targetUserId = data.replace('like_', '');
|
||||||
|
await this.handleLike(chatId, telegramId, targetUserId);
|
||||||
|
} else if (data.startsWith('dislike_')) {
|
||||||
|
const targetUserId = data.replace('dislike_', '');
|
||||||
|
await this.handleDislike(chatId, telegramId, targetUserId);
|
||||||
|
} else if (data.startsWith('superlike_')) {
|
||||||
|
const targetUserId = data.replace('superlike_', '');
|
||||||
|
await this.handleSuperlike(chatId, telegramId, targetUserId);
|
||||||
|
} else if (data.startsWith('view_profile_')) {
|
||||||
|
const targetUserId = data.replace('view_profile_', '');
|
||||||
|
await this.handleViewProfile(chatId, telegramId, targetUserId);
|
||||||
|
} else if (data.startsWith('more_photos_')) {
|
||||||
|
const targetUserId = data.replace('more_photos_', '');
|
||||||
|
await this.handleMorePhotos(chatId, telegramId, targetUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка лайков и ответных лайков из уведомлений
|
||||||
|
else if (data.startsWith('like_back:')) {
|
||||||
|
const targetUserId = data.replace('like_back:', '');
|
||||||
|
await this.likeBackHandler.handleLikeBack(chatId, telegramId, targetUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Матчи и чаты
|
||||||
|
else if (data === 'view_matches') {
|
||||||
|
await this.handleViewMatches(chatId, telegramId);
|
||||||
|
} else if (data === 'open_chats') {
|
||||||
|
await this.handleOpenChats(chatId, telegramId);
|
||||||
|
} else if (data === 'native_chats') {
|
||||||
|
await this.enhancedChatHandlers.showChatsNative(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('open_native_chat_')) {
|
||||||
|
const matchId = data.replace('open_native_chat_', '');
|
||||||
|
await this.enhancedChatHandlers.openNativeChat(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('chat_history_')) {
|
||||||
|
const matchId = data.replace('chat_history_', '');
|
||||||
|
await this.enhancedChatHandlers.showChatHistory(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('chat_')) {
|
||||||
|
const matchId = data.replace('chat_', '');
|
||||||
|
await this.handleOpenChat(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('send_message_')) {
|
||||||
|
const matchId = data.replace('send_message_', '');
|
||||||
|
await this.handleSendMessage(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('view_chat_profile_')) {
|
||||||
|
const matchId = data.replace('view_chat_profile_', '');
|
||||||
|
await this.handleViewChatProfile(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('unmatch_')) {
|
||||||
|
const matchId = data.replace('unmatch_', '');
|
||||||
|
await this.handleUnmatch(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('confirm_unmatch_')) {
|
||||||
|
const matchId = data.replace('confirm_unmatch_', '');
|
||||||
|
await this.handleConfirmUnmatch(chatId, telegramId, matchId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройки
|
||||||
|
else if (data === 'settings') {
|
||||||
|
await this.handleSettings(chatId, telegramId);
|
||||||
|
} else if (data === 'search_settings') {
|
||||||
|
await this.handleSearchSettings(chatId, telegramId);
|
||||||
|
} else if (data === 'notification_settings') {
|
||||||
|
await this.handleNotificationSettings(chatId, telegramId);
|
||||||
|
} else if (data === 'view_stats') {
|
||||||
|
await this.handleViewStats(chatId, telegramId);
|
||||||
|
} else if (data === 'view_profile_viewers') {
|
||||||
|
await this.handleViewProfileViewers(chatId, telegramId);
|
||||||
|
} else if (data === 'hide_profile') {
|
||||||
|
await this.handleHideProfile(chatId, telegramId);
|
||||||
|
} else if (data === 'delete_profile') {
|
||||||
|
await this.handleDeleteProfile(chatId, telegramId);
|
||||||
|
} else if (data === 'main_menu') {
|
||||||
|
await this.handleMainMenu(chatId, telegramId);
|
||||||
|
} else if (data === 'confirm_delete_profile') {
|
||||||
|
await this.handleConfirmDeleteProfile(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Информация
|
||||||
|
else if (data === 'how_it_works') {
|
||||||
|
await this.handleHowItWorks(chatId);
|
||||||
|
} else if (data === 'back_to_browsing') {
|
||||||
|
await this.handleStartBrowsing(chatId, telegramId);
|
||||||
|
} else if (data === 'get_vip') {
|
||||||
|
await this.vipController.showVipSearch(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// VIP функции
|
||||||
|
else if (data === 'vip_search') {
|
||||||
|
await this.vipController.showVipSearch(chatId, telegramId);
|
||||||
|
} else if (data === 'vip_quick_search') {
|
||||||
|
await this.vipController.performQuickVipSearch(chatId, telegramId);
|
||||||
|
} else if (data === 'vip_advanced_search') {
|
||||||
|
await this.vipController.startAdvancedSearch(chatId, telegramId);
|
||||||
|
} else if (data === 'vip_dating_goal_search') {
|
||||||
|
await this.vipController.showDatingGoalSearch(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('vip_goal_')) {
|
||||||
|
const goal = data.replace('vip_goal_', '');
|
||||||
|
await this.vipController.performDatingGoalSearch(chatId, telegramId, goal);
|
||||||
|
} else if (data.startsWith('vip_like_')) {
|
||||||
|
const targetTelegramId = data.replace('vip_like_', '');
|
||||||
|
await this.handleVipLike(chatId, telegramId, targetTelegramId);
|
||||||
|
} else if (data.startsWith('vip_superlike_')) {
|
||||||
|
const targetTelegramId = data.replace('vip_superlike_', '');
|
||||||
|
await this.handleVipSuperlike(chatId, telegramId, targetTelegramId);
|
||||||
|
} else if (data.startsWith('vip_dislike_')) {
|
||||||
|
const targetTelegramId = data.replace('vip_dislike_', '');
|
||||||
|
await this.handleVipDislike(chatId, telegramId, targetTelegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройки языка и переводы
|
||||||
|
else if (data === 'language_settings') {
|
||||||
|
await this.handleLanguageSettings(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('set_language_')) {
|
||||||
|
const languageCode = data.replace('set_language_', '');
|
||||||
|
await this.handleSetLanguage(chatId, telegramId, languageCode);
|
||||||
|
} else if (data.startsWith('translate_profile_')) {
|
||||||
|
const profileUserId = parseInt(data.replace('translate_profile_', ''));
|
||||||
|
await this.handleTranslateProfile(chatId, telegramId, profileUserId);
|
||||||
|
} else if (data === 'back_to_settings') {
|
||||||
|
await this.handleSettings(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройки уведомлений
|
||||||
|
else if (data === 'notifications') {
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
const userId = await this.profileService.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.answerCallbackQuery(query.id, { text: '❌ Вы не зарегистрированы.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = await this.notificationHandlers.getNotificationService().getNotificationSettings(userId);
|
||||||
|
await this.notificationHandlers.sendNotificationSettings(chatId, settings);
|
||||||
|
} else {
|
||||||
|
await this.handleNotificationSettings(chatId, telegramId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Обработка переключения настроек уведомлений
|
||||||
|
else if (data.startsWith('notif_toggle:') ||
|
||||||
|
data === 'notif_time' ||
|
||||||
|
data.startsWith('notif_time_set:') ||
|
||||||
|
data === 'notif_dnd' ||
|
||||||
|
data.startsWith('notif_dnd_set:') ||
|
||||||
|
data === 'notif_dnd_time' ||
|
||||||
|
data.startsWith('notif_dnd_time_set:') ||
|
||||||
|
data === 'notif_dnd_time_custom') {
|
||||||
|
// Делегируем обработку в NotificationHandlers, если он доступен
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
// Эти коллбэки уже обрабатываются в NotificationHandlers, поэтому здесь ничего не делаем
|
||||||
|
// NotificationHandlers уже зарегистрировал свои обработчики в register()
|
||||||
|
} else {
|
||||||
|
await this.bot.answerCallbackQuery(query.id, {
|
||||||
|
text: 'Функция настройки уведомлений недоступна.',
|
||||||
|
show_alert: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await this.bot.answerCallbackQuery(query.id, {
|
||||||
|
text: 'Функция в разработке!',
|
||||||
|
show_alert: false
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.bot.answerCallbackQuery(query.id);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Callback handler error:', error);
|
||||||
|
await this.bot.answerCallbackQuery(query.id, {
|
||||||
|
text: 'Произошла ошибка. Попробуйте еще раз.',
|
||||||
|
show_alert: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавим все необходимые методы для обработки коллбэков
|
||||||
|
async handleCreateProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleGenderSelection(chatId: number, telegramId: string, gender: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewMyProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleManagePhotos(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handlePreviewProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditName(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditAge(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditBio(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditHobbies(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditCity(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditJob(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditEducation(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditHeight(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditReligion(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditDatingGoal(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditLifestyle(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditSearchPreferences(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleAddPhoto(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDeletePhoto(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetMainPhoto(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDeletePhotoByIndex(chatId: number, telegramId: string, photoIndex: number): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetMainPhotoByIndex(chatId: number, telegramId: string, photoIndex: number): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetDatingGoal(chatId: number, telegramId: string, goal: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditSmoking(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditDrinking(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditKids(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetLifestyle(chatId: number, telegramId: string, type: string, value: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditAgeRange(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditDistance(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleStartBrowsing(chatId: number, telegramId: string, showAll: boolean = false): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleVipSearch(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSearchByGoal(chatId: number, telegramId: string, goal: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleNextCandidate(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleLike(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDislike(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSuperlike(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewProfile(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleMorePhotos(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewMatches(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleOpenChats(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleOpenChat(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSendMessage(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewChatProfile(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleUnmatch(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleConfirmUnmatch(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSearchSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewStats(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewProfileViewers(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleHideProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDeleteProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleMainMenu(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleConfirmDeleteProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleHowItWorks(chatId: number): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleVipLike(chatId: number, telegramId: string, targetTelegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleVipSuperlike(chatId: number, telegramId: string, targetTelegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleVipDislike(chatId: number, telegramId: string, targetTelegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleLanguageSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetLanguage(chatId: number, telegramId: string, languageCode: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleTranslateProfile(chatId: number, telegramId: string, profileUserId: number): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавим новый метод для настроек уведомлений (вызывает NotificationHandlers)
|
||||||
|
async handleNotificationSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
const userId = await this.profileService.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Вы не зарегистрированы. Используйте команду /start для регистрации.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Вызываем метод из notificationHandlers для получения настроек и отображения меню
|
||||||
|
const settings = await this.notificationHandlers.getNotificationService().getNotificationSettings(userId);
|
||||||
|
await this.notificationHandlers.sendNotificationSettings(chatId, settings);
|
||||||
|
} else {
|
||||||
|
// Если NotificationHandlers недоступен, показываем сообщение об ошибке
|
||||||
|
await this.bot.sendMessage(chatId, '⚙️ Настройки уведомлений временно недоступны. Попробуйте позже.');
|
||||||
|
await this.handleSettings(chatId, telegramId);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling notification settings:', error);
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Произошла ошибка при загрузке настроек уведомлений.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
src/handlers/callbackHandlers.ts.original
Normal file
BIN
src/handlers/callbackHandlers.ts.original
Normal file
Binary file not shown.
606
src/handlers/callbackHandlers.ts.stub
Normal file
606
src/handlers/callbackHandlers.ts.stub
Normal file
@@ -0,0 +1,606 @@
|
|||||||
|
import TelegramBot, { CallbackQuery, InlineKeyboardMarkup } from 'node-telegram-bot-api';
|
||||||
|
import { ProfileService } from '../services/profileService';
|
||||||
|
import { MatchingService } from '../services/matchingService';
|
||||||
|
import { ChatService } from '../services/chatService';
|
||||||
|
import { Profile } from '../models/Profile';
|
||||||
|
import { MessageHandlers } from './messageHandlers';
|
||||||
|
import { ProfileEditController } from '../controllers/profileEditController';
|
||||||
|
import { EnhancedChatHandlers } from './enhancedChatHandlers';
|
||||||
|
import { VipController } from '../controllers/vipController';
|
||||||
|
import { VipService } from '../services/vipService';
|
||||||
|
import { TranslationController } from '../controllers/translationController';
|
||||||
|
import { t } from '../services/localizationService';
|
||||||
|
import { LikeBackHandler } from './likeBackHandler';
|
||||||
|
import { NotificationHandlers } from './notificationHandlers';
|
||||||
|
|
||||||
|
export class CallbackHandlers {
|
||||||
|
private bot: TelegramBot;
|
||||||
|
private profileService: ProfileService;
|
||||||
|
private matchingService: MatchingService;
|
||||||
|
private chatService: ChatService;
|
||||||
|
private messageHandlers: MessageHandlers;
|
||||||
|
private profileEditController: ProfileEditController;
|
||||||
|
private enhancedChatHandlers: EnhancedChatHandlers;
|
||||||
|
private vipController: VipController;
|
||||||
|
private vipService: VipService;
|
||||||
|
private translationController: TranslationController;
|
||||||
|
private likeBackHandler: LikeBackHandler;
|
||||||
|
private notificationHandlers?: NotificationHandlers;
|
||||||
|
|
||||||
|
constructor(bot: TelegramBot, messageHandlers: MessageHandlers) {
|
||||||
|
this.bot = bot;
|
||||||
|
this.profileService = new ProfileService();
|
||||||
|
this.matchingService = new MatchingService();
|
||||||
|
this.chatService = new ChatService();
|
||||||
|
this.messageHandlers = messageHandlers;
|
||||||
|
this.profileEditController = new ProfileEditController(this.profileService);
|
||||||
|
this.enhancedChatHandlers = new EnhancedChatHandlers(bot);
|
||||||
|
this.vipController = new VipController(bot);
|
||||||
|
this.vipService = new VipService();
|
||||||
|
this.translationController = new TranslationController();
|
||||||
|
this.likeBackHandler = new LikeBackHandler(bot);
|
||||||
|
|
||||||
|
// Создаем экземпляр NotificationHandlers
|
||||||
|
try {
|
||||||
|
this.notificationHandlers = new NotificationHandlers(bot);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to initialize NotificationHandlers:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
register(): void {
|
||||||
|
this.bot.on('callback_query', (query) => this.handleCallback(query));
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleCallback(query: CallbackQuery): Promise<void> {
|
||||||
|
if (!query.data || !query.from || !query.message) return;
|
||||||
|
|
||||||
|
const telegramId = query.from.id.toString();
|
||||||
|
const chatId = query.message.chat.id;
|
||||||
|
const data = query.data;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Основные действия профиля
|
||||||
|
if (data === 'create_profile') {
|
||||||
|
await this.handleCreateProfile(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('gender_')) {
|
||||||
|
const gender = data.replace('gender_', '');
|
||||||
|
await this.handleGenderSelection(chatId, telegramId, gender);
|
||||||
|
} else if (data === 'view_my_profile') {
|
||||||
|
await this.handleViewMyProfile(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_profile') {
|
||||||
|
await this.handleEditProfile(chatId, telegramId);
|
||||||
|
} else if (data === 'manage_photos') {
|
||||||
|
await this.handleManagePhotos(chatId, telegramId);
|
||||||
|
} else if (data === 'preview_profile') {
|
||||||
|
await this.handlePreviewProfile(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Редактирование полей профиля
|
||||||
|
else if (data === 'edit_name') {
|
||||||
|
await this.handleEditName(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_age') {
|
||||||
|
await this.handleEditAge(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_bio') {
|
||||||
|
await this.handleEditBio(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_hobbies') {
|
||||||
|
await this.handleEditHobbies(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_city') {
|
||||||
|
await this.handleEditCity(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_job') {
|
||||||
|
await this.handleEditJob(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_education') {
|
||||||
|
await this.handleEditEducation(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_height') {
|
||||||
|
await this.handleEditHeight(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_religion') {
|
||||||
|
await this.handleEditReligion(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_dating_goal') {
|
||||||
|
await this.handleEditDatingGoal(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_lifestyle') {
|
||||||
|
await this.handleEditLifestyle(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_search_preferences') {
|
||||||
|
await this.handleEditSearchPreferences(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Управление фотографиями
|
||||||
|
else if (data === 'add_photo') {
|
||||||
|
await this.handleAddPhoto(chatId, telegramId);
|
||||||
|
} else if (data === 'delete_photo') {
|
||||||
|
await this.handleDeletePhoto(chatId, telegramId);
|
||||||
|
} else if (data === 'set_main_photo') {
|
||||||
|
await this.handleSetMainPhoto(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('delete_photo_')) {
|
||||||
|
const photoIndex = parseInt(data.replace('delete_photo_', ''));
|
||||||
|
await this.handleDeletePhotoByIndex(chatId, telegramId, photoIndex);
|
||||||
|
} else if (data.startsWith('set_main_photo_')) {
|
||||||
|
const photoIndex = parseInt(data.replace('set_main_photo_', ''));
|
||||||
|
await this.handleSetMainPhotoByIndex(chatId, telegramId, photoIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Цели знакомства
|
||||||
|
else if (data.startsWith('set_dating_goal_')) {
|
||||||
|
const goal = data.replace('set_dating_goal_', '');
|
||||||
|
await this.handleSetDatingGoal(chatId, telegramId, goal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Образ жизни
|
||||||
|
else if (data === 'edit_smoking') {
|
||||||
|
await this.handleEditSmoking(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_drinking') {
|
||||||
|
await this.handleEditDrinking(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_kids') {
|
||||||
|
await this.handleEditKids(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('set_smoking_')) {
|
||||||
|
const value = data.replace('set_smoking_', '');
|
||||||
|
await this.handleSetLifestyle(chatId, telegramId, 'smoking', value);
|
||||||
|
} else if (data.startsWith('set_drinking_')) {
|
||||||
|
const value = data.replace('set_drinking_', '');
|
||||||
|
await this.handleSetLifestyle(chatId, telegramId, 'drinking', value);
|
||||||
|
} else if (data.startsWith('set_kids_')) {
|
||||||
|
const value = data.replace('set_kids_', '');
|
||||||
|
await this.handleSetLifestyle(chatId, telegramId, 'kids', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройки поиска
|
||||||
|
else if (data === 'edit_age_range') {
|
||||||
|
await this.handleEditAgeRange(chatId, telegramId);
|
||||||
|
} else if (data === 'edit_distance') {
|
||||||
|
await this.handleEditDistance(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Просмотр анкет и свайпы
|
||||||
|
else if (data === 'start_browsing') {
|
||||||
|
await this.handleStartBrowsing(chatId, telegramId, false);
|
||||||
|
} else if (data === 'start_browsing_first') {
|
||||||
|
// Показываем всех пользователей для нового пользователя
|
||||||
|
await this.handleStartBrowsing(chatId, telegramId, true);
|
||||||
|
} else if (data === 'vip_search') {
|
||||||
|
await this.handleVipSearch(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('search_by_goal_')) {
|
||||||
|
const goal = data.replace('search_by_goal_', '');
|
||||||
|
await this.handleSearchByGoal(chatId, telegramId, goal);
|
||||||
|
} else if (data === 'next_candidate') {
|
||||||
|
await this.handleNextCandidate(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('like_')) {
|
||||||
|
const targetUserId = data.replace('like_', '');
|
||||||
|
await this.handleLike(chatId, telegramId, targetUserId);
|
||||||
|
} else if (data.startsWith('dislike_')) {
|
||||||
|
const targetUserId = data.replace('dislike_', '');
|
||||||
|
await this.handleDislike(chatId, telegramId, targetUserId);
|
||||||
|
} else if (data.startsWith('superlike_')) {
|
||||||
|
const targetUserId = data.replace('superlike_', '');
|
||||||
|
await this.handleSuperlike(chatId, telegramId, targetUserId);
|
||||||
|
} else if (data.startsWith('view_profile_')) {
|
||||||
|
const targetUserId = data.replace('view_profile_', '');
|
||||||
|
await this.handleViewProfile(chatId, telegramId, targetUserId);
|
||||||
|
} else if (data.startsWith('more_photos_')) {
|
||||||
|
const targetUserId = data.replace('more_photos_', '');
|
||||||
|
await this.handleMorePhotos(chatId, telegramId, targetUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка лайков и ответных лайков из уведомлений
|
||||||
|
else if (data.startsWith('like_back:')) {
|
||||||
|
const targetUserId = data.replace('like_back:', '');
|
||||||
|
await this.likeBackHandler.handleLikeBack(chatId, telegramId, targetUserId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Матчи и чаты
|
||||||
|
else if (data === 'view_matches') {
|
||||||
|
await this.handleViewMatches(chatId, telegramId);
|
||||||
|
} else if (data === 'open_chats') {
|
||||||
|
await this.handleOpenChats(chatId, telegramId);
|
||||||
|
} else if (data === 'native_chats') {
|
||||||
|
await this.enhancedChatHandlers.showChatsNative(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('open_native_chat_')) {
|
||||||
|
const matchId = data.replace('open_native_chat_', '');
|
||||||
|
await this.enhancedChatHandlers.openNativeChat(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('chat_history_')) {
|
||||||
|
const matchId = data.replace('chat_history_', '');
|
||||||
|
await this.enhancedChatHandlers.showChatHistory(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('chat_')) {
|
||||||
|
const matchId = data.replace('chat_', '');
|
||||||
|
await this.handleOpenChat(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('send_message_')) {
|
||||||
|
const matchId = data.replace('send_message_', '');
|
||||||
|
await this.handleSendMessage(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('view_chat_profile_')) {
|
||||||
|
const matchId = data.replace('view_chat_profile_', '');
|
||||||
|
await this.handleViewChatProfile(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('unmatch_')) {
|
||||||
|
const matchId = data.replace('unmatch_', '');
|
||||||
|
await this.handleUnmatch(chatId, telegramId, matchId);
|
||||||
|
} else if (data.startsWith('confirm_unmatch_')) {
|
||||||
|
const matchId = data.replace('confirm_unmatch_', '');
|
||||||
|
await this.handleConfirmUnmatch(chatId, telegramId, matchId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройки
|
||||||
|
else if (data === 'settings') {
|
||||||
|
await this.handleSettings(chatId, telegramId);
|
||||||
|
} else if (data === 'search_settings') {
|
||||||
|
await this.handleSearchSettings(chatId, telegramId);
|
||||||
|
} else if (data === 'notification_settings') {
|
||||||
|
await this.handleNotificationSettings(chatId, telegramId);
|
||||||
|
} else if (data === 'view_stats') {
|
||||||
|
await this.handleViewStats(chatId, telegramId);
|
||||||
|
} else if (data === 'view_profile_viewers') {
|
||||||
|
await this.handleViewProfileViewers(chatId, telegramId);
|
||||||
|
} else if (data === 'hide_profile') {
|
||||||
|
await this.handleHideProfile(chatId, telegramId);
|
||||||
|
} else if (data === 'delete_profile') {
|
||||||
|
await this.handleDeleteProfile(chatId, telegramId);
|
||||||
|
} else if (data === 'main_menu') {
|
||||||
|
await this.handleMainMenu(chatId, telegramId);
|
||||||
|
} else if (data === 'confirm_delete_profile') {
|
||||||
|
await this.handleConfirmDeleteProfile(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Информация
|
||||||
|
else if (data === 'how_it_works') {
|
||||||
|
await this.handleHowItWorks(chatId);
|
||||||
|
} else if (data === 'back_to_browsing') {
|
||||||
|
await this.handleStartBrowsing(chatId, telegramId);
|
||||||
|
} else if (data === 'get_vip') {
|
||||||
|
await this.vipController.showVipSearch(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// VIP функции
|
||||||
|
else if (data === 'vip_search') {
|
||||||
|
await this.vipController.showVipSearch(chatId, telegramId);
|
||||||
|
} else if (data === 'vip_quick_search') {
|
||||||
|
await this.vipController.performQuickVipSearch(chatId, telegramId);
|
||||||
|
} else if (data === 'vip_advanced_search') {
|
||||||
|
await this.vipController.startAdvancedSearch(chatId, telegramId);
|
||||||
|
} else if (data === 'vip_dating_goal_search') {
|
||||||
|
await this.vipController.showDatingGoalSearch(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('vip_goal_')) {
|
||||||
|
const goal = data.replace('vip_goal_', '');
|
||||||
|
await this.vipController.performDatingGoalSearch(chatId, telegramId, goal);
|
||||||
|
} else if (data.startsWith('vip_like_')) {
|
||||||
|
const targetTelegramId = data.replace('vip_like_', '');
|
||||||
|
await this.handleVipLike(chatId, telegramId, targetTelegramId);
|
||||||
|
} else if (data.startsWith('vip_superlike_')) {
|
||||||
|
const targetTelegramId = data.replace('vip_superlike_', '');
|
||||||
|
await this.handleVipSuperlike(chatId, telegramId, targetTelegramId);
|
||||||
|
} else if (data.startsWith('vip_dislike_')) {
|
||||||
|
const targetTelegramId = data.replace('vip_dislike_', '');
|
||||||
|
await this.handleVipDislike(chatId, telegramId, targetTelegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройки языка и переводы
|
||||||
|
else if (data === 'language_settings') {
|
||||||
|
await this.handleLanguageSettings(chatId, telegramId);
|
||||||
|
} else if (data.startsWith('set_language_')) {
|
||||||
|
const languageCode = data.replace('set_language_', '');
|
||||||
|
await this.handleSetLanguage(chatId, telegramId, languageCode);
|
||||||
|
} else if (data.startsWith('translate_profile_')) {
|
||||||
|
const profileUserId = parseInt(data.replace('translate_profile_', ''));
|
||||||
|
await this.handleTranslateProfile(chatId, telegramId, profileUserId);
|
||||||
|
} else if (data === 'back_to_settings') {
|
||||||
|
await this.handleSettings(chatId, telegramId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройки уведомлений
|
||||||
|
else if (data === 'notifications') {
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
const userId = await this.profileService.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.answerCallbackQuery(query.id, { text: '❌ Вы не зарегистрированы.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = await this.notificationHandlers.getNotificationService().getNotificationSettings(userId);
|
||||||
|
await this.notificationHandlers.sendNotificationSettings(chatId, settings);
|
||||||
|
} else {
|
||||||
|
await this.handleNotificationSettings(chatId, telegramId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Обработка переключения настроек уведомлений
|
||||||
|
else if (data.startsWith('notif_toggle:') ||
|
||||||
|
data === 'notif_time' ||
|
||||||
|
data.startsWith('notif_time_set:') ||
|
||||||
|
data === 'notif_dnd' ||
|
||||||
|
data.startsWith('notif_dnd_set:') ||
|
||||||
|
data === 'notif_dnd_time' ||
|
||||||
|
data.startsWith('notif_dnd_time_set:') ||
|
||||||
|
data === 'notif_dnd_time_custom') {
|
||||||
|
// Делегируем обработку в NotificationHandlers, если он доступен
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
// Эти коллбэки уже обрабатываются в NotificationHandlers, поэтому здесь ничего не делаем
|
||||||
|
// NotificationHandlers уже зарегистрировал свои обработчики в register()
|
||||||
|
} else {
|
||||||
|
await this.bot.answerCallbackQuery(query.id, {
|
||||||
|
text: 'Функция настройки уведомлений недоступна.',
|
||||||
|
show_alert: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await this.bot.answerCallbackQuery(query.id, {
|
||||||
|
text: 'Функция в разработке!',
|
||||||
|
show_alert: false
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.bot.answerCallbackQuery(query.id);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Callback handler error:', error);
|
||||||
|
await this.bot.answerCallbackQuery(query.id, {
|
||||||
|
text: 'Произошла ошибка. Попробуйте еще раз.',
|
||||||
|
show_alert: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавим все необходимые методы для обработки коллбэков
|
||||||
|
async handleCreateProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleGenderSelection(chatId: number, telegramId: string, gender: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewMyProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleManagePhotos(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handlePreviewProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditName(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditAge(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditBio(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditHobbies(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditCity(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditJob(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditEducation(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditHeight(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditReligion(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditDatingGoal(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditLifestyle(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditSearchPreferences(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleAddPhoto(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDeletePhoto(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetMainPhoto(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDeletePhotoByIndex(chatId: number, telegramId: string, photoIndex: number): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetMainPhotoByIndex(chatId: number, telegramId: string, photoIndex: number): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetDatingGoal(chatId: number, telegramId: string, goal: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditSmoking(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditDrinking(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditKids(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetLifestyle(chatId: number, telegramId: string, type: string, value: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditAgeRange(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleEditDistance(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleStartBrowsing(chatId: number, telegramId: string, showAll: boolean = false): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleVipSearch(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSearchByGoal(chatId: number, telegramId: string, goal: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleNextCandidate(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleLike(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDislike(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSuperlike(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewProfile(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleMorePhotos(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewMatches(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleOpenChats(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleOpenChat(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSendMessage(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewChatProfile(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleUnmatch(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleConfirmUnmatch(chatId: number, telegramId: string, matchId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSearchSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewStats(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleViewProfileViewers(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleHideProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleDeleteProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleMainMenu(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleConfirmDeleteProfile(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleHowItWorks(chatId: number): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleVipLike(chatId: number, telegramId: string, targetTelegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleVipSuperlike(chatId: number, telegramId: string, targetTelegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleVipDislike(chatId: number, telegramId: string, targetTelegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleLanguageSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleSetLanguage(chatId: number, telegramId: string, languageCode: string): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleTranslateProfile(chatId: number, telegramId: string, profileUserId: number): Promise<void> {
|
||||||
|
// Заглушка метода
|
||||||
|
}
|
||||||
|
|
||||||
|
// Добавим новый метод для настроек уведомлений (вызывает NotificationHandlers)
|
||||||
|
async handleNotificationSettings(chatId: number, telegramId: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
if (this.notificationHandlers) {
|
||||||
|
const userId = await this.profileService.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Вы не зарегистрированы. Используйте команду /start для регистрации.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Вызываем метод из notificationHandlers для получения настроек и отображения меню
|
||||||
|
const settings = await this.notificationHandlers.getNotificationService().getNotificationSettings(userId);
|
||||||
|
await this.notificationHandlers.sendNotificationSettings(chatId, settings);
|
||||||
|
} else {
|
||||||
|
// Если NotificationHandlers недоступен, показываем сообщение об ошибке
|
||||||
|
await this.bot.sendMessage(chatId, '⚙️ Настройки уведомлений временно недоступны. Попробуйте позже.');
|
||||||
|
await this.handleSettings(chatId, telegramId);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling notification settings:', error);
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Произошла ошибка при загрузке настроек уведомлений.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,16 +3,19 @@ import { ProfileService } from '../services/profileService';
|
|||||||
import { MatchingService } from '../services/matchingService';
|
import { MatchingService } from '../services/matchingService';
|
||||||
import { Profile } from '../models/Profile';
|
import { Profile } from '../models/Profile';
|
||||||
import { getUserTranslation } from '../services/localizationService';
|
import { getUserTranslation } from '../services/localizationService';
|
||||||
|
import { NotificationHandlers } from './notificationHandlers';
|
||||||
|
|
||||||
export class CommandHandlers {
|
export class CommandHandlers {
|
||||||
private bot: TelegramBot;
|
private bot: TelegramBot;
|
||||||
private profileService: ProfileService;
|
private profileService: ProfileService;
|
||||||
private matchingService: MatchingService;
|
private matchingService: MatchingService;
|
||||||
|
private notificationHandlers: NotificationHandlers;
|
||||||
|
|
||||||
constructor(bot: TelegramBot) {
|
constructor(bot: TelegramBot) {
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
this.profileService = new ProfileService();
|
this.profileService = new ProfileService();
|
||||||
this.matchingService = new MatchingService();
|
this.matchingService = new MatchingService();
|
||||||
|
this.notificationHandlers = new NotificationHandlers(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
register(): void {
|
register(): void {
|
||||||
@@ -23,6 +26,12 @@ export class CommandHandlers {
|
|||||||
this.bot.onText(/\/matches/, (msg: Message) => this.handleMatches(msg));
|
this.bot.onText(/\/matches/, (msg: Message) => this.handleMatches(msg));
|
||||||
this.bot.onText(/\/settings/, (msg: Message) => this.handleSettings(msg));
|
this.bot.onText(/\/settings/, (msg: Message) => this.handleSettings(msg));
|
||||||
this.bot.onText(/\/create_profile/, (msg: Message) => this.handleCreateProfile(msg));
|
this.bot.onText(/\/create_profile/, (msg: Message) => this.handleCreateProfile(msg));
|
||||||
|
|
||||||
|
// Регистрация обработчика настроек уведомлений
|
||||||
|
this.bot.onText(/\/notifications/, (msg: Message) => this.notificationHandlers.handleNotificationsCommand(msg));
|
||||||
|
|
||||||
|
// Регистрируем обработчики для уведомлений
|
||||||
|
this.notificationHandlers.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleStart(msg: Message): Promise<void> {
|
async handleStart(msg: Message): Promise<void> {
|
||||||
@@ -44,7 +53,8 @@ export class CommandHandlers {
|
|||||||
{ text: '⭐ VIP поиск', callback_data: 'vip_search' }
|
{ text: '⭐ VIP поиск', callback_data: 'vip_search' }
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{ text: '⚙️ Настройки', callback_data: 'settings' }
|
{ text: '⚙️ Настройки', callback_data: 'settings' },
|
||||||
|
{ text: '🔔 Уведомления', callback_data: 'notifications' }
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
@@ -84,6 +94,7 @@ export class CommandHandlers {
|
|||||||
/browse - Просмотр анкет
|
/browse - Просмотр анкет
|
||||||
/matches - Ваши матчи
|
/matches - Ваши матчи
|
||||||
/settings - Настройки
|
/settings - Настройки
|
||||||
|
/notifications - Настройки уведомлений
|
||||||
/help - Эта справка
|
/help - Эта справка
|
||||||
|
|
||||||
<EFBFBD> Как использовать:
|
<EFBFBD> Как использовать:
|
||||||
@@ -191,7 +202,7 @@ export class CommandHandlers {
|
|||||||
inline_keyboard: [
|
inline_keyboard: [
|
||||||
[
|
[
|
||||||
{ text: '🔍 Настройки поиска', callback_data: 'search_settings' },
|
{ text: '🔍 Настройки поиска', callback_data: 'search_settings' },
|
||||||
{ text: '🔔 Уведомления', callback_data: 'notification_settings' }
|
{ text: '🔔 Уведомления', callback_data: 'notifications' }
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
{ text: '🚫 Скрыть профиль', callback_data: 'hide_profile' },
|
{ text: '🚫 Скрыть профиль', callback_data: 'hide_profile' },
|
||||||
@@ -242,7 +253,10 @@ export class CommandHandlers {
|
|||||||
{ text: '✏️ Редактировать', callback_data: 'edit_profile' },
|
{ text: '✏️ Редактировать', callback_data: 'edit_profile' },
|
||||||
{ text: '📸 Фото', callback_data: 'manage_photos' }
|
{ text: '📸 Фото', callback_data: 'manage_photos' }
|
||||||
],
|
],
|
||||||
[{ text: '🔍 Начать поиск', callback_data: 'start_browsing' }]
|
[
|
||||||
|
{ text: '🔍 Начать поиск', callback_data: 'start_browsing' },
|
||||||
|
{ text: '🔔 Уведомления', callback_data: 'notifications' }
|
||||||
|
]
|
||||||
]
|
]
|
||||||
} : {
|
} : {
|
||||||
inline_keyboard: [
|
inline_keyboard: [
|
||||||
|
|||||||
@@ -168,25 +168,24 @@ export class EnhancedChatHandlers {
|
|||||||
|
|
||||||
// ===== СИСТЕМА УВЕДОМЛЕНИЙ =====
|
// ===== СИСТЕМА УВЕДОМЛЕНИЙ =====
|
||||||
|
|
||||||
// Отправить уведомление о новом сообщении
|
// Отправить уведомление о новом сообщении - теперь используем NotificationService
|
||||||
async sendMessageNotification(receiverTelegramId: string, senderName: string, messagePreview: string, matchId: string): Promise<void> {
|
async sendMessageNotification(receiverTelegramId: string, senderName: string, messagePreview: string, matchId: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const receiverChatId = parseInt(receiverTelegramId);
|
// Получаем идентификаторы пользователей для использования в NotificationService
|
||||||
|
const receiverUserId = await this.profileService.getUserIdByTelegramId(receiverTelegramId);
|
||||||
|
const sender = await this.chatService.getMatchInfo(matchId, receiverTelegramId);
|
||||||
|
|
||||||
await this.bot.sendMessage(
|
if (!receiverUserId || !sender?.otherUserId) {
|
||||||
receiverChatId,
|
console.error('Failed to get user IDs for notification');
|
||||||
`💌 *Новое сообщение от ${senderName}*\n\n` +
|
return;
|
||||||
`"${this.escapeMarkdown(messagePreview)}"\n\n` +
|
}
|
||||||
'👆 Нажмите "Открыть чат" для ответа',
|
|
||||||
{
|
// Используем сервис уведомлений для отправки более красивого уведомления
|
||||||
parse_mode: 'Markdown',
|
await this.notificationService.sendMessageNotification(
|
||||||
reply_markup: {
|
receiverUserId,
|
||||||
inline_keyboard: [
|
sender.otherUserId,
|
||||||
[{ text: '💬 Открыть чат', callback_data: `open_native_chat_${matchId}` }],
|
messagePreview,
|
||||||
[{ text: '📱 Все чаты', callback_data: 'native_chats' }]
|
matchId
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error sending message notification:', error);
|
console.error('Error sending message notification:', error);
|
||||||
@@ -218,9 +217,10 @@ export class EnhancedChatHandlers {
|
|||||||
const messageId = await this.chatService.sendMessage(
|
const messageId = await this.chatService.sendMessage(
|
||||||
matchId,
|
matchId,
|
||||||
telegramId,
|
telegramId,
|
||||||
msg.text || '[Медиа]',
|
msg.photo ?
|
||||||
msg.photo ? 'photo' : 'text',
|
(msg.caption || '[Фото]') + ' [file_id: ' + msg.photo[msg.photo.length - 1].file_id + ']' :
|
||||||
msg.photo ? msg.photo[msg.photo.length - 1].file_id : undefined
|
(msg.text || '[Медиа]'),
|
||||||
|
msg.photo ? 'photo' : 'text'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (messageId) {
|
if (messageId) {
|
||||||
|
|||||||
76
src/handlers/likeBackHandler.ts
Normal file
76
src/handlers/likeBackHandler.ts
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import TelegramBot from 'node-telegram-bot-api';
|
||||||
|
import { ProfileService } from '../services/profileService';
|
||||||
|
import { MatchingService } from '../services/matchingService';
|
||||||
|
|
||||||
|
export class LikeBackHandler {
|
||||||
|
private bot: TelegramBot;
|
||||||
|
private profileService: ProfileService;
|
||||||
|
private matchingService: MatchingService;
|
||||||
|
|
||||||
|
constructor(bot: TelegramBot) {
|
||||||
|
this.bot = bot;
|
||||||
|
this.profileService = new ProfileService();
|
||||||
|
this.matchingService = new MatchingService();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Функция для обработки обратного лайка из уведомления
|
||||||
|
async handleLikeBack(chatId: number, telegramId: string, targetUserId: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
// Получаем информацию о пользователях
|
||||||
|
const [userId, targetProfile] = await Promise.all([
|
||||||
|
this.profileService.getUserIdByTelegramId(telegramId),
|
||||||
|
this.profileService.getProfileByUserId(targetUserId)
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!userId || !targetProfile) {
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Не удалось найти профиль');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем, есть ли уже свайп
|
||||||
|
const existingSwipe = await this.matchingService.getSwipeBetweenUsers(userId, targetUserId);
|
||||||
|
if (existingSwipe) {
|
||||||
|
await this.bot.sendMessage(chatId, '❓ Вы уже оценили этот профиль ранее.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создаем свайп (лайк)
|
||||||
|
const result = await this.matchingService.createSwipe(userId, targetUserId, 'like');
|
||||||
|
|
||||||
|
if (result.isMatch) {
|
||||||
|
// Это матч!
|
||||||
|
await this.bot.sendMessage(
|
||||||
|
chatId,
|
||||||
|
'🎉 *Поздравляем! Это взаимно!*\n\n' +
|
||||||
|
`Вы и *${targetProfile.name}* понравились друг другу!\n` +
|
||||||
|
'Теперь вы можете начать общение.',
|
||||||
|
{
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '💬 Начать общение', callback_data: `start_chat:${targetUserId}` }],
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: `view_profile:${targetUserId}` }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await this.bot.sendMessage(
|
||||||
|
chatId,
|
||||||
|
'❤️ Вам понравился профиль ' + targetProfile.name + '!\n\n' +
|
||||||
|
'Если вы также понравитесь этому пользователю, будет создан матч.',
|
||||||
|
{
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '🔍 Продолжить поиск', callback_data: 'start_browsing' }]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in handleLikeBack:', error);
|
||||||
|
await this.bot.sendMessage(chatId, '❌ Произошла ошибка при обработке лайка');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -217,11 +217,12 @@ export class MessageHandlers {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Добавляем специальный callback для новых пользователей
|
||||||
const keyboard: InlineKeyboardMarkup = {
|
const keyboard: InlineKeyboardMarkup = {
|
||||||
inline_keyboard: [
|
inline_keyboard: [
|
||||||
[
|
[
|
||||||
{ text: '👤 Мой профиль', callback_data: 'view_my_profile' },
|
{ text: '👤 Мой профиль', callback_data: 'view_my_profile' },
|
||||||
{ text: '🔍 Начать поиск', callback_data: 'start_browsing' }
|
{ text: '🔍 Начать поиск', callback_data: 'start_browsing_first' }
|
||||||
],
|
],
|
||||||
[{ text: '⚙️ Настройки', callback_data: 'settings' }]
|
[{ text: '⚙️ Настройки', callback_data: 'settings' }]
|
||||||
]
|
]
|
||||||
@@ -493,7 +494,7 @@ export class MessageHandlers {
|
|||||||
updates.hobbies = value;
|
updates.hobbies = value;
|
||||||
break;
|
break;
|
||||||
case 'city':
|
case 'city':
|
||||||
// В БД поле называется 'location', но мы используем city в модели
|
// В БД поле называется 'city' (не 'location')
|
||||||
updates.city = value;
|
updates.city = value;
|
||||||
break;
|
break;
|
||||||
case 'job':
|
case 'job':
|
||||||
|
|||||||
644
src/handlers/notificationHandlers.ts
Normal file
644
src/handlers/notificationHandlers.ts
Normal file
@@ -0,0 +1,644 @@
|
|||||||
|
import TelegramBot from 'node-telegram-bot-api';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
import { query } from '../database/connection';
|
||||||
|
import { NotificationService } from '../services/notificationService';
|
||||||
|
|
||||||
|
interface NotificationSettings {
|
||||||
|
newMatches: boolean;
|
||||||
|
newMessages: boolean;
|
||||||
|
newLikes: boolean;
|
||||||
|
reminders: boolean;
|
||||||
|
dailySummary: boolean;
|
||||||
|
timePreference: 'morning' | 'afternoon' | 'evening' | 'night';
|
||||||
|
doNotDisturb: boolean;
|
||||||
|
doNotDisturbStart?: string;
|
||||||
|
doNotDisturbEnd?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NotificationHandlers {
|
||||||
|
private bot: TelegramBot;
|
||||||
|
private notificationService: NotificationService;
|
||||||
|
|
||||||
|
constructor(bot: TelegramBot) {
|
||||||
|
this.bot = bot;
|
||||||
|
this.notificationService = new NotificationService(bot);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Метод для получения экземпляра сервиса уведомлений
|
||||||
|
getNotificationService(): NotificationService {
|
||||||
|
return this.notificationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка команды /notifications
|
||||||
|
async handleNotificationsCommand(msg: TelegramBot.Message): Promise<void> {
|
||||||
|
const telegramId = msg.from?.id.toString();
|
||||||
|
if (!telegramId) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = await this.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.sendMessage(msg.chat.id, '❌ Вы не зарегистрированы. Используйте команду /start для регистрации.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = await this.notificationService.getNotificationSettings(userId);
|
||||||
|
await this.sendNotificationSettings(msg.chat.id, settings as NotificationSettings);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling notifications command:', error);
|
||||||
|
await this.bot.sendMessage(msg.chat.id, '❌ Произошла ошибка при загрузке настроек уведомлений.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Отправка меню настроек уведомлений
|
||||||
|
async sendNotificationSettings(chatId: number, settings: NotificationSettings): Promise<void> {
|
||||||
|
const message = `
|
||||||
|
🔔 *Настройки уведомлений*
|
||||||
|
|
||||||
|
Выберите, какие уведомления вы хотите получать:
|
||||||
|
|
||||||
|
${settings.newMatches ? '✅' : '❌'} Новые матчи
|
||||||
|
${settings.newMessages ? '✅' : '❌'} Новые сообщения
|
||||||
|
${settings.newLikes ? '✅' : '❌'} Новые лайки
|
||||||
|
${settings.reminders ? '✅' : '❌'} Напоминания
|
||||||
|
${settings.dailySummary ? '✅' : '❌'} Ежедневные сводки
|
||||||
|
|
||||||
|
⏰ Предпочтительное время: ${this.getTimePreferenceText(settings.timePreference)}
|
||||||
|
|
||||||
|
${settings.doNotDisturb ? '🔕' : '🔔'} Режим "Не беспокоить": ${settings.doNotDisturb ? 'Включен' : 'Выключен'}
|
||||||
|
${settings.doNotDisturb && settings.doNotDisturbStart && settings.doNotDisturbEnd ?
|
||||||
|
`с ${settings.doNotDisturbStart} до ${settings.doNotDisturbEnd}` : ''}
|
||||||
|
|
||||||
|
Нажмите на кнопку, чтобы изменить настройку:
|
||||||
|
`;
|
||||||
|
|
||||||
|
await this.bot.sendMessage(chatId, message, {
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[
|
||||||
|
{ text: `${settings.newMatches ? '✅' : '❌'} Новые матчи`, callback_data: 'notif_toggle:newMatches' },
|
||||||
|
{ text: `${settings.newMessages ? '✅' : '❌'} Новые сообщения`, callback_data: 'notif_toggle:newMessages' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: `${settings.newLikes ? '✅' : '❌'} Новые лайки`, callback_data: 'notif_toggle:newLikes' },
|
||||||
|
{ text: `${settings.reminders ? '✅' : '❌'} Напоминания`, callback_data: 'notif_toggle:reminders' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: `${settings.dailySummary ? '✅' : '❌'} Ежедневные сводки`, callback_data: 'notif_toggle:dailySummary' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: `⏰ Время: ${this.getTimePreferenceText(settings.timePreference)}`, callback_data: 'notif_time' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: `${settings.doNotDisturb ? '🔕' : '🔔'} Режим "Не беспокоить"`, callback_data: 'notif_dnd' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '↩️ Назад', callback_data: 'settings' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка переключения настройки уведомления
|
||||||
|
async handleNotificationToggle(callbackQuery: TelegramBot.CallbackQuery): Promise<void> {
|
||||||
|
const telegramId = callbackQuery.from?.id.toString();
|
||||||
|
if (!telegramId || !callbackQuery.message) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = await this.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Вы не зарегистрированы.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// notif_toggle:settingName
|
||||||
|
const settingName = callbackQuery.data?.split(':')[1];
|
||||||
|
if (!settingName) return;
|
||||||
|
|
||||||
|
const settings = await this.notificationService.getNotificationSettings(userId);
|
||||||
|
let updatedSettings: Partial<NotificationSettings> = { ...settings };
|
||||||
|
|
||||||
|
// Инвертируем значение настройки
|
||||||
|
if (settingName in updatedSettings) {
|
||||||
|
switch(settingName) {
|
||||||
|
case 'newMatches':
|
||||||
|
updatedSettings.newMatches = !updatedSettings.newMatches;
|
||||||
|
break;
|
||||||
|
case 'newMessages':
|
||||||
|
updatedSettings.newMessages = !updatedSettings.newMessages;
|
||||||
|
break;
|
||||||
|
case 'newLikes':
|
||||||
|
updatedSettings.newLikes = !updatedSettings.newLikes;
|
||||||
|
break;
|
||||||
|
case 'reminders':
|
||||||
|
updatedSettings.reminders = !updatedSettings.reminders;
|
||||||
|
break;
|
||||||
|
case 'dailySummary':
|
||||||
|
updatedSettings.dailySummary = !updatedSettings.dailySummary;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обновляем настройки
|
||||||
|
await this.notificationService.updateNotificationSettings(userId, updatedSettings);
|
||||||
|
|
||||||
|
// Отправляем обновленные настройки
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, {
|
||||||
|
text: `✅ Настройка "${this.getSettingName(settingName)}" ${updatedSettings[settingName as keyof NotificationSettings] ? 'включена' : 'отключена'}`
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.sendNotificationSettings(callbackQuery.message.chat.id, updatedSettings as NotificationSettings);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling notification toggle:', error);
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Произошла ошибка при обновлении настроек.' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка выбора времени для уведомлений
|
||||||
|
async handleTimePreference(callbackQuery: TelegramBot.CallbackQuery): Promise<void> {
|
||||||
|
if (!callbackQuery.message) return;
|
||||||
|
|
||||||
|
await this.bot.editMessageText('⏰ *Выберите предпочтительное время для уведомлений:*', {
|
||||||
|
chat_id: callbackQuery.message.chat.id,
|
||||||
|
message_id: callbackQuery.message.message_id,
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[
|
||||||
|
{ text: '🌅 Утро (9:00)', callback_data: 'notif_time_set:morning' },
|
||||||
|
{ text: '☀️ День (13:00)', callback_data: 'notif_time_set:afternoon' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '🌆 Вечер (19:00)', callback_data: 'notif_time_set:evening' },
|
||||||
|
{ text: '🌙 Ночь (22:00)', callback_data: 'notif_time_set:night' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '↩️ Назад', callback_data: 'notifications' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка установки времени для уведомлений
|
||||||
|
async handleTimePreferenceSet(callbackQuery: TelegramBot.CallbackQuery): Promise<void> {
|
||||||
|
const telegramId = callbackQuery.from?.id.toString();
|
||||||
|
if (!telegramId || !callbackQuery.message) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = await this.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Вы не зарегистрированы.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// notif_time_set:timePreference
|
||||||
|
const timePreference = callbackQuery.data?.split(':')[1] as 'morning' | 'afternoon' | 'evening' | 'night';
|
||||||
|
if (!timePreference) return;
|
||||||
|
|
||||||
|
const settings = await this.notificationService.getNotificationSettings(userId);
|
||||||
|
// Копируем существующие настройки и обновляем нужные поля
|
||||||
|
const existingSettings = settings as NotificationSettings;
|
||||||
|
const updatedSettings: NotificationSettings = {
|
||||||
|
...existingSettings,
|
||||||
|
timePreference
|
||||||
|
};
|
||||||
|
|
||||||
|
// Обновляем настройки
|
||||||
|
await this.notificationService.updateNotificationSettings(userId, updatedSettings);
|
||||||
|
|
||||||
|
// Отправляем обновленные настройки
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, {
|
||||||
|
text: `✅ Время уведомлений установлено на ${this.getTimePreferenceText(timePreference)}`
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.sendNotificationSettings(callbackQuery.message.chat.id, updatedSettings);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling time preference set:', error);
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Произошла ошибка при обновлении времени уведомлений.' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка режима "Не беспокоить"
|
||||||
|
async handleDndMode(callbackQuery: TelegramBot.CallbackQuery): Promise<void> {
|
||||||
|
if (!callbackQuery.message) return;
|
||||||
|
|
||||||
|
await this.bot.editMessageText('🔕 *Режим "Не беспокоить"*\n\nВыберите действие:', {
|
||||||
|
chat_id: callbackQuery.message.chat.id,
|
||||||
|
message_id: callbackQuery.message.message_id,
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[
|
||||||
|
{ text: '✅ Включить', callback_data: 'notif_dnd_set:on' },
|
||||||
|
{ text: '❌ Выключить', callback_data: 'notif_dnd_set:off' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '⏰ Настроить время', callback_data: 'notif_dnd_time' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '↩️ Назад', callback_data: 'notifications' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка установки режима "Не беспокоить"
|
||||||
|
async handleDndModeSet(callbackQuery: TelegramBot.CallbackQuery): Promise<void> {
|
||||||
|
const telegramId = callbackQuery.from?.id.toString();
|
||||||
|
if (!telegramId || !callbackQuery.message) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = await this.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Вы не зарегистрированы.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// notif_dnd_set:on/off
|
||||||
|
const mode = callbackQuery.data?.split(':')[1];
|
||||||
|
if (!mode) return;
|
||||||
|
|
||||||
|
const settings = await this.notificationService.getNotificationSettings(userId);
|
||||||
|
// Копируем существующие настройки и обновляем нужное поле
|
||||||
|
const existingSettings = settings as NotificationSettings;
|
||||||
|
let updatedSettings: NotificationSettings = {
|
||||||
|
...existingSettings,
|
||||||
|
doNotDisturb: mode === 'on'
|
||||||
|
};
|
||||||
|
|
||||||
|
// Если включаем режим "Не беспокоить", но не задано время, ставим дефолтные значения
|
||||||
|
if (mode === 'on' && (!updatedSettings.doNotDisturbStart || !updatedSettings.doNotDisturbEnd)) {
|
||||||
|
updatedSettings.doNotDisturbStart = '23:00';
|
||||||
|
updatedSettings.doNotDisturbEnd = '08:00';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обновляем настройки
|
||||||
|
await this.notificationService.updateNotificationSettings(userId, updatedSettings);
|
||||||
|
|
||||||
|
// Отправляем обновленные настройки
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, {
|
||||||
|
text: `✅ Режим "Не беспокоить" ${mode === 'on' ? 'включен' : 'выключен'}`
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.sendNotificationSettings(callbackQuery.message.chat.id, updatedSettings);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling DND mode set:', error);
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Произошла ошибка при обновлении режима "Не беспокоить".' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Настройка времени для режима "Не беспокоить"
|
||||||
|
async handleDndTimeSetup(callbackQuery: TelegramBot.CallbackQuery): Promise<void> {
|
||||||
|
if (!callbackQuery.message) return;
|
||||||
|
|
||||||
|
await this.bot.editMessageText('⏰ *Настройка времени для режима "Не беспокоить"*\n\nВыберите один из предустановленных вариантов или введите свой:', {
|
||||||
|
chat_id: callbackQuery.message.chat.id,
|
||||||
|
message_id: callbackQuery.message.message_id,
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[
|
||||||
|
{ text: '🌙 23:00 - 08:00', callback_data: 'notif_dnd_time_set:23:00:08:00' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '🌙 22:00 - 07:00', callback_data: 'notif_dnd_time_set:22:00:07:00' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '🌙 00:00 - 09:00', callback_data: 'notif_dnd_time_set:00:00:09:00' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '✏️ Ввести свой вариант', callback_data: 'notif_dnd_time_custom' }
|
||||||
|
],
|
||||||
|
[
|
||||||
|
{ text: '↩️ Назад', callback_data: 'notif_dnd' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Установка предустановленного времени для режима "Не беспокоить"
|
||||||
|
async handleDndTimeSet(callbackQuery: TelegramBot.CallbackQuery): Promise<void> {
|
||||||
|
const telegramId = callbackQuery.from?.id.toString();
|
||||||
|
if (!telegramId || !callbackQuery.message) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = await this.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Вы не зарегистрированы.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// notif_dnd_time_set:startTime:endTime
|
||||||
|
const parts = callbackQuery.data?.split(':');
|
||||||
|
if (parts && parts.length >= 4) {
|
||||||
|
const startTime = `${parts[2]}:${parts[3]}`;
|
||||||
|
const endTime = `${parts[4]}:${parts[5]}`;
|
||||||
|
|
||||||
|
const settings = await this.notificationService.getNotificationSettings(userId);
|
||||||
|
// Копируем существующие настройки и обновляем нужные поля
|
||||||
|
const existingSettings = settings as NotificationSettings;
|
||||||
|
const updatedSettings: NotificationSettings = {
|
||||||
|
...existingSettings,
|
||||||
|
doNotDisturb: true,
|
||||||
|
doNotDisturbStart: startTime,
|
||||||
|
doNotDisturbEnd: endTime
|
||||||
|
};
|
||||||
|
|
||||||
|
// Обновляем настройки
|
||||||
|
await this.notificationService.updateNotificationSettings(userId, updatedSettings);
|
||||||
|
|
||||||
|
// Отправляем обновленные настройки
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, {
|
||||||
|
text: `✅ Время "Не беспокоить" установлено с ${startTime} до ${endTime}`
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.sendNotificationSettings(callbackQuery.message.chat.id, updatedSettings);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling DND time set:', error);
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Произошла ошибка при настройке времени "Не беспокоить".' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запрос пользовательского времени для режима "Не беспокоить"
|
||||||
|
async handleDndTimeCustom(callbackQuery: TelegramBot.CallbackQuery): Promise<void> {
|
||||||
|
if (!callbackQuery.message) return;
|
||||||
|
|
||||||
|
// Устанавливаем ожидание пользовательского ввода
|
||||||
|
const userId = callbackQuery.from?.id.toString();
|
||||||
|
if (userId) {
|
||||||
|
await this.setUserState(userId, 'waiting_dnd_time');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.bot.editMessageText('⏰ *Введите время для режима "Не беспокоить"*\n\nУкажите время в формате:\n`с [ЧЧ:ММ] до [ЧЧ:ММ]`\n\nНапример: `с 23:30 до 07:00`', {
|
||||||
|
chat_id: callbackQuery.message.chat.id,
|
||||||
|
message_id: callbackQuery.message.message_id,
|
||||||
|
parse_mode: 'Markdown',
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [
|
||||||
|
[
|
||||||
|
{ text: '↩️ Отмена', callback_data: 'notif_dnd_time' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обработка пользовательского ввода времени для режима "Не беспокоить"
|
||||||
|
async handleDndTimeInput(msg: TelegramBot.Message): Promise<void> {
|
||||||
|
const telegramId = msg.from?.id.toString();
|
||||||
|
if (!telegramId) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = await this.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.sendMessage(msg.chat.id, '❌ Вы не зарегистрированы. Используйте команду /start для регистрации.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Очищаем состояние ожидания
|
||||||
|
await this.clearUserState(telegramId);
|
||||||
|
|
||||||
|
// Парсим введенное время
|
||||||
|
const timeRegex = /с\s+(\d{1,2}[:\.]\d{2})\s+до\s+(\d{1,2}[:\.]\d{2})/i;
|
||||||
|
const match = msg.text?.match(timeRegex);
|
||||||
|
|
||||||
|
if (match && match.length >= 3) {
|
||||||
|
let startTime = match[1].replace('.', ':');
|
||||||
|
let endTime = match[2].replace('.', ':');
|
||||||
|
|
||||||
|
// Проверяем и форматируем время
|
||||||
|
if (this.isValidTime(startTime) && this.isValidTime(endTime)) {
|
||||||
|
startTime = this.formatTime(startTime);
|
||||||
|
endTime = this.formatTime(endTime);
|
||||||
|
|
||||||
|
const settings = await this.notificationService.getNotificationSettings(userId);
|
||||||
|
// Копируем существующие настройки и обновляем нужные поля
|
||||||
|
const existingSettings = settings as NotificationSettings;
|
||||||
|
const updatedSettings: NotificationSettings = {
|
||||||
|
...existingSettings,
|
||||||
|
doNotDisturb: true,
|
||||||
|
doNotDisturbStart: startTime,
|
||||||
|
doNotDisturbEnd: endTime
|
||||||
|
};
|
||||||
|
|
||||||
|
// Обновляем настройки
|
||||||
|
await this.notificationService.updateNotificationSettings(userId, updatedSettings);
|
||||||
|
|
||||||
|
await this.bot.sendMessage(msg.chat.id, `✅ Время "Не беспокоить" установлено с ${startTime} до ${endTime}`);
|
||||||
|
await this.sendNotificationSettings(msg.chat.id, updatedSettings);
|
||||||
|
} else {
|
||||||
|
await this.bot.sendMessage(msg.chat.id, '❌ Неверный формат времени. Пожалуйста, используйте формат ЧЧ:ММ (например, 23:30).');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await this.bot.sendMessage(msg.chat.id, '❌ Неверный формат ввода. Пожалуйста, введите время в формате "с [ЧЧ:ММ] до [ЧЧ:ММ]" (например, "с 23:30 до 07:00").');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling DND time input:', error);
|
||||||
|
await this.bot.sendMessage(msg.chat.id, '❌ Произошла ошибка при настройке времени "Не беспокоить".');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка валидности времени
|
||||||
|
private isValidTime(time: string): boolean {
|
||||||
|
const regex = /^(\d{1,2}):(\d{2})$/;
|
||||||
|
const match = time.match(regex);
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
const hours = parseInt(match[1]);
|
||||||
|
const minutes = parseInt(match[2]);
|
||||||
|
return hours >= 0 && hours <= 23 && minutes >= 0 && minutes <= 59;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Форматирование времени в формат ЧЧ:ММ
|
||||||
|
private formatTime(time: string): string {
|
||||||
|
const [hours, minutes] = time.split(':').map(Number);
|
||||||
|
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получение текстового представления времени
|
||||||
|
private getTimePreferenceText(preference: string): string {
|
||||||
|
switch (preference) {
|
||||||
|
case 'morning': return 'Утро (9:00)';
|
||||||
|
case 'afternoon': return 'День (13:00)';
|
||||||
|
case 'evening': return 'Вечер (19:00)';
|
||||||
|
case 'night': return 'Ночь (22:00)';
|
||||||
|
default: return 'Вечер (19:00)';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получение названия настройки
|
||||||
|
private getSettingName(setting: string): string {
|
||||||
|
switch (setting) {
|
||||||
|
case 'newMatches': return 'Новые матчи';
|
||||||
|
case 'newMessages': return 'Новые сообщения';
|
||||||
|
case 'newLikes': return 'Новые лайки';
|
||||||
|
case 'reminders': return 'Напоминания';
|
||||||
|
case 'dailySummary': return 'Ежедневные сводки';
|
||||||
|
default: return setting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получение ID пользователя по Telegram ID
|
||||||
|
private async getUserIdByTelegramId(telegramId: string): Promise<string | null> {
|
||||||
|
try {
|
||||||
|
const result = await query(
|
||||||
|
'SELECT id FROM users WHERE telegram_id = $1',
|
||||||
|
[parseInt(telegramId)]
|
||||||
|
);
|
||||||
|
return result.rows.length > 0 ? result.rows[0].id : null;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error getting user by telegram ID:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Установка состояния ожидания пользователя
|
||||||
|
private async setUserState(telegramId: string, state: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
const userId = await this.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) return;
|
||||||
|
|
||||||
|
// Сначала проверяем, существуют ли столбцы state и state_data
|
||||||
|
const checkColumnResult = await query(`
|
||||||
|
SELECT column_name
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = 'users' AND column_name = 'state'
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (checkColumnResult.rows.length === 0) {
|
||||||
|
console.log('Adding state and state_data columns to users table...');
|
||||||
|
// Добавляем столбцы, если их нет
|
||||||
|
await query(`
|
||||||
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS state VARCHAR(255) NULL;
|
||||||
|
ALTER TABLE users ADD COLUMN IF NOT EXISTS state_data JSONB DEFAULT '{}'::jsonb;
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Теперь устанавливаем состояние
|
||||||
|
await query(
|
||||||
|
`UPDATE users
|
||||||
|
SET state = $1,
|
||||||
|
state_data = jsonb_set(COALESCE(state_data, '{}'::jsonb), '{timestamp}', to_jsonb(NOW()))
|
||||||
|
WHERE telegram_id = $2`,
|
||||||
|
[state, parseInt(telegramId)]
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error setting user state:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Очистка состояния ожидания пользователя
|
||||||
|
private async clearUserState(telegramId: string): Promise<void> {
|
||||||
|
try {
|
||||||
|
await query(
|
||||||
|
'UPDATE users SET state = NULL WHERE telegram_id = $1',
|
||||||
|
[parseInt(telegramId)]
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error clearing user state:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Регистрация обработчиков уведомлений
|
||||||
|
register(): void {
|
||||||
|
// Команда настройки уведомлений
|
||||||
|
this.bot.onText(/\/notifications/, this.handleNotificationsCommand.bind(this));
|
||||||
|
|
||||||
|
// Обработчик для кнопки настроек уведомлений в меню настроек
|
||||||
|
this.bot.on('callback_query', async (callbackQuery) => {
|
||||||
|
if (callbackQuery.data === 'notifications') {
|
||||||
|
const telegramId = callbackQuery.from?.id.toString();
|
||||||
|
if (!telegramId || !callbackQuery.message) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const userId = await this.getUserIdByTelegramId(telegramId);
|
||||||
|
if (!userId) {
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Вы не зарегистрированы.' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settings = await this.notificationService.getNotificationSettings(userId);
|
||||||
|
await this.sendNotificationSettings(callbackQuery.message.chat.id, settings as NotificationSettings);
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error handling notifications callback:', error);
|
||||||
|
await this.bot.answerCallbackQuery(callbackQuery.id, { text: '❌ Произошла ошибка при загрузке настроек уведомлений.' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (callbackQuery.data?.startsWith('notif_toggle:')) {
|
||||||
|
await this.handleNotificationToggle(callbackQuery);
|
||||||
|
}
|
||||||
|
else if (callbackQuery.data === 'notif_time') {
|
||||||
|
await this.handleTimePreference(callbackQuery);
|
||||||
|
}
|
||||||
|
else if (callbackQuery.data?.startsWith('notif_time_set:')) {
|
||||||
|
await this.handleTimePreferenceSet(callbackQuery);
|
||||||
|
}
|
||||||
|
else if (callbackQuery.data === 'notif_dnd') {
|
||||||
|
await this.handleDndMode(callbackQuery);
|
||||||
|
}
|
||||||
|
else if (callbackQuery.data?.startsWith('notif_dnd_set:')) {
|
||||||
|
await this.handleDndModeSet(callbackQuery);
|
||||||
|
}
|
||||||
|
else if (callbackQuery.data === 'notif_dnd_time') {
|
||||||
|
await this.handleDndTimeSetup(callbackQuery);
|
||||||
|
}
|
||||||
|
else if (callbackQuery.data?.startsWith('notif_dnd_time_set:')) {
|
||||||
|
await this.handleDndTimeSet(callbackQuery);
|
||||||
|
}
|
||||||
|
else if (callbackQuery.data === 'notif_dnd_time_custom') {
|
||||||
|
await this.handleDndTimeCustom(callbackQuery);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Обработчик пользовательского ввода для времени "Не беспокоить"
|
||||||
|
this.bot.on('message', async (msg) => {
|
||||||
|
if (!msg.text) return;
|
||||||
|
|
||||||
|
const telegramId = msg.from?.id.toString();
|
||||||
|
if (!telegramId) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Сначала проверяем, существует ли столбец state
|
||||||
|
const checkColumnResult = await query(`
|
||||||
|
SELECT column_name
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = 'users' AND column_name = 'state'
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (checkColumnResult.rows.length === 0) {
|
||||||
|
console.log('State column does not exist in users table. Skipping state check.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Теперь проверяем состояние пользователя
|
||||||
|
const result = await query(
|
||||||
|
'SELECT state FROM users WHERE telegram_id = $1',
|
||||||
|
[parseInt(telegramId)]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.rows.length > 0 && result.rows[0].state === 'waiting_dnd_time') {
|
||||||
|
await this.handleDndTimeInput(msg);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error checking user state:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
62
src/premium/README.md
Normal file
62
src/premium/README.md
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# Модуль премиум-функций Telegram Tinder Bot
|
||||||
|
|
||||||
|
Этот каталог содержит модули и скрипты для управления премиум-функциями бота.
|
||||||
|
|
||||||
|
## Содержимое
|
||||||
|
|
||||||
|
- `add-premium-columns.js` - Добавление колонок для премиум-функций в базу данных (версия JavaScript)
|
||||||
|
- `add-premium-columns.ts` - Добавление колонок для премиум-функций в базу данных (версия TypeScript)
|
||||||
|
- `add-premium-columns-direct.js` - Прямое добавление премиум-колонок без миграций
|
||||||
|
- `addPremiumColumn.js` - Добавление отдельной колонки премиум в таблицу пользователей
|
||||||
|
- `setPremiumStatus.js` - Обновление статуса премиум для пользователей
|
||||||
|
|
||||||
|
## Премиум-функции
|
||||||
|
|
||||||
|
В боте реализованы следующие премиум-функции:
|
||||||
|
|
||||||
|
1. **Неограниченные лайки** - снятие дневного лимита на количество лайков
|
||||||
|
2. **Супер-лайки** - возможность отправлять супер-лайки (повышенный приоритет)
|
||||||
|
3. **Просмотр лайков** - возможность видеть, кто поставил лайк вашему профилю
|
||||||
|
4. **Скрытый режим** - возможность скрывать свою активность
|
||||||
|
5. **Расширенные фильтры** - дополнительные параметры для поиска
|
||||||
|
|
||||||
|
## Использование
|
||||||
|
|
||||||
|
### Добавление премиум-колонок в базу данных
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node src/premium/add-premium-columns.js
|
||||||
|
```
|
||||||
|
|
||||||
|
### Изменение премиум-статуса пользователя
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { PremiumService } from '../services/premiumService';
|
||||||
|
|
||||||
|
// Установка премиум-статуса для пользователя
|
||||||
|
const premiumService = new PremiumService();
|
||||||
|
await premiumService.setPremiumStatus(userId, true, 30); // 30 дней премиума
|
||||||
|
```
|
||||||
|
|
||||||
|
## Интеграция в основной код
|
||||||
|
|
||||||
|
Проверка премиум-статуса должна выполняться следующим образом:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// В классах контроллеров
|
||||||
|
const isPremium = await this.premiumService.checkUserPremium(userId);
|
||||||
|
|
||||||
|
if (isPremium) {
|
||||||
|
// Предоставить премиум-функцию
|
||||||
|
} else {
|
||||||
|
// Сообщить о необходимости премиум-подписки
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Период действия премиум-статуса
|
||||||
|
|
||||||
|
По умолчанию премиум-статус устанавливается на 30 дней. Для изменения срока используйте третий параметр в методе `setPremiumStatus`.
|
||||||
|
|
||||||
|
## Дополнительная информация
|
||||||
|
|
||||||
|
Более подробная информация о премиум-функциях содержится в документации проекта в каталоге `docs/VIP_FUNCTIONS.md`.
|
||||||
46
src/premium/add-premium-columns-direct.js
Normal file
46
src/premium/add-premium-columns-direct.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// add-premium-columns.js
|
||||||
|
// Скрипт для добавления колонок premium и premium_expires_at в таблицу users
|
||||||
|
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
// Настройки подключения к базе данных из переменных окружения
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST || 'localhost',
|
||||||
|
port: process.env.DB_PORT || 5432,
|
||||||
|
database: process.env.DB_NAME || 'telegram_tinder_bot',
|
||||||
|
user: process.env.DB_USERNAME || 'postgres',
|
||||||
|
password: process.env.DB_PASSWORD || ''
|
||||||
|
});
|
||||||
|
|
||||||
|
async function addPremiumColumns() {
|
||||||
|
try {
|
||||||
|
console.log('Подключение к базе данных...');
|
||||||
|
const client = await pool.connect();
|
||||||
|
|
||||||
|
console.log('Добавление колонок premium и premium_expires_at в таблицу users...');
|
||||||
|
|
||||||
|
// SQL запрос для добавления колонок
|
||||||
|
const sql = `
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS premium BOOLEAN DEFAULT FALSE,
|
||||||
|
ADD COLUMN IF NOT EXISTS premium_expires_at TIMESTAMP;
|
||||||
|
`;
|
||||||
|
|
||||||
|
await client.query(sql);
|
||||||
|
console.log('✅ Колонки premium и premium_expires_at успешно добавлены в таблицу users');
|
||||||
|
|
||||||
|
// Закрытие соединения
|
||||||
|
client.release();
|
||||||
|
await pool.end();
|
||||||
|
console.log('Подключение к базе данных закрыто');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при добавлении колонок:', error);
|
||||||
|
await pool.end();
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запуск функции
|
||||||
|
addPremiumColumns();
|
||||||
40
src/premium/add-premium-columns.js
Normal file
40
src/premium/add-premium-columns.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// add-premium-columns.js
|
||||||
|
// Скрипт для добавления колонок premium и premium_expires_at в таблицу users
|
||||||
|
|
||||||
|
const { Client } = require('pg');
|
||||||
|
|
||||||
|
// Настройки подключения к базе данных
|
||||||
|
const client = new Client({
|
||||||
|
host: '192.168.0.102',
|
||||||
|
port: 5432,
|
||||||
|
user: 'trevor',
|
||||||
|
password: 'Cl0ud_1985!',
|
||||||
|
database: 'telegram_tinder_bot'
|
||||||
|
});
|
||||||
|
|
||||||
|
async function addPremiumColumns() {
|
||||||
|
try {
|
||||||
|
await client.connect();
|
||||||
|
console.log('Подключение к базе данных успешно установлено');
|
||||||
|
|
||||||
|
// SQL запрос для добавления колонок
|
||||||
|
const sql = `
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS premium BOOLEAN DEFAULT FALSE,
|
||||||
|
ADD COLUMN IF NOT EXISTS premium_expires_at TIMESTAMP;
|
||||||
|
`;
|
||||||
|
|
||||||
|
await client.query(sql);
|
||||||
|
console.log('Колонки premium и premium_expires_at успешно добавлены в таблицу users');
|
||||||
|
|
||||||
|
// Закрываем подключение
|
||||||
|
await client.end();
|
||||||
|
console.log('Подключение к базе данных закрыто');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при добавлении колонок:', error);
|
||||||
|
await client.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запуск функции
|
||||||
|
addPremiumColumns();
|
||||||
28
src/premium/add-premium-columns.ts
Normal file
28
src/premium/add-premium-columns.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// add-premium-columns.ts
|
||||||
|
// Скрипт для добавления колонок premium и premium_expires_at в таблицу users
|
||||||
|
|
||||||
|
import { query } from '../database/connection';
|
||||||
|
|
||||||
|
async function addPremiumColumns() {
|
||||||
|
try {
|
||||||
|
console.log('Добавление колонок premium и premium_expires_at в таблицу users...');
|
||||||
|
|
||||||
|
// SQL запрос для добавления колонок
|
||||||
|
const sql = `
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS premium BOOLEAN DEFAULT FALSE,
|
||||||
|
ADD COLUMN IF NOT EXISTS premium_expires_at TIMESTAMP;
|
||||||
|
`;
|
||||||
|
|
||||||
|
await query(sql);
|
||||||
|
console.log('✅ Колонки premium и premium_expires_at успешно добавлены в таблицу users');
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при добавлении колонок:', error);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запуск функции
|
||||||
|
addPremiumColumns();
|
||||||
58
src/premium/addPremiumColumn.js
Normal file
58
src/premium/addPremiumColumn.js
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// Скрипт для добавления колонки premium в таблицу users и установки premium для всех пользователей
|
||||||
|
require('dotenv').config();
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
// Создаем пул соединений
|
||||||
|
const pool = new Pool({
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432')
|
||||||
|
});
|
||||||
|
|
||||||
|
async function setAllUsersToPremium() {
|
||||||
|
try {
|
||||||
|
console.log('Проверяем наличие столбца premium в таблице users...');
|
||||||
|
|
||||||
|
const result = await pool.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.columns
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = 'users'
|
||||||
|
AND column_name = 'premium'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!result.rows[0].exists) {
|
||||||
|
console.log('🔄 Добавляем столбец premium...');
|
||||||
|
await pool.query(`ALTER TABLE users ADD COLUMN premium BOOLEAN DEFAULT false;`);
|
||||||
|
console.log('✅ Столбец premium успешно добавлен');
|
||||||
|
} else {
|
||||||
|
console.log('✅ Столбец premium уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Устанавливаем премиум-статус для всех пользователей...');
|
||||||
|
|
||||||
|
const updateResult = await pool.query(`
|
||||||
|
UPDATE users
|
||||||
|
SET premium = true
|
||||||
|
WHERE true
|
||||||
|
RETURNING id, telegram_id, premium
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(`✅ Успешно установлен премиум-статус для ${updateResult.rows.length} пользователей:`);
|
||||||
|
updateResult.rows.forEach(row => {
|
||||||
|
console.log(`ID: ${row.id.substr(0, 8)}... | Telegram ID: ${row.telegram_id} | Premium: ${row.premium}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('🎉 Все пользователи теперь имеют премиум-статус!');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при установке премиум-статуса:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
console.log('Соединение с базой данных закрыто');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setAllUsersToPremium();
|
||||||
73
src/premium/setPremiumStatus.js
Normal file
73
src/premium/setPremiumStatus.js
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
// Скрипт для установки премиум-статуса всем пользователям
|
||||||
|
require('dotenv').config();
|
||||||
|
const { Pool } = require('pg');
|
||||||
|
|
||||||
|
// Проверяем и выводим параметры подключения
|
||||||
|
console.log('Параметры подключения к БД:');
|
||||||
|
console.log('DB_USERNAME:', process.env.DB_USERNAME);
|
||||||
|
console.log('DB_HOST:', process.env.DB_HOST);
|
||||||
|
console.log('DB_NAME:', process.env.DB_NAME);
|
||||||
|
console.log('DB_PASSWORD:', process.env.DB_PASSWORD ? '[указан]' : '[не указан]');
|
||||||
|
console.log('DB_PORT:', process.env.DB_PORT);
|
||||||
|
|
||||||
|
// Создаем пул соединений
|
||||||
|
const pool = new Pool({
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432')
|
||||||
|
});
|
||||||
|
|
||||||
|
async function setAllUsersToPremium() {
|
||||||
|
try {
|
||||||
|
console.log('Устанавливаем премиум-статус для всех пользователей...');
|
||||||
|
|
||||||
|
// Проверка соединения с БД
|
||||||
|
console.log('Проверка соединения с БД...');
|
||||||
|
const testResult = await pool.query('SELECT NOW()');
|
||||||
|
console.log('✅ Соединение успешно:', testResult.rows[0].now);
|
||||||
|
|
||||||
|
// Проверка наличия столбца premium
|
||||||
|
console.log('Проверяем наличие столбца premium в таблице users...');
|
||||||
|
|
||||||
|
const checkResult = await pool.query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.columns
|
||||||
|
WHERE table_schema = 'public'
|
||||||
|
AND table_name = 'users'
|
||||||
|
AND column_name = 'premium'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
if (!checkResult.rows[0].exists) {
|
||||||
|
console.log('🔄 Добавляем столбец premium...');
|
||||||
|
await pool.query(`ALTER TABLE users ADD COLUMN premium BOOLEAN DEFAULT false;`);
|
||||||
|
console.log('✅ Столбец premium успешно добавлен');
|
||||||
|
} else {
|
||||||
|
console.log('✅ Столбец premium уже существует');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Устанавливаем premium=true для всех пользователей
|
||||||
|
const updateResult = await pool.query(`
|
||||||
|
UPDATE users
|
||||||
|
SET premium = true
|
||||||
|
WHERE true
|
||||||
|
RETURNING id, telegram_id, premium
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(`✅ Успешно установлен премиум-статус для ${updateResult.rows.length} пользователей:`);
|
||||||
|
updateResult.rows.forEach(row => {
|
||||||
|
console.log(`ID: ${row.id.substr(0, 8)}... | Telegram ID: ${row.telegram_id} | Premium: ${row.premium}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('🎉 Все пользователи теперь имеют премиум-статус!');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при установке премиум-статуса:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
console.log('Соединение с базой данных закрыто');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setAllUsersToPremium();
|
||||||
115
src/scripts/cleanDb.ts
Normal file
115
src/scripts/cleanDb.ts
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
#!/usr/bin/env ts-node
|
||||||
|
|
||||||
|
import 'dotenv/config';
|
||||||
|
import { testConnection, closePool, query } from '../database/connection';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Очистка базы данных и пересоздание схемы с нуля
|
||||||
|
*/
|
||||||
|
async function main() {
|
||||||
|
console.log('🚀 Очистка базы данных...');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Проверяем подключение
|
||||||
|
const connected = await testConnection();
|
||||||
|
if (!connected) {
|
||||||
|
console.error('❌ Не удалось подключиться к базе данных');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Сначала проверяем наличие таблиц
|
||||||
|
const tablesExist = await checkTablesExist();
|
||||||
|
|
||||||
|
if (tablesExist) {
|
||||||
|
console.log('🔍 Таблицы существуют. Выполняем удаление...');
|
||||||
|
|
||||||
|
// Удаляем существующие таблицы в правильном порядке
|
||||||
|
await dropAllTables();
|
||||||
|
console.log('✅ Все таблицы успешно удалены');
|
||||||
|
} else {
|
||||||
|
console.log('⚠️ Таблицы не обнаружены');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('🛠️ База данных очищена успешно');
|
||||||
|
console.log('ℹ️ Теперь вы можете выполнить npm run init:db для создания новой схемы');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при очистке базы данных:', error);
|
||||||
|
process.exit(1);
|
||||||
|
} finally {
|
||||||
|
await closePool();
|
||||||
|
console.log('👋 Соединение с базой данных закрыто');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Проверка существования таблиц в базе данных
|
||||||
|
*/
|
||||||
|
async function checkTablesExist(): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
const result = await query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_schema = 'public' AND table_name IN ('users', 'profiles', 'matches')
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
return result.rows[0].exists;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при проверке наличия таблиц:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Удаление всех таблиц из базы данных
|
||||||
|
*/
|
||||||
|
async function dropAllTables(): Promise<void> {
|
||||||
|
try {
|
||||||
|
// Отключаем ограничения внешних ключей для удаления таблиц
|
||||||
|
await query('SET CONSTRAINTS ALL DEFERRED;');
|
||||||
|
|
||||||
|
// Удаляем таблицы в порядке, учитывающем зависимости
|
||||||
|
console.log('Удаление таблицы notifications...');
|
||||||
|
await query('DROP TABLE IF EXISTS notifications CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы scheduled_notifications...');
|
||||||
|
await query('DROP TABLE IF EXISTS scheduled_notifications CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы reports...');
|
||||||
|
await query('DROP TABLE IF EXISTS reports CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы blocks...');
|
||||||
|
await query('DROP TABLE IF EXISTS blocks CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы messages...');
|
||||||
|
await query('DROP TABLE IF EXISTS messages CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы matches...');
|
||||||
|
await query('DROP TABLE IF EXISTS matches CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы swipes...');
|
||||||
|
await query('DROP TABLE IF EXISTS swipes CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы profiles...');
|
||||||
|
await query('DROP TABLE IF EXISTS profiles CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы users...');
|
||||||
|
await query('DROP TABLE IF EXISTS users CASCADE;');
|
||||||
|
|
||||||
|
console.log('Удаление таблицы pgmigrations...');
|
||||||
|
await query('DROP TABLE IF EXISTS pgmigrations CASCADE;');
|
||||||
|
|
||||||
|
// Восстанавливаем ограничения внешних ключей
|
||||||
|
await query('SET CONSTRAINTS ALL IMMEDIATE;');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при удалении таблиц:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Запуск скрипта
|
||||||
|
if (require.main === module) {
|
||||||
|
main();
|
||||||
|
}
|
||||||
|
|
||||||
|
export { main as cleanDB };
|
||||||
166
src/scripts/createTestData.ts
Normal file
166
src/scripts/createTestData.ts
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
import { Pool } from 'pg';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
import 'dotenv/config';
|
||||||
|
|
||||||
|
async function createTestSwipes() {
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Сначала получаем ID всех пользователей
|
||||||
|
const usersResult = await pool.query(`
|
||||||
|
SELECT users.id, telegram_id, first_name, gender
|
||||||
|
FROM users
|
||||||
|
JOIN profiles ON users.id = profiles.user_id
|
||||||
|
`);
|
||||||
|
|
||||||
|
const users = usersResult.rows;
|
||||||
|
console.log('Пользователи в системе:');
|
||||||
|
console.table(users);
|
||||||
|
|
||||||
|
if (users.length < 2) {
|
||||||
|
console.log('Недостаточно пользователей для создания свайпов');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создаем свайпы
|
||||||
|
console.log('Создаем тестовые свайпы...');
|
||||||
|
|
||||||
|
// Сначала проверим ограничения базы данных
|
||||||
|
const constraintsResult = await pool.query(`
|
||||||
|
SELECT
|
||||||
|
constraint_name,
|
||||||
|
table_name,
|
||||||
|
constraint_type
|
||||||
|
FROM
|
||||||
|
information_schema.table_constraints
|
||||||
|
WHERE
|
||||||
|
table_name = 'swipes'
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('Ограничения таблицы swipes:');
|
||||||
|
console.table(constraintsResult.rows);
|
||||||
|
|
||||||
|
// Создаем пары пользователей без дублирования
|
||||||
|
const userPairs = [];
|
||||||
|
const swipes = [];
|
||||||
|
|
||||||
|
// Мужчины и женщины для создания пар
|
||||||
|
const maleUsers = users.filter(user => user.gender === 'male');
|
||||||
|
const femaleUsers = users.filter(user => user.gender === 'female');
|
||||||
|
|
||||||
|
console.log(`Мужчин: ${maleUsers.length}, Женщин: ${femaleUsers.length}`);
|
||||||
|
|
||||||
|
for (const male of maleUsers) {
|
||||||
|
for (const female of femaleUsers) {
|
||||||
|
// Мужчина -> Женщина (70% лайк, 20% пропуск, 10% суперлайк)
|
||||||
|
const randomNum1 = Math.random();
|
||||||
|
let maleToFemaleType;
|
||||||
|
|
||||||
|
if (randomNum1 < 0.7) {
|
||||||
|
maleToFemaleType = 'like';
|
||||||
|
} else if (randomNum1 < 0.9) {
|
||||||
|
maleToFemaleType = 'pass';
|
||||||
|
} else {
|
||||||
|
maleToFemaleType = 'superlike';
|
||||||
|
}
|
||||||
|
|
||||||
|
const maleToFemale = {
|
||||||
|
id: uuidv4(),
|
||||||
|
user_id: male.id,
|
||||||
|
target_user_id: female.id,
|
||||||
|
type: maleToFemaleType,
|
||||||
|
is_match: false,
|
||||||
|
created_at: new Date()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Женщина -> Мужчина (80% шанс на лайк, если мужчина лайкнул)
|
||||||
|
if ((maleToFemaleType === 'like' || maleToFemaleType === 'superlike') && Math.random() < 0.8) {
|
||||||
|
const femaleToMale = {
|
||||||
|
id: uuidv4(),
|
||||||
|
user_id: female.id,
|
||||||
|
target_user_id: male.id,
|
||||||
|
type: Math.random() < 0.9 ? 'like' : 'superlike',
|
||||||
|
is_match: true,
|
||||||
|
created_at: new Date(new Date().getTime() + 1000) // На секунду позже
|
||||||
|
};
|
||||||
|
|
||||||
|
swipes.push(femaleToMale);
|
||||||
|
maleToFemale.is_match = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
swipes.push(maleToFemale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Подготовлено ${swipes.length} свайпов для добавления в базу`);
|
||||||
|
|
||||||
|
// Сначала удаляем все существующие свайпы
|
||||||
|
await pool.query('DELETE FROM swipes');
|
||||||
|
console.log('Существующие свайпы удалены');
|
||||||
|
|
||||||
|
// Добавляем новые свайпы
|
||||||
|
for (const swipe of swipes) {
|
||||||
|
await pool.query(`
|
||||||
|
INSERT INTO swipes (id, user_id, target_user_id, type, is_match, created_at)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
`, [swipe.id, swipe.user_id, swipe.target_user_id, swipe.type, swipe.is_match, swipe.created_at]);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Успешно добавлено ${swipes.length} свайпов`);
|
||||||
|
|
||||||
|
// Создаем матчи для взаимных лайков
|
||||||
|
console.log('Создаем матчи для взаимных лайков...');
|
||||||
|
|
||||||
|
// Сначала удаляем все существующие матчи
|
||||||
|
await pool.query('DELETE FROM matches');
|
||||||
|
console.log('Существующие матчи удалены');
|
||||||
|
|
||||||
|
// Находим пары взаимных лайков для создания матчей
|
||||||
|
const mutualLikesResult = await pool.query(`
|
||||||
|
SELECT
|
||||||
|
s1.user_id as user_id_1,
|
||||||
|
s1.target_user_id as user_id_2,
|
||||||
|
s1.created_at
|
||||||
|
FROM swipes s1
|
||||||
|
JOIN swipes s2 ON s1.user_id = s2.target_user_id AND s1.target_user_id = s2.user_id
|
||||||
|
WHERE (s1.type = 'like' OR s1.type = 'superlike')
|
||||||
|
AND (s2.type = 'like' OR s2.type = 'superlike')
|
||||||
|
AND s1.user_id < s2.user_id -- Избегаем дублирования пар
|
||||||
|
`);
|
||||||
|
|
||||||
|
const matches = [];
|
||||||
|
|
||||||
|
for (const mutualLike of mutualLikesResult.rows) {
|
||||||
|
const match = {
|
||||||
|
id: uuidv4(),
|
||||||
|
user_id_1: mutualLike.user_id_1,
|
||||||
|
user_id_2: mutualLike.user_id_2,
|
||||||
|
created_at: new Date(),
|
||||||
|
is_active: true,
|
||||||
|
is_super_match: Math.random() < 0.2 // 20% шанс быть суперматчем
|
||||||
|
};
|
||||||
|
|
||||||
|
matches.push(match);
|
||||||
|
|
||||||
|
await pool.query(`
|
||||||
|
INSERT INTO matches (id, user_id_1, user_id_2, created_at, is_active, is_super_match)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
`, [match.id, match.user_id_1, match.user_id_2, match.created_at, match.is_active, match.is_super_match]);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Успешно создано ${matches.length} матчей`);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при создании тестовых данных:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
createTestSwipes();
|
||||||
133
src/scripts/enhanceNotifications.ts
Normal file
133
src/scripts/enhanceNotifications.ts
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import { query } from '../database/connection';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
|
// Загружаем переменные окружения
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Скрипт для обновления механизма уведомлений
|
||||||
|
*/
|
||||||
|
export async function enhanceNotifications() {
|
||||||
|
try {
|
||||||
|
console.log('Enhancing notifications system...');
|
||||||
|
console.log('DB Connection Details:');
|
||||||
|
console.log(`- Host: ${process.env.DB_HOST}`);
|
||||||
|
console.log(`- Port: ${process.env.DB_PORT}`);
|
||||||
|
console.log(`- Database: ${process.env.DB_NAME}`);
|
||||||
|
|
||||||
|
// 1. Создаем расширение для генерации UUID, если его нет
|
||||||
|
await query(`
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
|
||||||
|
`);
|
||||||
|
|
||||||
|
// 2. Создаем таблицу для хранения типов уведомлений и шаблонов сообщений, если её нет
|
||||||
|
await query(`
|
||||||
|
CREATE TABLE IF NOT EXISTS notification_templates (
|
||||||
|
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
type VARCHAR(50) NOT NULL UNIQUE,
|
||||||
|
title TEXT NOT NULL,
|
||||||
|
message_template TEXT NOT NULL,
|
||||||
|
button_template JSONB NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
|
||||||
|
// 2. Вставляем базовые шаблоны для различных типов уведомлений
|
||||||
|
const templates = [
|
||||||
|
{
|
||||||
|
id: uuidv4(),
|
||||||
|
type: 'new_like',
|
||||||
|
title: 'Новый лайк!',
|
||||||
|
message_template: '❤️ *{{name}}* поставил(а) вам лайк!\n\nВозраст: {{age}}\n{{city}}\n\nОтветьте взаимностью или посмотрите профиль.',
|
||||||
|
button_template: JSON.stringify({
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '❤️ Лайк в ответ', callback_data: 'like_back:{{userId}}' },
|
||||||
|
{ text: '⛔️ Пропустить', callback_data: 'dislike_profile:{{userId}}' }
|
||||||
|
],
|
||||||
|
[{ text: '💕 Открыть все лайки', callback_data: 'view_likes' }]
|
||||||
|
]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: uuidv4(),
|
||||||
|
type: 'super_like',
|
||||||
|
title: 'Супер-лайк!',
|
||||||
|
message_template: '⭐️ *{{name}}* отправил(а) вам супер-лайк!\n\nВозраст: {{age}}\n{{city}}\n\nВы произвели особое впечатление! Ответьте взаимностью или посмотрите профиль.',
|
||||||
|
button_template: JSON.stringify({
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '❤️ Лайк в ответ', callback_data: 'like_back:{{userId}}' },
|
||||||
|
{ text: '⛔️ Пропустить', callback_data: 'dislike_profile:{{userId}}' }
|
||||||
|
],
|
||||||
|
[{ text: '💕 Открыть все лайки', callback_data: 'view_likes' }]
|
||||||
|
]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: uuidv4(),
|
||||||
|
type: 'new_match',
|
||||||
|
title: 'Новый матч!',
|
||||||
|
message_template: '🎊 *Ура! Это взаимно!* 🎊\n\nВы и *{{name}}* понравились друг другу!\nВозраст: {{age}}\n{{city}}\n\nСделайте первый шаг - напишите сообщение!',
|
||||||
|
button_template: JSON.stringify({
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '💬 Начать общение', callback_data: 'open_native_chat_{{matchId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '👀 Посмотреть профиль', callback_data: 'view_profile:{{userId}}' },
|
||||||
|
{ text: '📋 Все матчи', callback_data: 'native_chats' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: uuidv4(),
|
||||||
|
type: 'new_message',
|
||||||
|
title: 'Новое сообщение!',
|
||||||
|
message_template: '💌 *Новое сообщение!*\n\nОт: *{{name}}*\n\n"{{message}}"\n\nОтветьте на сообщение прямо сейчас!',
|
||||||
|
button_template: JSON.stringify({
|
||||||
|
inline_keyboard: [
|
||||||
|
[{ text: '📩 Ответить', callback_data: 'open_native_chat_{{matchId}}' }],
|
||||||
|
[
|
||||||
|
{ text: '👤 Профиль', callback_data: 'view_profile:{{userId}}' },
|
||||||
|
{ text: '📋 Все чаты', callback_data: 'native_chats' }
|
||||||
|
]
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Вставляем шаблоны с проверкой на конфликты
|
||||||
|
for (const template of templates) {
|
||||||
|
await query(`
|
||||||
|
INSERT INTO notification_templates
|
||||||
|
(id, type, title, message_template, button_template, created_at)
|
||||||
|
VALUES ($1, $2, $3, $4, $5, NOW())
|
||||||
|
ON CONFLICT (type) DO UPDATE
|
||||||
|
SET title = $3,
|
||||||
|
message_template = $4,
|
||||||
|
button_template = $5
|
||||||
|
`, [template.id, template.type, template.title, template.message_template, template.button_template]);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ Notification templates updated successfully');
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Error enhancing notifications:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если запускаем файл напрямую
|
||||||
|
if (require.main === module) {
|
||||||
|
enhanceNotifications().then(() => {
|
||||||
|
console.log('Notification system enhancement completed');
|
||||||
|
process.exit(0);
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('Error:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
120
src/scripts/getDatabaseInfo.ts
Normal file
120
src/scripts/getDatabaseInfo.ts
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
import { Pool } from 'pg';
|
||||||
|
import 'dotenv/config';
|
||||||
|
|
||||||
|
async function getDatabaseInfo() {
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('Подключение к базе данных...');
|
||||||
|
|
||||||
|
// Получаем информацию о пользователях
|
||||||
|
console.log('\n=== ПОЛЬЗОВАТЕЛИ ===');
|
||||||
|
const usersResult = await pool.query(`
|
||||||
|
SELECT id, telegram_id, username, first_name, last_name, premium, created_at
|
||||||
|
FROM users
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(`Всего пользователей: ${usersResult.rows.length}`);
|
||||||
|
console.table(usersResult.rows);
|
||||||
|
|
||||||
|
// Получаем информацию о профилях
|
||||||
|
console.log('\n=== ПРОФИЛИ ===');
|
||||||
|
const profilesResult = await pool.query(`
|
||||||
|
SELECT
|
||||||
|
p.user_id,
|
||||||
|
u.telegram_id,
|
||||||
|
u.first_name,
|
||||||
|
p.age,
|
||||||
|
p.gender,
|
||||||
|
p.interested_in as "интересуется",
|
||||||
|
p.bio,
|
||||||
|
p.dating_goal as "цель_знакомства",
|
||||||
|
p.is_visible,
|
||||||
|
p.created_at
|
||||||
|
FROM profiles p
|
||||||
|
JOIN users u ON p.user_id = u.id
|
||||||
|
ORDER BY p.created_at DESC
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(`Всего профилей: ${profilesResult.rows.length}`);
|
||||||
|
console.table(profilesResult.rows);
|
||||||
|
|
||||||
|
// Получаем информацию о свайпах
|
||||||
|
console.log('\n=== СВАЙПЫ ===');
|
||||||
|
|
||||||
|
// Сначала проверим, какие столбцы есть в таблице swipes
|
||||||
|
console.log('Получение структуры таблицы swipes...');
|
||||||
|
const swipesColumns = await pool.query(`
|
||||||
|
SELECT column_name, data_type
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = 'swipes'
|
||||||
|
`);
|
||||||
|
console.log('Структура таблицы swipes:');
|
||||||
|
console.table(swipesColumns.rows);
|
||||||
|
|
||||||
|
// Теперь запросим данные, используя правильные имена столбцов
|
||||||
|
const swipesResult = await pool.query(`
|
||||||
|
SELECT
|
||||||
|
s.id,
|
||||||
|
s.user_id,
|
||||||
|
u1.first_name as "от_кого",
|
||||||
|
s.target_user_id,
|
||||||
|
u2.first_name as "кому",
|
||||||
|
s.type,
|
||||||
|
s.created_at
|
||||||
|
FROM swipes s
|
||||||
|
JOIN users u1 ON s.user_id = u1.id
|
||||||
|
JOIN users u2 ON s.target_user_id = u2.id
|
||||||
|
ORDER BY s.created_at DESC
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(`Всего свайпов: ${swipesResult.rows.length}`);
|
||||||
|
console.table(swipesResult.rows);
|
||||||
|
|
||||||
|
// Получаем информацию о матчах
|
||||||
|
console.log('\n=== МАТЧИ ===');
|
||||||
|
|
||||||
|
// Сначала проверим, какие столбцы есть в таблице matches
|
||||||
|
console.log('Получение структуры таблицы matches...');
|
||||||
|
const matchesColumns = await pool.query(`
|
||||||
|
SELECT column_name, data_type
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = 'matches'
|
||||||
|
`);
|
||||||
|
console.log('Структура таблицы matches:');
|
||||||
|
console.table(matchesColumns.rows);
|
||||||
|
|
||||||
|
// Теперь запросим данные, используя правильные имена столбцов
|
||||||
|
const matchesResult = await pool.query(`
|
||||||
|
SELECT
|
||||||
|
m.id,
|
||||||
|
m.user_id_1,
|
||||||
|
u1.first_name as "пользователь_1",
|
||||||
|
m.user_id_2,
|
||||||
|
u2.first_name as "пользователь_2",
|
||||||
|
m.is_active,
|
||||||
|
m.created_at
|
||||||
|
FROM matches m
|
||||||
|
JOIN users u1 ON m.user_id_1 = u1.id
|
||||||
|
JOIN users u2 ON m.user_id_2 = u2.id
|
||||||
|
ORDER BY m.created_at DESC
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(`Всего матчей: ${matchesResult.rows.length}`);
|
||||||
|
console.table(matchesResult.rows);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при получении данных:', error);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getDatabaseInfo();
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
#!/usr/bin/env ts-node
|
#!/usr/bin/env ts-node
|
||||||
|
|
||||||
import { initializeDatabase, testConnection, closePool } from '../database/connection';
|
import 'dotenv/config';
|
||||||
|
import { initializeDatabase, testConnection, closePool, query } from '../database/connection';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Основная функция инициализации базы данных
|
||||||
|
*/
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log('🚀 Initializing database...');
|
console.log('🚀 Initializing database...');
|
||||||
|
|
||||||
@@ -13,90 +19,245 @@ async function main() {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Инициализируем схему
|
// Проверяем наличие таблицы миграций
|
||||||
await initializeDatabase();
|
const migrationTableExists = await checkMigrationsTable();
|
||||||
console.log('✅ Database initialized successfully');
|
|
||||||
|
if (migrationTableExists) {
|
||||||
|
console.log('🔍 Миграции уже настроены');
|
||||||
|
|
||||||
|
// Проверяем, есть ли необходимость в применении миграций
|
||||||
|
const pendingMigrations = await getPendingMigrations();
|
||||||
|
if (pendingMigrations.length > 0) {
|
||||||
|
console.log(`🔄 Найдено ${pendingMigrations.length} ожидающих миграций`);
|
||||||
|
console.log('✅ Рекомендуется запустить: npm run migrate:up');
|
||||||
|
} else {
|
||||||
|
console.log('✅ Все миграции уже применены');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('⚠️ Таблица миграций не обнаружена');
|
||||||
|
console.log('🛠️ Выполняется инициализация базы данных напрямую...');
|
||||||
|
|
||||||
|
// Выполняем традиционную инициализацию
|
||||||
|
await initializeDatabase();
|
||||||
|
console.log('✅ База данных инициализирована');
|
||||||
|
|
||||||
|
// Создаем дополнительные таблицы
|
||||||
|
await createAdditionalTables();
|
||||||
|
console.log('✅ Дополнительные таблицы созданы');
|
||||||
|
|
||||||
|
// Создаем таблицу миграций и отмечаем существующие миграции как выполненные
|
||||||
|
await setupMigrations();
|
||||||
|
console.log('✅ Настройка миграций завершена');
|
||||||
|
}
|
||||||
|
|
||||||
// Создаем дополнительные таблицы, если нужно
|
// Проверяем наличие необходимых колонок
|
||||||
await createAdditionalTables();
|
await ensureRequiredColumns();
|
||||||
console.log('✅ Additional tables created');
|
console.log('✅ Все необходимые колонки присутствуют');
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Database initialization failed:', error);
|
console.error('❌ Ошибка инициализации базы данных:', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} finally {
|
} finally {
|
||||||
await closePool();
|
await closePool();
|
||||||
console.log('👋 Database connection closed');
|
console.log('👋 Соединение с базой данных закрыто');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createAdditionalTables() {
|
/**
|
||||||
const { query } = await import('../database/connection');
|
* Проверка наличия таблицы миграций
|
||||||
|
*/
|
||||||
|
async function checkMigrationsTable(): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
const result = await query(`
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT FROM information_schema.tables
|
||||||
|
WHERE table_name = 'pgmigrations'
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
return result.rows[0].exists;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при проверке таблицы миграций:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Таблица для уведомлений
|
/**
|
||||||
await query(`
|
* Получение списка ожидающих миграций
|
||||||
CREATE TABLE IF NOT EXISTS notifications (
|
*/
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
async function getPendingMigrations(): Promise<string[]> {
|
||||||
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
try {
|
||||||
type VARCHAR(50) NOT NULL,
|
// Получаем выполненные миграции
|
||||||
data JSONB DEFAULT '{}',
|
const { rows } = await query('SELECT name FROM pgmigrations');
|
||||||
is_read BOOLEAN DEFAULT false,
|
const appliedMigrations = rows.map((row: { name: string }) => row.name);
|
||||||
created_at TIMESTAMP DEFAULT NOW()
|
|
||||||
);
|
// Получаем файлы миграций
|
||||||
`);
|
const migrationsDir = path.join(__dirname, '../../migrations');
|
||||||
|
if (!fs.existsSync(migrationsDir)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const migrationFiles = fs.readdirSync(migrationsDir)
|
||||||
|
.filter(file => file.endsWith('.js'))
|
||||||
|
.map(file => file.replace('.js', ''))
|
||||||
|
.sort();
|
||||||
|
|
||||||
|
// Находим невыполненные миграции
|
||||||
|
return migrationFiles.filter(file => !appliedMigrations.includes(file));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при проверке ожидающих миграций:', error);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Таблица для запланированных уведомлений
|
/**
|
||||||
await query(`
|
* Настройка системы миграций и отметка существующих миграций как выполненных
|
||||||
CREATE TABLE IF NOT EXISTS scheduled_notifications (
|
*/
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
async function setupMigrations(): Promise<void> {
|
||||||
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
try {
|
||||||
type VARCHAR(50) NOT NULL,
|
// Создаем таблицу миграций
|
||||||
data JSONB DEFAULT '{}',
|
await query(`
|
||||||
scheduled_at TIMESTAMP NOT NULL,
|
CREATE TABLE IF NOT EXISTS pgmigrations (
|
||||||
sent BOOLEAN DEFAULT false,
|
id SERIAL PRIMARY KEY,
|
||||||
sent_at TIMESTAMP,
|
name VARCHAR(255) NOT NULL,
|
||||||
created_at TIMESTAMP DEFAULT NOW()
|
run_on TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
||||||
);
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
// Получаем файлы миграций
|
||||||
|
const migrationsDir = path.join(__dirname, '../../migrations');
|
||||||
|
if (!fs.existsSync(migrationsDir)) {
|
||||||
|
console.log('⚠️ Директория миграций не найдена');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const files = fs.readdirSync(migrationsDir)
|
||||||
|
.filter(file => file.endsWith('.js'))
|
||||||
|
.sort();
|
||||||
|
|
||||||
|
// Отмечаем существующие миграции как выполненные
|
||||||
|
for (const file of files) {
|
||||||
|
const migrationName = file.replace('.js', '');
|
||||||
|
console.log(`✅ Отмечаем миграцию как выполненную: ${migrationName}`);
|
||||||
|
await query('INSERT INTO pgmigrations(name) VALUES($1)', [migrationName]);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при настройке миграций:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Таблица для отчетов и блокировок
|
/**
|
||||||
await query(`
|
* Создание дополнительных таблиц для приложения
|
||||||
CREATE TABLE IF NOT EXISTS reports (
|
*/
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
async function createAdditionalTables(): Promise<void> {
|
||||||
reporter_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
try {
|
||||||
reported_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
// Таблица для уведомлений
|
||||||
reason VARCHAR(100) NOT NULL,
|
await query(`
|
||||||
description TEXT,
|
CREATE TABLE IF NOT EXISTS notifications (
|
||||||
status VARCHAR(20) DEFAULT 'pending',
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
created_at TIMESTAMP DEFAULT NOW(),
|
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
resolved_at TIMESTAMP
|
type VARCHAR(50) NOT NULL,
|
||||||
);
|
data JSONB DEFAULT '{}',
|
||||||
`);
|
is_read BOOLEAN DEFAULT false,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
// Таблица для блокировок
|
// Таблица для запланированных уведомлений
|
||||||
await query(`
|
await query(`
|
||||||
CREATE TABLE IF NOT EXISTS blocks (
|
CREATE TABLE IF NOT EXISTS scheduled_notifications (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
blocker_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
blocked_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
type VARCHAR(50) NOT NULL,
|
||||||
created_at TIMESTAMP DEFAULT NOW(),
|
data JSONB DEFAULT '{}',
|
||||||
UNIQUE(blocker_id, blocked_id)
|
scheduled_at TIMESTAMP NOT NULL,
|
||||||
);
|
sent BOOLEAN DEFAULT false,
|
||||||
`);
|
sent_at TIMESTAMP,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
// Добавляем недостающие поля в users
|
// Таблица для отчетов и блокировок
|
||||||
await query(`
|
await query(`
|
||||||
ALTER TABLE users
|
CREATE TABLE IF NOT EXISTS reports (
|
||||||
ADD COLUMN IF NOT EXISTS notification_settings JSONB DEFAULT '{"newMatches": true, "newMessages": true, "newLikes": true, "reminders": true}';
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
`);
|
reporter_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
reported_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
reason VARCHAR(100) NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
status VARCHAR(20) DEFAULT 'pending',
|
||||||
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
resolved_at TIMESTAMP
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
// Индексы для производительности
|
// Таблица для блокировок
|
||||||
await query(`
|
await query(`
|
||||||
CREATE INDEX IF NOT EXISTS idx_notifications_user_type ON notifications(user_id, type);
|
CREATE TABLE IF NOT EXISTS blocks (
|
||||||
CREATE INDEX IF NOT EXISTS idx_scheduled_notifications_time ON scheduled_notifications(scheduled_at, sent);
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||||
CREATE INDEX IF NOT EXISTS idx_reports_status ON reports(status);
|
blocker_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
CREATE INDEX IF NOT EXISTS idx_blocks_blocker ON blocks(blocker_id);
|
blocked_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||||
`);
|
created_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
UNIQUE(blocker_id, blocked_id)
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Добавляем настройки уведомлений в users
|
||||||
|
await query(`
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS notification_settings JSONB DEFAULT '{"newMatches": true, "newMessages": true, "newLikes": true, "reminders": true}';
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Индексы для производительности
|
||||||
|
await query(`
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_notifications_user_type ON notifications(user_id, type);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_scheduled_notifications_time ON scheduled_notifications(scheduled_at, sent);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_reports_status ON reports(status);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_blocks_blocker ON blocks(blocker_id);
|
||||||
|
`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при создании дополнительных таблиц:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Проверка наличия всех необходимых колонок
|
||||||
|
*/
|
||||||
|
async function ensureRequiredColumns(): Promise<void> {
|
||||||
|
try {
|
||||||
|
// Проверка и добавление колонки updated_at в users
|
||||||
|
await query(`
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP DEFAULT NOW();
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Проверка и добавление колонок premium и premium_expires_at в users
|
||||||
|
await query(`
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS premium BOOLEAN DEFAULT FALSE;
|
||||||
|
`);
|
||||||
|
|
||||||
|
await query(`
|
||||||
|
ALTER TABLE users
|
||||||
|
ADD COLUMN IF NOT EXISTS premium_expires_at TIMESTAMP;
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Проверка и добавление колонки looking_for в profiles
|
||||||
|
await query(`
|
||||||
|
ALTER TABLE profiles
|
||||||
|
ADD COLUMN IF NOT EXISTS looking_for VARCHAR(20) DEFAULT 'both' CHECK (looking_for IN ('male', 'female', 'both'));
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Проверка и добавление колонки hobbies в profiles
|
||||||
|
await query(`
|
||||||
|
ALTER TABLE profiles
|
||||||
|
ADD COLUMN IF NOT EXISTS hobbies TEXT;
|
||||||
|
`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Ошибка при проверке необходимых колонок:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Запуск скрипта
|
// Запуск скрипта
|
||||||
|
|||||||
42
src/scripts/setPremium.ts
Normal file
42
src/scripts/setPremium.ts
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import { Pool } from 'pg';
|
||||||
|
|
||||||
|
async function setPremium(): Promise<void> {
|
||||||
|
// Создаем соединение с базой данных используя прямые параметры
|
||||||
|
const pool = new Pool({
|
||||||
|
host: '192.168.0.102',
|
||||||
|
port: 5432,
|
||||||
|
database: 'telegram_tinder_bot',
|
||||||
|
user: 'trevor',
|
||||||
|
password: 'Cl0ud_1985!',
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Установка премиума для всех пользователей
|
||||||
|
const result = await pool.query(`
|
||||||
|
UPDATE users
|
||||||
|
SET premium = true,
|
||||||
|
premium_expires_at = NOW() + INTERVAL '1 year'
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log('Premium set for all users successfully!');
|
||||||
|
console.log(`Updated ${result.rowCount} users`);
|
||||||
|
|
||||||
|
// Закрываем соединение с базой данных
|
||||||
|
await pool.end();
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error setting premium:', error);
|
||||||
|
|
||||||
|
// Закрываем соединение с базой данных в случае ошибки
|
||||||
|
try {
|
||||||
|
await pool.end();
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error closing pool:', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setPremium();
|
||||||
43
src/scripts/setPremiumDirectConnect.ts
Normal file
43
src/scripts/setPremiumDirectConnect.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { Pool } from 'pg';
|
||||||
|
import 'dotenv/config';
|
||||||
|
|
||||||
|
async function setAllUsersToPremium() {
|
||||||
|
const pool = new Pool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
database: process.env.DB_NAME,
|
||||||
|
user: process.env.DB_USERNAME,
|
||||||
|
password: process.env.DB_PASSWORD
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('Setting premium status for all users...');
|
||||||
|
console.log(`Connecting to database at ${process.env.DB_HOST}:${process.env.DB_PORT}...`);
|
||||||
|
|
||||||
|
const result = await pool.query(`
|
||||||
|
UPDATE users
|
||||||
|
SET premium = true
|
||||||
|
WHERE true
|
||||||
|
RETURNING id, telegram_id, username, first_name, premium
|
||||||
|
`);
|
||||||
|
|
||||||
|
console.log(`Successfully set premium status for ${result.rows.length} users:`);
|
||||||
|
console.table(result.rows);
|
||||||
|
|
||||||
|
console.log('All users are now premium!');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error setting premium status:', error);
|
||||||
|
console.error('Please check your database connection settings in .env file.');
|
||||||
|
console.log('Current settings:');
|
||||||
|
console.log(`- DB_HOST: ${process.env.DB_HOST}`);
|
||||||
|
console.log(`- DB_PORT: ${process.env.DB_PORT}`);
|
||||||
|
console.log(`- DB_NAME: ${process.env.DB_NAME}`);
|
||||||
|
console.log(`- DB_USERNAME: ${process.env.DB_USERNAME}`);
|
||||||
|
console.log(`- DB_PASSWORD: ${process.env.DB_PASSWORD ? '********' : 'not set'}`);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setAllUsersToPremium();
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user