diff --git a/LichessClientTG_bot/bot.py b/LichessClientTG_bot/bot.py
index 92be2d5..0036c53 100644
--- a/LichessClientTG_bot/bot.py
+++ b/LichessClientTG_bot/bot.py
@@ -83,6 +83,7 @@ class LichessBot:
"π ΠΠΎΡΡΡΠΏΠ½ΡΠ΅ ΠΊΠΎΠΌΠ°Π½Π΄Ρ:\n"
"/adduser - ΠΠΎΠ±Π°Π²ΠΈΡΡ ΠΈΠ³ΡΠΎΠΊΠ° Lichess Π΄Π»Ρ ΠΎΡΡΠ»Π΅ΠΆΠΈΠ²Π°Π½ΠΈΡ\n"
"/getgamers - ΠΡΠ±ΡΠ°ΡΡ Π°ΠΊΡΠΈΠ²Π½ΠΎΠ³ΠΎ ΠΈΠ³ΡΠΎΠΊΠ° (Π΄Π»Ρ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ Π±ΡΠ΄ΡΡ ΡΠ°Π±ΠΎΡΠ°ΡΡ ΠΊΠΎΠΌΠ°Π½Π΄Ρ /today ΠΈ ΡΠ΄)\n"
+ "/delgamer - Π£Π΄Π°Π»ΠΈΡΡ ΠΈΠ³ΡΠΎΠΊΠ° ΠΈΠ· ΡΠΏΠΈΡΠΊΠ° ΠΎΡΡΠ»Π΅ΠΆΠΈΠ²Π°Π΅ΠΌΡΡ
\n"
"/today - Π‘ΡΠ°ΡΠΈΡΡΠΈΠΊΠ° Π·Π° ΡΠ΅Π³ΠΎΠ΄Π½Ρ\n"
"/yesterday - Π‘ΡΠ°ΡΠΈΡΡΠΈΠΊΠ° Π·Π° Π²ΡΠ΅ΡΠ°\n"
"/week - Π‘ΡΠ°ΡΠΈΡΡΠΈΠΊΠ° Π·Π° Π½Π΅Π΄Π΅Π»Ρ\n"
@@ -269,6 +270,100 @@ class LichessBot:
else:
await query.edit_message_text("β ΠΠ³ΡΠΎΠΊ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½")
+ async def delgamer(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
+ """Show gamers list for deletion"""
+ user_id = update.effective_user.id
+ gamers = self.db.get_user_gamers(user_id)
+
+ if not gamers:
+ await update.message.reply_text("π Π£ Π²Π°Ρ Π½Π΅Ρ ΠΎΡΡΠ»Π΅ΠΆΠΈΠ²Π°Π΅ΠΌΡΡ
ΠΈΠ³ΡΠΎΠΊΠΎΠ².")
+ return
+
+ # Show loading message
+ loading_msg = await update.message.reply_text("π ΠΠ°Π³ΡΡΠΆΠ°Π΅ΠΌ ΡΠΏΠΈΡΠΎΠΊ ΠΈΠ³ΡΠΎΠΊΠΎΠ²...")
+
+ # Create text message with stats
+ text_lines = []
+ keyboard = []
+
+ for gamer in gamers:
+ status = "π’" if gamer['is_active'] else "βͺ"
+ username = gamer['username']
+
+ # Get user ratings from Lichess API
+ ratings_data = await self.lichess_api.get_user_ratings(username)
+
+ if ratings_data and 'perfs' in ratings_data:
+ perfs = ratings_data['perfs']
+ bullet_rating = perfs.get('bullet', {}).get('rating', 'N/A')
+ blitz_rating = perfs.get('blitz', {}).get('rating', 'N/A')
+ rapid_rating = perfs.get('rapid', {}).get('rating', 'N/A')
+ else:
+ bullet_rating = blitz_rating = rapid_rating = 'N/A'
+
+ period_minutes = gamer.get('period_minutes', 0)
+ period_text = f" Β· {period_minutes}ΠΌ" if period_minutes > 0 else ""
+
+ text_lines.append(
+ f"{status} {username} "
+ f"β‘ {bullet_rating} π₯ {blitz_rating} π {rapid_rating}{period_text}"
+ )
+
+ # Add delete button
+ keyboard.append([InlineKeyboardButton(
+ text=f"ποΈ {username}",
+ callback_data=f"delete_{gamer['id']}"
+ )])
+
+ gamers_text = "ποΈ ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΈΠ³ΡΠΎΠΊΠ° Π΄Π»Ρ ΡΠ΄Π°Π»Π΅Π½ΠΈΡ:\n\n" + "\n".join(text_lines)
+
+ reply_markup = InlineKeyboardMarkup(keyboard)
+
+ # Edit the loading message with the results
+ try:
+ await loading_msg.edit_text(
+ gamers_text,
+ parse_mode='HTML',
+ reply_markup=reply_markup
+ )
+ except Exception as e:
+ logger.error(f"Error editing message: {e}")
+ try:
+ await loading_msg.delete()
+ except:
+ pass
+ await update.message.reply_text(
+ gamers_text,
+ parse_mode='HTML',
+ reply_markup=reply_markup
+ )
+
+ async def handle_delete_gamer(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
+ """Handle gamer deletion"""
+ query = update.callback_query
+ await query.answer()
+
+ user_id = query.from_user.id
+ gamer_id = int(query.data.split('_')[1])
+
+ # Get gamer info before deletion
+ gamers = self.db.get_user_gamers(user_id)
+ gamer_to_delete = next((g for g in gamers if g['id'] == gamer_id), None)
+
+ if gamer_to_delete:
+ username = gamer_to_delete['username']
+ deleted = self.db.remove_user_gamer(user_id, gamer_id)
+
+ if deleted:
+ await query.edit_message_text(
+ f"β
ΠΠ³ΡΠΎΠΊ {username} ΡΠ΄Π°Π»Π΅Π½ ΠΈΠ· ΡΠΏΠΈΡΠΊΠ° ΠΎΡΡΠ»Π΅ΠΆΠΈΠ²Π°Π΅ΠΌΡΡ
.",
+ parse_mode='HTML'
+ )
+ else:
+ await query.edit_message_text("β ΠΠ΅ ΡΠ΄Π°Π»ΠΎΡΡ ΡΠ΄Π°Π»ΠΈΡΡ ΠΈΠ³ΡΠΎΠΊΠ°")
+ else:
+ await query.edit_message_text("β ΠΠ³ΡΠΎΠΊ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½")
+
async def get_stats(self, update: Update, context: ContextTypes.DEFAULT_TYPE, period: str):
"""Get statistics for a period"""
user_id = update.effective_user.id
@@ -509,6 +604,7 @@ class LichessBot:
application.add_handler(CommandHandler("start", self.start))
application.add_handler(adduser_conv)
application.add_handler(CommandHandler("getgamers", self.getgamers))
+ application.add_handler(CommandHandler("delgamer", self.delgamer))
application.add_handler(CommandHandler("today", self.today))
application.add_handler(CommandHandler("yesterday", self.yesterday))
application.add_handler(CommandHandler("week", self.week))
@@ -516,6 +612,7 @@ class LichessBot:
# Callback handlers
application.add_handler(CallbackQueryHandler(self.select_gamer, pattern="^select_"))
+ application.add_handler(CallbackQueryHandler(self.handle_delete_gamer, pattern="^delete_"))
application.add_handler(CallbackQueryHandler(self.select_period, pattern="^period_"))
def main():
diff --git a/LichessClientTG_bot/database.py b/LichessClientTG_bot/database.py
index d279ad8..595a839 100644
--- a/LichessClientTG_bot/database.py
+++ b/LichessClientTG_bot/database.py
@@ -239,6 +239,32 @@ class Database:
)
conn.commit()
+ def remove_user_gamer(self, user_id: int, gamer_id: int) -> bool:
+ """Remove gamer from user's tracked list"""
+ with sqlite3.connect(self.db_path) as conn:
+ cursor = conn.cursor()
+
+ # Delete the user-gamer relationship
+ cursor.execute(
+ "DELETE FROM user_gamers WHERE user_id = ? AND gamer_id = ?",
+ (user_id, gamer_id)
+ )
+ deleted = cursor.rowcount > 0
+
+ # Check if this gamer is still tracked by any other user
+ cursor.execute(
+ "SELECT COUNT(*) FROM user_gamers WHERE gamer_id = ?",
+ (gamer_id,)
+ )
+ other_users_count = cursor.fetchone()[0]
+
+ # If no other users track this gamer, remove from gamers table
+ if other_users_count == 0:
+ cursor.execute("DELETE FROM gamers WHERE id = ?", (gamer_id,))
+
+ conn.commit()
+ return deleted
+
def get_user_gamers_with_periods(self, user_id: int) -> List[Dict[str, Any]]:
"""Get all gamers for a user that have periods set"""
with sqlite3.connect(self.db_path) as conn: