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_"))