Добавлена команда /delgamer для удаления игроков
- Добавлен метод remove_user_gamer в database.py - Добавлена команда /delgamer с интерактивным списком игроков - Добавлен callback handler для удаления игроков - Если игрок удаляется у всех пользователей, он удаляется из gamers - Игроки показываются с рейтингами и статусом
This commit is contained in:
parent
539e0f3aa4
commit
e59bbb7d0e
2 changed files with 123 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue