Team Ai
Apppublic

Yash030/claude-code-proxy

sourceHugging Faceupdated 5mo agoView on Hugging Face
2likes
command_dispatcher.py39 linesDownload Raw Back to messaging
1"""Command parsing and dispatch for messaging handlers."""2 3from __future__ import annotations4 5from typing import Any6 7from .commands import handle_clear_command, handle_stats_command, handle_stop_command8from .models import IncomingMessage9 10 11def parse_command_base(text: str | None) -> str:12    """Return the slash command without bot mention suffix."""13    parts = (text or "").strip().split()14    cmd = parts[0] if parts else ""15    return cmd.split("@", 1)[0] if cmd else ""16 17 18def message_kind_for_command(command_base: str) -> str:19    """Return the persistence kind for an incoming message."""20    return "command" if command_base.startswith("/") else "content"21 22 23async def dispatch_command(24    handler: Any,25    incoming: IncomingMessage,26    command_base: str,27) -> bool:28    """Dispatch a known command and return whether it was handled."""29    commands = {30        "/clear": handle_clear_command,31        "/stop": handle_stop_command,32        "/stats": handle_stats_command,33    }34    command = commands.get(command_base)35    if command is None:36        return False37    await command(handler, incoming)38    return True39