"""Response building utilities for the community bot.""" from typing import List, Dict, Any, Optional from mautrix.types import MessageEvent class ResponseBuilder: """Builder for consistent response formatting.""" @staticmethod def build_html_response(title: str, content: str, allow_html: bool = True) -> str: """Build an HTML formatted response. Args: title: Response title content: Response content allow_html: Whether to allow HTML formatting Returns: str: Formatted response """ if allow_html: return f"
{title}
{content}
Error: {error}
" else: return f"Error: {error}" @staticmethod def build_success_response(message: str, allow_html: bool = True) -> str: """Build a success response. Args: message: Success message allow_html: Whether to allow HTML formatting Returns: str: Formatted success response """ if allow_html: return f"Success: {message}
" else: return f"Success: {message}" @staticmethod def build_list_response( title: str, items: List[str], allow_html: bool = True ) -> str: """Build a list response. Args: title: List title items: List items allow_html: Whether to allow HTML formatting Returns: str: Formatted list response """ if not items: return ResponseBuilder.build_html_response( title, "No items found.", allow_html ) if allow_html: items_html = "{title}
{items_html}
Users inactive for between {warn_threshold} and {kick_threshold} days:
"
f"{warn_list}
Users inactive for at least {kick_threshold} days:
"
f"{kick_list}
Ignored users:
{ignored_list}
Users banned:{ban_list_html}
Errors:{error_list_html}
No users were banned.
") return "".join(response_parts) @staticmethod def build_sync_results_response(results: Dict[str, List[str]]) -> str: """Build a sync results response. Args: results: Sync results data Returns: str: Formatted sync results """ added = results.get("added", []) dropped = results.get("dropped", []) response_parts = [] if added: added_html = "Added:
{added_html}
Dropped:
{dropped_html}
No changes made.
") return "".join(response_parts) @staticmethod def build_doctor_report_response(report: Dict[str, Any]) -> str: """Build a doctor report response. Args: report: Doctor report data Returns: str: Formatted doctor report """ response_parts = [] # Space information if report.get("space"): space = report["space"] space_info = f"Space: {space.get('room_id', 'Unknown')}{space_info}
") # Room information if report.get("rooms"): rooms_info = "Rooms:{rooms_info}
") # Issues if report.get("issues"): issues_html = "Issues:
{issues_html}
Warnings:
{warnings_html}
No issues found.
") return "".join(response_parts)