fab6169cf9
- UI: command-template-configs now resolves slot variables against the active provider first (varsRef[provider_type][slot]) before falling back to shared entries, so provider-specific slots like /search, /status, /repos, /issues, /boards show the Variables button and autocomplete. - Backend: /search, /find, /person, /place now normalize raw Immich API responses through build_asset_dict, extracting city/country from exifInfo and mapping isFavorite -> is_favorite so templates render location and favorite indicators. - Telegram: extract build_telegram_asset_entry into a shared helper so the notification dispatcher and command media groups agree on video typing and /video/playback URLs; videos no longer render as still thumbnails in /latest /random /favorites media mode. - Commands: send_media_group now reuses the same Telegram file_id caches as the notification dispatcher, avoiding re-upload churn for repeated commands.
86 lines
3.5 KiB
Python
86 lines
3.5 KiB
Python
"""Search-related Immich bot commands: search, find, person, place."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ..handler import _render_cmd_template
|
|
from .common import _format_assets, build_asset_dict
|
|
|
|
|
|
def _enrich_assets(assets: list[dict[str, Any]], asset_public_urls: dict[str, str]) -> list[dict[str, Any]]:
|
|
"""Normalize raw Immich assets and attach public_url from the pre-built map."""
|
|
pub = asset_public_urls or {}
|
|
return [
|
|
build_asset_dict(asset, public_url=pub.get(asset.get("id", ""), ""))
|
|
for asset in assets
|
|
]
|
|
|
|
|
|
async def cmd_search(
|
|
client: Any, args: str, all_album_ids: list[str], count: int,
|
|
locale: str, response_mode: str,
|
|
cmd_templates: dict[str, dict[str, str]],
|
|
asset_public_urls: dict[str, str] | None = None,
|
|
page: int = 1,
|
|
) -> str | dict[str, Any]:
|
|
"""Handle /search command."""
|
|
if not args:
|
|
return _render_cmd_template(cmd_templates, "no_results", locale, {"command": "search", "query": ""})
|
|
assets = await client.search_smart(args, album_ids=all_album_ids, limit=count, page=page)
|
|
assets = _enrich_assets(assets, asset_public_urls or {})
|
|
return _format_assets(assets, "search", args, locale, response_mode, client, cmd_templates)
|
|
|
|
|
|
async def cmd_find(
|
|
client: Any, args: str, all_album_ids: list[str], count: int,
|
|
locale: str, response_mode: str,
|
|
cmd_templates: dict[str, dict[str, str]],
|
|
asset_public_urls: dict[str, str] | None = None,
|
|
page: int = 1,
|
|
) -> str | dict[str, Any]:
|
|
"""Handle /find command."""
|
|
if not args:
|
|
return _render_cmd_template(cmd_templates, "no_results", locale, {"command": "find", "query": ""})
|
|
assets = await client.search_metadata(args, album_ids=all_album_ids, limit=count, page=page)
|
|
assets = _enrich_assets(assets, asset_public_urls or {})
|
|
return _format_assets(assets, "find", args, locale, response_mode, client, cmd_templates)
|
|
|
|
|
|
async def cmd_person(
|
|
client: Any, args: str, count: int,
|
|
locale: str, response_mode: str,
|
|
cmd_templates: dict[str, dict[str, str]],
|
|
asset_public_urls: dict[str, str] | None = None,
|
|
) -> str | dict[str, Any]:
|
|
"""Handle /person command."""
|
|
if not args:
|
|
return _render_cmd_template(cmd_templates, "no_results", locale, {"command": "person", "query": ""})
|
|
people = await client.get_people()
|
|
person_id = None
|
|
for pid, pname in people.items():
|
|
if args.lower() in pname.lower():
|
|
person_id = pid
|
|
break
|
|
if not person_id:
|
|
return _render_cmd_template(cmd_templates, "no_results", locale, {"command": "person", "query": args})
|
|
assets = await client.search_by_person(person_id, limit=count)
|
|
assets = _enrich_assets(assets, asset_public_urls or {})
|
|
return _format_assets(assets, "person", args, locale, response_mode, client, cmd_templates)
|
|
|
|
|
|
async def cmd_place(
|
|
client: Any, args: str, all_album_ids: list[str], count: int,
|
|
locale: str, response_mode: str,
|
|
cmd_templates: dict[str, dict[str, str]],
|
|
asset_public_urls: dict[str, str] | None = None,
|
|
) -> str | dict[str, Any]:
|
|
"""Handle /place command."""
|
|
if not args:
|
|
return _render_cmd_template(cmd_templates, "no_results", locale, {"command": "place", "query": ""})
|
|
assets = await client.search_smart(
|
|
f"photos taken in {args}", album_ids=all_album_ids, limit=count
|
|
)
|
|
assets = _enrich_assets(assets, asset_public_urls or {})
|
|
return _format_assets(assets, "place", args, locale, response_mode, client, cmd_templates)
|