mirror of
https://github.com/marcogll/talia_bot.git
synced 2026-01-14 04:55:19 +00:00
refactor: Overhaul project structure and role management
This commit implements the first phase of the new architectural vision for the Talia Bot.
Key changes include:
- Renamed the main application directory from `app` to `talia_bot` and updated all associated imports and configurations (`Dockerfile`, tests).
- Replaced the static, `.env`-based permission system with a dynamic, database-driven role management system.
- Introduced a `db.py` module to manage a SQLite database (`users.db`) for user persistence.
- Updated `identity.py` to fetch roles ('admin', 'crew', 'client') from the database.
- Rewrote the `README.md` and `.env.example` to align with the new project specification.
- Refactored the LLM module into the new `modules` structure.
This commit is contained in:
48
talia_bot/db.py
Normal file
48
talia_bot/db.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# talia_bot/db.py
|
||||
# This module will handle the database connection and operations.
|
||||
|
||||
import sqlite3
|
||||
import logging
|
||||
|
||||
DATABASE_FILE = "talia_bot/data/users.db"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def get_db_connection():
|
||||
"""Creates a connection to the SQLite database."""
|
||||
conn = sqlite3.connect(DATABASE_FILE)
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
def setup_database():
|
||||
"""Sets up the database tables if they don't exist."""
|
||||
try:
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Create the users table
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
telegram_id INTEGER UNIQUE NOT NULL,
|
||||
role TEXT NOT NULL CHECK(role IN ('admin', 'crew', 'client')),
|
||||
name TEXT,
|
||||
employee_id TEXT,
|
||||
branch TEXT
|
||||
)
|
||||
""")
|
||||
|
||||
conn.commit()
|
||||
logger.info("Database setup complete. 'users' table is ready.")
|
||||
except sqlite3.Error as e:
|
||||
logger.error(f"Database error during setup: {e}")
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
# This allows us to run the script directly to initialize the database
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger.info("Running database setup manually...")
|
||||
setup_database()
|
||||
logger.info("Manual setup finished.")
|
||||
Reference in New Issue
Block a user