Prevent duplicate Twitch session prompts
This commit is contained in:
17
app/main.py
17
app/main.py
@@ -92,20 +92,7 @@ async def get_or_create_twitch_session(channel_name: str) -> str:
|
||||
if not orchestrator:
|
||||
raise RuntimeError("Orchestrator not initialized")
|
||||
|
||||
normalized_channel = channel_name.lower()
|
||||
matching_sessions = [
|
||||
(session_id, session)
|
||||
for session_id, session in orchestrator.active_sessions.items()
|
||||
if session.get("channel_name", "").lower() == normalized_channel
|
||||
]
|
||||
if matching_sessions:
|
||||
session_id, _ = max(
|
||||
matching_sessions,
|
||||
key=lambda item: item[1].get("started_at", datetime.min),
|
||||
)
|
||||
return session_id
|
||||
|
||||
return await orchestrator.start_session(channel_name)
|
||||
return await orchestrator.ensure_single_active_session_for_channel(channel_name)
|
||||
|
||||
|
||||
async def handle_twitch_chat_message(message: TwitchChatMessage) -> None:
|
||||
@@ -159,8 +146,8 @@ async def startup_event():
|
||||
loop_interval_seconds=settings.AGENT_LOOP_INTERVAL_SECONDS
|
||||
)
|
||||
await orchestrator.restore_active_sessions()
|
||||
agent_loop_task = asyncio.create_task(agent_loop())
|
||||
await start_twitch_chat()
|
||||
agent_loop_task = asyncio.create_task(agent_loop())
|
||||
logger.info("Application started successfully")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to start application: {e}")
|
||||
|
||||
Reference in New Issue
Block a user