Files
tg_tinder_bot/scripts/update_bot_with_notifications.js
2025-09-18 13:46:35 +09:00

105 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Скрипт для проверки и исправления регистрации 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('🔔 Перезапустите бота для применения изменений');