fix by codex

This commit is contained in:
vrubelroman 2026-03-21 22:58:47 +03:00
parent 3ffcf97c3f
commit 63e28c279c
3 changed files with 67 additions and 21 deletions

View file

@ -64,6 +64,7 @@ class Database:
token TEXT,
is_active BOOLEAN DEFAULT FALSE,
period_minutes INTEGER DEFAULT 0,
last_period_end_ts INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES telegram_users(user_id),
FOREIGN KEY (gamer_id) REFERENCES gamers(id),
@ -77,6 +78,13 @@ class Database:
except sqlite3.OperationalError:
# Column already exists
pass
# Add last_period_end_ts column to persist periodic checkpoint across restarts
try:
cursor.execute("ALTER TABLE user_gamers ADD COLUMN last_period_end_ts INTEGER")
except sqlite3.OperationalError:
# Column already exists
pass
# Create admin_settings table for admin bot configuration
cursor.execute('''
@ -326,6 +334,39 @@ class Database:
(period_minutes, user_id, gamer_id)
)
conn.commit()
def get_period_checkpoint(self, user_id: int, gamer_id: int) -> Optional[int]:
"""Get persisted period checkpoint timestamp (seconds since epoch)."""
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute(
"SELECT last_period_end_ts FROM user_gamers WHERE user_id = ? AND gamer_id = ?",
(user_id, gamer_id)
)
row = cursor.fetchone()
if not row or row[0] is None:
return None
return int(row[0])
def set_period_checkpoint(self, user_id: int, gamer_id: int, checkpoint_ts: int):
"""Persist period checkpoint timestamp (seconds since epoch)."""
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute(
"UPDATE user_gamers SET last_period_end_ts = ? WHERE user_id = ? AND gamer_id = ?",
(checkpoint_ts, user_id, gamer_id)
)
conn.commit()
def clear_period_checkpoint(self, user_id: int, gamer_id: int):
"""Clear persisted period checkpoint."""
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute(
"UPDATE user_gamers SET last_period_end_ts = NULL WHERE user_id = ? AND gamer_id = ?",
(user_id, gamer_id)
)
conn.commit()
def remove_user_gamer(self, user_id: int, gamer_id: int) -> bool:
"""Remove gamer from user's tracked list"""