refactor: provider-agnostic bot command system + Gitea commands
Refactored the monolithic command handler (707 lines) into a pluggable provider-handler architecture: - Abstract ProviderCommandHandler interface (base.py) - Handler dispatch registry routes commands by provider type - Extracted all Immich logic into ImmichCommandHandler - New GiteaCommandHandler with /status, /repos, /issues, /prs, /commits - Multi-provider routing: groups context by provider type, finds handler - handler.py reduced to ~280 line thin orchestrator Gitea commands: - Extended GiteaClient with get_repo_issues, get_repo_pulls, get_repo_commits - 30 Jinja2 command templates (15 EN + 15 RU) - Gitea capabilities updated with 6 commands + 15 command_slots - Default command config + command template config seeded on startup - Rate limiting: Gitea API commands share "api" category (15s cooldown) Also: - Command configs API accepts "gitea" provider type - System command configs (user_id=0) visible to all users - Webhook URL shown on Gitea provider card and edit form - Scan interval hidden for webhook-based providers
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Provider command handler registry and routing."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from .base import ProviderCommandHandler
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_REGISTRY: dict[str, ProviderCommandHandler] = {}
|
||||
|
||||
|
||||
def register_handler(handler: ProviderCommandHandler) -> None:
|
||||
"""Register a provider command handler."""
|
||||
_REGISTRY[handler.provider_type] = handler
|
||||
_LOGGER.debug("Registered command handler for provider type: %s", handler.provider_type)
|
||||
|
||||
|
||||
def get_handler(provider_type: str) -> ProviderCommandHandler | None:
|
||||
"""Get the command handler for a provider type."""
|
||||
return _REGISTRY.get(provider_type)
|
||||
|
||||
|
||||
def get_all_handlers() -> dict[str, ProviderCommandHandler]:
|
||||
"""Get all registered handlers."""
|
||||
return dict(_REGISTRY)
|
||||
|
||||
|
||||
def _auto_register() -> None:
|
||||
"""Auto-register all built-in handlers."""
|
||||
from .immich_handler import ImmichCommandHandler
|
||||
from .gitea_handler import GiteaCommandHandler
|
||||
|
||||
register_handler(ImmichCommandHandler())
|
||||
register_handler(GiteaCommandHandler())
|
||||
|
||||
|
||||
# Auto-register on import
|
||||
_auto_register()
|
||||
Reference in New Issue
Block a user