admin panel
This commit is contained in:
parent
3362bf89e2
commit
23de80f94d
6 changed files with 424 additions and 20 deletions
|
|
@ -67,6 +67,15 @@ class Database:
|
|||
# Column already exists
|
||||
pass
|
||||
|
||||
# Create admin_settings table for admin bot configuration
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS admin_settings (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
|
||||
conn.commit()
|
||||
|
||||
# Migrate tokens from gamers to user_gamers if needed
|
||||
|
|
@ -329,3 +338,27 @@ class Database:
|
|||
})
|
||||
|
||||
return gamers
|
||||
|
||||
def get_admin_chat_id(self) -> Optional[int]:
|
||||
"""Get admin chat ID from database"""
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT value FROM admin_settings WHERE key = 'admin_chat_id'")
|
||||
result = cursor.fetchone()
|
||||
if result:
|
||||
try:
|
||||
return int(result[0])
|
||||
except (ValueError, TypeError):
|
||||
return None
|
||||
return None
|
||||
|
||||
def set_admin_chat_id(self, chat_id: int):
|
||||
"""Set admin chat ID in database"""
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
INSERT OR REPLACE INTO admin_settings (key, value, updated_at)
|
||||
VALUES ('admin_chat_id', ?, CURRENT_TIMESTAMP)
|
||||
''', (str(chat_id),))
|
||||
conn.commit()
|
||||
logger.info(f"Admin chat ID saved to database: {chat_id}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue