diff --git a/src/moai/bot/handlers/projects.py b/src/moai/bot/handlers/projects.py index 21ec17e..9294274 100644 --- a/src/moai/bot/handlers/projects.py +++ b/src/moai/bot/handlers/projects.py @@ -5,7 +5,13 @@ import re from telegram import Update from telegram.ext import ContextTypes -from moai.core.services.project import create_project, list_projects +from moai.core.models import Project +from moai.core.services.project import ( + create_project, + get_project, + get_project_by_name, + list_projects, +) async def projects_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: @@ -49,6 +55,10 @@ async def project_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> if subcommand == "new": await _handle_project_new(update, context, args[1:]) + elif subcommand == "select": + await _handle_project_select(update, context, args[1:]) + elif subcommand == "info": + await _handle_project_info(update, context) else: await update.message.reply_text( f"Unknown subcommand: {subcommand}\nAvailable: new, select, delete, models, info" @@ -84,3 +94,70 @@ async def _handle_project_new( f"Use /project select {project.id[:8]} to switch to this project.", parse_mode="Markdown", ) + + +async def _handle_project_select( + update: Update, context: ContextTypes.DEFAULT_TYPE, args: list[str] +) -> None: + """Handle /project select command.""" + if not args: + await update.message.reply_text("Usage: /project select ") + return + + identifier = " ".join(args) + + # Try to find by ID first (supports partial ID match) + project = await get_project(identifier) + + # If not found by ID, try by name + if project is None: + project = await get_project_by_name(identifier) + + if project is None: + await update.message.reply_text( + "Project not found. Use /projects to list available projects." + ) + return + + # Store selected project ID in user_data + context.user_data["selected_project_id"] = project.id + + await update.message.reply_text(f"Selected project: {project.name}") + + +async def _handle_project_info(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Handle /project info command.""" + project = await get_selected_project(context) + + if project is None: + await update.message.reply_text("No project selected. Use /project select first.") + return + + models_str = ", ".join(project.models) if project.models else "none" + # Note: discussion_count will be available when discussions are implemented + discussion_count = len(project.discussions) if project.discussions else 0 + + await update.message.reply_text( + f"*Project Info*\n\n" + f"Name: {project.name}\n" + f"ID: `{project.id}`\n" + f"Models: {models_str}\n" + f"Created: {project.created_at.strftime('%Y-%m-%d %H:%M')}\n" + f"Discussions: {discussion_count}", + parse_mode="Markdown", + ) + + +async def get_selected_project(context: ContextTypes.DEFAULT_TYPE) -> Project | None: + """Get the currently selected project from user_data. + + Args: + context: The telegram context with user_data. + + Returns: + The Project object if one is selected, None otherwise. + """ + project_id = context.user_data.get("selected_project_id") + if project_id is None: + return None + return await get_project(project_id)