Files
fckbot/bots/commands/registry.py
Markov Andrey 63900feece Update 86 files
- /rag/commands/expert.py
- /core/services/__init__.py
- /core/services/embedding_service.py
- /core/services/file_service.py
- /core/services/giga_client.py
- /core/services/kb_service.py
- /core/services/postgres_service.py
- /core/services/qdrant_service.py
- /core/services/reranker_service.py
- /core/functions/__init__.py
- /core/functions/check_consistency.py
- /core/functions/check_spelling.py
- /core/functions/critique_answer.py
- /core/functions/expand_query.py
- /core/functions/extract_metrics.py
- /core/functions/file_processor.py
- /core/functions/generate_document.py
- /core/functions/intent_classify.py
- /core/functions/rerank_context.py
- /core/functions/summarize_document.py
- /core/utils/__init__.py
- /core/utils/arg_parser.py
- /core/utils/config_loader.py
- /core/utils/layout_converter.py
- /core/utils/logger.py
- /core/utils/text_utils.py
- /core/utils/web_utils.py
- /bots/commands/__init__.py
- /bots/commands/base.py
- /bots/commands/create.py
- /core/commands/global_remove.py
- /core/commands/help.py
- /core/commands/info.py
- /core/commands/kb.py
- /core/commands/learn.py
- /core/commands/other.py
- /core/commands/registry.py
- /core/commands/stats.py
- /core/commands/template.py
- /core/handlers/__init__.py
- /core/handlers/message_handler.py
- /core/workers/__init__.py
- /core/workers/indexing_worker.py
- /core/xmpp/__init__.py
- /core/xmpp/client.py
- /bots/commands/global_remove.py
- /bots/commands/help.py
- /bots/commands/info.py
- /bots/commands/kb.py
- /bots/commands/registry.py
- /bots/commands/other.py
- /bots/commands/template.py
- /bots/commands/learn.py
- /bots/commands/stats.py
- /bots/handlers/message_handler.py
- /bots/handlers/__init__.py
- /bots/workers/__init__.py
- /bots/workers/indexing_worker.py
- /bots/xmpp/__init__.py
- /bots/xmpp/client.py
- /rag/services/qdrant_service.py
- /rag/services/giga_client.py
- /rag/services/embedding_service.py
- /rag/services/reranker_service.py
- /rag/services/__init__.py
- /rag/services/file_service.py
- /rag/services/postgres_service.py
- /rag/services/kb_service.py
- /rag/functions/check_spelling.py
- /rag/functions/__init__.py
- /rag/functions/extract_metrics.py
- /rag/functions/generate_document.py
- /rag/functions/expand_query.py
- /rag/functions/critique_answer.py
- /rag/functions/file_processor.py
- /rag/functions/check_consistency.py
- /rag/functions/summarize_document.py
- /rag/functions/rerank_context.py
- /rag/functions/intent_classify.py
- /rag/utils/__init__.py
- /rag/utils/layout_converter.py
- /rag/utils/text_utils.py
- /rag/utils/arg_parser.py
- /rag/utils/config_loader.py
- /rag/utils/logger.py
- /rag/utils/web_utils.py
2026-06-30 10:33:28 +00:00

63 lines
2.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""
Реестр команд связывает имя команды с объектом-обработчиком.
Поддерживает алиасы и подсказки при неизвестной команде.
"""
import difflib
from typing import Dict, List
# Импортируем все классы команд
from core.commands.info import InfoCommand
from core.commands.help import HelpCommand
from core.commands.learn import LearnCommand, StopLearnCommand, GlobalLearnCommand
from core.commands.kb import ClearCommand, GlobalClearCommand, KbCommand
from core.commands.stats import StatsCommand, StatusCommand, CleanCommand
from core.commands.expert import SummaryCommand, MetricsCommand
from core.commands.other import ResetCommand
from core.commands.global_remove import GlobalRemoveCommand
from core.commands.template import TemplateSaveCommand, TemplateListCommand, TemplateDeleteCommand
from core.commands.create import CreateCommand
def register_commands(bot) -> Dict[str, object]:
"""
Создаёт и возвращает словарь: имя_команды -> объект команды.
Включает основные имена и все алиасы.
"""
all_commands = [
InfoCommand(bot),
HelpCommand(bot),
LearnCommand(bot),
StopLearnCommand(bot),
GlobalLearnCommand(bot),
ClearCommand(bot),
GlobalClearCommand(bot),
KbCommand(bot),
StatsCommand(bot),
StatusCommand(bot),
CleanCommand(bot),
ResetCommand(bot),
SummaryCommand(bot),
MetricsCommand(bot),
GlobalRemoveCommand(bot),
TemplateSaveCommand(bot),
TemplateListCommand(bot),
TemplateDeleteCommand(bot),
CreateCommand(bot),
]
cmd_map = {}
for cmd in all_commands:
if cmd.name:
cmd_map[cmd.name.lower()] = cmd
for alias in cmd.aliases:
cmd_map[alias.lower()] = cmd
# Сохраняем список основных имён для подсказок (используется в message_handler)
bot._command_names = list(set(cmd.name for cmd in all_commands if cmd.name))
return cmd_map
def suggest_command(unknown_cmd: str, known_commands: List[str]) -> str:
"""Возвращает ближайшее известное имя команды (или None), используя difflib."""
matches = difflib.get_close_matches(unknown_cmd, known_commands, n=1, cutoff=0.6)
return matches[0] if matches else None