EN language only
This commit is contained in:
parent
3ec1fe614d
commit
3362bf89e2
4 changed files with 353 additions and 94 deletions
|
|
@ -22,10 +22,18 @@ class Database:
|
|||
username TEXT,
|
||||
first_name TEXT,
|
||||
last_name TEXT,
|
||||
language_code TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
|
||||
# Add language_code column if it doesn't exist
|
||||
try:
|
||||
cursor.execute("ALTER TABLE telegram_users ADD COLUMN language_code TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
# Column already exists
|
||||
pass
|
||||
|
||||
# Create gamers table (Lichess players only)
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS gamers (
|
||||
|
|
@ -104,7 +112,8 @@ class Database:
|
|||
logger.info(f"Migrated {migrated} tokens from gamers to user_gamers")
|
||||
|
||||
def add_or_get_telegram_user(self, user_id: int, username: Optional[str] = None,
|
||||
first_name: Optional[str] = None, last_name: Optional[str] = None) -> bool:
|
||||
first_name: Optional[str] = None, last_name: Optional[str] = None,
|
||||
language_code: Optional[str] = None) -> bool:
|
||||
"""Add or update Telegram user"""
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
cursor = conn.cursor()
|
||||
|
|
@ -114,13 +123,24 @@ class Database:
|
|||
|
||||
if not existing:
|
||||
cursor.execute(
|
||||
"INSERT INTO telegram_users (user_id, username, first_name, last_name) VALUES (?, ?, ?, ?)",
|
||||
(user_id, username, first_name, last_name)
|
||||
"INSERT INTO telegram_users (user_id, username, first_name, last_name, language_code) VALUES (?, ?, ?, ?, ?)",
|
||||
(user_id, username, first_name, last_name, language_code)
|
||||
)
|
||||
conn.commit()
|
||||
return True
|
||||
else:
|
||||
# Update language_code if provided (always update, even if None to clear old value)
|
||||
cursor.execute(
|
||||
"UPDATE telegram_users SET language_code = ? WHERE user_id = ?",
|
||||
(language_code, user_id)
|
||||
)
|
||||
conn.commit()
|
||||
return False
|
||||
|
||||
def get_user_language(self, user_id: int) -> str:
|
||||
"""Always return English language"""
|
||||
return 'en'
|
||||
|
||||
def add_gamer(self, username: str) -> int:
|
||||
"""Add a new gamer to the database (return gamer_id)"""
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue