feat(03-02): implement /project select and /project info handlers
Add project selection and info display: - /project select <id|name> stores selection in user_data - /project info displays selected project details - get_selected_project helper retrieves current project Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
70dd517e6a
commit
9922c333cb
1 changed files with 78 additions and 1 deletions
|
|
@ -5,7 +5,13 @@ import re
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
from telegram.ext import ContextTypes
|
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:
|
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":
|
if subcommand == "new":
|
||||||
await _handle_project_new(update, context, args[1:])
|
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:
|
else:
|
||||||
await update.message.reply_text(
|
await update.message.reply_text(
|
||||||
f"Unknown subcommand: {subcommand}\nAvailable: new, select, delete, models, info"
|
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.",
|
f"Use /project select {project.id[:8]} to switch to this project.",
|
||||||
parse_mode="Markdown",
|
parse_mode="Markdown",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def _handle_project_select(
|
||||||
|
update: Update, context: ContextTypes.DEFAULT_TYPE, args: list[str]
|
||||||
|
) -> None:
|
||||||
|
"""Handle /project select <id|name> command."""
|
||||||
|
if not args:
|
||||||
|
await update.message.reply_text("Usage: /project select <id|name>")
|
||||||
|
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 <name> 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)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue