Addidng chat_listener function for Twitch, adding custom overlay template for testing.

This commit is contained in:
2025-11-17 14:46:50 +01:00
parent 98cda57d90
commit 4013d3d23d
6 changed files with 119 additions and 4 deletions

20
main.py
View File

@@ -8,11 +8,12 @@ from contextlib import asynccontextmanager
from sqlalchemy.orm import Session
import models
from database import engine
from database import engine, SessionLocal
import auth # Import the new auth module
import schemas
from starlette.responses import Response
from config import settings # Import settings to get the secret key
from listener_manager import ListenerManager
# --- Absolute Path Configuration ---
# Get the absolute path of the directory where this file is located
@@ -24,10 +25,25 @@ TEMPLATES_DIR = os.path.join(BASE_DIR, "templates")
async def lifespan(app: FastAPI):
# This code runs on startup
print("Application startup: Creating database tables...")
app.state.listener_manager = ListenerManager()
models.Base.metadata.create_all(bind=engine)
print("Application startup: Database tables created.")
# Start listeners for all existing users
db = SessionLocal()
users = db.query(models.User).all()
db.close()
for user in users:
await app.state.listener_manager.start_listener_for_user(user)
yield
# Code below yield runs on shutdown, if needed
# This code runs on shutdown
print("Application shutdown: Stopping all listeners...")
manager = app.state.listener_manager
# Create a copy of keys to avoid runtime errors from changing dict size
for user_id in list(manager.active_listeners.keys()):
await manager.stop_listener_for_user(user_id)
app = FastAPI(lifespan=lifespan)