add command /profile

This commit is contained in:
vrubelroman 2025-11-21 23:16:35 +03:00
parent 56c1048bcc
commit 965b8775b7
3 changed files with 81 additions and 85 deletions

View file

@ -1179,6 +1179,70 @@ class LichessBot:
error_msg = "Не удалось установить язык" if lang == 'ru' else "❌ Failed to set language"
await query.edit_message_text(error_msg)
async def profile(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Show list of players to view their profiles"""
user_id = update.effective_user.id
gamers = self.db.get_user_gamers(user_id)
lang = self.get_user_language_from_update(update)
if not gamers:
await update.message.reply_text(t('no_gamers', lang))
return
# Create keyboard with player buttons
keyboard = []
for gamer in gamers:
username = gamer['username']
keyboard.append([
InlineKeyboardButton(
username,
callback_data=f"profile_{gamer['id']}"
)
])
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(
t('select_player_profile', lang),
reply_markup=reply_markup,
parse_mode='HTML'
)
async def handle_profile_selection(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Handle profile selection callback - send profile link"""
query = update.callback_query
await query.answer()
user_id = query.from_user.id
gamer_id = int(query.data.split('_')[1])
# Get gamer info
gamers = self.db.get_user_gamers(user_id)
selected_gamer = next((g for g in gamers if g['id'] == gamer_id), None)
if not selected_gamer:
lang = self.db.get_user_language(user_id)
await query.edit_message_text(t('gamer_not_found', lang))
return
username = selected_gamer['username']
profile_url = f"https://lichess.org/@/{username}"
lang = self.db.get_user_language(user_id)
# Send profile link
await query.message.reply_text(
f"🔗 <a href=\"{profile_url}\">{profile_url}</a>",
parse_mode='HTML'
)
# Edit original message to show confirmation
await query.edit_message_text(
t('profile_link_sent', lang),
parse_mode='HTML'
)
async def start_periodic_task(self, gamer: Dict[str, Any], user_id: int, period_minutes: int):
"""Start periodic task for a gamer"""
task_key = f"{gamer['id']}_{user_id}"
@ -1414,10 +1478,12 @@ class LichessBot:
application.add_handler(CommandHandler("support", self.support))
application.add_handler(CommandHandler("setperiod", self.setperiod))
application.add_handler(CommandHandler("set_lang", self.set_lang))
application.add_handler(CommandHandler("profile", self.profile))
application.add_handler(CommandHandler("test_admin_notify", self.test_admin_notify))
# Callback handlers (order matters - more specific patterns first)
application.add_handler(CallbackQueryHandler(self.handle_language_selection, pattern="^lang_"))
application.add_handler(CallbackQueryHandler(self.handle_profile_selection, pattern="^profile_"))
application.add_handler(CallbackQueryHandler(self.select_gamer_for_period, pattern="^select_gamer_period_"))
application.add_handler(CallbackQueryHandler(self.select_gamer, pattern="^select_"))
application.add_handler(CallbackQueryHandler(self.handle_delete_gamer, pattern="^delete_"))

View file

@ -37,6 +37,7 @@ TRANSLATIONS = {
"/lastYear_or_1000games - Statistics for the last year or last 1000 rated games (whichever comes first)\n"
"/setperiod - Set up periodic notifications for the active player\n"
"(active player changes in the /getgamers menu)\n"
"/profile - View Lichess profile links for tracked players\n"
"/set_lang - Select bot language (English / Russian)\n"
"/support - Contact the developer for support and feedback"
),
@ -123,6 +124,10 @@ TRANSLATIONS = {
'select_language': "🌐 <b>Select language / Выберите язык:</b>",
'language_set_en': "✅ Language set to English",
'language_set_ru': "✅ Язык установлен: Русский",
# Profile command
'select_player_profile': "👤 <b>Select player:</b>",
'profile_link_sent': "✅ Profile link sent",
},
'ru': {
# Start command
@ -151,11 +156,12 @@ TRANSLATIONS = {
"/today - Статистика за сегодня\n"
"/yesterday - Статистика за вчера\n"
"/week - Статистика за неделю\n"
"/lastYear_or_1000games - Статистика за последний год или последние 1000 рейтинговых игр (что наступит раньше)\n"
"/setperiod - Настроить периодические уведомления для активного игрока\n"
"(активный игрок меняется в меню /getgamers)\n"
"/set_lang - Выбрать язык бота\n"
"/support - Связаться с разработчиком для поддержки и обратной связи"
"/lastYear_or_1000games - Статистика за последний год или последние 1000 рейтинговых игр (что наступит раньше)\n"
"/setperiod - Настроить периодические уведомления для активного игрока\n"
"(активный игрок меняется в меню /getgamers)\n"
"/profile - Просмотр ссылок на профили Lichess отслеживаемых игроков\n"
"/set_lang - Выбрать язык бота\n"
"/support - Связаться с разработчиком для поддержки и обратной связи"
),
# Add gamer commands
@ -240,6 +246,10 @@ TRANSLATIONS = {
'select_language': "🌐 <b>Выберите язык / Select language:</b>",
'language_set_en': "✅ Language set to English",
'language_set_ru': "✅ Язык установлен: Русский",
# Profile command
'select_player_profile': "👤 <b>Выберите игрока:</b>",
'profile_link_sent': "✅ Ссылка на профиль отправлена",
}
}