pre=deploy

This commit is contained in:
2025-11-24 17:00:20 +09:00
parent 240864617f
commit 9106af4f8e
14 changed files with 1979 additions and 26 deletions

View File

@@ -49,6 +49,21 @@ export class CallbackHandlers {
this.likeBackHandler = new LikeBackHandler(bot);
}
// Вспомогательный метод для получения перевода с учетом языка пользователя
private async getTranslation(userId: string, key: string, options?: any): Promise<string> {
try {
const lang = await this.profileService.getUserLanguage(userId);
const LocalizationService = require('../services/localizationService').default;
const locService = LocalizationService.getInstance();
locService.setLanguage(lang);
return locService.t(key, options);
} catch (error) {
console.error('Translation error:', error);
// Возвращаем ключ как fallback
return key;
}
}
register(): void {
this.bot.on('callback_query', (query) => this.handleCallback(query));
}
@@ -61,6 +76,14 @@ export class CallbackHandlers {
const data = query.data;
try {
// Обработка выбора языка
if (data.startsWith('set_lang_')) {
const LanguageHandlers = require('./languageHandlers').LanguageHandlers;
const languageHandlers = new LanguageHandlers(this.bot);
await languageHandlers.handleSetLanguage(query);
return;
}
// Основные действия профиля
if (data === 'create_profile') {
await this.handleCreateProfile(chatId, telegramId);
@@ -105,11 +128,13 @@ export class CallbackHandlers {
}
await this.bot.sendMessage(chatId, `✅ Город подтверждён: *${userState.data.city}*\n\n📝 Теперь расскажите немного о себе (био):`, { parse_mode: 'Markdown' });
} else {
await this.bot.answerCallbackQuery(query.id, { text: 'Контекст не найден. Повторите, пожалуйста.' });
const errorText = await this.getTranslation(telegramId, 'errors.contextNotFound');
await this.bot.answerCallbackQuery(query.id, { text: errorText });
}
} catch (error) {
console.error('Error confirming city via callback:', error);
await this.bot.answerCallbackQuery(query.id, { text: 'Ошибка при подтверждении города' });
const errorText = await this.getTranslation(telegramId, 'errors.cityConfirmError');
await this.bot.answerCallbackQuery(query.id, { text: errorText });
}
} else if (data === 'edit_city_manual') {
try {
@@ -124,11 +149,13 @@ export class CallbackHandlers {
} catch (e) { }
await this.bot.sendMessage(chatId, '✏️ Введите название вашего города вручную:', { reply_markup: { remove_keyboard: true } });
} else {
await this.bot.answerCallbackQuery(query.id, { text: 'Контекст не найден. Повторите, пожалуйста.' });
const errorText = await this.getTranslation(telegramId, 'errors.contextNotFound');
await this.bot.answerCallbackQuery(query.id, { text: errorText });
}
} catch (error) {
console.error('Error switching to manual city input via callback:', error);
await this.bot.answerCallbackQuery(query.id, { text: 'Ошибка' });
const errorText = await this.getTranslation(telegramId, 'errors.generalError');
await this.bot.answerCallbackQuery(query.id, { text: errorText });
}
} else if (data === 'confirm_city_edit') {
try {
@@ -159,14 +186,17 @@ export class CallbackHandlers {
[{ text: '🏠 Главное меню', callback_data: 'main_menu' }]
]
};
await this.bot.sendMessage(chatId, 'Выберите действие:', { reply_markup: keyboard });
const selectActionText = await this.getTranslation(telegramId, 'buttons.selectAction');
await this.bot.sendMessage(chatId, selectActionText, { reply_markup: keyboard });
}, 500);
} else {
await this.bot.answerCallbackQuery(query.id, { text: 'Контекст не найден. Повторите, пожалуйста.' });
const errorText = await this.getTranslation(telegramId, 'errors.contextNotFound');
await this.bot.answerCallbackQuery(query.id, { text: errorText });
}
} catch (error) {
console.error('Error confirming city edit via callback:', error);
await this.bot.answerCallbackQuery(query.id, { text: 'Ошибка при подтверждении города' });
const errorText = await this.getTranslation(telegramId, 'errors.cityConfirmError');
await this.bot.answerCallbackQuery(query.id, { text: errorText });
}
} else if (data === 'edit_city_manual_edit') {
try {
@@ -423,15 +453,17 @@ export class CallbackHandlers {
// Эти коллбэки уже обрабатываются в NotificationHandlers, поэтому здесь ничего не делаем
// NotificationHandlers уже зарегистрировал свои обработчики в register()
} else {
const errorText = await this.getTranslation(telegramId, 'notifications.unavailable');
await this.bot.answerCallbackQuery(query.id, {
text: 'Функция настройки уведомлений недоступна.',
text: errorText,
show_alert: true
});
}
}
else {
const devText = await this.getTranslation(telegramId, 'notifications.inDevelopment');
await this.bot.answerCallbackQuery(query.id, {
text: 'Функция в разработке!',
text: devText,
show_alert: false
});
return;
@@ -441,8 +473,9 @@ export class CallbackHandlers {
} catch (error) {
console.error('Callback handler error:', error);
const errorText = await this.getTranslation(telegramId, 'errors.tryAgain');
await this.bot.answerCallbackQuery(query.id, {
text: 'Произошла ошибка. Попробуйте еще раз.',
text: errorText,
show_alert: true
});
}
@@ -540,11 +573,12 @@ export class CallbackHandlers {
]
};
const matchText = await this.getTranslation(telegramId, 'matches.mutualLike', {
name: targetProfile?.name || await this.getTranslation(telegramId, 'common.thisUser')
});
await this.bot.sendMessage(
chatId,
'🎉 ЭТО МАТЧ! 💕\n\n' +
'Вы понравились друг другу с ' + (targetProfile?.name || 'этим пользователем') + '!\n\n' +
'Теперь вы можете начать общение!',
'🎉 ЭТО МАТЧ! 💕\n\n' + matchText,
{ reply_markup: keyboard }
);
} else {
@@ -610,11 +644,12 @@ export class CallbackHandlers {
]
};
const superMatchText = await this.getTranslation(telegramId, 'matches.superLikeMatch', {
name: targetProfile?.name || await this.getTranslation(telegramId, 'common.thisUser')
});
await this.bot.sendMessage(
chatId,
'💖 СУПЕР МАТЧ! ⭐\n\n' +
'Ваш супер лайк произвел впечатление на ' + (targetProfile?.name || 'этого пользователя') + '!\n\n' +
'Начните общение первыми!',
'💖 СУПЕР МАТЧ! ⭐\n\n' + superMatchText,
{ reply_markup: keyboard }
);
} else {